4 * Copyright (c) 2012 - 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.
22 #include <libsyscommon/libgdbus.h>
23 #include <libsyscommon/resource-manager.h>
24 #include <system/syscommon-plugin-deviced-common-interface.h>
25 #include <system/syscommon-plugin-deviced-display-interface.h>
27 #include <libsyscommon/log.h>
29 #include "battery-parser.h"
30 #include "power-supply.h"
31 #include "lowbat-handler.h"
32 #include "battery-ops.h"
34 #include "display-lock.h"
35 #include "display-ops.h"
36 #include "display-state-transition.h"
38 #include "shared/eventsystem.h"
39 #include "shared/plugin.h"
40 #include "shared/device-notifier.h"
41 #include "shared/apps.h"
43 #define REMOVE_POPUP "remove_battery_popups"
45 static struct display_plugin *disp_plgn;
46 static struct battery_status *battery;
47 static guint abnormal_timer;
49 static int check_power_supply_noti(void)
54 static void health_timer_reset(void)
59 static gboolean health_timer_cb(void *data)
63 if (battery->health != HEALTH_LOW && battery->health != HEALTH_HIGH)
64 return G_SOURCE_REMOVE;
66 CRITICAL_LOG("Popup: Battery health status is not good, %s.", battery->health_s);
67 syscommon_notifier_emit_notify(DEVICED_NOTIFIER_BATTERY_HEALTH, (void *)&battery->health);
68 battery_pm_change_internal(DEVICED_EVENT_MISC_POPUP, LCD_DIM);
69 display_lock_request_unlock_with_option(DEVICED_EVENT_MISC_POPUP, LCD_OFF, PM_SLEEP_MARGIN);
70 display_lock_request_lock_with_option(DEVICED_EVENT_MISC_POPUP, LCD_DIM, STAY_CUR_STATE, 0);
71 if (battery->health == HEALTH_LOW)
72 battery_charge_err_low_act(NULL);
73 else if (battery->health == HEALTH_HIGH)
74 battery_charge_err_high_act(NULL);
75 return G_SOURCE_REMOVE;
78 static void abnormal_popup_dbus_signal_handler(GDBusConnection *conn,
87 if (battery->health == HEALTH_GOOD)
90 _I("Restart health timer.");
91 abnormal_timer = g_timeout_add_seconds(ABNORMAL_CHECK_TIMER_INTERVAL,
92 health_timer_cb, NULL);
93 if (abnormal_timer == 0)
94 _E("Failed to add abnormal check timer.");
97 static void battery_notification_init(void *data)
99 struct battery_plugin *plugin = (struct battery_plugin *)data;
105 _D("Add plugins for battery notification.");
106 plugin->check_power_supply_noti = check_power_supply_noti;
108 ret = gdbus_signal_subscribe(NULL, DEVICED_PATH_SYSNOTI,
109 DEVICED_INTERFACE_SYSNOTI, SIGNAL_CHARGEERR_RESPONSE, abnormal_popup_dbus_signal_handler, NULL, NULL);
111 _E("Failed to init dbus signal: %d", ret);
114 static const struct battery_ops battery_notification_ops = {
115 .name = "battery_notification",
116 .init = battery_notification_init,
119 BATTERY_OPS_REGISTER(&battery_notification_ops)
121 static void __CONSTRUCTOR__ initialize(void)
123 disp_plgn = get_var_display_plugin();
125 _E("Failed to get display plugin variable.");
127 battery = get_var_battery_status();
129 _E("Failed to get battery status structure.");