diff options
Diffstat (limited to 'plugins/wearable')
-rw-r--r-- | plugins/wearable/display/ambient-mode.c | 210 | ||||
-rw-r--r-- | plugins/wearable/display/auto-brightness.c | 681 | ||||
-rw-r--r-- | plugins/wearable/display/display-actor.c | 102 | ||||
-rw-r--r-- | plugins/wearable/display/display-dbus.c | 1168 | ||||
-rw-r--r-- | plugins/wearable/display/display-ops.c | 74 | ||||
-rw-r--r-- | plugins/wearable/display/input.c | 224 | ||||
-rw-r--r-- | plugins/wearable/display/lock-detector.c | 232 | ||||
-rw-r--r-- | plugins/wearable/display/poll.c | 174 | ||||
-rw-r--r-- | plugins/wearable/display/setting.c | 271 |
9 files changed, 0 insertions, 3136 deletions
diff --git a/plugins/wearable/display/ambient-mode.c b/plugins/wearable/display/ambient-mode.c deleted file mode 100644 index b15fd561..00000000 --- a/plugins/wearable/display/ambient-mode.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 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 <stdbool.h> -#include <fcntl.h> -#include <libsyscommon/dbus-system.h> - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "core/device-notifier.h" -#include "core/devices.h" - -#define ON "on" -#define OFF "off" - -#define SIGNAL_AMBIENT_MODE "AmbientMode" -#define CLOCK_START "clockstart" -#define CLOCK_END "clockend" -#define TIMEOUT_NONE (-1) -#define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ - -static int ambient_state; -static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; -static unsigned int update_count; - -void broadcast_ambient_state(int state) -{ - int ret; - - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); - if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); -} - -int ambient_get_condition(void) -{ - return ambient_condition; -} - -int ambient_get_state(void) -{ - return ambient_state; -} - -static void ambient_set_condition(keynode_t *key_nodes, void *data) -{ - int state; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - ambient_condition = vconf_keynode_get_bool(key_nodes); - _I("Ambient mode condition is %d.", ambient_condition); - - state = (ambient_condition == 0 ? 0 : 1); - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION, (void *)&state); - - set_dim_state(state); -} - -int ambient_set_state(int on) -{ - if (!ambient_condition) - return 0; - - broadcast_ambient_state(on); - - update_count = 0; - - if (!on) - ambient_pid = 0; - - _D("AMBIENT is %s.", (on ? ON : OFF)); - - ambient_state = on; - - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE, (void *)&ambient_state); - - return 0; -} - -void ambient_check_invalid_state(pid_t pid) -{ - if (pid != INTERNAL_LOCK_AMBIENT) - return; - - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - - if (is_emulator()) { - /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) - return; - } - - if (ambient_get_state() == false) - return; - - _E("Invalid state. Ambient state is change to off."); - - /* If lcd_power is on and ambient state is true - * when pm state is changed to sleep, - * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ - - ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); -} - -static void start_clock(void) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, - AMBIENT_CLOCK_WAITING_TIME); -} - -static void end_clock(pid_t pid) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); - - update_count++; - if (update_count == UINT_MAX) - update_count = 1; - ambient_pid = pid; - - _I("Enter real ambient state by process(%d).", - ambient_pid); -} - -int ambient_set_screen(char *screen, pid_t pid) -{ - if (!screen) - return -EINVAL; - - if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); - else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); - - return 0; -} - -static void ambient_init(void *data) -{ - int ret; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); - if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); -} - -static void ambient_exit(void *data) -{ - ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); -} - -static const struct display_ops ambient_ops = { - .name = "ambient", - .init = ambient_init, - .exit = ambient_exit, -}; - -DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/plugins/wearable/display/auto-brightness.c b/plugins/wearable/display/auto-brightness.c deleted file mode 100644 index efc415c8..00000000 --- a/plugins/wearable/display/auto-brightness.c +++ /dev/null @@ -1,681 +0,0 @@ -/* - * 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 <stdbool.h> -#include <stdio.h> -#include <math.h> -#include <limits.h> -#include <unistd.h> -#include <stdlib.h> -#include <sys/types.h> -#include <fcntl.h> -#include <vconf.h> -#include <sensor.h> - - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "device-node.h" -#include "setting.h" -#include "core/device-notifier.h" -#include "core/config-parser.h" - -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ -#define MAX_SAMPLING_COUNT 3 -#define MAX_FAULT 5 -#define DEFAULT_AUTOMATIC_BRT 5 -#define AUTOMATIC_DEVIDE_VAL 10 -#define AUTOMATIC_DELAY_TIME 500 /* 0.5 sec */ - -#define RADIAN_VALUE (57.2957) -#define ROTATION_90 90 -#define WORKING_ANGLE_MIN 0 -#define WORKING_ANGLE_MAX 20 - -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - -static int (*_default_action) (int); -static guint alc_timeout_id = 0; -static guint update_timeout; -static sensor_listener_h light_listener; -static sensor_listener_h accel_listener; -static int fault_count; -static int automatic_brt = DEFAULT_AUTOMATIC_BRT; -static int min_brightness = PM_MIN_BRIGHTNESS; -static char *min_brightness_name = 0; - -/* light sensor */ -static float lmax, lmin; - -static bool update_working_position(void) -{ - sensor_event_s data; - int ret; - float x, y, z, pitch, realg; - - if (!display_conf.accel_sensor_on) - return false; - - ret = sensor_listener_read_data(accel_listener, &data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get accelerometer data: %d", ret); - return true; - } - - x = data.values[0]; - y = data.values[1]; - z = data.values[2]; - - realg = (float)sqrt((x * x) + (y * y) + (z * z)); - pitch = ROTATION_90 - abs((int) (asin(z / realg) * RADIAN_VALUE)); - - _D("Accel data x=%f y=%f z=%f pitch=%f", x, y, z, pitch); - - if (pitch >= WORKING_ANGLE_MIN && pitch <= WORKING_ANGLE_MAX) - return true; - return false; -} - -static void alc_set_brightness(int setting, int value, float light) -{ - static float old; - int position, tmp_value = 0, ret; - - ret = backlight_ops.get_brightness(&tmp_value); - if (ret < 0) { - _E("Failed to get display brightness."); - return; - } - - if (value < min_brightness) - value = min_brightness; - - if (tmp_value != value) { - if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { - position = update_working_position(); - if (!position && (old > light)) { - _D("It's not working position, " - "LCD isn't getting dark."); - return; - } - } - int diff, step; - - diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) - step = (diff > 0 ? 1 : -1); - else - step = (int)ceil(diff / - (float)display_conf.brightness_change_step); - - _D("%d", step); - while (tmp_value != value) { - if (step == 0) break; - - tmp_value += step; - if ((step > 0 && tmp_value > value) || - (step < 0 && tmp_value < value)) - tmp_value = value; - - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); - } - _I("Load light data(%f). auto brt=%d min brightness=%d " - "brightness=%d", light, automatic_brt, min_brightness, value); - old = light; - } -} - -static bool check_brightness_changed(int value) -{ - int i; - static int values[MAX_SAMPLING_COUNT], count = 0; - - if (count >= MAX_SAMPLING_COUNT || count < 0) - count = 0; - - values[count++] = value; - - for (i = 0; i < MAX_SAMPLING_COUNT - 1; i++) - if (values[i] != values[i+1]) - return false; - return true; -} - -static bool alc_update_brt(bool setting) -{ - int value = 0; - int ret = -1; - sensor_event_s light_data; - int index; - float light; - - ret = sensor_listener_read_data(light_listener, &light_data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to read light sensor data: %d", ret); - goto out; - } - - index = light_data.value_count - 1; - if (index < 0 || light_data.values[index] < 0) { - _E("Invalid light sensor data."); - goto out; - } - - light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( - lmax, lmin, light, &value); - if (ret == -ENOTSUP) { - _E("Not supported to handle the light data."); - goto out; - } - - if (ret < 0 || value < PM_MIN_BRIGHTNESS || value > PM_MAX_BRIGHTNESS) { - _E("Failed to load light data. light=%f value=%d: %d", light, value, ret); - goto out; - } - - fault_count = 0; - - if (display_conf.continuous_sampling && - !check_brightness_changed(value) && - !setting) - return true; - - alc_set_brightness(setting, value, light); - - return true; - -out: - fault_count++; - - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { - if (alc_timeout_id) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - SETTING_BRIGHTNESS_AUTOMATIC_OFF); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - _E("Fault counts is over %d, disable automatic brightness.", MAX_FAULT); - return false; - } - return true; -} - -static gboolean alc_handler(void *data) -{ - if (pm_cur_state != S_NORMAL) { - if (alc_timeout_id > 0) - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - return G_SOURCE_REMOVE; - } - - if (!alc_update_brt(false)) - return G_SOURCE_REMOVE; - - if (alc_timeout_id != 0) - return G_SOURCE_CONTINUE; - - return G_SOURCE_REMOVE; -} - -static int alc_action(int timeout) -{ - /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } - - if (_default_action != NULL) - return _default_action(timeout); - - /* unreachable code */ - return -1; -} - -static int connect_sensor(void) -{ - int ret; - sensor_h sensor; - sensor_h *list = NULL; - int cnt = 0; - - _I("Connect with sensor fw."); - /* light sensor */ - ret = sensor_get_sensor_list(SENSOR_LIGHT, &list, &cnt); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor list: %d", ret); - goto error; - } - - /* TODO - * Sensor apis will be fixed - * to provide which sensor is effective among sensors */ - if (cnt == 3) /* three light sensors exist */ - sensor = list[2]; - else - sensor = list[0]; - - free(list); - - ret = sensor_get_min_range(sensor, &lmin); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor min range: %d", ret); - goto error; - } - ret = sensor_get_max_range(sensor, &lmax); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor max range: %d", ret); - goto error; - } - _I("Light sensor min(%f), max(%f)", lmin, lmax); - - ret = sensor_create_listener(sensor, &light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(light)."); - goto error; - } - sensor_listener_set_option(light_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start light sensor."); - sensor_destroy_listener(light_listener); - light_listener = 0; - goto error; - } - - if (!display_conf.accel_sensor_on) - goto success; - - /* accelerometer sensor */ - ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &sensor); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get default accel sensor."); - goto error; - } - ret = sensor_create_listener(&sensor, &accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(accel)."); - goto error; - } - sensor_listener_set_option(accel_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start accel sensor."); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - goto error; - } - -success: - fault_count = 0; - return 0; - -error: - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - return -EIO; -} - -static int disconnect_sensor(void) -{ - _I("Disconnect with sensor fw."); - /* light sensor*/ - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - - /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - - if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; - _default_action = NULL; - } - if (alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -void set_brightness_changed_state(void) -{ - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; - _D("Brightness changed in low battery," - "escape dim state (light)."); - } -} - -static int set_autobrightness_state(int status) -{ - int ret = -1; - int brt = -1; - int default_brt = -1; - - if (status == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (connect_sensor() < 0) - return -1; - - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - /* change alc action func */ - if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; - - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _I("Auto brightness paused."); - disconnect_sensor(); - } else { - disconnect_sensor(); - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - ret = get_setting_brightness(&default_brt); - if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { - _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; - if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } - default_brt = brt; - } - - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); - } - - return 0; -} - -static void set_alc_function(keynode_t *key_nodes, void *data) -{ - int status, ret; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - status = vconf_keynode_get_int(key_nodes); - - switch (status) { - case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - case SETTING_BRIGHTNESS_AUTOMATIC_ON: - case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - ret = set_autobrightness_state(status); - _D("Set auto brightness: %d", ret); - break; - default: - _E("Invalid value(%d)", status); - } -} - -static void set_alc_automatic_brt(keynode_t *key_nodes, void *data) -{ - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - automatic_brt = vconf_keynode_get_int(key_nodes) / AUTOMATIC_DEVIDE_VAL; - _D("Automatic brt(%d)", automatic_brt); - - alc_update_brt(true); -} - -static gboolean update_handler(void *data) -{ - int ret, on; - - update_timeout = 0; - - if (pm_cur_state != S_NORMAL) - return G_SOURCE_REMOVE; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); - if (ret < 0 || on != SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - return G_SOURCE_REMOVE; - } - - _D("Auto brightness is working."); - alc_update_brt(true); - - return G_SOURCE_REMOVE; -} - -static void update_auto_brightness(bool update) -{ - if (update_timeout) { - g_source_remove(update_timeout); - update_timeout = 0; - } - - if (update) { - update_timeout = g_timeout_add(AUTOMATIC_DELAY_TIME, - update_handler, NULL); - } -} - -static int prepare_lsensor(void *data) -{ - int status, ret; - int brt = -1; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - set_autobrightness_state(status); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - - /* add auto_brt_setting change handler */ - vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function, NULL); - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - - if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { - _E("Failed to get automatic brightness."); - } else { - automatic_brt = brt / AUTOMATIC_DEVIDE_VAL; - _I("Automatic brt(%d) init success.", automatic_brt); - } - - vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt, NULL); - - return 0; -} - -static void update_brightness_direct(void) -{ - int ret, status; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - alc_update_brt(true); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); -} - -static int set_autobrightness_min(int val, char *name) -{ - if (!name) - return -EINVAL; - - if (val < PM_MIN_BRIGHTNESS || val > PM_MAX_BRIGHTNESS) - return -EINVAL; - - min_brightness = val; - - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - min_brightness_name = strndup(name, strlen(name)); - - update_brightness_direct(); - - _I("Auto brightness min value changed. min_brightness=%d min_brightness_name=%s", - min_brightness, min_brightness_name); - - return 0; -} - -static void reset_autobrightness_min(GDBusConnection *conn, - const gchar *sender, - const gchar *unique_name, - gpointer data) -{ - if (!sender) - return; - - if (!min_brightness_name) - return; - - if (strcmp(sender, min_brightness_name)) - return; - - _I("Change to default min brightness. before=%d changed=%d brightness_name=%s", min_brightness, - PM_MIN_BRIGHTNESS, min_brightness_name); - min_brightness = PM_MIN_BRIGHTNESS; - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - - update_brightness_direct(); -} - -static int lcd_changed_cb(void *data) -{ - int lcd_state; - - if (!data) - return 0; - lcd_state = *(int *)data; - if (lcd_state == S_LCDOFF && alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -static int booting_done_cb(void *data) -{ - int state; - - if (!data) - return 0; - - state = *(int *)data; - if (state != true) - return 0; - - /* get light data from sensor fw */ - prepare_lsensor(NULL); - - return 0; -} - -static void exit_lsensor(void) -{ - vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt); - - set_autobrightness_state(SETTING_BRIGHTNESS_AUTOMATIC_OFF); -} - -static void auto_brightness_init(void *data) -{ - display_info.update_auto_brightness = update_auto_brightness; - display_info.set_autobrightness_min = set_autobrightness_min; - display_info.reset_autobrightness_min = reset_autobrightness_min; - - register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static void auto_brightness_exit(void *data) -{ - exit_lsensor(); - - unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static const struct display_ops display_autobrightness_ops = { - .name = "auto-brightness", - .init = auto_brightness_init, - .exit = auto_brightness_exit, -}; - -DISPLAY_OPS_REGISTER(&display_autobrightness_ops) - diff --git a/plugins/wearable/display/display-actor.c b/plugins/wearable/display/display-actor.c deleted file mode 100644 index bab86303..00000000 --- a/plugins/wearable/display/display-actor.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 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 "util.h" -#include "display-actor.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *actor_head; - -void display_add_actor(struct display_actor_ops *actor) -{ - DD_LIST_APPEND(actor_head, actor); -} - -static struct display_actor_ops *display_find_actor(enum display_actor_id id) -{ - dd_list *elem; - struct display_actor_ops *actor; - - DD_LIST_FOREACH(actor_head, elem, actor) { - if (actor->id == id) - return actor; - } - return NULL; -} - -int display_set_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps |= caps; - - return 0; -} - -int display_reset_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps &= ~caps; - - return 0; -} - -unsigned int display_get_caps(enum display_actor_id id) -{ - struct display_actor_ops *actor; - - if (id <= 0) - return 0; - - actor = display_find_actor(id); - if (!actor) - return 0; - - return actor->caps; -} - -int display_has_caps(unsigned int total_caps, unsigned int caps) -{ - if (!total_caps || !caps) - return false; - - if ((total_caps & caps) == caps) - return true; - - return false; -} - diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c deleted file mode 100644 index 308d665d..00000000 --- a/plugins/wearable/display/display-dbus.c +++ /dev/null @@ -1,1168 +0,0 @@ -/* - * 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. - */ - - -/** - * @file display-dbus.c - * @brief dbus interface - * - */ - -#include <error.h> -#include <stdbool.h> -#include <sys/types.h> -#include <unistd.h> -#include <device-node.h> -#include <libsyscommon/dbus-system.h> - -#include "ambient-mode.h" -#include "core/log.h" -#include "util.h" -#include "core.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-idler.h" -#include "apps/apps.h" -#include "dd-display.h" -#include "display-actor.h" -#include "display-ops.h" -#include <device/display.h> - -#define SIGNAL_HOMESCREEN "HomeScreen" - -#define DUMP_MODE_WATING_TIME 600000 - -#define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" -#define EXPIRED_POPUP_PID "_APP_PID_" -#define EXPIRED_POPUP_COMM "_APP_COMM_" -#define EXPIRED_POPUP_ID "_REQUEST_ID_" - -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - -GVariant *dbus_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->start(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->stop(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_lockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option1_str; - char *option2_str; - int timeout; - pid_t pid; - int state; - int flag; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); - - if (!state_str || timeout < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option1_str, STAYCURSTATE_STR)) - flag = STAY_CUR_STATE; - else if (!strcmp(option1_str, GOTOSTATENOW_STR)) - flag = GOTO_STATE_NOW; - else { - _E("%s option is invalid. set default option!", option1_str); - flag = STAY_CUR_STATE; - } - - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - - if (flag & GOTO_STATE_NOW) { - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - } - - if (check_dimstay(state, flag) == true) { - _E("LCD state can not be changed to OFF state now!"); - flag &= ~GOTO_STATE_NOW; - flag |= STAY_CUR_STATE; - } - - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); -out: - g_free(state_str); - g_free(option1_str); - g_free(option2_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_unlockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option_str; - pid_t pid; - int state; - int flag; - int ret = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ss)", &state_str, &option_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option_str, SLEEP_MARGIN_STR)) - flag = PM_SLEEP_MARGIN; - else if (!strcmp(option_str, RESET_TIMER_STR)) - flag = PM_RESET_TIMER; - else if (!strcmp(option_str, KEEP_TIMER_STR)) - flag = PM_KEEP_TIMER; - else { - _E("%s option is invalid. set default option!", option_str); - flag = PM_RESET_TIMER; - } - - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); -out: - g_free(state_str); - g_free(option_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_changestate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - pid_t pid; - int state; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &state_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else if (!strcmp(state_str, PM_STANDBY_STR)) - state = STANDBY; - else if (!strcmp(state_str, PM_SUSPEND_STR)) - state = SUSPEND; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - - if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); - ret = -EBUSY; - goto out; - } - - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); - - if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); -out: - g_free(state_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getdisplaycount(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = DEFAULT_DISPLAY_COUNT; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret, state; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - if (state == DISPLAY_STATE_NORMAL) - ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - else if (state == DISPLAY_STATE_SCREEN_DIM) - ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS; - else - ret = -EINVAL; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = -ENOTSUP; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt = -1, state, ret; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - - if (state == DISPLAY_STATE_NORMAL) - ret = backlight_ops.get_brightness(&brt); - else if (state == DISPLAY_STATE_SCREEN_DIM) { - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - if (ret >= 0) - ret = brt; - - _I("get brightness %d, %d", brt, ret); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int state, brt, autobrt, ret = 0, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(ii)", &state, &brt); - - //Check if brt is same with DIM - if (brt == 0) { - _E("application can not set this value(DIM VALUE:%d)", brt); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _E("auto_brightness state is ON, can not change the brightness value"); - ret = -EPERM; - goto error; - } - - if (state == DISPLAY_STATE_NORMAL) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } else if (state == DISPLAY_STATE_SCREEN_DIM) { - if (pm_cur_state == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - } - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - _I("set brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_holdbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt, autobrt, ret, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(i)", &brt); - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _D("Auto brightness will be paused"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - - _I("hold brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_releasebrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int bat, charger, changed, setting, brt, autobrt, ret = 0; - - CHECK_POWEROFF(); - - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); - if (ret < 0) { - _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger); - if (ret < 0) { - _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed); - if (ret < 0) { - _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting); - if (ret < 0) { - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.get_brightness(&brt); - if (ret < 0) - brt = ret; - - // check dim state - if (low_battery_state(bat) && - charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { - _D("batt warning low : brightness is not changed!"); - if (brt != 0) - backlight_ops.set_brightness(0); - goto error; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); - } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _D("Auto brightness will be enable"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setrefreshrate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int app, val, ret, control; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ii)", &app, &val); - - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { - ret = -EINVAL; - goto error; - } - - if (!display_conf.framerate_app[app]) { - _I("This case(%d) is not support in this target", app); - ret = -EPERM; - goto error; - } - - control = display_conf.control_display; - - if (control) - backlight_ops.off(NORMAL_MODE); - - _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); - if (ret < 0) - _E("Failed to set frame rate (%d)", ret); - - if (control) - backlight_ops.on(NORMAL_MODE); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int val, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - if (!display_info.set_autobrightness_min) { - ret = -EIO; - goto error; - } - g_variant_get(param, "(i)", &val); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = display_info.set_autobrightness_min(val, (char *)sender); - if (ret) { - _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); - goto error; - } - if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set autobrightness min %d by %d", val, pid); - } -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setlcdtimeout(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int on, dim, holdkey_block, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = set_lcd_timeout(on, dim, holdkey_block, sender); - if (ret) { - _W("fail to set lcd timeout %d by %d", ret, pid); - } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); - } - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lockscreenbgon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); - } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_dumpmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "on")) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, - STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_savelog(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - if (!device_poweroff(NULL)) - save_display_log(); - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_powerkeyignore(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &on); - - if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) - keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) - ret = keyfilter_ops->powerkey_lcdoff(); - else - ret = -ENOSYS; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_customlcdon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int timeout; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &timeout); - - ret = custom_lcdon(timeout); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_stay_touchscreen_off(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_lcd_paneloff_mode(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_actorcontrol(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0, val, actor; - char *op; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sii)", &op, &actor, &val); - - if (!strcmp(op, "set")) - ret = display_set_caps(actor, val); - else if (!strcmp(op, "reset")) - ret = display_reset_caps(actor, val); - else - ret = -EINVAL; - - g_free(op); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getcustombrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int status = 0; - - CHECK_POWEROFF(); - - status = backlight_ops.get_custom_status(); - - return g_variant_new("(i)", status); -} - -struct pmlock_expired_s { - char req_id[32]; - GDBusMethodInvocation *invocation; - int value; - pid_t pid; -}; - -static dd_list *expired_req_list; - -static int get_command(pid_t pid, char *comm, size_t len) -{ - FILE *fp; - char path[PATH_MAX]; - char name[NAME_MAX]; - char *tmp; - int ret; - - snprintf(path, sizeof(path), "/proc/%d/comm", pid); - - fp = fopen(path, "r"); - if (!fp) { - _E("Failed to open file %s, errno:%d", path, errno); - return -errno; - } - - ret = fread(name, 1, sizeof(name) - 1, fp); - name[ret] = '\0'; - fclose(fp); - - tmp = name; - while (*tmp != '\0') { - if (*tmp == '\n' || - *tmp == '\r') { - *tmp = '\0'; - break; - } - tmp++; - } - - snprintf(comm, len, "%s", name); - - return 0; -} - -GVariant *dbus_locktimeout_expired(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - pid_t pid; - char pid_str[16]; - char comm[NAME_MAX]; - struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &req_id); - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = get_command(pid, comm, sizeof(comm)); - if (ret < 0) { - _E("Failed to get command (%d)", ret); - goto out; - } - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(pid_str, sizeof(pid_str), "%d", pid); - ret = launch_system_app(APP_DEFAULT, 8, - APP_KEY_TYPE, - EXPIRED_POPUP_TYPE_POWER, - EXPIRED_POPUP_PID, - pid_str, - EXPIRED_POPUP_COMM, - comm, - EXPIRED_POPUP_ID, - req_id); - if (ret < 0) { - _E("Failed to launch pmlock expired popup(%d)", ret); - goto out; - } - - ex->pid = pid; - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - - ex->invocation = invocation; - - DD_LIST_APPEND(expired_req_list, ex); - - g_free(req_id); - return NULL; - -out: - gvar = g_variant_new("(i)", ret); - g_free(req_id); - if (ex) - free(ex); - return gvar; -} - -static gboolean app_term(gpointer data) -{ - struct pmlock_expired_s *ex = data; - - if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); - free(ex); - } - return G_SOURCE_REMOVE; -} - -static void expired_deliver_result(void *data) -{ - struct pmlock_expired_s *ex = data; - struct pmlock_expired_s *item = NULL; - dd_list *l; - size_t len; - int value; - char *id; - - if (!ex) - return; - - len = strlen(ex->req_id) + 1; - DD_LIST_FOREACH(expired_req_list, l, item) { - if (!strncmp(item->req_id, ex->req_id, len)) { - DD_LIST_REMOVE(expired_req_list, item); - break; - } - } - if (!item) - goto out; - - id = ex->req_id; - value = ex->value; - - _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" : - (value == 2) ? "KILL app" : "Release power lock"); - - if (!item->invocation) { - _E("item->invocation is null"); - goto out; - } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); - - if (value == 2) { - kill(item->pid, SIGTERM); - g_timeout_add(3000, app_term, (gpointer)item); - item = NULL; - } - -out: - free(ex); - free(item); -} - -GVariant *dbus_locktimeout_input(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - struct pmlock_expired_s *ex; - int value; - - CHECK_POWEROFF(); - - g_variant_get(param, "(si)", &req_id, &value); - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - ex->value = value; - - _I("req_id(%s), value(%d)", ex->req_id, ex->value); - - add_idle_request(expired_deliver_result, ex); - - ret = 0; - -out: - g_free(req_id); - return g_variant_new("(i)", ret); -} - -static const dbus_method_s dbus_methods[] = { - { "start", NULL, NULL, dbus_start }, - { "stop", NULL, NULL, dbus_stop }, - { "lockstate", "sssi", "i", dbus_lockstate }, - { "unlockstate", "ss", "i", dbus_unlockstate }, - { "changestate", "s", "i", dbus_changestate }, - { "ChangeState", "s", "i", dbus_changestate }, - { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */ - { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */ - { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */ - { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin }, - { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout }, - { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon }, - { "GetDisplayCount", NULL, "i", dbus_getdisplaycount }, - { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness }, - { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness }, - { "GetBrightness", "i", "i", dbus_getbrightness }, - { "SetBrightness", "ii", "i", dbus_setbrightness }, - { "HoldBrightness", "i", "i", dbus_holdbrightness }, - { "ReleaseBrightness", NULL, "i", dbus_releasebrightness }, - { "SetRefreshRate", "ii", "i", dbus_setrefreshrate }, - { "Dumpmode", "s", "i", dbus_dumpmode }, - { "SaveLog", NULL, NULL, dbus_savelog }, - { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, - { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, - { "CustomLCDOn", "i", "i", dbus_customlcdon }, - { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, - { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, - { "ActorControl", "sii", "i", dbus_actorcontrol }, - { "CustomBrightness", NULL, "i", dbus_getcustombrightness }, - { "CurrentBrightness", NULL, "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */ - { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, - { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_DISPLAY, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void homescreen_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - char *screen; - pid_t pid; - - g_variant_get(param, "(s)", &screen); - - _D("screen : %s", screen); - - pid = dbus_connection_get_sender_pid(conn, sender); - ambient_set_screen(screen, pid); - g_free(screen); -} - -/* - * Default capability - * api := LCDON | LCDOFF | BRIGHTNESS - * gesture := LCDON - */ -static struct display_actor_ops display_api_actor = { - .id = DISPLAY_ACTOR_API, - .caps = DISPLAY_CAPA_LCDON | - DISPLAY_CAPA_LCDOFF | - DISPLAY_CAPA_BRIGHTNESS, -}; - -static struct display_actor_ops display_gesture_actor = { - .id = DISPLAY_ACTOR_GESTURE, - .caps = DISPLAY_CAPA_LCDON, -}; - -int init_pm_dbus(void) -{ - int ret; - - display_add_actor(&display_api_actor); - display_add_actor(&display_gesture_actor); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - ret = subscribe_dbus_signal(NULL, - DEVICED_OBJECT_PATH, - DEVICED_INTERFACE_NAME, - SIGNAL_HOMESCREEN, - homescreen_signal_handler, - NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } - - return 0; -} - diff --git a/plugins/wearable/display/display-ops.c b/plugins/wearable/display/display-ops.c deleted file mode 100644 index 22b91371..00000000 --- a/plugins/wearable/display/display-ops.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 "util.h" -#include "display-ops.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *disp_head; - -void add_display(const struct display_ops *disp) -{ - DD_LIST_APPEND(disp_head, disp); -} - -void remove_display(const struct display_ops *disp) -{ - DD_LIST_REMOVE(disp_head, disp); -} - -const struct display_ops *find_display_feature(const char *name) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - if (!strcmp(disp->name, name)) - return disp; - } - return NULL; -} - -void display_ops_init(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] initialize", disp->name); - if (disp->init) - disp->init(data); - } -} - -void display_ops_exit(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] deinitialize", disp->name); - if (disp->exit) - disp->exit(data); - } -} - diff --git a/plugins/wearable/display/input.c b/plugins/wearable/display/input.c deleted file mode 100644 index a9865047..00000000 --- a/plugins/wearable/display/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 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 <fcntl.h> -#include <sys/stat.h> -#include <linux/input.h> -#include <libinput.h> - -#include "util.h" -#include "core.h" -#include "poll.h" - -#define SEAT_NAME "seat0" - -static struct udev *udev; -static struct libinput *li; -static guint efd; - -int (*pm_callback) (int, PMMsg *); - -static inline void process_event(struct libinput_event *ev) -{ - static const struct device_ops *display_device_ops; - struct input_event input; - struct libinput *li; - struct libinput_event_keyboard *k; - unsigned int time; - int fd; - - if (!pm_callback) - return; - - if (!display_device_ops) { - display_device_ops = find_device("display"); - if (!display_device_ops) - return; - } - - /* do not operate when display stops */ - if (device_get_status(display_device_ops) - != DEVICE_OPS_STATUS_START) { - _E("display status is stop"); - return; - } - - switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; - case LIBINPUT_EVENT_KEYBOARD_KEY: - k = libinput_event_get_keyboard_event(ev); - time = libinput_event_keyboard_get_time(k); - li = libinput_event_get_context(ev); - - input.time.tv_sec = MSEC_TO_SEC(time); - input.time.tv_usec = MSEC_TO_USEC(time % 1000); - input.type = EV_KEY; - input.code = libinput_event_keyboard_get_key(k); - input.value = libinput_event_keyboard_get_key_state(k); - - fd = libinput_get_fd(li); - _D("time %ld.%06ld type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); - input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - case LIBINPUT_EVENT_TOUCH_UP: - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; - break; - default: - break; - } - - /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); -} - -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -int init_input(void) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return -EPERM; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return -EPERM; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return -EPERM; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return -EPERM; - } - - return 0; -} - -int exit_input(void) -{ - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ - - if (li) - libinput_unref(li); - - if (udev) - udev_unref(udev); - - return 0; -} diff --git a/plugins/wearable/display/lock-detector.c b/plugins/wearable/display/lock-detector.c deleted file mode 100644 index 0560ef49..00000000 --- a/plugins/wearable/display/lock-detector.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * 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. - */ - - -/** - * @file lock-detector.c - * @brief - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdbool.h> -#include <errno.h> -#include <sys/time.h> -#include <unistd.h> -#include <sys/types.h> - -#include "util.h" -#include "core.h" -#include "core/list.h" - -struct lock_info { - unsigned long hash; - char *name; - int state; - int count; - long locktime; - long unlocktime; - long time; -}; - -#define LIMIT_COUNT 128 - -static dd_list *lock_info_list; - -static long get_time(void) -{ - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); -} - -static void shrink_lock_info_list(void) -{ - dd_list *l, *l_prev; - struct lock_info *info; - unsigned int count; - - count = DD_LIST_LENGTH(lock_info_list); - if (count <= LIMIT_COUNT) - return; - _D("list is shrink : count %d", count); - - DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { - if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); - if (info->name) - free(info->name); - free(info); - count--; - } - if (count <= (LIMIT_COUNT / 2)) - break; - } -} - -int set_lock_time(const char *pname, int state) -{ - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - info->count += 1; - if (info->locktime == 0) - info->locktime = get_time(); - info->unlocktime = 0; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } - - info = malloc(sizeof(struct lock_info)); - if (!info) { - _E("Malloc is failed for lock_info!"); - return -ENOMEM; - } - - info->hash = val; - info->name = strndup(pname, strlen(pname)); - info->state = state; - info->count = 1; - info->locktime = get_time(); - info->unlocktime = 0; - info->time = 0; - - DD_LIST_APPEND(lock_info_list, info); - - return 0; -} - -int set_unlock_time(const char *pname, int state) -{ - bool find = false; - long diff; - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - find = true; - break; - } - - if (!find) - return -EINVAL; - - if (info->locktime == 0) - return -EINVAL; - - /* update time */ - info->unlocktime = get_time(); - diff = info->unlocktime - info->locktime; - if (diff > 0) - info->time += diff; - info->locktime = 0; - - if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) - shrink_lock_info_list(); - - return 0; -} - -void free_lock_info_list(void) -{ - dd_list *l, *l_next; - struct lock_info *info; - - if (!lock_info_list) - return; - - DD_LIST_FOREACH_SAFE(lock_info_list, l, l_next, info) { - DD_LIST_REMOVE(lock_info_list, info); - if (info->name) - free(info->name); - free(info); - } - lock_info_list = NULL; -} - -void print_lock_info_list(int fd) -{ - struct lock_info *info; - dd_list *l; - char buf[255]; - int ret; - - if (!lock_info_list) - return; - - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; - if (info->locktime != 0 && info->unlocktime == 0) - time = get_time() - info->locktime; - snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - } -} - diff --git a/plugins/wearable/display/poll.c b/plugins/wearable/display/poll.c deleted file mode 100644 index ee0471d3..00000000 --- a/plugins/wearable/display/poll.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * 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. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include <stdio.h> -#include "util.h" -#include "core.h" -#include "poll.h" -#include "display/display-ops.h" - -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(pm_status_flag & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static bool state_supported(enum state_t st) -{ - if (states[st].trans) - return true; - return false; -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -void init_pm_internal() -{ - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; -} diff --git a/plugins/wearable/display/setting.c b/plugins/wearable/display/setting.c deleted file mode 100644 index b109d8c7..00000000 --- a/plugins/wearable/display/setting.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * 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 <stdlib.h> -#include <errno.h> -#include <stdbool.h> -#include <bundle.h> -#include <eventsystem.h> - -#include "ambient-mode.h" -#include "core.h" -#include "util.h" -#include "setting.h" -#include "display-ops.h" - -#define LCD_DIM_RATIO 0.3 -#define LCD_MAX_DIM_TIMEOUT 7000 -#define LCD_MIN_DIM_TIMEOUT 500 - -static const char *setting_keys[SETTING_GET_END] = { - [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, - [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS, - [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE, - [SETTING_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, -}; - -static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; -static bool lock_screen_bg_state = false; -static int force_lcdtimeout = 0; -static int custom_on_timeout = 0; -static int custom_normal_timeout = 0; -static int custom_dim_timeout = 0; - -static void display_state_send_system_event(int state) -{ - bundle *b; - const char *str; - - if (state == S_NORMAL) - str = EVT_VAL_DISPLAY_NORMAL; - else if (state == S_LCDDIM) - str = EVT_VAL_DISPLAY_DIM; - else if (state == S_LCDOFF) - str = EVT_VAL_DISPLAY_OFF; - else - return; - - _I("eventsystem (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); -} - -int set_force_lcdtimeout(int timeout) -{ - if (timeout < 0) - return -EINVAL; - - force_lcdtimeout = timeout; - - return 0; -} - -int __get_lock_screen_state(void) -{ - return lock_screen_state; -} - -void set_lock_screen_state(int state) -{ - switch (state) { - case VCONFKEY_IDLE_LOCK: - case VCONFKEY_IDLE_UNLOCK: - lock_screen_state = state; - break; - default: - lock_screen_state = VCONFKEY_IDLE_UNLOCK; - } -} - -int get_lock_screen_bg_state(void) -{ - return lock_screen_bg_state; -} - -void set_lock_screen_bg_state(bool state) -{ - _I("state is %d", state); - lock_screen_bg_state = state; -} - -int set_setting_pmstate(int val) -{ - static int old = -1; - int ret; - - if (old == val) - return 0; - old = val; - - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); - - return ret; -} - -int get_setting_brightness(int *level) -{ - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; -} - -void get_dim_timeout(int *dim_timeout) -{ - int vconf_timeout, on_timeout, val, ret; - - if (custom_dim_timeout > 0) { - *dim_timeout = custom_dim_timeout; - return; - } - - if (ambient_get_condition() == true) { - *dim_timeout = LCD_MIN_DIM_TIMEOUT; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - val = (double)on_timeout * LCD_DIM_RATIO; - if (val > LCD_MAX_DIM_TIMEOUT) - val = LCD_MAX_DIM_TIMEOUT; - - *dim_timeout = val; -} - -void get_run_timeout(int *timeout) -{ - int dim_timeout = -1; - int vconf_timeout = -1; - int on_timeout; - int ret; - - if (custom_normal_timeout > 0) { - *timeout = custom_normal_timeout; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - if (on_timeout == 0) { - *timeout = on_timeout; - return; - } - - get_dim_timeout(&dim_timeout); - *timeout = on_timeout - dim_timeout; -} - -int set_custom_lcdon_timeout(int timeout) -{ - int changed = (custom_on_timeout == timeout ? false : true); - - custom_on_timeout = timeout; - - if (timeout <= 0) { - custom_normal_timeout = 0; - custom_dim_timeout = 0; - return changed; - } - - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; - custom_normal_timeout = timeout - custom_dim_timeout; - - _I("custom normal(%d), dim(%d)", custom_normal_timeout, - custom_dim_timeout); - - return changed; -} - -static int setting_cb(keynode_t *key_nodes, void *data) -{ - keynode_t *tmp = key_nodes; - int index; - - index = (int)((intptr_t)data); - if (index > SETTING_END) { - _E("Unknown setting key: %s, idx=%d", - vconf_keynode_get_name(tmp), index); - return -1; - } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); - - return 0; -} - -int init_setting(int (*func) (int key_idx, int val)) -{ - int i; - - if (func != NULL) - disp_plgn.update_pm_setting = func; - - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { - /* - * To pass an index data through the vconf infratstructure - * without memory allocation, an index data becomes typecast - * to proper pointer size on each architecture. - */ - vconf_notify_key_changed(setting_keys[i], (void *)setting_cb, - (void *)((intptr_t)i)); - } - - disp_plgn.get_lock_screen_state = __get_lock_screen_state; - - return 0; -} - -int exit_setting(void) -{ - int i; - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) - vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb); - - return 0; -} - |