static bool battery_dev_available = false;
static int load_uevent(struct parse_result *result, void *user_data);
static int event_handler_state_changed(void *data);
+static void power_supply_exit(void *data);
inline struct battery_status *get_var_battery_status(void)
{
return 1;
}
-static void battery_invalidate_vconf(int value)
+static void battery_disable_module(int value)
{
int retval;
static const struct invalidate_list {
if (list[i].member)
*(list[i].member) = value;
}
+
+ power_supply_exit(NULL);
}
static void battery_changed(struct battery_info *info, void *data)
if (battery.present) {
process_power_supply(&battery.capacity);
} else {
- _D("Battery disconnected");
- battery_invalidate_vconf(-ENODEV);
+ CRITICAL_LOG_E("Battery disconnected. Disable the battery module.");
+ battery_disable_module(-ENODEV);
}
}
-static void power_supply_status_init(void)
+static gboolean power_supply_update_during_booting(void *data)
{
- int r;
+ int retval;
- r = hal_device_battery_get_current_state(battery_changed, NULL);
- if (battery_dev_available && (r != -ENODEV)) {
- if (r < 0 || battery.capacity < 0) {
- _E("Failed to get battery capacity (capa: %d, ret: %d)", battery.capacity, r);
- return;
- }
- } else {
- r = config_parse(POWER_SUPPLY_UEVENT, load_uevent, &battery);
- if (r < 0) {
- _E("Failed to load %s, %d Use default value.", POWER_SUPPLY_UEVENT, r);
- return;
- }
- battery.health = HEALTH_GOOD;
- battery.present = PRESENT_NORMAL;
- process_power_supply(&battery.capacity);
+ if (!battery_dev_available)
+ return G_SOURCE_REMOVE;
+
+ retval = hal_device_battery_get_current_state(battery_changed, NULL);
+ if (retval == -ENODEV) {
+ CRITICAL_LOG_E("There is no battery detected. Disable the battery module.");
+ battery_disable_module(retval);
+ return G_SOURCE_REMOVE;
}
-}
-static gboolean power_supply_update(void *data)
-{
- power_supply_status_init();
return G_SOURCE_CONTINUE;
}
{
_D("Battery init timer during booting.");
power_timer = g_timeout_add(BATTERY_CHECK_TIMER_INTERVAL,
- power_supply_update, NULL);
+ power_supply_update_during_booting, NULL);
if (power_timer == 0)
_E("Failed to add battery init timer during booting.");
else
_I("Started battery init timer during booting.");
}
-static void power_supply_timer_stop(void)
-{
- int retval;
-
- if (power_timer == 0)
- return;
- _I("Stop battery init timer during booting.");
- g_source_remove(power_timer);
- power_timer = 0;
-
- /* check battery has been initialized until booting done */
- retval = hal_device_battery_get_current_state(battery_changed, NULL);
- if (retval < 0) {
- _E("Failed to initialize battery state");
- battery_invalidate_vconf(retval);
- }
-}
-
static GVariant *dbus_get_charger_status(GDBusConnection *conn,
const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
static int delayed_init_done(void *data)
{
static int done;
+ int retval;
device_notifier_state_e state = DEVICE_NOTIFIER_STATE_START;
if (data == NULL)
if (done == 0)
return done;
- power_supply_timer_stop();
+ if (power_timer) {
+ g_source_remove(power_timer);
+ power_timer = 0;
+ }
+
+ /* check battery has been initialized */
+ retval = hal_device_battery_get_current_state(battery_changed, NULL);
+ if (retval == -ENODEV) {
+ CRITICAL_LOG_E("Failed to initialize battery state, %d. Disable the battery module.", retval);
+ battery_disable_module(retval);
+ return done;
+ }
+
event_handler_state_changed((void *)&state);
_I("booting done %s(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d : %s)",
{
device_notifier_state_e state = DEVICE_NOTIFIER_STATE_STOP;
+ unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
unregister_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed);
event_handler_state_changed((void *)&state);