4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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.
24 enum apps_enable_type{
29 #define SIGNAL_CHARGE_NOW "ChargeNow"
30 #define SIGNAL_CHARGER_STATUS "ChargerStatus"
31 #define SIGNAL_TEMP_GOOD "TempGood"
33 #define METHOD_LOWBAT_POPUP_DISABLE "LowBatteryDisable"
34 #define METHOD_LOWBAT_POPUP_ENABLE "LowBatteryEnable"
36 static E_DBus_Signal_Handler *edbus_charge_now_handler;
37 static E_DBus_Signal_Handler *edbus_charger_status_handler;
38 static E_DBus_Signal_Handler *edbus_temp_good_handler;
39 static E_DBus_Connection *edbus_conn;
41 static struct power_supply_type {
50 } power_supply_types [] = {
51 {"norm", S_ENTER, "100","Charging", "Good", "2", "1", "CHARGE"},
52 {"norm", S_ENTER, "100","Discharging", "Good", "1", "1", "DISCHARGE"},
53 {"norm", S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
55 {"heat1",S_ENTER, "100","Discharging", "Overheat", "1", "1", NULL},
56 {"heat1",S_ENTER, "100","Not charging","Overheat", "2", "1", "HEALTH(H) BEFORE CHARGE"},
57 {"heat1",S_LEAVE, "100","Discharging", "Overheat", "1", "1", "DISCHARGE"},
58 {"heat1",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
60 {"heat2",S_ENTER, "100","Charging", "Good", "2", "1", NULL},
61 {"heat2",S_ENTER, "100","Not charging","Overheat", "2", "1", "HEALTH(H) AFTER CHARGE"},
62 {"heat2",S_LEAVE, "100","Discharging", "Overheat", "1", "1", "DISCHARGE"},
63 {"heat2",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
65 {"cold1",S_ENTER, "100","Discharging", "Cold", "1", "1", NULL},
66 {"cold1",S_ENTER, "100","Not charging","Cold", "2", "1", "HEALTH(L) BEFORE CHARGE"},
67 {"cold1",S_LEAVE, "100","Discharging", "Cold", "1", "1", "DISCHARGE"},
68 {"cold1",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
70 {"cold2",S_ENTER, "100","Charging", "Good", "2", "1", NULL},
71 {"cold2",S_ENTER, "100","Not charging","Cold", "2", "1", "HEALTH(L) AFTER CHARGE"},
72 {"cold2",S_LEAVE, "100","Discharging", "Cold", "1", "1", "DISCHARGE"},
73 {"cold2",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
75 {"ovp", S_ENTER, "100","Discharging", "Over voltage", "1", "1", "OVP"},
76 {"ovp", S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
78 {"pres1",S_ENTER, "100","Discharging", "Good", "1", "0", NULL},
79 {"pres1",S_ENTER, "100","Not charging","Good", "2", "0", "PRESENT BEFORE CHARGE"},
80 {"pres1",S_LEAVE, "100","Discharging", "Good", "1", "0", "DISCHARGE"},
81 {"pres1",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
83 {"pres2",S_ENTER, "100","Charging", "Good", "2", "1", NULL},
84 {"pres2",S_ENTER, "100","Not charging","Good", "2", "0", "PRESENT AFTER CHARGE"},
85 {"pres2",S_LEAVE, "100","Discharging", "Good", "1", "0", "DISCHARGE"},
86 {"pres2",S_LEAVE, "100","Discharging", "Good", "1", "1", NULL}, //init
88 {"bat15",S_ENTER, "15", "Discharging", "Good", "1", "1", "LOWBAT 15%"}, //lowbat 15%
89 {"bat15",S_LEAVE, "15", "Charging", "Good", "2", "1", "LOWBAT 15%"},
90 {"bat5", S_ENTER, "5", "Discharging", "Good", "1", "1", "LOWBAT 5%"}, //lowbat 5%
91 {"bat5", S_LEAVE, "5", "Charging", "Good", "2", "1", "LOWBAT 5%"},
92 {"bat3", S_ENTER, "3", "Discharging", "Good", "1", "1", "LOWBAT 3%"}, //lowbat 3%
93 {"bat3", S_LEAVE, "3", "Charging", "Good", "2", "1", "LOWBAT 3%"},
94 {"bat1", S_ENTER, "1", "Discharging", "Good", "1", "1", "LOWBAT 1%"}, //lowbat 1%
95 {"bat1", S_LEAVE, "1", "Charging", "Good", "2", "1", "LOWBAT 1%"},
97 {"ta", S_ENTER, "100","Charging", "Good", "2", "1", "CHARGE"}, //charging
98 {"ta", S_LEAVE, "100","Discharging", "Good", "1", "1", "DISCHARGE"},//discharging
100 {"full", S_ENTER, "100","Full", "Good", "2", "1", "CHARGE"}, //full
101 {"full", S_LEAVE, "100","Discharging", "Good", "1", "1", "DISCHARGE"},//discharging
103 {"capa", S_ENTER, "100","Discharging", "Good", "1", "1", "CAPACITY"},//discharging
104 {"capa", S_LEAVE, "100","Charging", "Good", "2", "1", "CAPACITY"},//charging
107 static void unregister_edbus_signal_handler(void)
109 e_dbus_signal_handler_del(edbus_conn, edbus_charge_now_handler);
110 e_dbus_signal_handler_del(edbus_conn, edbus_charger_status_handler);
111 e_dbus_signal_handler_del(edbus_conn, edbus_temp_good_handler);
112 e_dbus_connection_close(edbus_conn);
116 static void power_supply_changed(void *data, DBusMessage *msg)
122 _I("edbus signal Received");
124 r = dbus_message_is_signal(msg, DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGE_NOW);
126 _E("dbus_message_is_signal error");
130 _I("%s - %s", DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGE_NOW);
132 dbus_error_init(&err);
133 r = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
135 _E("dbus_message_get_args error");
138 _I("receive data : %d", val);
141 static int register_charge_now_handler(void)
147 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
150 goto edbus_handler_out;
153 edbus_charge_now_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_BATTERY,
154 DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGE_NOW, power_supply_changed, NULL);
155 if (!(edbus_charge_now_handler)) {
157 goto edbus_handler_connection_out;
161 edbus_handler_connection_out:
162 e_dbus_connection_close(edbus_conn);
168 static void charger_status_changed(void *data, DBusMessage *msg)
174 _I("edbus signal Received");
176 r = dbus_message_is_signal(msg, DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGER_STATUS);
178 _E("dbus_message_is_signal error");
182 _I("%s - %s", DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGER_STATUS);
184 dbus_error_init(&err);
185 r = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
187 _E("dbus_message_get_args error");
190 _I("receive data : %d", val);
193 static int register_charger_status_handler(void)
199 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
202 goto edbus_handler_out;
205 edbus_charger_status_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_BATTERY,
206 DEVICED_INTERFACE_BATTERY, SIGNAL_CHARGER_STATUS, charger_status_changed, NULL);
207 if (!(edbus_charger_status_handler)) {
209 goto edbus_handler_connection_out;
213 edbus_handler_connection_out:
214 e_dbus_connection_close(edbus_conn);
220 static void temp_status_changed(void *data, DBusMessage *msg)
226 _I("edbus signal Received");
228 r = dbus_message_is_signal(msg, DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD);
230 _E("dbus_message_is_signal error");
234 _I("%s - %s", DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD);
237 static int register_temp_good_handler(void)
243 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
246 goto edbus_handler_out;
249 edbus_temp_good_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_BATTERY,
250 DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD, temp_status_changed, NULL);
251 if (!(edbus_temp_good_handler)) {
253 goto edbus_handler_connection_out;
257 edbus_handler_connection_out:
258 e_dbus_connection_close(edbus_conn);
263 static void power_supply_signal(void)
266 register_charge_now_handler();
267 register_charger_status_handler();
268 register_temp_good_handler();
269 ecore_main_loop_begin();
272 static int power_supply(int index)
279 param[0] = POWER_SUBSYSTEM;
281 param[2] = power_supply_types[index].capacity;
282 param[3] = power_supply_types[index].charge_status;
283 param[4] = power_supply_types[index].health;
284 param[5] = power_supply_types[index].online;
285 param[6] = power_supply_types[index].present;
287 msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
288 DEVICED_PATH_SYSNOTI,
289 DEVICED_INTERFACE_SYSNOTI,
290 POWER_SUBSYSTEM, "sisssss", param);
292 _E("fail : %s %s %s %s",
293 DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
298 dbus_error_init(&err);
300 ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
302 _E("no message : [%s:%s]", err.name, err.message);
303 dbus_error_free(&err);
307 if (power_supply_types[index].name != NULL)
308 _I("++++++++++[START] %s ++++++++++", power_supply_types[index].name);
309 _I("C(%s , %s) P(%s) STATUS(%s) HEALTH(%s)",
310 power_supply_types[index].capacity,
311 power_supply_types[index].online,
312 power_supply_types[index].present,
313 power_supply_types[index].charge_status,
314 power_supply_types[index].health);
315 if (power_supply_types[index].name != NULL)
316 _I("++++++++++[END] %s ++++++++++", power_supply_types[index].name);
318 _R("[NG] ---- %s", __func__);
320 _R("[OK] ---- %s : C(%s , %s) P(%s) S(%s) H(%s)",
322 power_supply_types[index].capacity,
323 power_supply_types[index].online,
324 power_supply_types[index].present,
325 power_supply_types[index].charge_status,
326 power_supply_types[index].health);
327 dbus_message_unref(msg);
328 dbus_error_free(&err);
329 sleep(TEST_WAIT_TIME_INTERVAL);
333 static void scenario(char *scenario)
337 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
338 if (strcmp(scenario, power_supply_types[index].scenario) != 0)
344 static void unit(char *unit, int status)
348 char *scenario = NULL;
350 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
351 scenario = power_supply_types[index].scenario;
352 if (strcmp(unit, scenario) != 0 ||
353 power_supply_types[index].status != status)
362 index = strlen(unit);
363 if (index < 0 || index > 3)
366 index = strtol(unit, NULL, 10);
367 if (index < 0 || index > 100)
370 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
371 if (strcmp("capa", power_supply_types[index].scenario) != 0 ||
372 power_supply_types[index].status != status)
374 power_supply_types[index].capacity = unit;
375 _D("%s", power_supply_types[index].capacity);
380 static void full(char *unit, char *capacity, int status)
383 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
384 if (strcmp(unit, power_supply_types[index].scenario) != 0 ||
385 power_supply_types[index].status != status)
387 power_supply_types[index].capacity = capacity;
388 _D("%s", power_supply_types[index].capacity);
393 static void lowbat_popup(char *status)
403 if (val != APPS_ENABLE && val != APPS_DISABLE)
406 if (val == APPS_ENABLE)
407 method = METHOD_LOWBAT_POPUP_ENABLE;
409 method = METHOD_LOWBAT_POPUP_DISABLE;
410 msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
412 DEVICED_INTERFACE_APPS,
416 _E("fail : %s %s %s %s",
417 DEVICED_BUS_NAME, DEVICED_PATH_APPS, DEVICED_INTERFACE_APPS, method);
421 dbus_error_init(&err);
423 ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
425 _E("no message : [%s:%s]", err.name, err.message);
426 dbus_error_free(&err);
431 _R("[NG] ---- %s : V(%s %d)", __func__, method, val);
433 _R("[OK] ---- %s : V(%s %d)", __func__, method, val);
434 dbus_message_unref(msg);
435 dbus_error_free(&err);
436 sleep(TEST_WAIT_TIME_INTERVAL);
440 static void power_supply_init(void *data)
445 for (index = 0; index < ARRAY_SIZE(power_supply_types); index++)
449 static void power_supply_exit(void *data)
454 static int power_supply_unit(int argc, char **argv)
460 if (strcmp("wait", argv[2]) == 0)
461 power_supply_signal();
462 else if (strcmp("popup", argv[2]) == 0)
463 lowbat_popup(argv[3]);
464 else if (strcmp("scenario", argv[2]) == 0)
466 else if (strcmp("enter", argv[3]) == 0)
467 unit(argv[2], S_ENTER);
468 else if (strcmp("leave", argv[3]) == 0)
469 unit(argv[2], S_LEAVE);
470 else if (strcmp("enter", argv[4]) == 0)
471 full(argv[2], argv[3], S_ENTER);
472 else if (strcmp("leave", argv[4]) == 0)
473 full(argv[2], argv[3], S_LEAVE);
477 static const struct test_ops power_test_ops = {
478 .priority = TEST_PRIORITY_NORMAL,
480 .init = power_supply_init,
481 .exit = power_supply_exit,
482 .unit = power_supply_unit,
485 TEST_OPS_REGISTER(&power_test_ops)