4 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <app_manager.h>
21 #include "popup-common.h"
23 #define APP_PID "_APP_PID_"
24 #define APP_COMM "_APP_COMM_"
25 #define REQ_ID "_REQUEST_ID_"
27 #define DBUS_POWER_BUS "org.tizen.system.deviced"
28 #define DBUS_POWER_PATH "/Org/Tizen/System/DeviceD/Display"
29 #define DBUS_POWER_IFACE "org.tizen.system.deviced.display"
30 #define METHOD_LOCK_TIMEOUT_INPUT "LockTimeoutInput"
32 static const struct popup_ops power_lock_expired_ops;
33 static bool result_sended;
34 static char *request_id;
36 enum button_selected {
42 static void send_result(int result)
53 param[0] = request_id;
54 snprintf(buf, sizeof(buf), "%d", result);
56 ret = popup_dbus_method_sync(
60 METHOD_LOCK_TIMEOUT_INPUT,
63 _E("Failed to deliver the result (%d)", ret);
66 static int power_lock_expired_get_content(const struct popup_ops *ops, char *content, unsigned int len)
68 char *text, *pid_str, *name;
69 struct object_ops *obj;
76 ret = get_object_by_ops(ops, &obj);
78 _E("Failed to get object (%d)", ret);
82 pid_str = (char *)bundle_get_val(obj->b, APP_PID);
84 _E("Failed to get app pid");
88 request_id = (char *)bundle_get_val(obj->b, REQ_ID);
90 _E("Failed to get request id");
95 ret = app_manager_get_app_id(pid, &name);
96 if (ret != APP_MANAGER_ERROR_NONE) {
97 name = (char *)bundle_get_val(obj->b, APP_COMM);
99 _E("Failed to get app command");
104 text = _("\"%s\" is using too much battery power. Close \"%s\" ?");
106 snprintf(content, len, text, name, name);
112 static void power_lock_expired_allow_app(const struct popup_ops *ops)
114 _I("Allow is selected");
116 unload_simple_popup(ops);
118 send_result(ALLOW_APP);
120 terminate_if_no_popup();
123 static void power_lock_expired_close_app(const struct popup_ops *ops)
125 _I("Close is selected");
127 unload_simple_popup(ops);
129 send_result(CLOSE_APP);
131 terminate_if_no_popup();
134 static void power_lock_expired_terminate(const struct popup_ops *ops)
136 send_result(CLOSE_APP);
137 result_sended = false;
140 static const struct popup_ops power_lock_expired_ops = {
141 .name = "power_lock_expired",
142 .pattern = FEEDBACK_PATTERN_LOWBATT,
143 .show = load_simple_popup,
144 .get_content = power_lock_expired_get_content,
145 .left_text = "IDS_COM_SK_CANCEL",
146 .left = power_lock_expired_allow_app,
147 .right_text = "IDS_COM_SK_OK",
148 .right = power_lock_expired_close_app,
149 .terminate = power_lock_expired_terminate,
152 /* Constructor to register Power popup */
153 static __attribute__ ((constructor)) void power_register_popup(void)
155 register_popup(&power_lock_expired_ops);