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 "popup-common.h"
22 #define DEVICED_PATH_SYSNOTI "/Org/Tizen/System/DeviceD/SysNoti"
23 #define DEVICED_INTERFACE_SYSNOTI "org.tizen.system.deviced.SysNoti"
24 #define SIGNAL_CHARGEERR_RESPONSE "ChargeErrResponse"
26 static const struct popup_ops lowbattery_poweroff_ops;
27 static const struct popup_ops charge_error_low_ops;
28 static const struct popup_ops charge_error_high_ops;
29 static const struct popup_ops battery_disconnected_ops;
31 #define DEVICED_BUS_NAME "org.tizen.system.deviced"
32 #define REBOOT_OBJECT_PATH "/Org/Tizen/System/DeviceD/Reboot"
33 #define REBOOT_INTERFACE_NAME DEVICED_BUS_NAME".reboot"
35 #define REBOOT_METHOD "reboot"
36 #define REBOOT_OPERATION_OFF "poweroff"
38 static int lowbattery_launch(bundle *b, const struct popup_ops *ops);
40 static int remove_other_lowbattery_popups(const struct popup_ops *ops)
42 if (ops != &lowbattery_poweroff_ops)
43 unload_simple_popup(&lowbattery_poweroff_ops);
48 static int remove_other_charge_popups(bundle *b, const struct popup_ops *ops)
50 if (ops != &charge_error_low_ops)
51 unload_simple_popup(&charge_error_low_ops);
53 if (ops != &charge_error_high_ops)
54 unload_simple_popup(&charge_error_high_ops);
56 if (ops != &battery_disconnected_ops)
57 unload_simple_popup(&battery_disconnected_ops);
62 static void charger_status_changed(keynode_t *key, void *data)
65 const struct popup_ops *ops = data;
67 status = vconf_keynode_get_int(key);
68 if (status != VCONFKEY_SYSMAN_CHARGER_CONNECTED)
71 if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
72 charger_status_changed) < 0)
73 _E("Failed to release vconf key handler.");
75 unload_simple_popup(ops);
77 terminate_if_no_popup();
80 static void battery_status_changed(keynode_t *key, void *data)
83 const struct popup_ops *ops = data;
85 status = vconf_keynode_get_int(key);
86 if (status < VCONFKEY_SYSMAN_BAT_LEVEL_HIGH)
89 if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
90 battery_status_changed) < 0)
91 _E("Failed to release vconf key handler.");
93 unload_simple_popup(ops);
95 terminate_if_no_popup();
98 static void unregister_charger_status_handler(void)
100 vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
101 charger_status_changed);
104 static void unregister_battery_status_handler(void)
106 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
107 battery_status_changed);
110 static void register_charger_status_handler(const struct popup_ops *ops)
112 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
113 charger_status_changed, (void *)ops) < 0)
114 _E("Failed to register vconf key handler.");
117 static void register_battery_status_handler(const struct popup_ops *ops)
119 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
120 battery_status_changed, (void *)ops) < 0)
121 _E("Failed to register vconf key handler.");
124 static int lowbattery_launch(bundle *b, const struct popup_ops *ops)
126 unregister_charger_status_handler();
127 unregister_battery_status_handler();
128 remove_other_lowbattery_popups(ops);
129 register_charger_status_handler(ops);
130 register_battery_status_handler(ops);
135 static void lowbattery_terminate(const struct popup_ops *ops)
137 unregister_charger_status_handler();
138 unregister_battery_status_handler();
141 static void poweroff_clicked(const struct popup_ops *ops)
143 static int bPowerOff = 0;
152 unload_simple_popup(ops);
154 param[0] = REBOOT_OPERATION_OFF;
155 snprintf(data, sizeof(data), "0");
157 ret = popup_dbus_method_sync(DEVICED_BUS_NAME,
159 REBOOT_INTERFACE_NAME,
163 _E("Failed to request poweroff to deviced: %d", ret);
166 static void charge_error_ok_clicked(const struct popup_ops *ops)
168 _I("OK is selected.");
169 unload_simple_popup(ops);
171 if (broadcast_dbus_signal(DEVICED_PATH_SYSNOTI,
172 DEVICED_INTERFACE_SYSNOTI,
173 SIGNAL_CHARGEERR_RESPONSE,
175 _E("Failed to send signal.");
177 terminate_if_no_popup();
180 static int remove_battery_popups(bundle *b, const struct popup_ops *ops)
182 _I("Remove battery related popups.");
183 unload_simple_popup(&lowbattery_poweroff_ops);
184 unload_simple_popup(&charge_error_low_ops);
185 unload_simple_popup(&charge_error_high_ops);
186 unload_simple_popup(&battery_disconnected_ops);
187 terminate_if_no_popup();
191 static const struct popup_ops lowbattery_poweroff_ops = {
192 .name = "lowbattery_poweroff",
193 .pattern = FEEDBACK_PATTERN_LOWBATT,
194 .show = load_simple_popup,
195 .content = "IDS_COM_POP_LOW_BATTERY_PHONE_WILL_SHUT_DOWN",
196 .left_text = "IDS_COM_SK_OK",
197 .left = poweroff_clicked,
198 .pre = lowbattery_launch,
199 .terminate = lowbattery_terminate,
202 static const struct popup_ops battery_remove_ops = {
203 .name = "remove_battery_popups",
204 .show = remove_battery_popups,
207 static const struct popup_ops charge_error_low_ops = {
208 .name = "chargeerrlow",//"charge_error_low",
209 .pattern = FEEDBACK_PATTERN_LOWBATT,
210 .show = load_simple_popup,
211 .content = "IDS_QP_BODY_CHARGING_PAUSED_BATTERY_TEMPERATURE_TOO_LOW",
212 .left_text = "IDS_COM_SK_OK",
213 .left = charge_error_ok_clicked,
214 .pre = remove_other_charge_popups,
217 static const struct popup_ops charge_error_high_ops = {
218 .name = "chargeerrhigh",//"charge_error_high",
219 .pattern = FEEDBACK_PATTERN_LOWBATT,
220 .show = load_simple_popup,
221 .content = "IDS_QP_BODY_CHARGING_PAUSED_BATTERY_TEMPERATURE_TOO_HIGH",
222 .left_text = "IDS_COM_SK_OK",
223 .left = charge_error_ok_clicked,
224 .pre = remove_other_charge_popups,
227 static const struct popup_ops battery_disconnected_ops = {
228 .name = "battdisconnect",//"battery_disconnected",
229 .pattern = FEEDBACK_PATTERN_LOWBATT,
230 .show = load_simple_popup,
231 .content = "IDS_COM_POP_BATTERY_DISCONNECTED_ABB",
232 .left_text = "IDS_COM_SK_OK",
235 /* Constructor to register lowbattery button */
236 static __attribute__ ((constructor)) void battery_register_popup(void)
238 register_popup(&lowbattery_poweroff_ops);
239 register_popup(&battery_remove_ops);
240 register_popup(&charge_error_low_ops);
241 register_popup(&charge_error_high_ops);
242 register_popup(&battery_disconnected_ops);