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_"
25 #define DBUS_POWER_PATH "/Org/Tizen/System/DeviceD/Power"
26 #define DBUS_POWER_IFACE "org.tizen.system.deviced.power"
27 #define METHOD_POWER_LOCK_EXPIRED "PowerLockExpired"
29 static const struct popup_ops power_lock_expired_ops;
30 static bool signal_broadcasted;
32 enum button_selected {
37 static void send_result_dbus_signal(int result)
43 if (signal_broadcasted)
46 signal_broadcasted = true;
48 snprintf(buf, sizeof(buf), "%d", result);
50 ret = broadcast_dbus_signal(DBUS_POWER_PATH,
52 METHOD_POWER_LOCK_EXPIRED,
55 _E("FAIL: broadcast_dbus_signal(%d)", ret);
58 static int power_lock_expired_get_content(const struct popup_ops *ops, char *content, unsigned int len)
60 char *text, *pid_str, *name;
61 struct object_ops *obj;
68 ret = get_object_by_ops(ops, &obj);
70 _E("Failed to get object (%d)", ret);
74 pid_str = (char *)bundle_get_val(obj->b, APP_PID);
76 _E("Failed to get app pid");
81 ret = app_manager_get_app_id(pid, &name);
82 if (ret != APP_MANAGER_ERROR_NONE) {
83 _E("Failed to get app name(%d)", ret);
87 text = _("\"%s\" is using too much battery power. Close \"%s\" ?");
89 snprintf(content, len, text, name, name);
95 static void power_lock_expired_allow_app(const struct popup_ops *ops)
97 _I("Allow is selected");
99 unload_simple_popup(ops);
101 send_result_dbus_signal(ALLOW_APP);
103 terminate_if_no_popup();
106 static void power_lock_expired_close_app(const struct popup_ops *ops)
108 _I("Close is selected");
110 unload_simple_popup(ops);
112 send_result_dbus_signal(CLOSE_APP);
114 terminate_if_no_popup();
117 static void power_lock_expired_terminate(const struct popup_ops *ops)
119 send_result_dbus_signal(CLOSE_APP);
120 signal_broadcasted = false;
123 static const struct popup_ops power_lock_expired_ops = {
124 .name = "power_lock_expired",
125 .show = load_simple_popup,
126 .get_content = power_lock_expired_get_content,
127 .left_text = "IDS_COM_SK_CANCEL",
128 .left = power_lock_expired_allow_app,
129 .right_text = "IDS_COM_SK_OK",
130 .right = power_lock_expired_close_app,
131 .terminate = power_lock_expired_terminate,
134 /* Constructor to register Power popup */
135 static __attribute__ ((constructor)) void power_register_popup(void)
137 register_popup(&power_lock_expired_ops);