+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <libsyscommon/libgdbus.h>
-#include <libsyscommon/resource-manager.h>
-#include <system/syscommon-plugin-deviced-common-interface.h>
-#include <system/syscommon-plugin-deviced-display-interface.h>
-#include <system/syscommon-plugin-deviced-battery-interface.h>
-
-#include <libsyscommon/log.h>
-#include "battery.h"
-#include "battery-parser.h"
-#include "power-supply.h"
-#include "lowbat-handler.h"
-#include "battery-ops.h"
-#include "core.h"
-#include "display-lock.h"
-#include "display-ops.h"
-#include "display-state-transition.h"
-#include "poll.h"
-#include "shared/eventsystem.h"
-#include "shared/plugin.h"
-#include "shared/device-notifier.h"
-#include "shared/apps.h"
-
-#define REMOVE_POPUP "remove_battery_popups"
-
-static struct display_plugin *disp_plgn;
-static guint abnormal_timer;
-
-static void health_timer_reset(void)
-{
- abnormal_timer = 0;
-}
-
-static gboolean health_timer_cb(void *data)
-{
- int ret = 0;
- enum syscommon_deviced_battery_health_type battery_health;
- char *battery_health_s = NULL;
- bool battery_do_not_disturb = false;
-
- health_timer_reset();
-
- ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_BATTERY),
- DEVICED_BATTERY_ATTR_INT_STATUS_HEALTH, (int32_t *) &battery_health);
- if (ret < 0) {
- _E("Failed to get battery health status.");
- return G_SOURCE_REMOVE;
- }
-
- if (battery_health != SYSCOMMON_DEVICED_BATTERY_HEALTH_LOW && battery_health != SYSCOMMON_DEVICED_BATTERY_HEALTH_HIGH)
- return G_SOURCE_REMOVE;
-
- battery_health_s = calloc(1, SYSCOMMON_RESMAN_BUFF_MAX);
- if (battery_health_s) {
- battery_health_s[SYSCOMMON_RESMAN_BUFF_MAX - 1] = '\0';
- ret = syscommon_resman_get_resource_attr_string(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_BATTERY),
- DEVICED_BATTERY_ATTR_STRING_STATUS_HEALTH, battery_health_s);
- if (ret == 0) {
- CRITICAL_LOG("Popup: Battery health status is not good, %s.", battery_health_s);
- }
- free(battery_health_s);
- }
-
- syscommon_notifier_emit_notify(DEVICED_NOTIFIER_BATTERY_HEALTH, (void *)&battery_health);
- ret = syscommon_resman_get_resource_attr_bool(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_BATTERY),
- DEVICED_BATTERY_ATTR_BOOL_DO_NOT_DISTURB, &battery_do_not_disturb);
- if (ret == 0 && !battery_do_not_disturb)
- syscommon_resman_set_resource_attr_uint64_2(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
- DEVICED_DISPLAY_ATTR_TUPLE2_CURRENT_STATE_WITH_OPTION, DEVICED_EVENT_MISC_POPUP, SYSCOMMON_DEVICED_DISPLAY_STATE_DIM);
-
- syscommon_resman_set_resource_attr_uint64_3(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
- DEVICED_DISPLAY_ATTR_TUPLE3_UNLOCK_WITH_OPTION, DEVICED_EVENT_MISC_POPUP,
- SYSCOMMON_DEVICED_DISPLAY_STATE_OFF, DEVICED_DISPLAY_LOCK_SLEEP_MARGIN);
-
- syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
- DEVICED_DISPLAY_ATTR_TUPLE4_LOCK_WITH_OPTION, DEVICED_EVENT_MISC_POPUP,
- SYSCOMMON_DEVICED_DISPLAY_STATE_DIM, DEVICED_DISPLAY_STATE_STAY_CUR_STATE, 0);
-
- if (battery_health == SYSCOMMON_DEVICED_BATTERY_HEALTH_LOW) {
- syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
- DEVICED_DISPLAY_ATTR_TUPLE4_LOCK_WITH_OPTION, DEVICED_EVENT_BATTERY_HEALTH_OVERCOOL,
- SYSCOMMON_DEVICED_DISPLAY_STATE_OFF, DEVICED_DISPLAY_STATE_STAY_CUR_STATE, 60000);
- syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_BATTERY),
- DEVICED_BATTERY_ATTR_INT_LOW_BATTERY_POPUP, SYSCOMMON_DEVICED_BATTERY_OPT_ERR_TEMP_LOW);
- } else if (battery_health == SYSCOMMON_DEVICED_BATTERY_HEALTH_HIGH) {
- syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
- DEVICED_DISPLAY_ATTR_TUPLE4_LOCK_WITH_OPTION, DEVICED_EVENT_BATTERY_HEALTH_OVERHEAT,
- SYSCOMMON_DEVICED_DISPLAY_STATE_OFF, DEVICED_DISPLAY_STATE_STAY_CUR_STATE, 60000);
- syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_BATTERY),
- DEVICED_BATTERY_ATTR_INT_LOW_BATTERY_POPUP, SYSCOMMON_DEVICED_BATTERY_OPT_ERR_TEMP_HIGH);
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static void abnormal_popup_dbus_signal_handler(GDBusConnection *conn,
- const gchar *sender,
- const gchar *path,
- const gchar *iface,
- const gchar *name,
- GVariant *param,
- gpointer user_data)
-
-{
- int ret = 0;
- enum syscommon_deviced_battery_health_type battery_health;
-
- ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_BATTERY),
- DEVICED_BATTERY_ATTR_INT_STATUS_HEALTH, (int32_t *) &battery_health);
- if (ret < 0) {
- _E("Failed to get battery health status.");
- return;
- }
-
- if (battery_health == SYSCOMMON_DEVICED_BATTERY_HEALTH_GOOD)
- return;
-
- _I("Restart health timer.");
- abnormal_timer = g_timeout_add_seconds(DEVICED_BATTERY_ABNORMAL_CHECK_TIMER_INTERVAL,
- health_timer_cb, NULL);
- if (abnormal_timer == 0)
- _E("Failed to add abnormal check timer.");
-}
-
-static void battery_notification_init(void *data)
-{
- struct battery_plugin *plugin = (struct battery_plugin *)data;
- int ret;
-
- if (!plugin)
- return;
-
- _D("Add plugins for battery notification.");
-
- ret = gdbus_signal_subscribe(NULL, DEVICED_PATH_SYSNOTI,
- DEVICED_INTERFACE_SYSNOTI, SIGNAL_CHARGEERR_RESPONSE, abnormal_popup_dbus_signal_handler, NULL, NULL);
- if (ret <= 0)
- _E("Failed to init dbus signal: %d", ret);
-}
-
-static const struct battery_ops battery_notification_ops = {
- .name = "battery_notification",
- .init = battery_notification_init,
-};
-
-BATTERY_OPS_REGISTER(&battery_notification_ops)
-
-static void __CONSTRUCTOR__ initialize(void)
-{
- disp_plgn = get_var_display_plugin();
- if (!disp_plgn)
- _E("Failed to get display plugin variable.");
-}