From ae85d143f511cefbca6dc9ada94d39e378787287 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 6 Jul 2020 13:46:31 +0900 Subject: [PATCH 01/16] Fix not to defer processing lowbat on realoff If uevent continues to occur shorter than 1.5s on realoff state, it defers processing lowbattery infinitely and makes poweroff sequence unreachable. For that case, added exception to process lowbat immediately when the battery state is realoff. Change-Id: I90354fa261f73aa2e5b8451078576fcc070166a8 Signed-off-by: Youngjae Cho (cherry picked from commit c07e2dda8467cd2df6ccea80f3449e1a05993f31) --- src/battery/lowbat-handler.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 7e56f44..d3aa3b4 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -740,15 +740,25 @@ static gboolean low_battery_charge_status(void *data) static int lowbat_execute(void *data) { + int capacity = *(int *)data; + /* In battery kernel side, it has a requirement that battery charging event must get quickly. * So deviced receives the discharging and charging event within 1.5 sec, * added a timer to wait for the second signal, if there is no second signal then execute * the lowbat_execute. */ - if (low_batt_sig_timer) + if (low_batt_sig_timer) { g_source_remove(low_batt_sig_timer); + low_batt_sig_timer = 0; + } - low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data); + /* Do lowbat_process immediately rather deferring it when poweroff is needed. + * This prevents poweroff from being delayed infinitely when the uevent continues + * to occur shorter than 1.5 seconds on realoff capacity */ + if (capacity <= battery_info.realoff) + low_battery_charge_status(data); + else + low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data); return 0; } -- 2.7.4 From 6d4e597efd23e1d557e3455d8dacb54afa0e572b Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 6 Jul 2020 14:26:58 +0900 Subject: [PATCH 02/16] Add auto-test for brightness Usage: deviced-auto-test wearable brightness [tcname] Change-Id: Ied1e76aa411e0d78e912ad7050de4e0077933728 Signed-off-by: Youngjae Cho --- plugins/wearable/display/device-interface.c | 4 + src/auto-test/CMakeLists.txt | 1 + src/auto-test/auto-test.conf | 1 + src/auto-test/battery.c | 2 +- src/auto-test/brightness.c | 380 ++++++++++++++++++++++++++++ src/display/device-interface.h | 1 + src/display/display-dbus.c | 14 + 7 files changed, 402 insertions(+), 1 deletion(-) create mode 100644 src/auto-test/brightness.c diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index aef69d6..dc6d70c 100755 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -77,6 +77,7 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" struct _backlight_ops backlight_ops; + struct _power_ops power_ops; static int mainlock_status = POWER_UNLOCK; @@ -988,6 +989,9 @@ static void _init_ops(void) backlight_ops.blink = blink; backlight_ops.release_blink = release_blink; + /* auto-test only function */ + backlight_ops.get_brightness_raw = get_brightness; /* always fetch brightness from node even LBM mode */ + power_ops.suspend = system_suspend; power_ops.enable_autosleep = system_enable_autosleep; power_ops.power_lock = system_power_lock; diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index e840808..5623865 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -24,6 +24,7 @@ SET(SRCS test_dbus_interface.c battery-monitor-test.c udev.c + brightness.c ) FOREACH(flag ${pkgs_CFLAGS}) diff --git a/src/auto-test/auto-test.conf b/src/auto-test/auto-test.conf index 1b4f78e..6ae9444 100644 --- a/src/auto-test/auto-test.conf +++ b/src/auto-test/auto-test.conf @@ -14,6 +14,7 @@ udev=1 battery-monitor=1 battery=1 display=1 +brightness=1 led=0 power=1 proc=1 diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c index 4193e2b..ebb3bd2 100644 --- a/src/auto-test/battery.c +++ b/src/auto-test/battery.c @@ -788,7 +788,7 @@ static void full_scenario(char *unit, char *capacity, int status) } } -static void battery_scenario(char *unit, int status) +void battery_scenario(char *unit, int status) { int index; int found = 0; diff --git a/src/auto-test/brightness.c b/src/auto-test/brightness.c new file mode 100644 index 0000000..bb25d3c --- /dev/null +++ b/src/auto-test/brightness.c @@ -0,0 +1,380 @@ +#include +#include +#include +#include + +#include + +#include "test.h" + +#define CMD_INTERVAL_SEC 1 /* second */ +#define CMD_LONG_INTERVAL_SEC 3 /* second */ + +#define print_command(command) \ + do {\ + printf("%12s | ", command); \ + fflush(stdout); \ + sleep(CMD_INTERVAL_SEC); \ + } while(0) + +extern void battery_scenario(char *unit, int status); + +static bool tc_success; +static int success, fail; + +static void start_udev(void) +{ + dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, + "udev", + g_variant_new("(sis)", "udev", 1, "start")); +} + +static void stop_udev(void) +{ + dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, + "udev", + g_variant_new("(sis)", "udev", 1, "stop")); +} + +static int call_display_method_sync(const char *method, GVariant *param) +{ + GVariant *msg; + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + method, param); + if (!msg) { + _E("Failed to %s.", method); + return -1; + } + + return 0; +} + +static void check_result(int expect_default, int expect_current) +{ + int result_default; + int result_current; + bool match_default; + bool match_current; + GVariant *msg; + + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "GetBrightnessInfo", NULL); + if (!msg) { + _E("Failed to GetBrightnessInfo."); + return; + } + + if (!dh_get_param_from_var(msg, "(ii)", &result_default, &result_current)) { + _D("Return type mismatching from GetBrightnessInfo."); + return; + } + + match_default = expect_default == result_default; + match_current = expect_current == result_current; + + printf("%6d %6d %c | %6d %6d %c\n", + expect_default, result_default, match_default ? ' ' : 'X', + expect_current, result_current, match_current ? ' ' : 'X'); + + tc_success &= (match_default && match_current); +} + +static void hbm_on(int expect_default, int expect_current) +{ + print_command("HBM ON"); + + call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 120)); + check_result(expect_default, expect_current); + sleep(CMD_INTERVAL_SEC); +} + +static void hbm_off(int expect_default, int expect_current) +{ + print_command("HBM OFF"); + + call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 0)); + check_result(expect_default, expect_current); + sleep(CMD_INTERVAL_SEC); +} + +static void lbm_on(int expect_default, int expect_current) +{ + print_command("LBM ON"); + + call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 110)); + check_result(expect_default, expect_current); + sleep(CMD_INTERVAL_SEC); +} + +static void lbm_off(int expect_default, int expect_current) +{ + print_command("LBM OFF"); + + call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 0)); + check_result(expect_default, expect_current); + sleep(CMD_INTERVAL_SEC); +} + +static void hold(int hold, int expect_default, int expect_current) +{ + char command[32]; + + snprintf(command, sizeof(command), "HOLD %d", hold); + print_command(command); + + call_display_method_sync("HoldBrightness", g_variant_new("(i)", hold)); + check_result(expect_default, expect_current); + sleep(CMD_INTERVAL_SEC); +} + +static void release(int expect_default, int expect_current) +{ + print_command("RELEASE"); + + call_display_method_sync("ReleaseBrightness", NULL); + check_result(expect_default, expect_current); + sleep(CMD_INTERVAL_SEC); +} + +static void lowdim_on(int expect_default, int expect_current) +{ + print_command("LOWDIM ON"); + + battery_scenario("bat3", 1); + + check_result(expect_default, expect_current); + sleep(CMD_LONG_INTERVAL_SEC); +} + +static void lowdim_off(int expect_default, int expect_current) +{ + print_command("LOWDIM OFF"); + + battery_scenario("bat3", 0); + + check_result(expect_default, expect_current); + sleep(CMD_LONG_INTERVAL_SEC); +} + +static void set(int brightness, int expect_default, int expect_current) +{ + char command[32]; + + snprintf(command, sizeof(command), "SET %d", brightness); + print_command(command); + + call_display_method_sync("SetBrightness", g_variant_new("(ii)", 0, brightness)); + sleep(CMD_INTERVAL_SEC); + check_result(expect_default, expect_current); +} + +static void abnormal_health_on(int expect_default, int expect_current) +{ + print_command("ABNORMAL ON"); + + battery_scenario("heat1", 1); + + check_result(expect_default, expect_current); + sleep(CMD_LONG_INTERVAL_SEC); +} + +static void abnormal_health_off(int expect_default, int expect_current) +{ + print_command("ABNORMAL OFF"); + + battery_scenario("heat1", 0); + + check_result(expect_default, expect_current); + sleep(CMD_LONG_INTERVAL_SEC); +} + +static void initialize_test_env(int brightness, const char *fname) +{ + printf("[%s]\n", fname); + + tc_success = true; + + call_display_method_sync("ChangeState", g_variant_new("(s)", "lcdoff")); + sleep(CMD_INTERVAL_SEC); + call_display_method_sync("ChangeState", g_variant_new("(s)", "lcdon")); + sleep(CMD_LONG_INTERVAL_SEC); + printf(" Init brightness: %3d\n", brightness); + call_display_method_sync("SetBrightness", g_variant_new("(ii)", 0, brightness)); + sleep(CMD_INTERVAL_SEC); + call_display_method_sync("lockstate", g_variant_new("(sssi)", "lcdon", "staycurstate", "NULL", 0)); + sleep(CMD_INTERVAL_SEC); + + printf(" | default | current\n"); + printf(" Command | expect result | expect result\n"); + sleep(CMD_INTERVAL_SEC); +} +#define initialize(brightness) initialize_test_env(brightness, __func__) + +#define DEFINE_TC(tcname) static void tc_##tcname(void) +DEFINE_TC(hbm) +{ + initialize(50); + + hbm_on(50, 100); + hbm_off(50, 50); +} + +DEFINE_TC(lbm) +{ + initialize(100); + + /* BrtTable=1,20,40,50,60,70,80,90,95,100 + * Level=4 + * It lowers brightness 4 level down */ + lbm_on(100, 70); + set(1, 1, 1); + set(20, 20, 1); + set(40, 40, 1); + set(50, 50, 1); + set(60, 60, 1); + set(70, 70, 20); + set(80, 80, 40); + set(90, 90, 50); + set(95, 95, 60); + set(100, 100, 70); + lbm_off(100, 100); +} + +DEFINE_TC(hold) +{ + initialize(50); + + hold(100, 50, 100); + release(50, 50); +} + +DEFINE_TC(set) +{ + initialize(100); + + set(40, 40, 40); +} + +DEFINE_TC(lowdim) +{ + initialize(100); + + lowdim_on(100, 0); + lowdim_off(100, 100); +} + +DEFINE_TC(abnormal_health) +{ + initialize(100); + + abnormal_health_on(100, 0); + abnormal_health_off(100, 100); +} + +DEFINE_TC(custom1) +{ + initialize(50); + + lowdim_on(50, 0); + hold(100, 50, 100); + lbm_on(50, 100); + lbm_off(50, 100); + release(50, 0); + lowdim_off(50, 50); +} + +#define TESTCASE(tc_function) {.tcname = #tc_function, .tc = tc_##tc_function } +struct tc_list { + const char *tcname; + void (*tc)(void); +} tc[] = { + /* default testcase */ + TESTCASE(hbm), + TESTCASE(lbm), + TESTCASE(hold), + TESTCASE(set), + TESTCASE(lowdim), + TESTCASE(abnormal_health), + + /* custom testcase */ + TESTCASE(custom1), +}; + +#define array_len(arr) (sizeof(arr) / sizeof((arr)[0])) +static void do_test(const char *tcname) +{ + int i; + int timeout; + int ret = -1; + + ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, &timeout); + if (ret == 0) + vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 300); + + stop_udev(); + + if (tcname) { + for (i = 0; i < array_len(tc); ++i) { + if (strcmp(tcname, tc[i].tcname)) + continue; + tc[i].tc(); + if (tc_success) + ++success; + else + ++fail; + printf("--------------------------------------------------\n"); + } + } else { + for (i = 0; i < array_len(tc); ++i) { + tc[i].tc(); + if (tc_success) + ++success; + else + ++fail; + printf("--------------------------------------------------\n"); + } + } + printf("Success: %d, Fail: %d\n", success, fail); + + start_udev(); + if (ret == 0) + vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, timeout); +} + +static void brightness_init(void *data) +{ + do_test(NULL); +} + +static int brightness_unit(int argc, char **argv) +{ + if (argc < 4) + do_test(NULL); + else + do_test(argv[3]); + + return 0; +} + +static void brightness_exit(void *data) +{ + _I("End brightness test."); +} + +static const struct test_ops brightness_test_ops = { + .priority = TEST_PRIORITY_NORMAL, + .name = "brightness", + .init = brightness_init, + .exit = brightness_exit, + .unit = brightness_unit, +}; + +TEST_OPS_REGISTER(&brightness_test_ops) diff --git a/src/display/device-interface.h b/src/display/device-interface.h index 8ca2236..b02a997 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -88,6 +88,7 @@ struct _backlight_ops { int (*set_force_brightness)(int level); int (*set_brightness)(int val); int (*get_brightness)(int *val); + int (*get_brightness_raw)(int *val); void (*restore_brightness_func)(void); int (*get_brightness_by_light_sensor)(float lmax, float lmin, float light, int *brt); int (*get_image_effect)(enum display_image_effect *effect); diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 1cadc8b..a2ffc01 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -1145,6 +1145,19 @@ static GVariant *dbus_dimstay_control(GDBusConnection *conn, return g_variant_new("(i)", 0); } +static GVariant *dbus_getbrightnessinfo(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int default_brightness; + int current_brightness; + + default_brightness = backlight_ops.get_default_brt(); + backlight_ops.get_brightness_raw(¤t_brightness); + + return g_variant_new("(ii)", default_brightness, current_brightness); +} + static const dbus_method_s dbus_methods[] = { { "start", NULL, NULL, dbus_start }, { "stop", NULL, NULL, dbus_stop }, @@ -1181,6 +1194,7 @@ static const dbus_method_s dbus_methods[] = { { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, { "DimStayControl", "i", "i", dbus_dimstay_control }, + { "GetBrightnessInfo", NULL, "ii", dbus_getbrightnessinfo}, /* Add methods here */ }; -- 2.7.4 From 2a51d72f9687e8a8c9ed9f69c2c676feeede8dfb Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 16 Jun 2020 11:34:03 +0900 Subject: [PATCH 03/16] Add brightness interaction Add brightness interaction among - Set - Hold - HBM - LBM - LowbatteryDim - DimStay (Battery Abnormal Health) The condition in display_dimstay_check() is deleted, if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) return true; as all the brightness controlled by HBM/LBM/Hold/Release/Set is allowed to change even though in low battery dim situation. Checking HBM state after LCDON is deleted, as now sensord always notify deviced about the brightness state on receiving LCDOn signal. Change-Id: I2fc2babde83656d0743f113b5547e6edea72768f Signed-off-by: Youngjae Cho --- .../wearable/display/auto-brightness-sensorhub.c | 267 ++++++++++++++++----- .../wearable/display/auto-brightness-sensorhub.h | 93 +++++++ plugins/wearable/display/core.c | 18 +- plugins/wearable/display/device-interface.c | 3 - plugins/wearable/display/display-handler.c | 50 ++-- plugins/wearable/display/hbm.c | 149 +++--------- plugins/wearable/display/lbm.c | 66 ++--- plugins/wearable/display/lbm.h | 2 + src/display/display-dbus.c | 36 ++- src/display/display-ops.h | 2 + src/display/display.h | 26 ++ 11 files changed, 448 insertions(+), 264 deletions(-) diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index 13b0d38..b3aac8b 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -36,6 +36,7 @@ #define LOWBATCAPACITY 5 static int auto_brightness_state = SETTING_BRIGHTNESS_AUTOMATIC_OFF; +static bool lbm, hbm, hold, lowdim; static void change_brightness_transit(int start, int end) { @@ -45,7 +46,6 @@ static void change_brightness_transit(int start, int end) static void set_brightness_level(int level) { - int old_level = 0; if (pm_cur_state != S_NORMAL) return; /* @@ -60,61 +60,37 @@ static void set_brightness_level(int level) return; } - backlight_ops.get_brightness(&old_level); - switch (level) { case LBM_LEVEL: /* * received LBM enable * change brightness to under LBM_BRIGHTNESS_LOW and set lbm state */ - if (hbm_get_state()) { - hbm_set_state(false); - _I("HBM mode disabled."); - } - if (!lbm_get_state()) { - lbm_set_state(true); - _I("LBM mode enabled."); - } + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); + auto_brightness_control(BR_LBM_ON, BR_IMPLICIT); break; case HBM_LEVEL: - /* HBM must do not turn on at DIM_STY state. */ + /* HBM must do not turn on at DIM_STAY state. */ if (pm_status_flag & DIM_MASK) break; - /* * received HBM enable * change brightness to MAX value and set hbm state */ - if (lbm_get_state()) { - lbm_set_state(false); - _I("Disabling LBM before enabling HBM."); - } - - if (!hbm_get_state()) { - change_brightness_transit(old_level, PM_MAX_BRIGHTNESS); - hbm_set_state(true); - _I("HBM mode enabled."); - } - + auto_brightness_control(BR_LBM_OFF, BR_IMPLICIT); + auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); break; case SPECIFIC_MODE_OFF: /* - * received HBM disable - * unset hbm state and change brightness to setting value + * Disable LBM or HBM. + * If the flag hold is set when disabling LBM, brightness remains + * held brightness. (FYI. HBM and Hold cannot be both enabled, so + * no need to consider hold flag when disabling HBM) + * Otherwise, brightness changes to default or dim brightness + * depending on flag lowdim. */ - - level = backlight_ops.get_default_brt(); - - if (hbm_get_state()) - hbm_set_state(false); - - if (lbm_get_state()) - lbm_set_state(false); - - if (old_level != level) - change_brightness_transit(old_level, level); - + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); + auto_brightness_control(BR_LBM_OFF, BR_IMPLICIT); break; default: /* @@ -123,21 +99,11 @@ static void set_brightness_level(int level) if (auto_brightness_state != SETTING_BRIGHTNESS_AUTOMATIC_ON) return; - if (hbm_get_state()) - hbm_set_state(false); - - if (lbm_get_state()) - lbm_set_state(false); - - if (old_level != level) { - change_brightness_transit(old_level, level); - backlight_ops.set_default_brt(level); - } - + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); + auto_brightness_control(BR_LBM_OFF, BR_IMPLICIT); + auto_brightness_control(BR_SET_BRIGHTNESS, level); break; } - - device_notify(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, NULL); } static void set_default_brightness(void) @@ -159,15 +125,13 @@ static void set_automatic_state_cb(keynode_t *key_nodes, void *data) switch (auto_brightness_state) { case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - if (hbm_get_state()) - hbm_set_state(false); + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); /* escape dim state if it's in low battery.*/ set_brightness_changed_state(); set_default_brightness(); break; case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - if (hbm_get_state()) - hbm_set_state(false); + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); break; case SETTING_BRIGHTNESS_AUTOMATIC_ON: set_brightness_changed_state(); @@ -177,11 +141,198 @@ static void set_automatic_state_cb(keynode_t *key_nodes, void *data) } } +static void change_flag(bool *flag, bool value) +{ + // previous + int plbm = lbm; + int phbm = hbm; + int phold = hold; + int pld = lowdim; + + if (flag != &lbm && flag != &hbm && flag != &hold && flag != &lowdim) { + _E("Invalid flag setting."); + return; + } + + if (*flag == value) + return; + + // update + *flag = value; + + _D("Change flag LBM/HBM/Hold/LowDim: %d%d%d%d -> %d%d%d%d", + plbm, phbm, phold, pld, + lbm, hbm, hold, lowdim); +} + +int auto_brightness_control(enum brightness_request_e request, int set_brightness) +{ + int default_brightness; + int current_brightness; + int ret; + + default_brightness = backlight_ops.get_default_brt(); + backlight_ops.get_brightness(¤t_brightness); + + if (request == BR_LBM_ON) { + if (!get_lbm_setting()) + return 0; + if (!lbm && !hbm && !hold && !lowdim) { + change_brightness_transit(default_brightness, lbm_down_brt(default_brightness)); + lbm_set_state(true); + backlight_ops.set_brightness(default_brightness); + change_flag(&lbm, 1); + } else if (!lbm && !hbm && !hold && lowdim) { + change_brightness_transit(current_brightness, lbm_down_brt(current_brightness)); + lbm_set_state(true); + backlight_ops.set_brightness(current_brightness); + change_flag(&lbm, 1); + } else if (!lbm && !hbm && hold) { + change_flag(&lbm, 1); + } + } else if (request == BR_HBM_ON) { + if (!lbm && !hbm && !hold) { + if (!lowdim) + change_brightness_transit(default_brightness, PM_MAX_BRIGHTNESS); + else + change_brightness_transit(current_brightness, PM_MAX_BRIGHTNESS); + hbm_set_state(true); + change_flag(&hbm, 1); + } else if (!lbm && !hbm && hold) { + _E("Someone holds brightness, HBM is ignored."); + return -EBUSY; + } + } else if (request == BR_HOLD_BRIGHTNESS) { + if (hbm) { + _E("HBM state. Hold brightness is ignored."); + return -EBUSY; + } + if (lbm && !hold) { + lbm_set_state(false); + change_brightness_transit(lbm_down_brt(current_brightness), set_brightness); + } else { + backlight_ops.set_brightness(set_brightness); + } + change_flag(&hold, 1); + } else if (request == BR_LOWDIM_ON) { + if (!lowdim) { + if (!hbm && !hold && pm_cur_state == S_NORMAL) + backlight_ops.dim(); + change_flag(&lowdim, 1); + } + } else if (request == BR_LBM_OFF) { + if (lbm && !hold) { + lbm_set_state(false); + change_flag(&lbm, 0); + + /* called by DEVICE_NOTIFIER_LCD_OFF_COMPLETE, no need to change brightness */ + if (pm_cur_state != S_NORMAL) + return 0; + + if (!lowdim) { + change_brightness_transit(lbm_down_brt(default_brightness), default_brightness); + backlight_ops.set_brightness(default_brightness); + } else { + backlight_ops.dim(); + } + } else if (lbm && hold) { + change_flag(&lbm, 0); + } + } else if (request == BR_HBM_OFF) { + if (hbm) { + hbm_set_state(false); + if (!lowdim) + change_brightness_transit(PM_MAX_BRIGHTNESS, default_brightness); + else + change_brightness_transit(PM_MAX_BRIGHTNESS, PM_DIM_BRIGHTNESS); + change_flag(&hbm, 0); + } + } else if (request == BR_RELEASE_BRIGHTNESS) { + if (!lbm && hold) { + change_flag(&hold, 0); + + /* called by DEVICE_NOTIFIER_LCD_OFF_COMPLETE, no need to change brightness */ + if (pm_cur_state != S_NORMAL) + return 0; + + if (!lowdim) + backlight_ops.set_brightness(default_brightness); + else + backlight_ops.dim(); + } else if (lbm && hold) { + change_flag(&hold, 0); + if (!lowdim) { + change_brightness_transit(current_brightness, lbm_down_brt(default_brightness)); + lbm_set_state(true); + backlight_ops.set_brightness(default_brightness); + } else { + change_brightness_transit(current_brightness, lbm_down_brt(PM_DIM_BRIGHTNESS)); + lbm_set_state(true); + backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); + } + } + } else if (request == BR_LOWDIM_OFF) { + if (lowdim) { + if (!hbm && !hold && pm_cur_state == S_NORMAL) + backlight_ops.update(); + change_flag(&lowdim, 0); + } + } else if (request == BR_SET_BRIGHTNESS) { + if (lbm && hold) + lbm_set_state(true); + change_flag(&lowdim, 0); + change_flag(&hold, 0); + backlight_ops.set_default_brt(set_brightness); + if (!hbm) { + ret = backlight_ops.set_brightness(set_brightness); + if (ret < 0) { + _E("Failed to set brightness to %d.", set_brightness); + return ret; + } + } + ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, set_brightness); + if (ret < 0) + _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); + } else { + _E("Invalid request, %d", request); + return -EINVAL; + } + + return 0; +} + +static int display_off_changed(void *data) +{ + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); + + return 0; +} + +static int display_off_complete_changed(void *data) +{ + auto_brightness_control(BR_LBM_OFF, BR_IMPLICIT); + auto_brightness_control(BR_RELEASE_BRIGHTNESS, BR_IMPLICIT); + + return 0; +} + +/* restore brightness on recovering battery health to normal */ +int auto_brightness_restore(void) +{ + /* maintain hold brightness */ + if (hold) + return 0; + + /* update to the default brightness */ + return backlight_ops.update(); +} + int prepare_level_handler(void) { int status, ret; display_info.set_brightness_level = set_brightness_level; + disp_plgn.auto_brightness_control = auto_brightness_control; ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); if (ret >= 0) @@ -190,6 +341,9 @@ int prepare_level_handler(void) vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, set_automatic_state_cb, NULL); + register_notifier(DEVICE_NOTIFIER_LCD_OFF, display_off_changed); + register_notifier(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, display_off_complete_changed); + return 0; } @@ -198,4 +352,7 @@ void exit_level_handler(void) vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, set_automatic_state_cb); set_default_brightness(); + + unregister_notifier(DEVICE_NOTIFIER_LCD_OFF, display_off_changed); + unregister_notifier(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, display_off_complete_changed); } diff --git a/plugins/wearable/display/auto-brightness-sensorhub.h b/plugins/wearable/display/auto-brightness-sensorhub.h index afa306a..0b8e3f8 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.h +++ b/plugins/wearable/display/auto-brightness-sensorhub.h @@ -28,7 +28,100 @@ #define LBM_LEVEL 110 #define HBM_LEVEL 120 +#include "display/display.h" + int prepare_level_handler(void); void exit_level_handler(void); +/* Control brightness considering various situations overlap each other, such as + * HBM on/off, LBM on/off, Hold on/off, LowDim on/off, DimStay, Set + * + * [State and Flag] + * Brightness is managed by 4 flag + * L H Ho Ld + * 0 0 0 0 + * (L: LBM / H: HBM / Ho: Hold / Ld: Lowbattery Dim) + * + * State is combination of those 4 flags, for example + * 0010 -> Only hold brightness is enabled + * 1011 -> LBM, Hold, Lowbattery dim enabled + * + * There are state pairs that cannot be both enabled. + * LBM and HBM cannot be both enabled. + * - On eabling one, always disables the other one. + * HBM and Hold cannot be both enabled. + * - An request that arrives first takes priority over request arrives later. + * First arriving one is enabled and the later one is ignored. + * + * And there is a special state related to brightness, abnormal battery health. + * This is not managed by using flag because it only makes brightness dim temporarily, + * and all controlling brightness works the way it was regardless of whether + * the abnormal battery health is happened. The only thing to do is deciding the brightness + * to restore when battery health returned to normal, default or hold brightness. For example, + * Default(70) -> Abnormal(Dim) -> Normal : restore to default brightness 70 + * Default(70) -> Hold(100) -> Abnormal(Dim) -> Normal : restore to hold brightness 100 + * + * [Request] + * There are 9 requests, 4 are enabling request, 4 are disabling request, and 1 is set request. + * Enabling request : LBM on, HBM on, Hold, LowbatteryDim on + * Disabling request: LBM off, HBM off, Release, LowbatteryDim off + * Set request: set default brightness and changes brightness to default. Set by user. + * + * [Policy] + * Define action(flag setting and brightness change) by request and state. + * + * Request LBM on + * - State 0000, 0001: enable LBM. change brightness to default(0000) or dim(0001) + * - State 0010, 0011: do not enable LBM as someone holds brightness + * - Set L flag to the above states + * + * Request HBM on + * - State 0000, 0001: Only these state can be enablied with HBM. + * Change brightness to MAX and enable HBM. + * - Set H flag to the above states + * + * Request Hold + * - State 0000, 0001: change brightness to hold brightness + * - State 0010, 0011, 1010, 1011: As Hold flag has already been set, just change + * brightness to request one + * - State 1000, 1001: If LBM has been enabled and nobody holds brightness, then + * disable LBM first and apply Hold brightness + * Set Ho flag to the above states + * + * Request Lowbattery Dim on + * - State 0000, 1000: change brightness to dim + * - State 0010, 0100, 1010: do nothing as someone request HBM/Hold request. At these + * states, stay that brightness, not to change to dim brightness + * - Set Ld flag to the above states + * + * Request LBM off + * - State 1000, 1001: disable LBM, change brightness to default(1000) or dim(1001) + * - State 1010, 1011: do nothing as these state, LBM have already been disabled as + * someone had requested HBM/Hold. Stay that brightness + * - Unset L flag to the above states + * + * Request HBM off + * - State 0100, 0101: disable HBM, change brightness to default(0010) or dim(0011) + * - Unset H flag to the above states + * + * Request Release + * - State 0010, 0011: change brightness to default(0010) or dim(0011) + * - State 1010, 1011: enable LBM, change brightness to default(1010) or dim(1011) + * - Unset Ho flag to the above states + * + * Request Lowbattery Dim off + * - State 0001, 1001: change brightness to default + * - State 0011, 0101, 1011: do nothing as someone request HBM/Hold request + * - Unset Ld flag to the above states + * + * Request brightness set + * - For all possible states, Set default brightness, Update brightness vconf + * - For states that HBM disabled, change brightness to default brightness. + * - Unset Ho, Ld flag to the states that H flag isn't set. + */ +int auto_brightness_control(enum brightness_request_e request, int set_brightness); + +/* Restore brightness on recovering battery health to normal */ +int auto_brightness_restore(void); + #endif diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 5e2fc8c..e6c3fae 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -39,6 +39,7 @@ #include #include +#include "auto-brightness-sensorhub.h" #include "ambient-mode.h" #include "util.h" #include "core.h" @@ -1751,13 +1752,13 @@ static int default_check(int curr, int next) static void default_saving_mode(int onoff) { - if (onoff) + if (onoff) { pm_status_flag |= PWRSV_FLAG; - else + auto_brightness_control(BR_LOWDIM_ON, BR_IMPLICIT); + } else { pm_status_flag &= ~PWRSV_FLAG; - - if (pm_cur_state == S_NORMAL) - backlight_ops.update(); + auto_brightness_control(BR_LOWDIM_OFF, BR_IMPLICIT); + } } static int poll_callback(int condition, PMMsg *data) @@ -2142,14 +2143,15 @@ static int battery_health_changed(void *data) if (health == HEALTH_GOOD) { pm_status_flag &= ~BATTERY_FLAG; pm_status_flag &= ~DIMSTAY_FLAG; + if (backlight_ops.get_lcd_power() == DPMS_ON) + auto_brightness_restore(); } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { pm_status_flag |= BATTERY_FLAG; pm_status_flag |= DIMSTAY_FLAG; + if (backlight_ops.get_lcd_power() == DPMS_ON) + backlight_ops.update(); } - if (backlight_ops.get_lcd_power() == DPMS_ON) - backlight_ops.update(); - return 0; } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index dc6d70c..0655878 100755 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -304,9 +304,6 @@ bool display_dimstay_check(void) if (pm_status_flag & DIM_FLAG) return true; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) - return true; - return false; } diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index 9ef1014..1c5dd09 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -44,20 +44,27 @@ enum charging_lcd_state { }; static guint autobrt_timer; -static bool lcdon_from_aod; static int autobrtlevel; -static gboolean display_autobrt_changed(gpointer data) -{ +static bool aod_clock_displayed; /* True while AOD screen is displayed */ +static gboolean lcdon_from_aod_cb(gpointer data) +{ int level = (int) data; autobrt_timer = 0; + backlight_ops.transit_state(DPMS_ON); display_info.set_brightness_level(level); + /* lcdon is completed, aod disappered */ + aod_clock_displayed = false; + return G_SOURCE_REMOVE; } +/* For AOD state, there is race condition between + * HomeScreen dbus signal and AutoBrightnessChanged dbus method call. + * Cannot decide which one arrives first */ static GVariant *dbus_autobrightnesschanged(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -74,18 +81,22 @@ static GVariant *dbus_autobrightnesschanged(GDBusConnection *conn, } if (display_info.set_brightness_level) { - if (autobrt_timer) + if (autobrt_timer) { g_source_remove(autobrt_timer); + autobrt_timer = 0; + } + + device_notify(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, NULL); /* When display state changes from AOD to LCDON, brightness change * effect seems sluggish because of heavy load of jobs for turning on * display. So delay this brightness change a bit to avoid this * heavy loaded time and therefore make it change smoothly. */ - if (lcdon_from_aod) { - autobrtlevel = level; - autobrt_timer = g_timeout_add(200, display_autobrt_changed, (gpointer)level); - } else { - display_autobrt_changed((gpointer)level); + if (aod_clock_displayed) { + autobrtlevel = level; /* reserve the level, defer applying */ + autobrt_timer = g_timeout_add(200, lcdon_from_aod_cb, (gpointer)level); + } else { /* S_NORMAL state or LCDON from usual OFF state, not from AOD */ + display_info.set_brightness_level(level); } } else { ret = -ENOTSUP; @@ -118,13 +129,24 @@ static void aod_change_signal(GDBusConnection *conn, /* clock-viewer sends "clockchanged" as signal parameter when AOD->LCDON. * On catching this signal, do change brightness immediately. */ if (!strcmp(screen, CLOCK_CHANGED)) { - lcdon_from_aod = false; - if (autobrt_timer) { + /* aod_clock_displayed can be false if this clockchanged siganl arrives after 200ms timeout. + * In this situation, there is noting to do because all the + * brightness-related task, which should have been done in this routine, + * have been performed by timeout callback, lcdon_from_aod_cb(). */ + if (!aod_clock_displayed) + return; + + backlight_ops.transit_state(DPMS_ON); + if (autobrt_timer) { /* if there is reserved level, apply it */ g_source_remove(autobrt_timer); - display_autobrt_changed((gpointer)autobrtlevel); + autobrt_timer = 0; + display_info.set_brightness_level(autobrtlevel); } + /* lcdon is completed, aod disappered */ + aod_clock_displayed = false; } else if (!strcmp(screen, CLOCK_END)) { - lcdon_from_aod = true; + /* lcdoff is completed, aod showed up */ + aod_clock_displayed = true; } out: @@ -168,7 +190,7 @@ static void display_handler_init(void *data) prepare_level_handler(); register_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); - lcdon_from_aod = false; + aod_clock_displayed = false; ret = subscribe_dbus_signal(NULL, DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME, diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c index e5e132e..27fc2ca 100644 --- a/plugins/wearable/display/hbm.c +++ b/plugins/wearable/display/hbm.c @@ -19,6 +19,7 @@ #include #include +#include "auto-brightness-sensorhub.h" #include "weaks.h" #include "display-info.h" #include "display/util.h" @@ -71,29 +72,15 @@ static void hbm_set_offtime(int timeout) static gboolean hbm_off_cb(void *data) { - int ret; - timer = 0; if (pm_cur_state != S_NORMAL) { _D("Hbm timeout, but it's not display normal."); return G_SOURCE_REMOVE; } - hbm_set_offtime(0); - - ret = sys_set_str(hbm_path, OFF); - if (ret < 0) - _E("Failed to off hbm."); - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, - display_conf.pm_default_brightness); - if (ret < 0) { - _E("Failed to set vconf value lcd brightness, %d.", ret); - return G_SOURCE_REMOVE; - } - backlight_ops.set_default_brt(display_conf.pm_default_brightness); - backlight_ops.update(); - broadcast_hbm_state(SIGNAL_HBM_OFF); + hbm_set_offtime(0); + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); return G_SOURCE_REMOVE; } @@ -141,6 +128,7 @@ int hbm_get_state(void) int hbm_set_state(int hbm) { + int ret; if (!hbm_path) return -ENODEV; @@ -149,19 +137,11 @@ int hbm_set_state(int hbm) else broadcast_hbm_state(SIGNAL_HBM_OFF); - return sys_set_str(hbm_path, (hbm ? ON : OFF)); -} - -static void hbm_turn_on(void) -{ - if (!hbm_get_state()) - hbm_set_state(true); -} + ret = sys_set_str(hbm_path, (hbm ? ON : OFF)); + if (ret < 0) + _E("Failed to HBM %s.", hbm ? "ON" : " OFF"); -static void hbm_turn_off(void) -{ - if (hbm_get_state()) - hbm_set_state(false); + return ret; } static int hbm_set_state_with_timeout(int hbm, int timeout) @@ -171,7 +151,11 @@ static int hbm_set_state_with_timeout(int hbm, int timeout) if (hbm && (timeout <= 0)) return -EINVAL; - ret = hbm_set_state(hbm); + if (hbm) + ret = auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); + else + ret = auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); + if (ret < 0) return ret; @@ -186,7 +170,6 @@ static int hbm_set_state_with_timeout(int hbm, int timeout) } else { hbm_set_offtime(0); hbm_end_timer(); - broadcast_hbm_state(SIGNAL_HBM_OFF); } return 0; @@ -195,7 +178,6 @@ static int hbm_set_state_with_timeout(int hbm, int timeout) static void hbm_check_timeout(void) { struct timespec now; - int ret; if (timer) { g_source_remove(timer); @@ -203,10 +185,8 @@ static void hbm_check_timeout(void) } if (offtime.tv_sec == 0) { - if (hbm_get_state() == true) { - _E("It's invalid state. HBM is turned off."); - hbm_set_state(false); - } + _E("It's invalid state. HBM is turned off."); + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); return; } @@ -216,64 +196,14 @@ static void hbm_check_timeout(void) /* check it's timeout */ if (now.tv_sec >= offtime.tv_sec) { hbm_set_offtime(0); - - ret = sys_set_str(hbm_path, OFF); - if (ret < 0) - _E("Failed to off HBM."); - backlight_ops.update(); - broadcast_hbm_state(SIGNAL_HBM_OFF); + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); } else { _D("HBM state is restored."); - hbm_set_state(true); + auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); hbm_start_timer(offtime.tv_sec - now.tv_sec); } } -static void hbm_get_level(GVariant *var, void *user_data, GError *err) -{ - int level, brt; - - if (!var) { - _D("Invalid parameter."); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &level)) { - _E("Failed to get message, %s.", g_variant_get_type_string(var)); - goto out; - } - - if (level == HBM_LEVEL && hbm_get_state() == false) { - _I("Lux was high already, HBM enable"); - backlight_ops.get_brightness(&brt); - backlight_ops.transit_brt(brt, PM_MAX_BRIGHTNESS, - display_conf.brightness_change_step); - hbm_set_state(true); - } -out: - g_variant_unref(var); -} - -static gboolean hbm_check_handler(gpointer data) -{ - int ret; - - ret = dbus_handle_method_async_with_reply(COORD_BUS_NAME, - COORD_PATH_AUTOBRIGHTNESS, - COORD_INTERFACE_AUTOBRIGHTNESS, - "GetLevel", - NULL, - NULL, - hbm_get_level, - -1, - NULL); - - if (ret < 0) - _D("Failed to call coord.autobrightness.GetLevel method, %d", ret); - - return G_SOURCE_REMOVE; -} - static int display_state_changed(void *data) { int state; @@ -295,17 +225,13 @@ static int display_state_changed(void *data) */ if (!get_outdoor_setting || pm_old_state == S_LCDDIM) hbm_check_timeout(); - - (void) g_timeout_add(300, hbm_check_handler, NULL); break; case S_LCDDIM: case S_LCDOFF: case S_SLEEP: - if (hbm_get_state() == true) { - ret = hbm_set_state(false); - if (ret < 0) - _E("Failed to off hbm."); - } + ret = auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); + if (ret < 0) + _E("Failed to off hbm."); hbm_end_timer(); break; } @@ -313,24 +239,6 @@ static int display_state_changed(void *data) return 0; } -static int display_off_changed(void *data) -{ - int brt; - - if (hbm_get_state() == false) - return 0; - - hbm_turn_off(); - - brt = backlight_ops.get_default_brt(); - if (pm_status_flag & DIMSTAY_FLAG) - _D("skip auto change brightness"); - else - backlight_ops.transit_brt(PM_MAX_BRIGHTNESS, brt, display_conf.brightness_change_step); - - return 0; -} - static GVariant *dbus_gethbm(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -378,7 +286,6 @@ static const dbus_interface_u dbus_interface = { static int hbm_func(unsigned int cmd, void *arg) { int ret = 0; - int *on; struct hbmsetstate *hss; switch (cmd) { @@ -386,22 +293,22 @@ static int hbm_func(unsigned int cmd, void *arg) ret = hbm_get_state(); break; case HBM_SET_STATE: - on = (int *)arg; - ret = hbm_set_state(*on); + if ((int *)arg) + ret = auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); + else + ret = auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); break; case HBM_TURN_ON: - hbm_turn_on(); + ret = auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); break; case HBM_TURN_OFF: - hbm_turn_off(); + case HBM_TURN_OFF_STATE: + ret = auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); break; case HBM_SET_TIMEOUT_STATE: hss = (struct hbmsetstate *)arg; ret = hbm_set_state_with_timeout(hss->hbm, hss->timeout); break; - case HBM_TURN_OFF_STATE: - hbm_turn_off(); - break; default: ret = -EINVAL; break; @@ -479,13 +386,11 @@ static void hbm_init(void *data) /* register notifier */ register_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); - register_notifier(DEVICE_NOTIFIER_LCD_OFF, display_off_changed); } static void hbm_exit(void *data) { /* unregister notifier */ - unregister_notifier(DEVICE_NOTIFIER_LCD_OFF, display_off_changed); unregister_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); /* diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index 2f7a452..18d71a6 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -19,6 +19,7 @@ #include #include +#include "auto-brightness-sensorhub.h" #include "lbm.h" #include "display-info.h" #include "display/util.h" @@ -45,7 +46,6 @@ struct lbm_config lbm_conf = { .aod_brightness_level = 0, }; -static bool lbm_state; static int lbm_setting_mode; static int system_brightness; static struct display_device *display_dev; @@ -76,7 +76,7 @@ static int get_level_by_brt(int brt) return -EINVAL; } -static int lbm_down_brt(int brt) +int lbm_down_brt(int brt) { int level; int down_level; @@ -100,19 +100,8 @@ static int lbm_down_brt(int brt) return lbm_conf.brt_table[down_level]; } -int lbm_get_state(void) -{ - if (!lbm_conf.support) - return -ENODEV; - - return lbm_state; -} - static int lbm_get_brightness(int *val) { - if (system_brightness == 0) - _E("Failed to get brightness."); - *val = system_brightness; return 0; @@ -199,39 +188,28 @@ static void lbm_change_brightness(int start, int end, int step) int lbm_set_state(int lbm) { - int brt; - _I("lbm_set_state"); - - if (lbm == lbm_state) { - _W("already lbm %s", (lbm_state ? "on" : "off")); - return 0; - } - - if (!lbm || lbm_setting_mode) { - lbm_state = lbm; - broadcast_lbm_state(lbm_state); - } + _I("lbm_set_state, %d", lbm); - brt = backlight_ops.get_default_brt(); - _I("Default brightness: %d", brt); - if (lbm && lbm_setting_mode) { - _I("Lowering Brightness."); - backlight_ops.transit_brt(brt, lbm_down_brt(brt), LBM_TRANSIT_STEP); - backlight_ops.get_brightness(&system_brightness); + broadcast_lbm_state(lbm); + if (lbm) { backlight_ops.set_brightness = lbm_set_brightness; backlight_ops.get_brightness = lbm_get_brightness; backlight_ops.transit_brt = lbm_change_brightness; } else { - system_brightness = 0; backlight_ops.restore_brightness_func(); - backlight_ops.transit_brt(lbm_down_brt(brt), brt, display_conf.brightness_change_step); } - backlight_ops.set_brightness(brt); - return 0; } +int lbm_get_state(void) +{ + if (!lbm_conf.support) + return -ENODEV; + + return backlight_ops.set_brightness == lbm_set_brightness; +} + static void lbm_table_load(char *value, struct lbm_config *c) { char *p, *saveptr; @@ -299,21 +277,12 @@ static void lbm_mode_changed(keynode_t *key_nodes, void *data) lbm_setting_mode = mode; - if (lbm_get_state()) - lbm_set_state(false); + auto_brightness_control(BR_LBM_OFF, BR_IMPLICIT); } -static int display_off_changed(void *data) +bool get_lbm_setting(void) { - int brt; - - backlight_ops.get_brightness(&brt); - backlight_ops.restore_brightness_func(); - backlight_ops.set_brightness(brt); - - lbm_state = 0; - - return 0; + return lbm_setting_mode; } static GVariant *dbus_getlbm(GDBusConnection *conn, @@ -363,9 +332,6 @@ static void lbm_init(void *data) display_dev = display_dev_get(); _I("LBM setting value is %d.", lbm_setting_mode); - - /* register notifier */ - register_notifier(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, display_off_changed); } static const struct display_ops display_lbm_ops = { diff --git a/plugins/wearable/display/lbm.h b/plugins/wearable/display/lbm.h index 9401ac6..98ab935 100644 --- a/plugins/wearable/display/lbm.h +++ b/plugins/wearable/display/lbm.h @@ -42,6 +42,8 @@ extern struct lbm_config lbm_conf; int lbm_get_state(void); int lbm_set_state(int lbm); +int lbm_down_brt(int brt); +bool get_lbm_setting(void); /** * @} diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index a2ffc01..0ba5e5f 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -42,6 +42,7 @@ #include "dd-display.h" #include "display-actor.h" #include "display-ops.h" +#include "display.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" @@ -443,15 +444,18 @@ static GVariant *dbus_setbrightness(GDBusConnection *conn, pm_status_flag &= ~DIM_MASK; - backlight_ops.set_default_brt(brt); 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()); + if (disp_plgn.auto_brightness_control) { + ret = disp_plgn.auto_brightness_control(BR_SET_BRIGHTNESS, brt); + } else { + backlight_ops.set_default_brt(brt); + 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); @@ -503,7 +507,11 @@ static GVariant *dbus_holdbrightness(GDBusConnection *conn, 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 (disp_plgn.auto_brightness_control) + ret = disp_plgn.auto_brightness_control(BR_HOLD_BRIGHTNESS, brt); + else + ret = backlight_ops.set_brightness(brt); + if (ret < 0) goto error; @@ -570,7 +578,7 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, brt = ret; // check dim state - if (low_battery_state(bat) && + if (!disp_plgn.auto_brightness_control && low_battery_state(bat) && charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { _D("batt warning low : brightness is not changed!"); if (brt != 0) @@ -579,8 +587,12 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, } if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); + if (disp_plgn.auto_brightness_control) { + disp_plgn.auto_brightness_control(BR_RELEASE_BRIGHTNESS, BR_IMPLICIT); + } else { + 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); diff --git a/src/display/display-ops.h b/src/display/display-ops.h index 49a36ea..2842837 100644 --- a/src/display/display-ops.h +++ b/src/display/display-ops.h @@ -23,6 +23,7 @@ #include #include "core/common.h" #include "core/devices.h" +#include "display.h" struct display_ops { char *name; @@ -67,6 +68,7 @@ struct display_plugin { int (*get_lock_screen_state) (); bool system_wakeup_flag; const char* (*device_flags_to_string) (enum device_flags flags); + int (*auto_brightness_control) (enum brightness_request_e request, int set_brightness); }; extern struct display_plugin disp_plgn; diff --git a/src/display/display.h b/src/display/display.h index 3b14241..7443039 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -24,4 +24,30 @@ #include "core/common.h" void lcd_direct_control(enum dpms_state state, int flags); + +enum brightness_request_e { + BR_MIN = 0, + /* entering request */ + BR_LBM_ON, + BR_HBM_ON, + BR_HOLD_BRIGHTNESS, + BR_LOWDIM_ON, /* low battery dim */ + + /* exiting request */ + BR_LBM_OFF, + BR_HBM_OFF, + BR_RELEASE_BRIGHTNESS, + BR_LOWDIM_OFF, /* low battery dim off */ + + /* special */ + BR_SET_BRIGHTNESS, + + BR_MAX, +}; + +/* request for brightness that managed internally. + * BR_HOLD_BRIGHTNESS and BR_SET_BRIGHTNESS does not use this implicit brightness + * for request, but explicitly request for a brightness value */ +#define BR_IMPLICIT (-1) + #endif -- 2.7.4 From 9e4fc570daae503c1cff39835486d93f7e7e52e8 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 7 Jul 2020 17:16:19 +0900 Subject: [PATCH 04/16] Add vibration intensity control logic for bezel Change-Id: I1025c52aa25e549bd56b35d54a570fd5078813d7 Signed-off-by: Youngjae Cho (cherry picked from commit fd2915816cc1dd60ec856fea0afaa3649b5154bb) --- plugins/wearable/display/bezel.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 3c94acb..4817c6b 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -31,6 +31,10 @@ #define VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE "db/setting/wakeup_by_bezel_enable" #endif +#ifndef VCONFKEY_SETAPPL_TOUCH_BEZEL_FEEDBACK_VIBRATION_LEVEL_INT +#define VCONFKEY_SETAPPL_TOUCH_BEZEL_FEEDBACK_VIBRATION_LEVEL_INT "db/setting/touch_bezel/feedback/vibration_level" +#endif + enum bezel_type { BEZEL_NOTSUP = 0, BEZEL_HARD, @@ -108,6 +112,31 @@ static void bezel_rotary_event_cb(keynode_t *key_nodes, void *data) } } +static void bezel_rotary_vibration_set_state(int state) +{ + int ret; + + if (!bezel_dev) + return; + + ret = bezel_dev->set_vib_state(state); + if (ret < 0) + _E("Can't set vib state %d (ret %d)", state, ret); +} + +static void bezel_rotary_vibration_changed_cb(keynode_t *key_nodes, void *data) +{ + int bezel_vib_state; + + assert(key_nodes); + + bezel_vib_state = vconf_keynode_get_int(key_nodes); + + _I("bezel rotary vibration state is %d", bezel_vib_state); + + bezel_rotary_vibration_set_state(bezel_vib_state); +} + static int bezel_probe(void *data) { struct hw_info *info; @@ -140,6 +169,7 @@ static void bezel_init(void *data) { int ret; int bezel_rotary_event; + int bezel_vib_state = -1; enum bezel_state init_bezel_state; if (!bezel_dev) @@ -181,6 +211,8 @@ static void bezel_init(void *data) _E("Failed to get vconf value for goodnight mode: %d.", vconf_get_ext_errno()); } else if (bezel_type == BEZEL_SOFT) { vconf_notify_key_changed(VCONFKEY_SETAPPL_ROTARY_EVENT_ENABLED_BOOL, bezel_rotary_event_cb, NULL); + vconf_notify_key_changed(VCONFKEY_SETAPPL_TOUCH_BEZEL_FEEDBACK_VIBRATION_LEVEL_INT, + bezel_rotary_vibration_changed_cb, NULL); ret = vconf_get_bool(VCONFKEY_SETAPPL_ROTARY_EVENT_ENABLED_BOOL, &bezel_rotary_event); if (ret == 0) { @@ -192,7 +224,14 @@ static void bezel_init(void *data) } else { _E("Failed to get vconf value for rotary event by bezen enabled: %d.", vconf_get_ext_errno()); } + + ret = vconf_get_int(VCONFKEY_SETAPPL_TOUCH_BEZEL_FEEDBACK_VIBRATION_LEVEL_INT, &bezel_vib_state); + if (ret == 0) + bezel_rotary_vibration_set_state(bezel_vib_state); + else + _E("Failed to get vconf value for touch bezel feedback vibration level: %d", vconf_get_ext_errno()); } + _I("bezel condition (wakeup:%d) (rotary_event:%d) (bezel_vib_state %d)", bezel_wakeup, bezel_rotary_event, bezel_vib_state); } static void bezel_exit(void *data) -- 2.7.4 From 7496986c48f3c7c73d41517c097c6901f1e8279b Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 7 Jul 2020 18:17:32 +0900 Subject: [PATCH 05/16] Fix coverity issue Change-Id: Ia9a1a6aa32514a482ce64345088ad99be59e9634 Signed-off-by: Youngjae Cho --- plugins/wearable/display/bezel.c | 2 +- src/auto-test/brightness.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 4817c6b..8258be8 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -168,7 +168,7 @@ static int bezel_probe(void *data) static void bezel_init(void *data) { int ret; - int bezel_rotary_event; + int bezel_rotary_event = -1; int bezel_vib_state = -1; enum bezel_state init_bezel_state; diff --git a/src/auto-test/brightness.c b/src/auto-test/brightness.c index bb25d3c..301ca2b 100644 --- a/src/auto-test/brightness.c +++ b/src/auto-test/brightness.c @@ -316,8 +316,10 @@ static void do_test(const char *tcname) int ret = -1; ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, &timeout); - if (ret == 0) - vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 300); + if (ret == 0) { + if (vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 300) < 0) + printf("Failed to set LCDNORMAL timeout.\n"); + } stop_udev(); -- 2.7.4 From 8d7518cfe438ea31ae85f014b1e155617ae904c6 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 8 Jul 2020 11:18:09 +0900 Subject: [PATCH 06/16] Fix coverity issue Change-Id: Ia09f20d916d8128c07aea903dca24a5afa5a562e Signed-off-by: Youngjae Cho --- src/auto-test/brightness.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/auto-test/brightness.c b/src/auto-test/brightness.c index 301ca2b..97d9912 100644 --- a/src/auto-test/brightness.c +++ b/src/auto-test/brightness.c @@ -318,7 +318,7 @@ static void do_test(const char *tcname) ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, &timeout); if (ret == 0) { if (vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 300) < 0) - printf("Failed to set LCDNORMAL timeout.\n"); + printf("Failed to set LCDNORMAL timeout, %d.\n", vconf_get_ext_errno()); } stop_udev(); @@ -347,8 +347,10 @@ static void do_test(const char *tcname) printf("Success: %d, Fail: %d\n", success, fail); start_udev(); - if (ret == 0) - vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, timeout); + if (ret == 0) { + if (vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, timeout) < 0) + printf("Failed to restore LCDNORMAL timeout, %d.\n", vconf_get_ext_errno()); + } } static void brightness_init(void *data) -- 2.7.4 From 5fc046ee4a2541e395017063a63ee4d98dab504f Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 7 Jul 2020 19:46:49 +0900 Subject: [PATCH 07/16] Change global variable to static one Change-Id: I371c2bb10dd31fd0080c6c87a62b27be9891a5fa Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 4 ++-- plugins/mobile/display/core.c | 4 ++-- plugins/tv/display/core.c | 4 ++-- plugins/tv/display/state-tv.c | 2 +- plugins/wearable/display/core.c | 4 ++-- plugins/wearable/display/lbm.c | 2 +- plugins/wearable/display/lbm.h | 6 ------ src/battery-monitor/battery-monitor.c | 6 +++--- src/battery-monitor/battery-monitor.h | 2 -- src/core/log.c | 2 +- src/led/touch-key.c | 2 +- src/power-shutdown/shutdown.c | 2 +- src/shared/plugin.c | 2 +- src/time/time-handler.c | 2 +- src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c | 12 ++++++------ src/usb/usb.c | 2 +- src/usbhost/usb-host.c | 8 ++++---- 17 files changed, 29 insertions(+), 37 deletions(-) mode change 100755 => 100644 src/shared/plugin.c diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 764effe..896f0b2 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -97,8 +97,8 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; -guint timeout_src_id; -int system_wakeup_flag = false; +static guint timeout_src_id; +static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 71f2ea3..90a2222 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -99,8 +99,8 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; -guint timeout_src_id; -int system_wakeup_flag = false; +static guint timeout_src_id; +static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index fd2c5cc..40864ba 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -97,8 +97,8 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; -guint timeout_src_id; -int system_wakeup_flag = false; +static guint timeout_src_id; +static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 435ae19..9dd39d3 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -527,7 +527,7 @@ static void set_tv_operations(enum state_t st, change_state_action(st, action); } -struct _tv_states { +static struct _tv_states { enum state_t state; char *name; int (*check)(int curr, int next); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index e6c3fae..0f61aab 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -104,8 +104,8 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; -guint timeout_src_id; -int system_wakeup_flag = false; +static guint timeout_src_id; +static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index 18d71a6..3d19dd2 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -38,7 +38,7 @@ #define LBM_TRANSIT_STEP 20 -struct lbm_config lbm_conf = { +static struct lbm_config lbm_conf = { .support = 0, .down_level = 0, .brt_table_size = 0, diff --git a/plugins/wearable/display/lbm.h b/plugins/wearable/display/lbm.h index 98ab935..cec29d6 100644 --- a/plugins/wearable/display/lbm.h +++ b/plugins/wearable/display/lbm.h @@ -34,12 +34,6 @@ struct lbm_config { int aod_brightness_level; }; -/* - * Global variables - * lbm_conf : configuration of lbm - */ -extern struct lbm_config lbm_conf; - int lbm_get_state(void); int lbm_set_state(int lbm); int lbm_down_brt(int brt); diff --git a/src/battery-monitor/battery-monitor.c b/src/battery-monitor/battery-monitor.c index fdae897..50e719a 100644 --- a/src/battery-monitor/battery-monitor.c +++ b/src/battery-monitor/battery-monitor.c @@ -33,7 +33,7 @@ #define DBUS_DEVICED_BM_MEMBER "GetBMData" /* battery-monitor interface */ -_battery_monitor_ops bm_ops; +static _battery_monitor_ops bm_ops; typedef enum { B_LOW = 0, @@ -52,7 +52,7 @@ static enum state_t prev_lcd_state = S_LCDOFF; * key(appid) : (char *) * val(elapsed time/ms) : (unsigned int *) */ -GHashTable *ht_apptime; +static GHashTable *ht_apptime; static bool bm_started = false; static struct timespec bm_time_start; @@ -125,7 +125,7 @@ static void bds_timer_start(void) } /* dbus signal subscription id : AppStatusChange */ -guint dbus_sub_id; +static guint dbus_sub_id; static void init_bds_brightness_time(void) { diff --git a/src/battery-monitor/battery-monitor.h b/src/battery-monitor/battery-monitor.h index 25dde1e..542eb73 100644 --- a/src/battery-monitor/battery-monitor.h +++ b/src/battery-monitor/battery-monitor.h @@ -27,8 +27,6 @@ typedef struct { int (*update_bds_brightness_record)(unsigned int val); } _battery_monitor_ops; -extern _battery_monitor_ops bm_ops; - int update_bds_record(enum state_t lcd_state); int update_bds_brightness_record(unsigned int val); diff --git a/src/core/log.c b/src/core/log.c index bd629a8..679eee8 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -27,7 +27,7 @@ void __cyg_profile_func_enter(void *, void *) void __cyg_profile_func_exit(void *, void *) __attribute__ ((no_instrument_function)); -int g_trace_depth = -2; +static int g_trace_depth = -2; void __cyg_profile_func_enter(void *func, void *caller) { diff --git a/src/led/touch-key.c b/src/led/touch-key.c index 281f0a8..b1dc8f2 100644 --- a/src/led/touch-key.c +++ b/src/led/touch-key.c @@ -44,7 +44,7 @@ #define GET_BRIGHTNESS(val) (((val) >> 24) & 0xFF) #define SET_BRIGHTNESS(val) (((val) & 0xFF) << 24) -struct led_device *touchled_dev; +static struct led_device *touchled_dev; static guint hardkey_timeout_id; static int hardkey_duration; diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c index ddf899e..e1a5d33 100644 --- a/src/power-shutdown/shutdown.c +++ b/src/power-shutdown/shutdown.c @@ -50,7 +50,7 @@ enum { #define UMOUNT_RW_PATH_SYSTEM "/opt" #define MAX_UMOUNT_KILL_RETRY 4 -char *progname; +static char *progname; static int usage(void) { diff --git a/src/shared/plugin.c b/src/shared/plugin.c old mode 100755 new mode 100644 index da0d754..d90315f --- a/src/shared/plugin.c +++ b/src/shared/plugin.c @@ -42,7 +42,7 @@ struct display_plugin disp_plgn; struct battery_plugin battery_plgn; -GList *plgn_list; +static GList *plgn_list; int load_plugin(const char *id, void **h) { diff --git a/src/time/time-handler.c b/src/time/time-handler.c index ad99aa4..5dc56c8 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -67,7 +67,7 @@ static const time_t default_time = 2147483645; /* max(32bit) -3sec */ static guint tfdh; /* tfd change noti */ -int tfd = -1; +static int tfd = -1; static gboolean tfd_cb(gint fd, GIOCondition condition, gpointer user_data); static int timerfd_check_stop(int fd); diff --git a/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c b/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c index fa66a88..0579d18 100644 --- a/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c +++ b/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c @@ -54,13 +54,13 @@ enum { } while (0) #define BUFSIZE 512 -char int_buf[BUFSIZE]; -char bulk_buf[BUFSIZE]; +static char int_buf[BUFSIZE]; +static char bulk_buf[BUFSIZE]; -pthread_cond_t enable_cond = PTHREAD_COND_INITIALIZER; -pthread_cond_t disable_cond = PTHREAD_COND_INITIALIZER; -pthread_mutex_t ready_lock; -int connected = 0; +static pthread_cond_t enable_cond = PTHREAD_COND_INITIALIZER; +static pthread_cond_t disable_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t ready_lock; +static int connected = 0; /* Close all ep files */ void cleanup_ffs(int *ep) diff --git a/src/usb/usb.c b/src/usb/usb.c index f41c9d9..8bff078 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -487,7 +487,7 @@ static void usb_exit(void *data) usb_release(); } -struct extcon_ops extcon_usb_ops = { +static struct extcon_ops extcon_usb_ops = { .name = EXTCON_CABLE_USB, .init = usb_init, .exit = usb_exit, diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 99ab941..48cabf0 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -52,7 +52,7 @@ #define ROOTPATH tzplatform_getenv(TZ_SYS_VAR) #define POLICY_FILENAME "usbhost-policy" -char *POLICY_FILEPATH; +static char *POLICY_FILEPATH; /** * Below usb host class is defined by www.usb.org. @@ -126,9 +126,9 @@ static inline int is_policy_temporary(struct policy_entry *entry) entry->value == POLICY_DENY_NOW; } -dd_list *access_list; +static dd_list *access_list; -struct usbhost_open_request { +static struct usbhost_open_request { GDBusMethodInvocation *invocation; char *path; //struct user_credentials cred; @@ -1200,7 +1200,7 @@ static int extcon_usbhost_state_changed(int status) return 0; } -struct extcon_ops extcon_usbhost_ops = { +static struct extcon_ops extcon_usbhost_ops = { .name = EXTCON_CABLE_USB_HOST, .update = extcon_usbhost_state_changed, }; -- 2.7.4 From d643fd2b712307a29cd2d91c129d5223c7fd693d Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 8 Jul 2020 15:06:42 +0900 Subject: [PATCH 08/16] Move pm_cur_state to display.c to remove global variable Change-Id: If9eb70c2b8fdeff1f4248983fa5d8b07bd6de86b Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 172 ++++++++++---------- plugins/iot/display/device-interface.c | 13 +- plugins/iot/display/key-filter.c | 10 +- plugins/mobile/display/core.c | 174 ++++++++++---------- plugins/mobile/display/device-interface.c | 13 +- plugins/mobile/display/key-filter.c | 8 +- plugins/tv/display/core.c | 178 ++++++++++----------- plugins/tv/display/device-interface.c | 13 +- plugins/tv/display/key-filter.c | 8 +- plugins/tv/display/state-tv.c | 76 ++++----- .../wearable/display/auto-brightness-sensorhub.c | 10 +- plugins/wearable/display/bezel.c | 4 +- plugins/wearable/display/core.c | 176 ++++++++++---------- plugins/wearable/display/device-interface.c | 13 +- plugins/wearable/display/hbm.c | 2 +- plugins/wearable/display/key-filter.c | 8 +- plugins/wearable/display/powersaver.c | 2 +- src/display/ambient-mode.c | 12 +- src/display/auto-brightness.c | 4 +- src/display/core.h | 2 - src/display/display-dbus.c | 8 +- src/display/display.c | 12 ++ src/display/display.h | 2 + 23 files changed, 468 insertions(+), 452 deletions(-) mode change 100755 => 100644 plugins/wearable/display/device-interface.c mode change 100755 => 100644 src/display/ambient-mode.c diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 896f0b2..52de9bf 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -95,7 +95,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_cur_state; int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; @@ -534,7 +533,7 @@ static void del_state_cond(void *data, enum state_t state) set_unlock_time(pid, state); if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) set_process_active(false, pid); @@ -561,14 +560,14 @@ static gboolean del_off_cond(void *data) /* timeout handler */ gboolean timeout_handler(void *data) { - _I("Time out state %s", states[pm_cur_state].name); + _I("Time out state %s", states[get_pm_cur_state()].name); if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; } - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return G_SOURCE_REMOVE; } @@ -577,7 +576,7 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - if (pm_cur_state == S_LCDOFF + if ((get_pm_cur_state() == S_LCDOFF) && (is_emulator() == true || display_conf.sleep_support == false)) return; @@ -587,14 +586,14 @@ void reset_timeout(int timeout) timeout_src_id = 0; } - if (trans_table[pm_cur_state][EVENT_TIMEOUT] == pm_cur_state) + if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state()) return; if (timeout > 0) timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } /* get configurations from setting */ @@ -690,16 +689,16 @@ void set_dim_state(bool on) { _I("Dim state is %d.", on); update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } void lcd_on_direct(enum device_flags flags) { if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) { + && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); power_ops.power_lock(); - pm_cur_state = S_NORMAL; + set_pm_cur_state(S_NORMAL); } _D("lcd is on directly"); @@ -722,9 +721,9 @@ static gboolean timer_refresh_cb(gpointer data) struct state *st; /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; if (st->action) st->action(st->timeout); @@ -747,9 +746,9 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -791,9 +790,9 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -832,9 +831,9 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -876,9 +875,9 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -891,10 +890,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = pm_cur_state; - pm_cur_state = next; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next); - st = &states[pm_cur_state]; + st = &states[get_pm_cur_state()]; if (st && st->action) { if (timeout < 0) @@ -986,8 +985,8 @@ static void proc_condition_lock(PMMsg *data) flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && pm_cur_state == S_SLEEP && - power_ops.get_power_lock() == POWER_UNLOCK) + if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && + (power_ops.get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1114,15 +1113,15 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); } else { if (flags & PM_FLAG_RESET_TIMER) - reset_timeout(states[pm_cur_state].timeout); + reset_timeout(states[get_pm_cur_state()].timeout); } if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return 0; } @@ -1257,7 +1256,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", - states[pm_cur_state].name); + states[get_pm_cur_state()].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1351,7 +1350,7 @@ int check_lcdoff_direct(void) if (pm_old_state != S_NORMAL) return false; - if (pm_cur_state != S_LCDDIM) + if (get_pm_cur_state() != S_LCDDIM) return false; if (!display_conf.dimming) @@ -1384,17 +1383,17 @@ int check_lcdoff_direct(void) */ static int default_trans(int evt) { - struct state *st = &states[pm_cur_state]; + struct state *st = &states[get_pm_cur_state()]; int next_state; - next_state = (enum state_t)trans_table[pm_cur_state][evt]; + next_state = (enum state_t)trans_table[get_pm_cur_state()][evt]; /* check conditions */ - while (st->check && !st->check(pm_cur_state, next_state)) { + while (st->check && !st->check(get_pm_cur_state(), next_state)) { /* There is a condition. */ - _I("%s locked. Trans to %s failed.", states[pm_cur_state].name, + _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(pm_cur_state)) { + if (!check_processes(get_pm_cur_state())) { /* This is valid condition * The application that sent the condition is running now. */ return -1; @@ -1402,24 +1401,24 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = next_state; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next_state); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) { - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDOFF) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) update_display_time(); if (check_lcdoff_direct() == true) { /* enter next state directly */ - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { - if (pm_cur_state == S_SLEEP + if ((get_pm_cur_state() == S_SLEEP) && (is_emulator() == true || display_conf.sleep_support == false)) return 0; @@ -1478,7 +1477,7 @@ static void check_lock_screen(void) /* default enter action function */ static int default_action(int timeout) { - int wakeup_count = -1; + int wakeup_count = -1, pm_cur_state; time_t now; double diff; static time_t last_update_time = 0; @@ -1490,8 +1489,8 @@ static int default_action(int timeout) return -EINVAL; } - if (pm_cur_state != S_SLEEP) { - if (pm_cur_state == S_NORMAL && + if (get_pm_cur_state() != S_SLEEP) { + if ((get_pm_cur_state() == S_NORMAL) && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); @@ -1500,32 +1499,33 @@ static int default_action(int timeout) /* set timer with current state timeout */ reset_timeout(timeout); - if (pm_cur_state == S_NORMAL) { + if (get_pm_cur_state() == S_NORMAL) { time(&last_update_time); last_timeout = timeout; } else { _I("Timout set: %s state %d ms", - states[pm_cur_state].name, timeout); + states[get_pm_cur_state()].name, timeout); } } - if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { + if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); } - set_setting_pmstate(pm_cur_state); + set_setting_pmstate(get_pm_cur_state()); + pm_cur_state = get_pm_cur_state(); device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { + if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[pm_cur_state].name, last_timeout, diff); + states[get_pm_cur_state()].name, last_timeout, diff); } - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: /* * normal state : backlight on and restore @@ -1593,7 +1593,7 @@ static int default_action(int timeout) go_suspend: #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, pm_cur_state); + pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { @@ -1609,17 +1609,17 @@ go_suspend: /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); else /* system waked up by user input */ - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } return 0; go_lcd_off: if (!power_ops.get_power_lock_support()) { /* Resume !! */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); } return 0; } @@ -1670,7 +1670,7 @@ static void default_saving_mode(int onoff) else pm_status_flag &= ~PWRSV_FLAG; - if (pm_cur_state == S_NORMAL) + if (get_pm_cur_state() == S_NORMAL) backlight_ops.update(); } @@ -1685,13 +1685,13 @@ static int poll_callback(int condition, PMMsg *data) } if (condition == INPUT_POLL_EVENT) { - if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) + if ((get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) _I("Input event signal at Display Off"); time(&now); if (last_t != now || - pm_cur_state == S_LCDOFF || - pm_cur_state == S_SLEEP) { - states[pm_cur_state].trans(EVENT_INPUT); + (get_pm_cur_state() == S_LCDOFF) || + (get_pm_cur_state() == S_SLEEP)) { + states[get_pm_cur_state()].trans(EVENT_INPUT); last_t = now; } } @@ -1713,14 +1713,14 @@ static int update_setting(int key_idx, int val) switch (key_idx) { case SETTING_TO_NORMAL: update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_HALLIC_OPEN: hallic_open = val; update_display_time(); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM) - states[pm_cur_state].trans(EVENT_INPUT); - else if (pm_cur_state == S_SLEEP && hallic_open) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) + states[get_pm_cur_state()].trans(EVENT_INPUT); + else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); break; case SETTING_LOW_BATT: @@ -1779,21 +1779,21 @@ static int update_setting(int key_idx, int val) } /* LCD on if lock screen show before waiting time */ - if (pm_cur_state == S_NORMAL && + if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && backlight_ops.get_lcd_power() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOCK_SCREEN_BG: set_lock_screen_bg_state(val); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_POWEROFF: switch (val) { @@ -1933,8 +1933,8 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) } /* Apply new backlight time */ update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); if (holdkey_block) { custom_holdkey_block = true; @@ -1987,8 +1987,8 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_holdkey_block = false; update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); } static int booting_done(void *data) @@ -2144,7 +2144,7 @@ static gboolean delayed_init_dpms(gpointer data) if (!init_dpms()) return G_SOURCE_CONTINUE; - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: case S_LCDDIM: lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); @@ -2351,12 +2351,12 @@ static void display_init(void *data) disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); - /* initial display state right after the booting done */ + /* Initial display state right after the booting done */ if (is_lcdon_blocked()) - pm_cur_state = S_LCDOFF; + set_pm_cur_state(S_LCDOFF); else - pm_cur_state = S_NORMAL; - ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + set_pm_cur_state(S_NORMAL); + ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); @@ -2387,8 +2387,8 @@ static void display_exit(void *data) status = DEVICE_OPS_STATUS_STOP; /* Set current state to S_NORMAL */ - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); + set_pm_cur_state(S_NORMAL); + set_setting_pmstate(get_pm_cur_state()); /* timeout is not needed */ reset_timeout(TIMEOUT_NONE); diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 47c037a..e3aa582 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -42,6 +42,7 @@ #include "core.h" #include "device-node.h" #include "display/display-dpms.h" +#include "display/display.h" #define SET_SUSPEND_TIME 0.5 @@ -104,9 +105,9 @@ static int bl_onoff(int on, enum device_flags flags) #ifdef ENABLE_PM_LOG if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); else pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); #endif @@ -362,7 +363,7 @@ static int backlight_on(enum device_flags flags) cnt++; ret = bl_onoff(DPMS_ON, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif return ret; @@ -393,7 +394,7 @@ static int backlight_off(enum device_flags flags) ret = bl_onoff(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); #endif return ret; @@ -406,9 +407,9 @@ static int backlight_dim(void) ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) - pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM, get_pm_cur_state()); else - pm_history_save(PM_LOG_LCD_DIM_FAIL, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM_FAIL, get_pm_cur_state()); #endif return ret; } diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 8ddae17..801a86d 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -104,12 +104,12 @@ static int booting_check = true; static inline int current_state_in_on(void) { - return (pm_cur_state == S_LCDDIM || pm_cur_state == S_NORMAL); + return ((get_pm_cur_state() == S_LCDDIM) || (get_pm_cur_state() == S_NORMAL)); } static inline void restore_custom_brightness(void) { - if (pm_cur_state == S_LCDDIM && + if ((get_pm_cur_state() == S_LCDDIM) && backlight_ops.get_custom_status()) backlight_ops.custom_update(); } @@ -688,10 +688,10 @@ static int check_key_filter(void *data, int fd) break; case EV_REL: - if (pm_cur_state == S_LCDOFF && bezel_wakeup) { + if ((get_pm_cur_state() == S_LCDOFF) && bezel_wakeup) { switch_on_lcd(LCD_ON_BY_BEZEL); - ignore = false; - } else if (pm_cur_state != S_LCDOFF) + ignore = false; + } else if (get_pm_cur_state() != S_LCDOFF) ignore = false; break; case EV_ABS: diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 90a2222..e02dab8 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -97,7 +97,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_cur_state; int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; @@ -541,7 +540,7 @@ static void del_state_cond(void *data, enum state_t state) set_unlock_time(pid, state); if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) set_process_active(false, pid); @@ -568,14 +567,14 @@ static gboolean del_off_cond(void *data) /* timeout handler */ gboolean timeout_handler(void *data) { - _I("Time out state %s", states[pm_cur_state].name); + _I("Time out state %s", states[get_pm_cur_state()].name); if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; } - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return G_SOURCE_REMOVE; } @@ -584,7 +583,7 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - if (pm_cur_state == S_LCDOFF + if ((get_pm_cur_state() == S_LCDOFF) && (is_emulator() == true || display_conf.sleep_support == false)) return; @@ -594,14 +593,14 @@ void reset_timeout(int timeout) timeout_src_id = 0; } - if (trans_table[pm_cur_state][EVENT_TIMEOUT] == pm_cur_state) + if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state()) return; if (timeout > 0) timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } /* get configurations from setting */ @@ -697,16 +696,16 @@ void set_dim_state(bool on) { _I("Dim state is %d.", on); update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } void lcd_on_direct(enum device_flags flags) { if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) { + && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); power_ops.power_lock(); - pm_cur_state = S_NORMAL; + set_pm_cur_state(S_NORMAL); } _D("lcd is on directly"); @@ -729,9 +728,9 @@ static gboolean timer_refresh_cb(gpointer data) struct state *st; /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; if (st->action) st->action(st->timeout); @@ -754,9 +753,9 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -798,9 +797,9 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -839,9 +838,9 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -883,9 +882,9 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -898,10 +897,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = pm_cur_state; - pm_cur_state = next; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next); - st = &states[pm_cur_state]; + st = &states[get_pm_cur_state()]; if (st && st->action) { if (timeout < 0) @@ -985,7 +984,7 @@ static void proc_condition_lock(PMMsg *data) char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; - int holdkey_block,ret; + int holdkey_block, ret; bool value = true; unsigned int flags; const char *lock_type = NULL; @@ -997,8 +996,8 @@ static void proc_condition_lock(PMMsg *data) flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && pm_cur_state == S_SLEEP && - power_ops.get_power_lock() == POWER_UNLOCK) + if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && + (power_ops.get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1124,15 +1123,15 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); } else { if (flags & PM_FLAG_RESET_TIMER) - reset_timeout(states[pm_cur_state].timeout); + reset_timeout(states[get_pm_cur_state()].timeout); } if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return 0; } @@ -1267,7 +1266,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", - states[pm_cur_state].name); + states[get_pm_cur_state()].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1361,7 +1360,7 @@ int check_lcdoff_direct(void) if (pm_old_state != S_NORMAL) return false; - if (pm_cur_state != S_LCDDIM) + if (get_pm_cur_state() != S_LCDDIM) return false; if (!display_conf.dimming) @@ -1394,17 +1393,17 @@ int check_lcdoff_direct(void) */ static int default_trans(int evt) { - struct state *st = &states[pm_cur_state]; + struct state *st = &states[get_pm_cur_state()]; int next_state; - next_state = (enum state_t)trans_table[pm_cur_state][evt]; + next_state = (enum state_t)trans_table[get_pm_cur_state()][evt]; /* check conditions */ - while (st->check && !st->check(pm_cur_state, next_state)) { + while (st->check && !st->check(get_pm_cur_state(), next_state)) { /* There is a condition. */ - _I("%s locked. Trans to %s failed.", states[pm_cur_state].name, + _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(pm_cur_state)) { + if (!check_processes(get_pm_cur_state())) { /* This is valid condition * The application that sent the condition is running now. */ return -1; @@ -1412,24 +1411,24 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = next_state; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next_state); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) { - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDOFF) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) update_display_time(); if (check_lcdoff_direct() == true) { /* enter next state directly */ - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { - if (pm_cur_state == S_SLEEP + if ((get_pm_cur_state() == S_SLEEP) && (is_emulator() == true || display_conf.sleep_support == false)) return 0; @@ -1488,7 +1487,7 @@ static void check_lock_screen(void) /* default enter action function */ static int default_action(int timeout) { - int wakeup_count = -1; + int wakeup_count = -1, pm_cur_state; time_t now; double diff; static time_t last_update_time = 0; @@ -1500,8 +1499,8 @@ static int default_action(int timeout) return -EINVAL; } - if (pm_cur_state != S_SLEEP) { - if (pm_cur_state == S_NORMAL && + if (get_pm_cur_state() != S_SLEEP) { + if ((get_pm_cur_state() == S_NORMAL) && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); @@ -1510,32 +1509,33 @@ static int default_action(int timeout) /* set timer with current state timeout */ reset_timeout(timeout); - if (pm_cur_state == S_NORMAL) { + if (get_pm_cur_state() == S_NORMAL) { time(&last_update_time); last_timeout = timeout; } else { _I("Timout set: %s state %d ms", - states[pm_cur_state].name, timeout); + states[get_pm_cur_state()].name, timeout); } } - if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { + if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); } - set_setting_pmstate(pm_cur_state); + set_setting_pmstate(get_pm_cur_state()); + pm_cur_state = get_pm_cur_state(); device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { + if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[pm_cur_state].name, last_timeout, diff); + states[get_pm_cur_state()].name, last_timeout, diff); } - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: /* * normal state : backlight on and restore @@ -1603,7 +1603,7 @@ static int default_action(int timeout) go_suspend: #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, pm_cur_state); + pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { @@ -1619,17 +1619,17 @@ go_suspend: /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); else /* system waked up by user input */ - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } return 0; go_lcd_off: if (!power_ops.get_power_lock_support()) { /* Resume !! */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); } return 0; } @@ -1680,7 +1680,7 @@ static void default_saving_mode(int onoff) else pm_status_flag &= ~PWRSV_FLAG; - if (pm_cur_state == S_NORMAL) + if (get_pm_cur_state() == S_NORMAL) backlight_ops.update(); } @@ -1695,13 +1695,13 @@ static int poll_callback(int condition, PMMsg *data) } if (condition == INPUT_POLL_EVENT) { - if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) + if ((get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) _I("Input event signal at Display Off"); time(&now); - if (last_t != now || - pm_cur_state == S_LCDOFF || - pm_cur_state == S_SLEEP) { - states[pm_cur_state].trans(EVENT_INPUT); + if ((last_t != now) || + (get_pm_cur_state() == S_LCDOFF) || + (get_pm_cur_state() == S_SLEEP)) { + states[get_pm_cur_state()].trans(EVENT_INPUT); last_t = now; } } @@ -1723,14 +1723,14 @@ static int update_setting(int key_idx, int val) switch (key_idx) { case SETTING_TO_NORMAL: update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_HALLIC_OPEN: hallic_open = val; update_display_time(); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM) - states[pm_cur_state].trans(EVENT_INPUT); - else if (pm_cur_state == S_SLEEP && hallic_open) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) + states[get_pm_cur_state()].trans(EVENT_INPUT); + else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); break; case SETTING_LOW_BATT: @@ -1789,21 +1789,21 @@ static int update_setting(int key_idx, int val) } /* LCD on if lock screen show before waiting time */ - if (pm_cur_state == S_NORMAL && + if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && backlight_ops.get_lcd_power() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOCK_SCREEN_BG: set_lock_screen_bg_state(val); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_POWEROFF: switch (val) { @@ -1943,8 +1943,8 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) } /* Apply new backlight time */ update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); if (holdkey_block) { custom_holdkey_block = true; @@ -1997,8 +1997,8 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_holdkey_block = false; update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); } static int booting_done(void *data) @@ -2154,7 +2154,7 @@ static gboolean delayed_init_dpms(gpointer data) if (!init_dpms()) return G_SOURCE_CONTINUE; - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: case S_LCDDIM: lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); @@ -2363,10 +2363,10 @@ static void display_init(void *data) /* Initial display state right after the booting done */ if (is_lcdon_blocked()) - pm_cur_state = S_LCDOFF; + set_pm_cur_state(S_LCDOFF); else - pm_cur_state = S_NORMAL; - ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + set_pm_cur_state(S_NORMAL); + ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); @@ -2397,8 +2397,8 @@ static void display_exit(void *data) status = DEVICE_OPS_STATUS_STOP; /* Set current state to S_NORMAL */ - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); + set_pm_cur_state(S_NORMAL); + set_setting_pmstate(get_pm_cur_state()); /* timeout is not needed */ reset_timeout(TIMEOUT_NONE); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 36a5c56..8697ab3 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -42,6 +42,7 @@ #include "core.h" #include "device-node.h" #include "display/display-dpms.h" +#include "display/display.h" #include "power/boot.h" #define SET_SUSPEND_TIME 0.5 @@ -105,9 +106,9 @@ static int bl_onoff(int on, enum device_flags flags) #ifdef ENABLE_PM_LOG if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); else pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); #endif @@ -363,7 +364,7 @@ static int backlight_on(enum device_flags flags) cnt++; ret = bl_onoff(DPMS_ON, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif return ret; @@ -394,7 +395,7 @@ static int backlight_off(enum device_flags flags) ret = bl_onoff(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); #endif return ret; @@ -407,9 +408,9 @@ static int backlight_dim(void) ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) - pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM, get_pm_cur_state()); else - pm_history_save(PM_LOG_LCD_DIM_FAIL, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM_FAIL, get_pm_cur_state()); #endif return ret; } diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index d1ea239..57903f8 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -104,12 +104,12 @@ static int booting_check = true; static inline int current_state_in_on(void) { - return (pm_cur_state == S_LCDDIM || pm_cur_state == S_NORMAL); + return ((get_pm_cur_state() == S_LCDDIM) || (get_pm_cur_state() == S_NORMAL)); } static inline void restore_custom_brightness(void) { - if (pm_cur_state == S_LCDDIM && + if ((get_pm_cur_state() == S_LCDDIM) && backlight_ops.get_custom_status()) backlight_ops.custom_update(); } @@ -715,10 +715,10 @@ static int check_key_filter(void *data, int fd) break; case EV_REL: - if (pm_cur_state == S_LCDOFF && bezel_wakeup) { + if ((get_pm_cur_state() == S_LCDOFF) && bezel_wakeup) { switch_on_lcd(LCD_ON_BY_BEZEL); ignore = false; - } else if (pm_cur_state != S_LCDOFF) + } else if (get_pm_cur_state() != S_LCDOFF) ignore = false; break; case EV_ABS: diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 40864ba..169bd60 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -95,7 +95,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_cur_state; int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; @@ -534,7 +533,7 @@ static void del_state_cond(void *data, enum state_t state) set_unlock_time(pid, state); if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) set_process_active(false, pid); @@ -561,14 +560,14 @@ static gboolean del_off_cond(void *data) /* timeout handler */ gboolean timeout_handler(void *data) { - _I("Time out state %s", states[pm_cur_state].name); + _I("Time out state %s", states[get_pm_cur_state()].name); if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; } - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return G_SOURCE_REMOVE; } @@ -577,24 +576,24 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - if (pm_cur_state == S_LCDOFF + if ((get_pm_cur_state() == S_LCDOFF) && (is_emulator() == true || display_conf.sleep_support == false)) return; - _I("Reset timeout(%d ms) pm_cur_state(%d).", timeout, pm_cur_state); + _I("Reset timeout(%d ms) pm_cur_state(%d).", timeout, get_pm_cur_state()); if (timeout_src_id != 0) { g_source_remove(timeout_src_id); timeout_src_id = 0; } - if (trans_table[pm_cur_state][EVENT_TIMEOUT] == pm_cur_state) + if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state()) return; if (timeout > 0) timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } /* get configurations from setting */ @@ -690,16 +689,16 @@ void set_dim_state(bool on) { _I("Dim state is %d.", on); update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } void lcd_on_direct(enum device_flags flags) { if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) { + && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); power_ops.power_lock(); - pm_cur_state = S_NORMAL; + set_pm_cur_state(S_NORMAL); } _D("lcd is on directly"); @@ -722,9 +721,9 @@ static gboolean timer_refresh_cb(gpointer data) struct state *st; /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; if (st->action) st->action(st->timeout); @@ -747,9 +746,9 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -791,9 +790,9 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -832,9 +831,9 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -876,9 +875,9 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -891,10 +890,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = pm_cur_state; - pm_cur_state = next; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next); - st = &states[pm_cur_state]; + st = &states[get_pm_cur_state()]; if (st && st->action) { if (timeout < 0) @@ -986,8 +985,8 @@ static void proc_condition_lock(PMMsg *data) flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && pm_cur_state == S_SLEEP && - power_ops.get_power_lock() == POWER_UNLOCK) + if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && + (power_ops.get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1114,15 +1113,15 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); } else { if (flags & PM_FLAG_RESET_TIMER) - reset_timeout(states[pm_cur_state].timeout); + reset_timeout(states[get_pm_cur_state()].timeout); } if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return 0; } @@ -1257,7 +1256,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", - states[pm_cur_state].name); + states[get_pm_cur_state()].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1351,7 +1350,7 @@ int check_lcdoff_direct(void) if (pm_old_state != S_NORMAL) return false; - if (pm_cur_state != S_LCDDIM) + if (get_pm_cur_state() != S_LCDDIM) return false; if (!display_conf.dimming) @@ -1384,17 +1383,17 @@ int check_lcdoff_direct(void) */ static int default_trans(int evt) { - struct state *st = &states[pm_cur_state]; + struct state *st = &states[get_pm_cur_state()]; int next_state; - next_state = (enum state_t)trans_table[pm_cur_state][evt]; + next_state = (enum state_t)trans_table[get_pm_cur_state()][evt]; /* check conditions */ - while (st->check && !st->check(pm_cur_state, next_state)) { + while (st->check && !st->check(get_pm_cur_state(), next_state)) { /* There is a condition. */ - _I("%s locked. Trans to %s failed.", states[pm_cur_state].name, + _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(pm_cur_state)) { + if (!check_processes(get_pm_cur_state())) { /* This is valid condition * The application that sent the condition is running now. */ return -1; @@ -1402,24 +1401,24 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = next_state; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next_state); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) { - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDOFF) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) update_display_time(); if (check_lcdoff_direct() == true) { /* enter next state directly */ - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { - if (pm_cur_state == S_SLEEP + if ((get_pm_cur_state() == S_SLEEP) && (is_emulator() == true || display_conf.sleep_support == false)) return 0; @@ -1478,7 +1477,7 @@ static void check_lock_screen(void) /* default enter action function */ static int default_action(int timeout) { - int wakeup_count = -1; + int wakeup_count = -1, pm_cur_state; time_t now; double diff; static time_t last_update_time = 0; @@ -1490,8 +1489,8 @@ static int default_action(int timeout) return -EINVAL; } - if (pm_cur_state != S_SLEEP) { - if (pm_cur_state == S_NORMAL && + if (get_pm_cur_state() != S_SLEEP) { + if ((get_pm_cur_state() == S_NORMAL) && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); @@ -1500,32 +1499,33 @@ static int default_action(int timeout) /* set timer with current state timeout */ reset_timeout(timeout); - if (pm_cur_state == S_NORMAL) { + if (get_pm_cur_state() == S_NORMAL) { time(&last_update_time); last_timeout = timeout; } else { _I("Timout set: %s state %d ms", - states[pm_cur_state].name, timeout); + states[get_pm_cur_state()].name, timeout); } } - if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { + if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); } - set_setting_pmstate(pm_cur_state); + set_setting_pmstate(get_pm_cur_state()); + pm_cur_state = get_pm_cur_state(); device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { + if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[pm_cur_state].name, last_timeout, diff); + states[get_pm_cur_state()].name, last_timeout, diff); } - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: /* * normal state : backlight on and restore @@ -1593,7 +1593,7 @@ static int default_action(int timeout) go_suspend: #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, pm_cur_state); + pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { @@ -1609,17 +1609,17 @@ go_suspend: /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); else /* system waked up by user input */ - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } return 0; go_lcd_off: if (!power_ops.get_power_lock_support()) { /* Resume !! */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); } return 0; } @@ -1670,7 +1670,7 @@ static void default_saving_mode(int onoff) else pm_status_flag &= ~PWRSV_FLAG; - if (pm_cur_state == S_NORMAL) + if (get_pm_cur_state() == S_NORMAL) backlight_ops.update(); } @@ -1685,13 +1685,13 @@ static int poll_callback(int condition, PMMsg *data) } if (condition == INPUT_POLL_EVENT) { - if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) + if ((get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) _I("Input event signal at Display Off"); time(&now); - if (last_t != now || - pm_cur_state == S_LCDOFF || - pm_cur_state == S_SLEEP) { - states[pm_cur_state].trans(EVENT_INPUT); + if ((last_t != now) || + (get_pm_cur_state() == S_LCDOFF) || + (get_pm_cur_state() == S_SLEEP)) { + states[get_pm_cur_state()].trans(EVENT_INPUT); last_t = now; } } @@ -1713,14 +1713,14 @@ static int update_setting(int key_idx, int val) switch (key_idx) { case SETTING_TO_NORMAL: update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_HALLIC_OPEN: hallic_open = val; update_display_time(); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM) - states[pm_cur_state].trans(EVENT_INPUT); - else if (pm_cur_state == S_SLEEP && hallic_open) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) + states[get_pm_cur_state()].trans(EVENT_INPUT); + else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); break; case SETTING_LOW_BATT: @@ -1779,21 +1779,21 @@ static int update_setting(int key_idx, int val) } /* LCD on if lock screen show before waiting time */ - if (pm_cur_state == S_NORMAL && + if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && backlight_ops.get_lcd_power() != DPMS_ON && - is_lcdon_blocked() != LCDON_BLOCK_NONE) + is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOCK_SCREEN_BG: set_lock_screen_bg_state(val); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_POWEROFF: switch (val) { @@ -1933,8 +1933,8 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) } /* Apply new backlight time */ update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); if (holdkey_block) { custom_holdkey_block = true; @@ -1987,8 +1987,8 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_holdkey_block = false; update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); } static int booting_done(void *data) @@ -2144,7 +2144,7 @@ static gboolean delayed_init_dpms(gpointer data) if (!init_dpms()) return G_SOURCE_CONTINUE; - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: case S_LCDDIM: lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); @@ -2351,12 +2351,12 @@ static void display_init(void *data) disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); - /* initial display state right after the booting done */ + /* Initial display state right after the booting done */ if (is_lcdon_blocked()) - pm_cur_state = S_LCDOFF; + set_pm_cur_state(S_LCDOFF); else - pm_cur_state = S_NORMAL; - ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + set_pm_cur_state(S_NORMAL); + ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); @@ -2387,8 +2387,8 @@ static void display_exit(void *data) status = DEVICE_OPS_STATUS_STOP; /* Set current state to S_NORMAL */ - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); + set_pm_cur_state(S_NORMAL); + set_setting_pmstate(get_pm_cur_state()); /* timeout is not needed */ reset_timeout(TIMEOUT_NONE); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 47c037a..e3aa582 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -42,6 +42,7 @@ #include "core.h" #include "device-node.h" #include "display/display-dpms.h" +#include "display/display.h" #define SET_SUSPEND_TIME 0.5 @@ -104,9 +105,9 @@ static int bl_onoff(int on, enum device_flags flags) #ifdef ENABLE_PM_LOG if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); else pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); #endif @@ -362,7 +363,7 @@ static int backlight_on(enum device_flags flags) cnt++; ret = bl_onoff(DPMS_ON, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif return ret; @@ -393,7 +394,7 @@ static int backlight_off(enum device_flags flags) ret = bl_onoff(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); #endif return ret; @@ -406,9 +407,9 @@ static int backlight_dim(void) ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) - pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM, get_pm_cur_state()); else - pm_history_save(PM_LOG_LCD_DIM_FAIL, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM_FAIL, get_pm_cur_state()); #endif return ret; } diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 88324d7..8a4239f 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -104,12 +104,12 @@ static int booting_check = true; static inline int current_state_in_on(void) { - return (pm_cur_state == S_LCDDIM || pm_cur_state == S_NORMAL); + return ((get_pm_cur_state() == S_LCDDIM) || (get_pm_cur_state() == S_NORMAL)); } static inline void restore_custom_brightness(void) { - if (pm_cur_state == S_LCDDIM && + if ((get_pm_cur_state() == S_LCDDIM) && backlight_ops.get_custom_status()) backlight_ops.custom_update(); } @@ -682,10 +682,10 @@ static int check_key_filter(void *data, int fd) break; case EV_REL: - if (pm_cur_state == S_LCDOFF && bezel_wakeup) { + if ((get_pm_cur_state() == S_LCDOFF) && bezel_wakeup) { switch_on_lcd(LCD_ON_BY_BEZEL); ignore = false; - } else if (pm_cur_state != S_LCDOFF) + } else if (get_pm_cur_state() != S_LCDOFF) ignore = false; break; case EV_ABS: diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 9dd39d3..279538e 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -47,10 +47,10 @@ static int change_state(pid_t pid, int type, enum state_t st) int ret; if (type == PM_CONTROL_EVENT && states[st].check) { - ret = states[pm_cur_state].check(pm_cur_state, st); + ret = states[get_pm_cur_state()].check(get_pm_cur_state(), st); if (ret != 0) { _E("(%s) State Locked. Cannot be changed to (%s)", - states[pm_cur_state].name, states[st].name); + states[get_pm_cur_state()].name, states[st].name); return ret; } } @@ -74,8 +74,8 @@ static int tv_proc_change_state(unsigned int cond, pid_t pid) int ret; next = GET_COND_STATE(cond); - if (pm_cur_state == next) { - _I("current state (%d) == next state (%d)", pm_cur_state, next); + if (get_pm_cur_state() == next) { + _I("current state (%d) == next state (%d)", get_pm_cur_state(), next); return 0; } @@ -107,8 +107,8 @@ unsigned long long get_uptime(void) static int lcdon_check(int curr, int next) { /* do not changed to next state if who lock the normal mode */ - check_processes(pm_cur_state); - if (check_lock_state(pm_cur_state)) { + check_processes(get_pm_cur_state()); + if (check_lock_state(get_pm_cur_state())) { _I("S_LCDON Lock state"); return 1; } @@ -128,7 +128,7 @@ static int lcdon_pre(void *data) */ device_notify(DEVICE_NOTIFIER_POWER_RESUME, NULL); - if (pm_cur_state == S_STANDBY) { + if (get_pm_cur_state() == S_STANDBY) { _I("send pre state change NORMAL"); ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, @@ -163,9 +163,9 @@ static int lcdon_post(void *data) static int lcdon_action(int timeout) { - if (pm_cur_state != pm_old_state && - pm_cur_state != S_SLEEP) - set_setting_pmstate(pm_cur_state); + if ((get_pm_cur_state() != pm_old_state) && + (get_pm_cur_state() != S_SLEEP)) + set_setting_pmstate(get_pm_cur_state()); if (pm_old_state != S_LCDOFF && pm_old_state != S_SLEEP) { @@ -192,9 +192,9 @@ static int lcdon_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDON; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDON); + st = &states[get_pm_cur_state()]; if (st->action) st->action(0); @@ -235,9 +235,9 @@ static int lcdoff_post(void *data) static int lcdoff_action(int timeout) { - if (pm_cur_state != pm_old_state && - pm_cur_state != S_SLEEP) - set_setting_pmstate(pm_cur_state); + if ((get_pm_cur_state() != pm_old_state) && + (get_pm_cur_state() != S_SLEEP)) + set_setting_pmstate(get_pm_cur_state()); if (pm_old_state == S_SUSPEND || pm_old_state == S_LCDOFF) @@ -260,9 +260,9 @@ static int lcdoff_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; if (st->action) st->action(0); @@ -340,9 +340,9 @@ static gboolean standby_go_next_state(void *data) static int standby_action(int timeout) { - if (pm_cur_state != pm_old_state && - pm_cur_state != S_SLEEP) - set_setting_pmstate(pm_cur_state); + if ((get_pm_cur_state() != pm_old_state) && + (get_pm_cur_state() != S_SLEEP)) + set_setting_pmstate(get_pm_cur_state()); backlight_ops.off(0); @@ -366,9 +366,9 @@ static int standby_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_STANDBY; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_STANDBY); + st = &states[get_pm_cur_state()]; if (st->action) st->action(0); @@ -422,9 +422,9 @@ static int suspend_action(int timeout) { struct state *st; - if (pm_cur_state != pm_old_state && - pm_cur_state != S_SLEEP) - set_setting_pmstate(pm_cur_state); + if ((get_pm_cur_state() != pm_old_state) && + (get_pm_cur_state() != S_SLEEP)) + set_setting_pmstate(get_pm_cur_state()); /* TODO: set wakeup count */ @@ -435,9 +435,9 @@ static int suspend_action(int timeout) /* Resume !! */ /* system waked up by devices */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; if (st->action) st->action(0); @@ -457,16 +457,16 @@ static int suspend_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; if (st->action) st->action(0); - pm_old_state = pm_cur_state; - pm_cur_state = S_SUSPEND; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_SUSPEND); + st = &states[get_pm_cur_state()]; if (st->action) st->action(0); @@ -506,7 +506,7 @@ static int display_lock_changed(void *data) { bool state = (bool)data; - if (pm_cur_state != S_STANDBY) + if (get_pm_cur_state() != S_STANDBY) return 0; if (!state) diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index b3aac8b..391cb2b 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -46,7 +46,7 @@ static void change_brightness_transit(int start, int end) static void set_brightness_level(int level) { - if (pm_cur_state != S_NORMAL) + if (get_pm_cur_state() != S_NORMAL) return; /* if (battery.capacity <= LOWBATCAPACITY && battery.charge_now != CHARGER_CHARGING) @@ -216,7 +216,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes change_flag(&hold, 1); } else if (request == BR_LOWDIM_ON) { if (!lowdim) { - if (!hbm && !hold && pm_cur_state == S_NORMAL) + if (!hbm && !hold && (get_pm_cur_state() == S_NORMAL)) backlight_ops.dim(); change_flag(&lowdim, 1); } @@ -226,7 +226,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes change_flag(&lbm, 0); /* called by DEVICE_NOTIFIER_LCD_OFF_COMPLETE, no need to change brightness */ - if (pm_cur_state != S_NORMAL) + if (get_pm_cur_state() != S_NORMAL) return 0; if (!lowdim) { @@ -252,7 +252,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes change_flag(&hold, 0); /* called by DEVICE_NOTIFIER_LCD_OFF_COMPLETE, no need to change brightness */ - if (pm_cur_state != S_NORMAL) + if (get_pm_cur_state() != S_NORMAL) return 0; if (!lowdim) @@ -273,7 +273,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes } } else if (request == BR_LOWDIM_OFF) { if (lowdim) { - if (!hbm && !hold && pm_cur_state == S_NORMAL) + if (!hbm && !hold && (get_pm_cur_state() == S_NORMAL)) backlight_ops.update(); change_flag(&lowdim, 0); } diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 8258be8..4ae19fa 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -71,7 +71,7 @@ static void theater_changed_cb(keynode_t *key_nodes, void *data) theater_mode = vconf_keynode_get_bool(key_nodes); _I("Theater mode: %d.", theater_mode); - if (pm_cur_state == LCD_OFF) { + if (get_pm_cur_state() == LCD_OFF) { state = bezel_wakeup_control(); bezel_dev->set_state(state); } @@ -86,7 +86,7 @@ static void goodnight_changed_cb(keynode_t *key_nodes, void *data) goodnight_mode = vconf_keynode_get_bool(key_nodes); _I("Goodnight mode: %d.", goodnight_mode); - if (pm_cur_state == LCD_OFF) { + if (get_pm_cur_state() == LCD_OFF) { state = bezel_wakeup_control(); bezel_dev->set_state(state); } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 0f61aab..c7678a2 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -102,7 +102,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_cur_state; int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; @@ -560,7 +559,7 @@ static void del_state_cond(void *data, enum state_t state) set_unlock_time(pid, state); if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) set_process_active(false, pid); @@ -587,14 +586,14 @@ static gboolean del_off_cond(void *data) /* timeout handler */ gboolean timeout_handler(void *data) { - _I("Time out state %s", states[pm_cur_state].name); + _I("Time out state %s", states[get_pm_cur_state()].name); if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; } - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return G_SOURCE_REMOVE; } @@ -603,7 +602,7 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - if (pm_cur_state == S_LCDOFF + if ((get_pm_cur_state() == S_LCDOFF) && (is_emulator() == true || display_conf.sleep_support == false)) return; @@ -613,14 +612,14 @@ void reset_timeout(int timeout) timeout_src_id = 0; } - if (trans_table[pm_cur_state][EVENT_TIMEOUT] == pm_cur_state) + if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state()) return; if (timeout > 0) timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } /* get configurations from setting */ @@ -716,7 +715,7 @@ void set_dim_state(bool on) { _I("Dim state is %d.", on); update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } void lcd_on_direct(enum device_flags flags) @@ -724,10 +723,10 @@ void lcd_on_direct(enum device_flags flags) int ret; if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) { + && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); power_ops.power_lock(); - pm_cur_state = S_NORMAL; + set_pm_cur_state(S_NORMAL); } ret = is_lcdon_blocked(); @@ -771,9 +770,9 @@ static gboolean timer_refresh_cb(gpointer data) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; if (st->action) st->action(st->timeout); @@ -808,9 +807,9 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -853,9 +852,9 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -894,9 +893,9 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_NORMAL); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -943,9 +942,9 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = S_LCDOFF; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(S_LCDOFF); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) @@ -958,10 +957,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = pm_cur_state; - pm_cur_state = next; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next); - st = &states[pm_cur_state]; + st = &states[get_pm_cur_state()]; if (st && st->action) { if (timeout < 0) @@ -1053,8 +1052,8 @@ static void proc_condition_lock(PMMsg *data) flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && pm_cur_state == S_SLEEP && - power_ops.get_power_lock() == POWER_UNLOCK) + if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && + (power_ops.get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1181,15 +1180,15 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); } else { if (flags & PM_FLAG_RESET_TIMER) - reset_timeout(states[pm_cur_state].timeout); + reset_timeout(states[get_pm_cur_state()].timeout); } if (!timeout_src_id) - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); return 0; } @@ -1324,7 +1323,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", - states[pm_cur_state].name); + states[get_pm_cur_state()].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1418,7 +1417,7 @@ int check_lcdoff_direct(void) if (pm_old_state != S_NORMAL) return false; - if (pm_cur_state != S_LCDDIM) + if (get_pm_cur_state() != S_LCDDIM) return false; if (!display_conf.dimming) @@ -1451,17 +1450,17 @@ int check_lcdoff_direct(void) */ static int default_trans(int evt) { - struct state *st = &states[pm_cur_state]; + struct state *st = &states[get_pm_cur_state()]; int next_state, ret; - next_state = (enum state_t)trans_table[pm_cur_state][evt]; + next_state = (enum state_t)trans_table[get_pm_cur_state()][evt]; /* check conditions */ - while (st->check && !st->check(pm_cur_state, next_state)) { + while (st->check && !st->check(get_pm_cur_state(), next_state)) { /* There is a condition. */ - _I("%s locked. Trans to %s failed.", states[pm_cur_state].name, + _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(pm_cur_state)) { + if (!check_processes(get_pm_cur_state())) { /* This is valid condition * The application that sent the condition is running now. */ return -1; @@ -1477,24 +1476,24 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = pm_cur_state; - pm_cur_state = next_state; - st = &states[pm_cur_state]; + pm_old_state = get_pm_cur_state(); + set_pm_cur_state(next_state); + st = &states[get_pm_cur_state()]; /* enter action */ if (st->action) { - if (pm_cur_state == S_LCDOFF) + if (get_pm_cur_state() == S_LCDOFF) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDOFF) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) update_display_time(); if (check_lcdoff_direct() == true) { /* enter next state directly */ - states[pm_cur_state].trans(EVENT_TIMEOUT); + states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { - if (pm_cur_state == S_SLEEP + if ((get_pm_cur_state() == S_SLEEP) && (is_emulator() == true || display_conf.sleep_support == false)) return 0; @@ -1553,7 +1552,7 @@ static void check_lock_screen(void) /* default enter action function */ static int default_action(int timeout) { - int wakeup_count = -1; + int wakeup_count = -1, pm_cur_state; int ret; time_t now; double diff; @@ -1568,14 +1567,14 @@ static int default_action(int timeout) ret = is_lcdon_blocked(); if (ret != LCDON_BLOCK_NONE) { - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM) { + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) { _W("LCDON is blocked, %d.", ret); return -ENOTSUP; } } - if (pm_cur_state != S_SLEEP) { - if (pm_cur_state == S_NORMAL && + if (get_pm_cur_state() != S_SLEEP) { + if ((get_pm_cur_state() == S_NORMAL) && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); @@ -1584,35 +1583,36 @@ static int default_action(int timeout) /* set timer with current state timeout */ reset_timeout(timeout); - if (pm_cur_state == S_NORMAL) { + if (get_pm_cur_state() == S_NORMAL) { time(&last_update_time); last_timeout = timeout; } else { _I("Timout set: %s state %d ms", - states[pm_cur_state].name, timeout); + states[get_pm_cur_state()].name, timeout); } } - if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { + if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); } - set_setting_pmstate(pm_cur_state); + set_setting_pmstate(get_pm_cur_state()); + pm_cur_state = get_pm_cur_state(); device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { + if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[pm_cur_state].name, last_timeout, diff); + states[get_pm_cur_state()].name, last_timeout, diff); } /* update status for batter monitor */ - update_bds_record(pm_cur_state); + update_bds_record(get_pm_cur_state()); - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: /* * normal state : backlight on and restore @@ -1680,7 +1680,7 @@ static int default_action(int timeout) go_suspend: #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, pm_cur_state); + pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { @@ -1696,17 +1696,17 @@ go_suspend: /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); else /* system waked up by user input */ - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); } return 0; go_lcd_off: if (!power_ops.get_power_lock_support()) { /* Resume !! */ - states[pm_cur_state].trans(EVENT_DEVICE); + states[get_pm_cur_state()].trans(EVENT_DEVICE); } return 0; } @@ -1772,13 +1772,13 @@ static int poll_callback(int condition, PMMsg *data) } if (condition == INPUT_POLL_EVENT) { - if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) + if ((get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) _I("Input event signal at Display Off"); time(&now); - if (last_t != now || - pm_cur_state == S_LCDOFF || - pm_cur_state == S_SLEEP) { - states[pm_cur_state].trans(EVENT_INPUT); + if ((last_t != now) || + (get_pm_cur_state() == S_LCDOFF) || + (get_pm_cur_state() == S_SLEEP)) { + states[get_pm_cur_state()].trans(EVENT_INPUT); last_t = now; } } @@ -1800,14 +1800,14 @@ static int update_setting(int key_idx, int val) switch (key_idx) { case SETTING_TO_NORMAL: update_display_time(); - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_HALLIC_OPEN: hallic_open = val; update_display_time(); - if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM) - states[pm_cur_state].trans(EVENT_INPUT); - else if (pm_cur_state == S_SLEEP && hallic_open) + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) + states[get_pm_cur_state()].trans(EVENT_INPUT); + else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); break; case SETTING_LOW_BATT: @@ -1866,21 +1866,21 @@ static int update_setting(int key_idx, int val) } /* LCD on if lock screen show before waiting time */ - if (pm_cur_state == S_NORMAL && + if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && backlight_ops.get_lcd_power() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOCK_SCREEN_BG: set_lock_screen_bg_state(val); update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_POWEROFF: switch (val) { @@ -2024,8 +2024,8 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) } /* Apply new backlight time */ update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); if (holdkey_block) { custom_holdkey_block = true; @@ -2078,8 +2078,8 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_holdkey_block = false; update_display_time(); - if (pm_cur_state == S_NORMAL) - states[pm_cur_state].trans(EVENT_INPUT); + if (get_pm_cur_state() == S_NORMAL) + states[get_pm_cur_state()].trans(EVENT_INPUT); } static int booting_done(void *data) @@ -2236,7 +2236,7 @@ static gboolean delayed_init_dpms(gpointer data) if (!init_dpms()) return G_SOURCE_CONTINUE; - switch (pm_cur_state) { + switch (get_pm_cur_state()) { case S_NORMAL: case S_LCDDIM: lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); @@ -2475,12 +2475,12 @@ static void display_init(void *data) disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); - /* initial display state right after the booting done */ + /* Initial display state right after the booting done */ if (is_lcdon_blocked()) - pm_cur_state = S_LCDOFF; + set_pm_cur_state(S_LCDOFF); else - pm_cur_state = S_NORMAL; - ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + set_pm_cur_state(S_NORMAL); + ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); @@ -2511,8 +2511,8 @@ static void display_exit(void *data) status = DEVICE_OPS_STATUS_STOP; /* Set current state to S_NORMAL */ - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); + set_pm_cur_state(S_NORMAL); + set_setting_pmstate(get_pm_cur_state()); /* timeout is not needed */ reset_timeout(TIMEOUT_NONE); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100755 new mode 100644 index 0655878..c01a8d1 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -42,6 +42,7 @@ #include "core.h" #include "device-node.h" #include "display/display-dpms.h" +#include "display/display.h" #include "battery-monitor.h" #include "battery/power-supply.h" @@ -112,9 +113,9 @@ static int bl_onoff(int on, enum device_flags flags) #ifdef ENABLE_PM_LOG if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); else pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); #endif @@ -369,7 +370,7 @@ static int backlight_on(enum device_flags flags) cnt++; ret = bl_onoff(DPMS_ON, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); + pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif return ret; @@ -400,7 +401,7 @@ static int backlight_off(enum device_flags flags) ret = bl_onoff(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); + pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); #endif return ret; @@ -413,9 +414,9 @@ static int backlight_dim(void) ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) - pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM, get_pm_cur_state()); else - pm_history_save(PM_LOG_LCD_DIM_FAIL, pm_cur_state); + pm_history_save(PM_LOG_LCD_DIM_FAIL, get_pm_cur_state()); #endif return ret; } diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c index 27fc2ca..56c09f1 100644 --- a/plugins/wearable/display/hbm.c +++ b/plugins/wearable/display/hbm.c @@ -74,7 +74,7 @@ static gboolean hbm_off_cb(void *data) { timer = 0; - if (pm_cur_state != S_NORMAL) { + if (get_pm_cur_state() != S_NORMAL) { _D("Hbm timeout, but it's not display normal."); return G_SOURCE_REMOVE; } diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index e84836a..621197c 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -104,12 +104,12 @@ static int booting_check = true; static inline int current_state_in_on(void) { - return (pm_cur_state == S_LCDDIM || pm_cur_state == S_NORMAL); + return ((get_pm_cur_state() == S_LCDDIM) || (get_pm_cur_state() == S_NORMAL)); } static inline void restore_custom_brightness(void) { - if (pm_cur_state == S_LCDDIM && + if ((get_pm_cur_state() == S_LCDDIM) && backlight_ops.get_custom_status()) backlight_ops.custom_update(); } @@ -662,10 +662,10 @@ static int check_key_filter(void *data, int fd) break; case EV_REL: - if (pm_cur_state == S_LCDOFF && bezel_wakeup) { + if ((get_pm_cur_state() == S_LCDOFF) && bezel_wakeup) { switch_on_lcd(LCD_ON_BY_BEZEL); ignore = false; - } else if (pm_cur_state != S_LCDOFF) + } else if (get_pm_cur_state() != S_LCDOFF) ignore = false; break; case EV_ABS: diff --git a/plugins/wearable/display/powersaver.c b/plugins/wearable/display/powersaver.c index 5847afc..8177e49 100644 --- a/plugins/wearable/display/powersaver.c +++ b/plugins/wearable/display/powersaver.c @@ -55,7 +55,7 @@ static int set_powersaver_mode(int mode) backlight_ops.update(); get_run_timeout(&timeout); states[S_NORMAL].timeout = timeout; - states[pm_cur_state].trans(EVENT_INPUT); + states[get_pm_cur_state()].trans(EVENT_INPUT); return 0; } diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c old mode 100755 new mode 100644 index dc45e15..281e9be --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -160,9 +160,9 @@ void ambient_check_invalid_state(pid_t pid) static void ambient_start_clock(void) { - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) + if ((get_pm_cur_state() == S_NORMAL) || + (get_pm_cur_state() == S_LCDDIM) || + (ambient_state == false)) return; if (disp_plgn.pm_lock_internal) @@ -172,9 +172,9 @@ static void ambient_start_clock(void) static void ambient_end_clock(pid_t pid) { - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) + if ((get_pm_cur_state() == S_NORMAL) || + (get_pm_cur_state() == S_LCDDIM) || + (ambient_state == false)) return; if (update_count == 0) { diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 665b3f8..9166fc8 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -234,7 +234,7 @@ out: static gboolean alc_handler(void *data) { - if (pm_cur_state != S_NORMAL) { + if (get_pm_cur_state() != S_NORMAL) { if (alc_timeout_id > 0) g_source_remove(alc_timeout_id); alc_timeout_id = 0; @@ -489,7 +489,7 @@ static gboolean update_handler(void *data) update_timeout = 0; - if (pm_cur_state != S_NORMAL) + if (get_pm_cur_state() != S_NORMAL) return G_SOURCE_REMOVE; ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); diff --git a/src/display/core.h b/src/display/core.h index eb9ddb5..bfcab6a 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -96,11 +96,9 @@ enum state_t { /* * Global variables - * pm_cur_state : current state * states : state definitions * trans_table : state transition table */ -extern int pm_cur_state; extern int pm_old_state; /* diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 0ba5e5f..4c7d6ad 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -383,13 +383,13 @@ static GVariant *dbus_getbrightness(GDBusConnection *conn, { int brt = -1, ret, result; - if (pm_cur_state == S_NORMAL) { + if (get_pm_cur_state() == S_NORMAL) { ret = backlight_ops.get_brightness(&brt); if (ret < 0) result = 0; else result = brt; - } else if (pm_cur_state == S_LCDDIM) { + } else if (get_pm_cur_state() == S_LCDDIM) { 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()); @@ -457,7 +457,7 @@ static GVariant *dbus_setbrightness(GDBusConnection *conn, _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) { + if (get_pm_cur_state() == S_LCDDIM) { ret = backlight_ops.set_brightness(brt); if (ret < 0) goto error; @@ -1151,7 +1151,7 @@ static GVariant *dbus_dimstay_control(GDBusConnection *conn, pm_status_flag &= ~DIM_FLAG; } - if (pm_cur_state == S_NORMAL) + if (get_pm_cur_state() == S_NORMAL) backlight_ops.update(); return g_variant_new("(i)", 0); diff --git a/src/display/display.c b/src/display/display.c index de55369..0025b09 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -25,6 +25,18 @@ #include "core/list.h" #include "core/common.h" +static int pm_cur_state; + +inline int get_pm_cur_state(void) +{ + return pm_cur_state; +} + +inline void set_pm_cur_state(int cur_state) +{ + pm_cur_state = cur_state; +} + void lcd_direct_control(enum dpms_state state, int flags) { const struct device_ops *ops = NULL; diff --git a/src/display/display.h b/src/display/display.h index 7443039..cc733f1 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -24,6 +24,8 @@ #include "core/common.h" void lcd_direct_control(enum dpms_state state, int flags); +int get_pm_cur_state(void); +void set_pm_cur_state(int cur_state); enum brightness_request_e { BR_MIN = 0, -- 2.7.4 From 55afcfab2e2130c20c9ff6a1d0165969322c06fa Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 13 Jul 2020 16:02:17 +0900 Subject: [PATCH 09/16] Move pm_old_state to display.c to remove global variable Change-Id: Id366233f17a0ab7cee367775ce5758a8df21854d Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 33 ++++++++++++++++----------------- plugins/mobile/display/core.c | 33 ++++++++++++++++----------------- plugins/tv/display/core.c | 33 ++++++++++++++++----------------- plugins/tv/display/state-tv.c | 30 +++++++++++++++--------------- plugins/wearable/display/core.c | 33 ++++++++++++++++----------------- plugins/wearable/display/hbm.c | 2 +- src/display/core.h | 7 ------- src/display/display.c | 11 +++++++++++ src/display/display.h | 2 ++ 9 files changed, 93 insertions(+), 91 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 52de9bf..b7e6d9f 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -95,7 +95,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; @@ -721,7 +720,7 @@ static gboolean timer_refresh_cb(gpointer data) struct state *st; /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -746,7 +745,7 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -790,7 +789,7 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -831,7 +830,7 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -875,7 +874,7 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -890,7 +889,7 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next); st = &states[get_pm_cur_state()]; @@ -1347,7 +1346,7 @@ int check_lcdoff_direct(void) int ret, lock, cradle; int hdmi_state; - if (pm_old_state != S_NORMAL) + if (get_pm_old_state() != S_NORMAL) return false; if (get_pm_cur_state() != S_LCDDIM) @@ -1401,7 +1400,7 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next_state); st = &states[get_pm_cur_state()]; @@ -1508,7 +1507,7 @@ static int default_action(int timeout) } } - if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); @@ -1518,7 +1517,7 @@ static int default_action(int timeout) device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { + if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", @@ -1531,9 +1530,9 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); - else if (pm_old_state == S_LCDDIM) + else if (get_pm_old_state() == S_LCDDIM) backlight_ops.update(); if (check_lcd_is_on() == false) @@ -1541,18 +1540,18 @@ static int default_action(int timeout) break; case S_LCDDIM: - if (pm_old_state == S_NORMAL && + if ((get_pm_old_state() == S_NORMAL) && backlight_ops.get_custom_status()) backlight_ops.save_custom_brightness(); /* lcd dim state : dim the brightness */ backlight_ops.dim(); - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); break; case S_LCDOFF: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ if (backlight_ops.get_lcd_power() == DPMS_ON) @@ -1565,7 +1564,7 @@ static int default_action(int timeout) break; case S_SLEEP: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); if (backlight_ops.get_lcd_power() == DPMS_ON) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index e02dab8..c7c6b1c 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -97,7 +97,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; @@ -728,7 +727,7 @@ static gboolean timer_refresh_cb(gpointer data) struct state *st; /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -753,7 +752,7 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -797,7 +796,7 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -838,7 +837,7 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -882,7 +881,7 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -897,7 +896,7 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next); st = &states[get_pm_cur_state()]; @@ -1357,7 +1356,7 @@ int check_lcdoff_direct(void) int ret, lock, cradle; int hdmi_state; - if (pm_old_state != S_NORMAL) + if (get_pm_old_state() != S_NORMAL) return false; if (get_pm_cur_state() != S_LCDDIM) @@ -1411,7 +1410,7 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next_state); st = &states[get_pm_cur_state()]; @@ -1518,7 +1517,7 @@ static int default_action(int timeout) } } - if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); @@ -1528,7 +1527,7 @@ static int default_action(int timeout) device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { + if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", @@ -1541,9 +1540,9 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); - else if (pm_old_state == S_LCDDIM) + else if (get_pm_old_state() == S_LCDDIM) backlight_ops.update(); if (check_lcd_is_on() == false) @@ -1551,18 +1550,18 @@ static int default_action(int timeout) break; case S_LCDDIM: - if (pm_old_state == S_NORMAL && + if ((get_pm_old_state() == S_NORMAL) && backlight_ops.get_custom_status()) backlight_ops.save_custom_brightness(); /* lcd dim state : dim the brightness */ backlight_ops.dim(); - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); break; case S_LCDOFF: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ if (backlight_ops.get_lcd_power() == DPMS_ON) @@ -1575,7 +1574,7 @@ static int default_action(int timeout) break; case S_SLEEP: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); if (backlight_ops.get_lcd_power() == DPMS_ON) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 169bd60..c4d4bed 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -95,7 +95,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; @@ -721,7 +720,7 @@ static gboolean timer_refresh_cb(gpointer data) struct state *st; /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -746,7 +745,7 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -790,7 +789,7 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -831,7 +830,7 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -875,7 +874,7 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -890,7 +889,7 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next); st = &states[get_pm_cur_state()]; @@ -1347,7 +1346,7 @@ int check_lcdoff_direct(void) int ret, lock, cradle; int hdmi_state; - if (pm_old_state != S_NORMAL) + if (get_pm_old_state() != S_NORMAL) return false; if (get_pm_cur_state() != S_LCDDIM) @@ -1401,7 +1400,7 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next_state); st = &states[get_pm_cur_state()]; @@ -1508,7 +1507,7 @@ static int default_action(int timeout) } } - if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); @@ -1518,7 +1517,7 @@ static int default_action(int timeout) device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { + if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", @@ -1531,9 +1530,9 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); - else if (pm_old_state == S_LCDDIM) + else if (get_pm_old_state() == S_LCDDIM) backlight_ops.update(); if (check_lcd_is_on() == false) @@ -1541,18 +1540,18 @@ static int default_action(int timeout) break; case S_LCDDIM: - if (pm_old_state == S_NORMAL && + if ((get_pm_old_state() == S_NORMAL) && backlight_ops.get_custom_status()) backlight_ops.save_custom_brightness(); /* lcd dim state : dim the brightness */ backlight_ops.dim(); - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); break; case S_LCDOFF: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ if (backlight_ops.get_lcd_power() == DPMS_ON) @@ -1565,7 +1564,7 @@ static int default_action(int timeout) break; case S_SLEEP: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); if (backlight_ops.get_lcd_power() == DPMS_ON) diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 279538e..68f6a1e 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -163,13 +163,13 @@ static int lcdon_post(void *data) static int lcdon_action(int timeout) { - if ((get_pm_cur_state() != pm_old_state) && + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) set_setting_pmstate(get_pm_cur_state()); - if (pm_old_state != S_LCDOFF && - pm_old_state != S_SLEEP) { - _I("pm_old_state (%s). Skip lcd on", states[pm_old_state].name); + if ((get_pm_old_state() != S_LCDOFF) && + (get_pm_old_state() != S_SLEEP)) { + _I("pm_old_state (%s). Skip lcd on", states[get_pm_old_state()].name); return 0; } @@ -192,7 +192,7 @@ static int lcdon_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDON); st = &states[get_pm_cur_state()]; @@ -235,12 +235,12 @@ static int lcdoff_post(void *data) static int lcdoff_action(int timeout) { - if ((get_pm_cur_state() != pm_old_state) && + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) set_setting_pmstate(get_pm_cur_state()); - if (pm_old_state == S_SUSPEND || - pm_old_state == S_LCDOFF) + if ((get_pm_old_state() == S_SUSPEND) || + (get_pm_old_state() == S_LCDOFF)) return 0; backlight_ops.off(0); @@ -260,7 +260,7 @@ static int lcdoff_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -340,7 +340,7 @@ static gboolean standby_go_next_state(void *data) static int standby_action(int timeout) { - if ((get_pm_cur_state() != pm_old_state) && + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) set_setting_pmstate(get_pm_cur_state()); @@ -366,7 +366,7 @@ static int standby_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_STANDBY); st = &states[get_pm_cur_state()]; @@ -422,7 +422,7 @@ static int suspend_action(int timeout) { struct state *st; - if ((get_pm_cur_state() != pm_old_state) && + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) set_setting_pmstate(get_pm_cur_state()); @@ -435,7 +435,7 @@ static int suspend_action(int timeout) /* Resume !! */ /* system waked up by devices */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -457,14 +457,14 @@ static int suspend_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; if (st->action) st->action(0); - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_SUSPEND); st = &states[get_pm_cur_state()]; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index c7678a2..b880d4e 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -102,7 +102,6 @@ unsigned int pm_status_flag; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; -int pm_old_state; static guint timeout_src_id; static int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; @@ -770,7 +769,7 @@ static gboolean timer_refresh_cb(gpointer data) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -807,7 +806,7 @@ int custom_lcdon(int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -852,7 +851,7 @@ int custom_lcdoff(enum device_flags flag) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -893,7 +892,7 @@ int display_on_by_reason(const char *reason, int timeout) update_display_time(); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; @@ -942,7 +941,7 @@ int display_off_by_reason(const char *reason) lcd_off_procedure(flag); /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; @@ -957,7 +956,7 @@ static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next); st = &states[get_pm_cur_state()]; @@ -1414,7 +1413,7 @@ int check_lcdoff_direct(void) int ret, lock, cradle; int hdmi_state; - if (pm_old_state != S_NORMAL) + if (get_pm_old_state() != S_NORMAL) return false; if (get_pm_cur_state() != S_LCDDIM) @@ -1476,7 +1475,7 @@ static int default_trans(int evt) } /* state transition */ - pm_old_state = get_pm_cur_state(); + set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(next_state); st = &states[get_pm_cur_state()]; @@ -1592,7 +1591,7 @@ static int default_action(int timeout) } } - if ((get_pm_cur_state() != pm_old_state) && (get_pm_cur_state() != S_SLEEP)) { + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); power_ops.power_lock(); @@ -1602,7 +1601,7 @@ static int default_action(int timeout) device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } - if ((pm_old_state == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { + if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { time(&now); diff = difftime(now, last_update_time); _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", @@ -1618,9 +1617,9 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); - else if (pm_old_state == S_LCDDIM) + else if (get_pm_old_state() == S_LCDDIM) backlight_ops.update(); if (check_lcd_is_on() == false) @@ -1628,18 +1627,18 @@ static int default_action(int timeout) break; case S_LCDDIM: - if (pm_old_state == S_NORMAL && + if ((get_pm_old_state() == S_NORMAL) && backlight_ops.get_custom_status()) backlight_ops.save_custom_brightness(); /* lcd dim state : dim the brightness */ backlight_ops.dim(); - if (pm_old_state == S_LCDOFF || pm_old_state == S_SLEEP) + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); break; case S_LCDOFF: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ if (backlight_ops.get_lcd_power() == DPMS_ON) @@ -1652,7 +1651,7 @@ static int default_action(int timeout) break; case S_SLEEP: - if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); if (backlight_ops.get_lcd_power() == DPMS_ON) diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c index 56c09f1..ecbb2f2 100644 --- a/plugins/wearable/display/hbm.c +++ b/plugins/wearable/display/hbm.c @@ -223,7 +223,7 @@ static int display_state_changed(void *data) * outdoor-enhance-mode supported * : check & restore hbm when old state is dim only. */ - if (!get_outdoor_setting || pm_old_state == S_LCDDIM) + if (!get_outdoor_setting || (get_pm_old_state() == S_LCDDIM)) hbm_check_timeout(); break; case S_LCDDIM: diff --git a/src/display/core.h b/src/display/core.h index bfcab6a..98803c7 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -95,13 +95,6 @@ enum state_t { }; /* - * Global variables - * states : state definitions - * trans_table : state transition table - */ -extern int pm_old_state; - -/* * @brief State structure */ struct state { diff --git a/src/display/display.c b/src/display/display.c index 0025b09..d3dcccc 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -26,6 +26,7 @@ #include "core/common.h" static int pm_cur_state; +static int pm_old_state; inline int get_pm_cur_state(void) { @@ -37,6 +38,16 @@ inline void set_pm_cur_state(int cur_state) pm_cur_state = cur_state; } +inline int get_pm_old_state(void) +{ + return pm_old_state; +} + +inline void set_pm_old_state(int old_state) +{ + pm_old_state = old_state; +} + void lcd_direct_control(enum dpms_state state, int flags) { const struct device_ops *ops = NULL; diff --git a/src/display/display.h b/src/display/display.h index cc733f1..4449d92 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -25,7 +25,9 @@ void lcd_direct_control(enum dpms_state state, int flags); int get_pm_cur_state(void); +int get_pm_old_state(void); void set_pm_cur_state(int cur_state); +void set_pm_old_state(int old_state); enum brightness_request_e { BR_MIN = 0, -- 2.7.4 From 1cfcf7133aa3c15ae0b391ee77c6af0f1662082b Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 15 Jul 2020 13:20:50 +0900 Subject: [PATCH 10/16] Add null checking code before calling a bezel HAL Change-Id: Idb80accdaefb7820a0776ca55415d2ffd115d83f Signed-off-by: Youngjae Cho (cherry picked from commit 3809eaa73c98dbc14fae730352fc877e19622f7c) --- plugins/wearable/display/bezel.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 4ae19fa..45bc040 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -68,6 +68,11 @@ static void theater_changed_cb(keynode_t *key_nodes, void *data) assert(key_nodes); + if (!bezel_dev || !bezel_dev->set_state) { + _E("bezel_dev->set_state is not supported."); + return; + } + theater_mode = vconf_keynode_get_bool(key_nodes); _I("Theater mode: %d.", theater_mode); @@ -83,6 +88,11 @@ static void goodnight_changed_cb(keynode_t *key_nodes, void *data) assert(key_nodes); + if (!bezel_dev || !bezel_dev->set_state) { + _E("bezel_dev->set_state is not supported."); + return; + } + goodnight_mode = vconf_keynode_get_bool(key_nodes); _I("Goodnight mode: %d.", goodnight_mode); @@ -101,6 +111,11 @@ static void bezel_rotary_event_cb(keynode_t *key_nodes, void *data) bezel_state = (enum bezel_state) vconf_keynode_get_bool(key_nodes); + if (!bezel_dev || !bezel_dev->set_sw_state) { + _E("bezel_dev->set_sw_state is not supported."); + return; + } + ret = bezel_dev->set_sw_state(bezel_state); if (ret == 0) { @@ -116,8 +131,10 @@ static void bezel_rotary_vibration_set_state(int state) { int ret; - if (!bezel_dev) + if (!bezel_dev || !bezel_dev->set_vib_state) { + _E("bezel_dev->set_vib_state is not supported."); return; + } ret = bezel_dev->set_vib_state(state); if (ret < 0) -- 2.7.4 From 0ac70c1aaea9c8ff3097dad2f55f3d763eb84296 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 15 Jul 2020 14:35:20 +0900 Subject: [PATCH 11/16] Add missing NULL check of calling HAL Change-Id: I85454fd6ce2bebd041025240e0b7c1606b9e6ec4 Signed-off-by: Youngjae Cho --- src/battery/power-supply.c | 2 +- src/led/torch.c | 2 +- src/touchscreen/touchscreen.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 37619d9..15a78db 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1663,7 +1663,7 @@ static void add_power_supply_handler(void) static void remove_power_supply_handler(void) { - if (battery_dev) + if (battery_dev && battery_dev->unregister_changed_event) battery_dev->unregister_changed_event(battery_changed); else unregister_kernel_uevent_control(&uh); diff --git a/src/led/torch.c b/src/led/torch.c index eed1736..fa6ed51 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -97,7 +97,7 @@ static GVariant *dbus_set_brightness(GDBusConnection *conn, g_variant_get(param, "(ii)", &val, &enable); - if (!led_dev) { + if (!led_dev || !led_dev->set_state) { _E("There is no led device."); ret = -ENOENT; goto error; diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index d9c6e59..9bbd93b 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -248,7 +248,7 @@ static int touchscreen_dump(FILE *fp, int mode, void *dump_data) int ret; enum touchscreen_state state; - if (!touchscreen_dev) + if (!touchscreen_dev || !touchscreen_dev->get_state) return 0; ret = touchscreen_dev->get_state(&state); -- 2.7.4 From 2c8e93d26f6e40a1065fd64ff511f4d7bf0140d0 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 14 Jul 2020 21:34:50 +0900 Subject: [PATCH 12/16] Devide pm_status_flag into set and clear functions to remove global variable set_pm_status_flag is to add flag in pm_status_flag clear_pm_status_flag is to clear flag in pm_status_flag Change-Id: If3d9b6969c5a86338b66ca96f1b65fac7efff3a7 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 52 +++++++++++----------- plugins/iot/display/device-interface.c | 8 ++-- plugins/iot/display/key-filter.c | 2 +- plugins/mobile/display/core.c | 50 ++++++++++----------- plugins/mobile/display/device-interface.c | 8 ++-- plugins/mobile/display/key-filter.c | 2 +- plugins/tv/display/core.c | 50 ++++++++++----------- plugins/tv/display/device-interface.c | 8 ++-- plugins/tv/display/key-filter.c | 2 +- .../wearable/display/auto-brightness-sensorhub.c | 2 +- plugins/wearable/display/core.c | 50 ++++++++++----------- plugins/wearable/display/device-interface.c | 6 +-- plugins/wearable/display/key-filter.c | 2 +- plugins/wearable/display/lbm.c | 4 +- src/display/auto-brightness.c | 8 ++-- src/display/core.h | 2 - src/display/display-dbus.c | 7 ++- src/display/display.c | 16 +++++++ src/display/display.h | 3 ++ src/display/poll.c | 2 +- 20 files changed, 146 insertions(+), 138 deletions(-) mode change 100644 => 100755 plugins/wearable/display/device-interface.c diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index b7e6d9f..f3d2f49 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -90,8 +90,6 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); -unsigned int pm_status_flag; - static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -1308,7 +1306,7 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", pm_status_flag); + snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", get_pm_status_flag()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -1665,9 +1663,9 @@ static int default_check(int curr, int next) static void default_saving_mode(int onoff) { if (onoff) - pm_status_flag |= PWRSV_FLAG; + set_pm_status_flag(PWRSV_FLAG); else - pm_status_flag &= ~PWRSV_FLAG; + clear_pm_status_flag(PWRSV_FLAG); if (get_pm_cur_state() == S_NORMAL) backlight_ops.update(); @@ -1687,7 +1685,7 @@ static int poll_callback(int condition, PMMsg *data) if ((get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) _I("Input event signal at Display Off"); time(&now); - if (last_t != now || + if ((last_t != now) || (get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) { states[get_pm_cur_state()].trans(EVENT_INPUT); @@ -1724,14 +1722,14 @@ static int update_setting(int key_idx, int val) break; case SETTING_LOW_BATT: if (low_battery_state(val)) { - if (!(pm_status_flag & CHRGR_FLAG)) + if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } else { - if (pm_status_flag & PWRSV_FLAG) + if (get_pm_status_flag() & PWRSV_FLAG) power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; - pm_status_flag &= ~BRTCH_FLAG; + clear_pm_status_flag(LOWBT_FLAG); + clear_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, false); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1739,11 +1737,11 @@ static int update_setting(int key_idx, int val) break; case SETTING_CHARGING: if (val) { - if (pm_status_flag & LOWBT_FLAG) { + if (get_pm_status_flag() & LOWBT_FLAG) { power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; + clear_pm_status_flag(LOWBT_FLAG); } - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); } else { int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, @@ -1754,14 +1752,14 @@ static int update_setting(int key_idx, int val) } if (low_battery_state(bat_state)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } - pm_status_flag &= ~CHRGR_FLAG; + clear_pm_status_flag(CHRGR_FLAG); } break; case SETTING_BRT_LEVEL: - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; + if (get_pm_status_flag() & PWRSV_FLAG) { + set_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, true); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1797,11 +1795,11 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); break; case POWEROFF_TYPE_DIRECT: case POWEROFF_TYPE_RESTART: - pm_status_flag |= PWROFF_FLAG; + set_pm_status_flag(PWROFF_FLAG); break; } break; @@ -1828,7 +1826,7 @@ static void check_seed_status(void) /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { @@ -1851,9 +1849,9 @@ static void check_seed_status(void) _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } if (low_battery_state(bat_state)) { - if (!(pm_status_flag & CHRGR_FLAG)) { + if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } } @@ -2049,11 +2047,11 @@ static int battery_health_changed(void *data) _I("battery health change %d", health); if (health == HEALTH_GOOD) { - pm_status_flag &= ~BATTERY_FLAG; - pm_status_flag &= ~DIMSTAY_FLAG; + clear_pm_status_flag(BATTERY_FLAG); + clear_pm_status_flag(DIMSTAY_FLAG); } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { - pm_status_flag |= BATTERY_FLAG; - pm_status_flag |= DIMSTAY_FLAG; + set_pm_status_flag(BATTERY_FLAG); + set_pm_status_flag(DIMSTAY_FLAG); } if (backlight_ops.get_lcd_power() == DPMS_ON) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index e3aa582..cd94bfe 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -292,10 +292,10 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { - if (pm_status_flag & DIM_FLAG) + if (get_pm_status_flag() & DIM_FLAG) return true; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if ((get_pm_status_flag() & PWRSV_FLAG) && !(get_pm_status_flag() & BRTCH_FLAG)) return true; return false; @@ -319,7 +319,7 @@ static void change_brightness(int start, int end, int step) if (prev == end) return; - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) end = 0; _I("start %d end %d step %d", start, end, step); @@ -592,7 +592,7 @@ static int set_brightness(int val) val = force_brightness; } - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) val = 0; /* Maximum Brightness to users is 100. diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 801a86d..6de2c63 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -118,7 +118,7 @@ static void pwroff_popup(void) { int ret; - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); if (ret < 0) _E("Failed to launch power off popup."); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index c7c6b1c..91868eb 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -92,8 +92,6 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); -unsigned int pm_status_flag; - static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -1318,7 +1316,7 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", pm_status_flag); + snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", get_pm_status_flag()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -1675,9 +1673,9 @@ static int default_check(int curr, int next) static void default_saving_mode(int onoff) { if (onoff) - pm_status_flag |= PWRSV_FLAG; + set_pm_status_flag(PWRSV_FLAG); else - pm_status_flag &= ~PWRSV_FLAG; + clear_pm_status_flag(PWRSV_FLAG); if (get_pm_cur_state() == S_NORMAL) backlight_ops.update(); @@ -1734,14 +1732,14 @@ static int update_setting(int key_idx, int val) break; case SETTING_LOW_BATT: if (low_battery_state(val)) { - if (!(pm_status_flag & CHRGR_FLAG)) + if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } else { - if (pm_status_flag & PWRSV_FLAG) + if (get_pm_status_flag() & PWRSV_FLAG) power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; - pm_status_flag &= ~BRTCH_FLAG; + clear_pm_status_flag(LOWBT_FLAG); + clear_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, false); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1749,11 +1747,11 @@ static int update_setting(int key_idx, int val) break; case SETTING_CHARGING: if (val) { - if (pm_status_flag & LOWBT_FLAG) { + if (get_pm_status_flag() & LOWBT_FLAG) { power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; + clear_pm_status_flag(LOWBT_FLAG); } - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); } else { int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, @@ -1764,14 +1762,14 @@ static int update_setting(int key_idx, int val) } if (low_battery_state(bat_state)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } - pm_status_flag &= ~CHRGR_FLAG; + clear_pm_status_flag(CHRGR_FLAG); } break; case SETTING_BRT_LEVEL: - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; + if (get_pm_status_flag() & PWRSV_FLAG) { + set_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, true); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1807,11 +1805,11 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); break; case POWEROFF_TYPE_DIRECT: case POWEROFF_TYPE_RESTART: - pm_status_flag |= PWROFF_FLAG; + set_pm_status_flag(PWROFF_FLAG); break; } break; @@ -1838,7 +1836,7 @@ static void check_seed_status(void) /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { @@ -1861,9 +1859,9 @@ static void check_seed_status(void) _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } if (low_battery_state(bat_state)) { - if (!(pm_status_flag & CHRGR_FLAG)) { + if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } } @@ -2059,11 +2057,11 @@ static int battery_health_changed(void *data) _I("battery health change %d", health); if (health == HEALTH_GOOD) { - pm_status_flag &= ~BATTERY_FLAG; - pm_status_flag &= ~DIMSTAY_FLAG; + clear_pm_status_flag(BATTERY_FLAG); + clear_pm_status_flag(DIMSTAY_FLAG); } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { - pm_status_flag |= BATTERY_FLAG; - pm_status_flag |= DIMSTAY_FLAG; + set_pm_status_flag(BATTERY_FLAG); + set_pm_status_flag(DIMSTAY_FLAG); } if (backlight_ops.get_lcd_power() == DPMS_ON) diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 8697ab3..022b616 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -293,10 +293,10 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { - if (pm_status_flag & DIM_FLAG) + if (get_pm_status_flag() & DIM_FLAG) return true; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if ((get_pm_status_flag() & PWRSV_FLAG) && !(get_pm_status_flag() & BRTCH_FLAG)) return true; return false; @@ -320,7 +320,7 @@ static void change_brightness(int start, int end, int step) if (prev == end) return; - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) end = 0; _I("start %d end %d step %d", start, end, step); @@ -593,7 +593,7 @@ static int set_brightness(int val) val = force_brightness; } - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) val = 0; /* Maximum Brightness to users is 100. diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 57903f8..1bd2c08 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -134,7 +134,7 @@ static void longkey_pressed(void) _D("No poweroff capability!"); return; } - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); } static gboolean longkey_restore_cb(void *data) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index c4d4bed..40315b5 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -90,8 +90,6 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); -unsigned int pm_status_flag; - static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -1308,7 +1306,7 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", pm_status_flag); + snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", get_pm_status_flag()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -1665,9 +1663,9 @@ static int default_check(int curr, int next) static void default_saving_mode(int onoff) { if (onoff) - pm_status_flag |= PWRSV_FLAG; + set_pm_status_flag(PWRSV_FLAG); else - pm_status_flag &= ~PWRSV_FLAG; + clear_pm_status_flag(PWRSV_FLAG); if (get_pm_cur_state() == S_NORMAL) backlight_ops.update(); @@ -1724,14 +1722,14 @@ static int update_setting(int key_idx, int val) break; case SETTING_LOW_BATT: if (low_battery_state(val)) { - if (!(pm_status_flag & CHRGR_FLAG)) + if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } else { - if (pm_status_flag & PWRSV_FLAG) + if (get_pm_status_flag() & PWRSV_FLAG) power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; - pm_status_flag &= ~BRTCH_FLAG; + clear_pm_status_flag(LOWBT_FLAG); + clear_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, false); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1739,11 +1737,11 @@ static int update_setting(int key_idx, int val) break; case SETTING_CHARGING: if (val) { - if (pm_status_flag & LOWBT_FLAG) { + if (get_pm_status_flag() & LOWBT_FLAG) { power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; + clear_pm_status_flag(LOWBT_FLAG); } - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); } else { int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, @@ -1754,14 +1752,14 @@ static int update_setting(int key_idx, int val) } if (low_battery_state(bat_state)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } - pm_status_flag &= ~CHRGR_FLAG; + clear_pm_status_flag(CHRGR_FLAG); } break; case SETTING_BRT_LEVEL: - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; + if (get_pm_status_flag() & PWRSV_FLAG) { + set_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, true); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1797,11 +1795,11 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); break; case POWEROFF_TYPE_DIRECT: case POWEROFF_TYPE_RESTART: - pm_status_flag |= PWROFF_FLAG; + set_pm_status_flag(PWROFF_FLAG); break; } break; @@ -1828,7 +1826,7 @@ static void check_seed_status(void) /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { @@ -1851,9 +1849,9 @@ static void check_seed_status(void) _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } if (low_battery_state(bat_state)) { - if (!(pm_status_flag & CHRGR_FLAG)) { + if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } } @@ -2049,11 +2047,11 @@ static int battery_health_changed(void *data) _I("battery health change %d", health); if (health == HEALTH_GOOD) { - pm_status_flag &= ~BATTERY_FLAG; - pm_status_flag &= ~DIMSTAY_FLAG; + clear_pm_status_flag(BATTERY_FLAG); + clear_pm_status_flag(DIMSTAY_FLAG); } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { - pm_status_flag |= BATTERY_FLAG; - pm_status_flag |= DIMSTAY_FLAG; + set_pm_status_flag(BATTERY_FLAG); + set_pm_status_flag(DIMSTAY_FLAG); } if (backlight_ops.get_lcd_power() == DPMS_ON) diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index e3aa582..cd94bfe 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -292,10 +292,10 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { - if (pm_status_flag & DIM_FLAG) + if (get_pm_status_flag() & DIM_FLAG) return true; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if ((get_pm_status_flag() & PWRSV_FLAG) && !(get_pm_status_flag() & BRTCH_FLAG)) return true; return false; @@ -319,7 +319,7 @@ static void change_brightness(int start, int end, int step) if (prev == end) return; - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) end = 0; _I("start %d end %d step %d", start, end, step); @@ -592,7 +592,7 @@ static int set_brightness(int val) val = force_brightness; } - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) val = 0; /* Maximum Brightness to users is 100. diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 8a4239f..c11aff4 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -118,7 +118,7 @@ static void pwroff_popup(void) { int ret; - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); if (ret < 0) _E("Failed to launch power off popup."); diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index 391cb2b..b5c6e47 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -71,7 +71,7 @@ static void set_brightness_level(int level) break; case HBM_LEVEL: /* HBM must do not turn on at DIM_STAY state. */ - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) break; /* * received HBM enable diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index b880d4e..3453a09 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -97,8 +97,6 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); -unsigned int pm_status_flag; - static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -1375,7 +1373,7 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", pm_status_flag); + snprintf(buf, sizeof(buf), "pm_status_flag: %#x\n", get_pm_status_flag()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -1752,10 +1750,10 @@ static int default_check(int curr, int next) static void default_saving_mode(int onoff) { if (onoff) { - pm_status_flag |= PWRSV_FLAG; + set_pm_status_flag(PWRSV_FLAG); auto_brightness_control(BR_LOWDIM_ON, BR_IMPLICIT); } else { - pm_status_flag &= ~PWRSV_FLAG; + clear_pm_status_flag(PWRSV_FLAG); auto_brightness_control(BR_LOWDIM_OFF, BR_IMPLICIT); } } @@ -1811,14 +1809,14 @@ static int update_setting(int key_idx, int val) break; case SETTING_LOW_BATT: if (low_battery_state(val)) { - if (!(pm_status_flag & CHRGR_FLAG)) + if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } else { - if (pm_status_flag & PWRSV_FLAG) + if (get_pm_status_flag() & PWRSV_FLAG) power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; - pm_status_flag &= ~BRTCH_FLAG; + clear_pm_status_flag(LOWBT_FLAG); + clear_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, false); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1826,11 +1824,11 @@ static int update_setting(int key_idx, int val) break; case SETTING_CHARGING: if (val) { - if (pm_status_flag & LOWBT_FLAG) { + if (get_pm_status_flag() & LOWBT_FLAG) { power_saving_func(false); - pm_status_flag &= ~LOWBT_FLAG; + clear_pm_status_flag(LOWBT_FLAG); } - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); } else { int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, @@ -1841,14 +1839,14 @@ static int update_setting(int key_idx, int val) } if (low_battery_state(bat_state)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } - pm_status_flag &= ~CHRGR_FLAG; + clear_pm_status_flag(CHRGR_FLAG); } break; case SETTING_BRT_LEVEL: - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; + if (get_pm_status_flag() & PWRSV_FLAG) { + set_pm_status_flag(BRTCH_FLAG); ret = vconf_set_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, true); if (ret < 0) _E("Failed to set vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); @@ -1884,11 +1882,11 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); break; case POWEROFF_TYPE_DIRECT: case POWEROFF_TYPE_RESTART: - pm_status_flag |= PWROFF_FLAG; + set_pm_status_flag(PWROFF_FLAG); break; } break; @@ -1915,7 +1913,7 @@ static void check_seed_status(void) /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) - pm_status_flag |= CHRGR_FLAG; + set_pm_status_flag(CHRGR_FLAG); ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { @@ -1938,9 +1936,9 @@ static void check_seed_status(void) _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } if (low_battery_state(bat_state)) { - if (!(pm_status_flag & CHRGR_FLAG)) { + if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); - pm_status_flag |= LOWBT_FLAG; + set_pm_status_flag(LOWBT_FLAG); } } @@ -2140,13 +2138,13 @@ static int battery_health_changed(void *data) _I("battery health change %d", health); if (health == HEALTH_GOOD) { - pm_status_flag &= ~BATTERY_FLAG; - pm_status_flag &= ~DIMSTAY_FLAG; + clear_pm_status_flag(BATTERY_FLAG); + clear_pm_status_flag(DIMSTAY_FLAG); if (backlight_ops.get_lcd_power() == DPMS_ON) auto_brightness_restore(); } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { - pm_status_flag |= BATTERY_FLAG; - pm_status_flag |= DIMSTAY_FLAG; + set_pm_status_flag(BATTERY_FLAG); + set_pm_status_flag(DIMSTAY_FLAG); if (backlight_ops.get_lcd_power() == DPMS_ON) backlight_ops.update(); } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100644 new mode 100755 index c01a8d1..14fc45e --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -302,7 +302,7 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { - if (pm_status_flag & DIM_FLAG) + if (get_pm_status_flag() & DIM_FLAG) return true; return false; @@ -326,7 +326,7 @@ static void change_brightness(int start, int end, int step) if (prev == end) return; - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) end = 0; _I("start %d end %d step %d", start, end, step); @@ -599,7 +599,7 @@ static int set_brightness(int val) val = force_brightness; } - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) val = 0; /* Maximum Brightness to users is 100. diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 621197c..5500a8d 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -134,7 +134,7 @@ static void longkey_pressed(void) _D("No poweroff capability!"); return; } - pm_status_flag &= ~PWROFF_FLAG; + clear_pm_status_flag(PWROFF_FLAG); } static gboolean longkey_restore_cb(void *data) diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index 3d19dd2..41a5bb2 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -116,7 +116,7 @@ static int lbm_set_brightness(int val) return -ENOENT; } - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) val = 0; else brt = lbm_down_brt(val); @@ -148,7 +148,7 @@ static void lbm_change_brightness(int start, int end, int step) if (prev == end) return; - if (pm_status_flag & DIM_MASK) + if (get_pm_status_flag() & DIM_MASK) end = 0; _I("Start %d, end %d, step %d.", start, end, step); diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 9166fc8..c8ce92f 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -217,7 +217,7 @@ static bool alc_update_brt(bool setting) out: fault_count++; - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { + if ((fault_count > MAX_FAULT) && !(get_pm_status_flag() & PWROFF_FLAG)) { if (alc_timeout_id) { g_source_remove(alc_timeout_id); alc_timeout_id = 0; @@ -253,7 +253,7 @@ static gboolean alc_handler(void *data) static int alc_action(int timeout) { /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { + if (alc_timeout_id == 0 && !(get_pm_status_flag() & PWRSV_FLAG)) { display_info.update_auto_brightness(true); alc_timeout_id = @@ -391,8 +391,8 @@ static int disconnect_sensor(void) void set_brightness_changed_state(void) { - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; + if (get_pm_status_flag() & PWRSV_FLAG) { + set_pm_status_flag(BRTCH_FLAG); _D("Brightness changed in low battery," "escape dim state (light)."); } diff --git a/src/display/core.h b/src/display/core.h index 98803c7..d3fded2 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -76,8 +76,6 @@ enum pm_log_type { void pm_history_save(enum pm_log_type, int); #endif -extern unsigned int pm_status_flag; - /* * State enumeration */ diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 4c7d6ad..0182c70 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -442,8 +442,7 @@ static GVariant *dbus_setbrightness(GDBusConnection *conn, goto error; } - pm_status_flag &= ~DIM_MASK; - + clear_pm_status_flag(DIM_MASK); if (state == DISPLAY_STATE_NORMAL) { if (disp_plgn.auto_brightness_control) { ret = disp_plgn.auto_brightness_control(BR_SET_BRIGHTNESS, brt); @@ -1145,10 +1144,10 @@ static GVariant *dbus_dimstay_control(GDBusConnection *conn, if (dimstay) { _I("Set DIM_FLAG."); - pm_status_flag |= DIM_FLAG; + set_pm_status_flag(DIM_FLAG); } else { _I("Unset DIM_FLAG."); - pm_status_flag &= ~DIM_FLAG; + clear_pm_status_flag(DIM_FLAG); } if (get_pm_cur_state() == S_NORMAL) diff --git a/src/display/display.c b/src/display/display.c index d3dcccc..e4de7d3 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -27,6 +27,7 @@ static int pm_cur_state; static int pm_old_state; +static unsigned int pm_status_flag; inline int get_pm_cur_state(void) { @@ -48,6 +49,21 @@ inline void set_pm_old_state(int old_state) pm_old_state = old_state; } +inline unsigned int get_pm_status_flag(void) +{ + return pm_status_flag; +} + +inline void set_pm_status_flag(unsigned int status_flag) +{ + pm_status_flag |= status_flag; +} + +inline void clear_pm_status_flag(unsigned int status_flag) +{ + pm_status_flag &= ~status_flag; +} + void lcd_direct_control(enum dpms_state state, int flags) { const struct device_ops *ops = NULL; diff --git a/src/display/display.h b/src/display/display.h index 4449d92..fe1fe07 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -28,6 +28,9 @@ int get_pm_cur_state(void); int get_pm_old_state(void); void set_pm_cur_state(int cur_state); void set_pm_old_state(int old_state); +unsigned int get_pm_status_flag(void); +void set_pm_status_flag(unsigned int status_flag); +void clear_pm_status_flag(unsigned int status_flag); enum brightness_request_e { BR_MIN = 0, diff --git a/src/display/poll.c b/src/display/poll.c index c734a68..19451dd 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -47,7 +47,7 @@ int check_dimstay(int next_state, int flag) if (!(flag & GOTO_STATE_NOW)) return false; - if (!(pm_status_flag & DIMSTAY_FLAG)) + if (!(get_pm_status_flag() & DIMSTAY_FLAG)) return false; return true; -- 2.7.4 From 7fe06d44ffcb4395779da5503b6508dd5d567180 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 21 Jul 2020 13:34:24 +0900 Subject: [PATCH 13/16] Do not control sw bezel on changing display state sw bezel is only controlled by vconf. Change-Id: I44a75eed17ccd3cd5115bce810cd15a017bfdf9f Signed-off-by: Youngjae Cho (cherry picked from commit b8151da7cb2cc94a21b99aaebfe1ba9ac31e603b) --- plugins/wearable/display/bezel.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 45bc040..557baee 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -280,10 +280,8 @@ static int bezel_start(enum device_flags flags) if (bezel_type == BEZEL_HARD) return bezel_dev->set_state(BEZEL_TURNON); - else if (bezel_type == BEZEL_SOFT) - return bezel_dev->set_sw_state(BEZEL_TURNON); - else - return -ENOTSUP; + + return 0; } static int bezel_stop(enum device_flags flags) @@ -296,10 +294,9 @@ static int bezel_stop(enum device_flags flags) if (bezel_type == BEZEL_HARD) { state = bezel_wakeup_control(); return bezel_dev->set_state(state); - } else if (bezel_type == BEZEL_SOFT) - return bezel_dev->set_sw_state(BEZEL_TURNOFF); - else - return -ENOTSUP; + } + + return 0; } /* -- 2.7.4 From ec0c8ae86c88d2e5f42b133ff408416e75ebeef3 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 23 Jul 2020 10:19:15 +0900 Subject: [PATCH 14/16] Change abnormal health popup lcddim lock to 60s In the below commit, 6b0553796377417ea333f246742dc302e024cc6e it is missed that update macro to 1 min. Change-Id: I3c761d3107ff62e6137505d6fca38b5f6dec92bc Signed-off-by: Youngjae Cho (cherry picked from commit 1eb746baa6176ba20528236afc1a28e1000ff421) --- src/battery/power-supply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 15a78db..d22495e 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -80,7 +80,7 @@ #define RETRY_MAX 5 #define BATTERY_CHECK_TIMER_INTERVAL 500 /* 0.5 second */ -#define LCD_DIM_TIME_IN_BATTERY_HEALTH 10000 /* ms */ +#define LCD_DIM_TIME_IN_BATTERY_HEALTH 60000 /* ms */ static void uevent_power_handler(struct udev_device *dev); static const struct uevent_handler uh = { -- 2.7.4 From da3b2c902be0ae1b9befc94f8aa54430b9c16d76 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 23 Jul 2020 13:38:11 +0900 Subject: [PATCH 15/16] Apply new power management feature, Doze mode Change-Id: Ia515c2130c1b68eab6dc5bc2b5a3d2beb62c1114 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 12 ++- plugins/mobile/display/core.c | 12 ++- plugins/tv/display/core.c | 12 ++- plugins/wearable/display/core.c | 6 ++ src/power/boot.c | 3 + src/power/doze.c | 174 ++++++++++++++++++++++++++++++++++++++++ src/power/doze.h | 27 +++++++ 7 files changed, 237 insertions(+), 9 deletions(-) create mode 100644 src/power/doze.c create mode 100644 src/power/doze.h diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index f3d2f49..bc8cf99 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -57,6 +57,7 @@ #include "battery/power-supply.h" #include "power/power-handler.h" #include "power/boot.h" +#include "power/doze.h" #include "dd-display.h" #include "display-dpms.h" #include "display-signal.h" @@ -325,6 +326,8 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; + leave_doze(); + /* * Display on procedure * step 1. broadcast lcd on signal with cause @@ -409,6 +412,7 @@ inline void lcd_off_procedure(enum device_flags flag) * - a. display off * - b. TSP(touch screen) and touchkey disable * step 4. broadcast lcd off complete siganl + * step 5. enter doze mode if it is enabled */ _I("[lcdstep] 0x%lx", flags); @@ -442,12 +446,14 @@ inline void lcd_off_procedure(enum device_flags flag) DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); - if (flags & AMBIENT_MODE) + if (flags & AMBIENT_MODE) { broadcast_lcd_off_late(flags); - else + } else { broadcast_lcd_off(SIGNAL_POST, flags); + device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); + } - device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); + enter_doze(); } void set_stay_touchscreen_off(int val) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 91868eb..8b7142b 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -57,6 +57,7 @@ #include "battery/power-supply.h" #include "power/power-handler.h" #include "power/boot.h" +#include "power/doze.h" #include "dd-display.h" #include "display/display-dpms.h" #include "proximity.h" @@ -332,6 +333,8 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; + leave_doze(); + /* * Display on procedure * step 1. broadcast lcd on signal with cause @@ -416,6 +419,7 @@ inline void lcd_off_procedure(enum device_flags flag) * - a. display off * - b. TSP(touch screen) and touchkey disable * step 4. broadcast lcd off complete siganl + * step 5. enter doze mode if it is enabled */ _I("[lcdstep] 0x%lx", flags); @@ -449,12 +453,14 @@ inline void lcd_off_procedure(enum device_flags flag) DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); - if (flags & AMBIENT_MODE) + if (flags & AMBIENT_MODE) { broadcast_lcd_off_late(flags); - else + } else { broadcast_lcd_off(SIGNAL_POST, flags); + device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); + } - device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); + enter_doze(); } void set_stay_touchscreen_off(int val) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 40315b5..dd0c311 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -57,6 +57,7 @@ #include "battery/power-supply.h" #include "power/power-handler.h" #include "power/boot.h" +#include "power/doze.h" #include "dd-display.h" #include "display-dpms.h" #include "display-signal.h" @@ -325,6 +326,8 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; + leave_doze(); + /* * Display on procedure * step 1. broadcast lcd on signal with cause @@ -409,6 +412,7 @@ inline void lcd_off_procedure(enum device_flags flag) * - a. display off * - b. TSP(touch screen) and touchkey disable * step 4. broadcast lcd off complete siganl + * step 5. enter doze mode if it is enabled */ _I("[lcdstep] 0x%lx", flags); @@ -442,12 +446,14 @@ inline void lcd_off_procedure(enum device_flags flag) DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); - if (flags & AMBIENT_MODE) + if (flags & AMBIENT_MODE) { broadcast_lcd_off_late(flags); - else + } else { broadcast_lcd_off(SIGNAL_POST, flags); + device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); + } - device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); + enter_doze(); } void set_stay_touchscreen_off(int val) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 3453a09..094c829 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -58,6 +58,7 @@ #include "battery/power-supply.h" #include "power/power-handler.h" #include "power/boot.h" +#include "power/doze.h" #include "dd-display.h" #include "display/display-dpms.h" #include "display-info.h" @@ -343,6 +344,8 @@ void lcd_on_procedure(int state, enum device_flags flag) flags |= flag; int ret; + leave_doze(); + /* * Display on procedure * step 0. check if display is detached (only for factory mode) @@ -435,6 +438,7 @@ inline void lcd_off_procedure(enum device_flags flag) * - a. display off * - b. TSP(touch screen) and touchkey disable * step 4. broadcast lcd off complete siganl + * step 5. enter doze mode if it is enabled */ _I("[lcdstep] 0x%lx", flags); @@ -474,6 +478,8 @@ inline void lcd_off_procedure(enum device_flags flag) broadcast_lcd_off(SIGNAL_POST, flags); device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); } + + enter_doze(); } void set_stay_touchscreen_off(int val) diff --git a/src/power/boot.c b/src/power/boot.c index 77b04bc..6595810 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -29,6 +29,7 @@ #include "core/common.h" #include "display/poll.h" #include "display/display-ops.h" +#include "doze.h" #define SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED "StartupFinished" #define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED "UserSessionStartupFinished" @@ -81,6 +82,8 @@ static void booting_done_received(GDBusConnection *conn, disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); _I("Signal booting done."); + + doze_init(); } void add_booting_done_handler(void *data) diff --git a/src/power/doze.c b/src/power/doze.c new file mode 100644 index 0000000..743e44e --- /dev/null +++ b/src/power/doze.c @@ -0,0 +1,174 @@ +/* + * deviced + * + * Copyright (c) 2020 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 + +#include "doze.h" +#include "core/log.h" +#include "core/device-notifier.h" +#include "display/core.h" + +#define DOZE_DISABLED 0 +#define DOZE_ENABLED 1 +static int doze_mode; /* doze from setting */ + +enum doze_level { + DOZE_LEVEL_0 = 0, /* doze off mode */ + DOZE_LEVEL_1, + DOZE_LEVEL_MAX, +}; +static enum doze_level doze_level; +static int display_state; +static bool doze_initialized = false; + +static int change_doze_level(enum doze_level level) +{ + int ret; + + if (level < DOZE_LEVEL_0 || level >= DOZE_LEVEL_MAX) { + _E("Invalid doze level %d.", level); + return -EINVAL; + } + + if (doze_level == level) + return 0; + + _D("Change doze level, %d -> %d.", doze_level, level); + doze_level = level; + + ret = vconf_set_int(VCONFKEY_SYSMAN_DOZE_MODE_LEVEL, doze_level); + if (ret < 0) { + _E("Failed to set doze level, %d.", vconf_get_ext_errno()); + return ret; + } + + return 0; +} + +static void _enter_doze(void) +{ + /* already in doze mode */ + if (doze_level >= DOZE_LEVEL_1) + return; + + _D("Entering doze mode."); + change_doze_level(DOZE_LEVEL_1); +} + +static void _leave_doze(void) +{ + /* already not in doze mode */ + if (doze_level == DOZE_LEVEL_0) + return; + + _D("Leaving doze mode."); + change_doze_level(DOZE_LEVEL_0); +} + +void enter_doze(void) +{ + if (!doze_initialized) + return; + + if (doze_mode == DOZE_DISABLED) + return; + + _enter_doze(); +} + +void leave_doze(void) +{ + if (!doze_initialized) + return; + + if (doze_mode == DOZE_DISABLED) + return; + + _leave_doze(); +} + +static int display_changed_cb(void *data) +{ + display_state = *(int *)data; + + return 0; +} + +static void setting_doze_mode_cb(keynode_t *key, void *data) +{ + int val; + + val = vconf_keynode_get_bool(key); + + if (val < 0) { + _E("Failed to get vconf value for doze, %d.", vconf_get_ext_errno()); + return; + } + + if (doze_mode == val) + return; + + doze_mode = val; + + if (!doze_initialized) + return; + + if (doze_mode == DOZE_DISABLED) { + _leave_doze(); + _D("Doze mode disabled."); + } else if (doze_mode == DOZE_ENABLED) { + _D("Doze mode enabled."); + if (display_state == S_LCDOFF || display_state == S_SLEEP) + _enter_doze(); + } + +} + +int doze_init(void) +{ + int ret; + + ret = vconf_get_bool(VCONFKEY_SETAPPL_DOZE_MODE, &doze_mode); + if (ret < 0) { + _E("Failed to get vconf value for doze, %d.", vconf_get_ext_errno()); + return ret; + } + + ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DOZE_MODE, setting_doze_mode_cb, NULL); + if (ret < 0) { + _E("Failed to register vconf notify."); + return ret; + } + + doze_level = DOZE_LEVEL_0; + + register_notifier(DEVICE_NOTIFIER_LCD, display_changed_cb); + + doze_initialized = true; + _D("Doze mode initialized. doze_mode: %d.", doze_mode); + + return 0; +} + +int doze_exit(void) +{ + doze_initialized = false; + + unregister_notifier(DEVICE_NOTIFIER_LCD, display_changed_cb); + + return 0; +} diff --git a/src/power/doze.h b/src/power/doze.h new file mode 100644 index 0000000..435fdd9 --- /dev/null +++ b/src/power/doze.h @@ -0,0 +1,27 @@ +/* + * deviced + * + * Copyright (c) 2020 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. + */ + +#ifndef __DOZE_H__ +#define __DOZE_H__ + +void enter_doze(void); +void leave_doze(void); +int doze_init(void); +int doze_exit(void); + +#endif -- 2.7.4 From f4406db7ac8fe849c47c7b4fe2d3a06599b407d0 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 27 Jul 2020 13:35:58 +0900 Subject: [PATCH 16/16] Add DPMS checklist for dependable DPMS control For guaranteeing HBMOFF before DPMS OFF, needs for checker has arisen. There can be corner case that HBM hasn't been offed before DPMS OFF. To detect such situation, introduced checklist. And check right before the DPMS request, guaranteeing HBMOFF. Change-Id: Id490891f98ec2896b5b6b566aedc741c4c7b2f91 Signed-off-by: Youngjae Cho (cherry picked from commit 084c700b17ffdba0b3e3b295ece1867faaf8bb0a) --- plugins/wearable/display/hbm.c | 23 +++++++++++++++++++++++ src/display/display-dpms.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/display/display-dpms.h | 2 ++ 3 files changed, 65 insertions(+) diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c index ecbb2f2..698b49e 100644 --- a/plugins/wearable/display/hbm.c +++ b/plugins/wearable/display/hbm.c @@ -25,6 +25,7 @@ #include "display/util.h" #include "display/core.h" #include "display/display-ops.h" +#include "display/display-dpms.h" #include "core/common.h" #include "core/device-notifier.h" #include "core/config-parser.h" @@ -367,6 +368,25 @@ static char *find_hbm_node() return result; } +static void dpms_check_hbm_off(void) +{ + int real_hbm = hbm_get_state(); + + if (real_hbm == true) { + _W("HBM still enabled right before DPMS OFF, turn off HBM."); + auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); + + /* check once more whether the HBM is really OFFed by auto_brightness_control */ + real_hbm = hbm_get_state(); + + /* hbm state, flag mismatch occured. Force HBMOFF */ + if (real_hbm == true) { + _E("HBM state, flag mismatch occured. Force HBMOFF."); + hbm_set_state(false); + } + } +} + static void hbm_init(void *data) { int ret; @@ -386,6 +406,9 @@ static void hbm_init(void *data) /* register notifier */ register_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); + + /* double check to guarantee HBMOFF before DPMS OFF */ + register_dpms_checklist(DPMS_OFF, dpms_check_hbm_off); } static void hbm_exit(void *data) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index b1932fb..81be588 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -26,6 +26,9 @@ #include #include "core/log.h" +#include "core/list.h" +#include "core/device-notifier.h" +#include "display/device-interface.h" #include "display/util.h" #include "display/display-dpms.h" #include "display/device-interface.h" @@ -426,6 +429,41 @@ static bool dpms_is_available(void) return dpms_client; } +static dd_list *dpms_on_checklist; +static dd_list *dpms_off_checklist; + +/* Check for critical checklist before dpms control. + * The checklist should be minimized for responsiveness */ +static void check_dpms_checklist(int mode) +{ + dd_list *elem; + void (*checker)(void); + + if (mode == DPMS_ON) + DD_LIST_FOREACH(dpms_on_checklist, elem, checker) + checker(); + else if (mode == DPMS_OFF || mode == DPMS_FORCE_OFF) + DD_LIST_FOREACH(dpms_off_checklist, elem, checker) + checker(); +} + +void __register_dpms_checklist(int mode, void (*checker)(void), const char *caller) +{ + if (!checker) + return; + + CRITICAL_LOG("%s registered dpms(%s) checklist, %p.", caller, + mode == DPMS_ON ? "DPMS_ON" : + mode == DPMS_OFF ? "DPMS_OFF" : + mode == DPMS_FORCE_OFF ? "DPMS_FORCE_OFF" : "Unknown", + checker); + + if (mode == DPMS_ON) + DD_LIST_APPEND(dpms_on_checklist, checker); + else if (mode == DPMS_OFF || mode == DPMS_FORCE_OFF) + DD_LIST_APPEND(dpms_off_checklist, checker); +} + /* * Wait for a dpms response for a given timeout. */ @@ -469,6 +507,8 @@ void dpms_set_state(int on) dpms_set_state_done = false; + check_dpms_checklist(mode); + tizen_dpms_manager_set_dpms(dpms_client->tz_dpms_mng, dpms_client->wl_output, mode); wl_display_flush(dpms_client->wl_disp); diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h index 6c401be..4a936ee 100644 --- a/src/display/display-dpms.h +++ b/src/display/display-dpms.h @@ -23,4 +23,6 @@ void dpms_set_state(int on); int dpms_get_state(void); bool init_dpms(void); void exit_dpms(void); +void __register_dpms_checklist(int mode, void (*checker)(void), const char *caller); +#define register_dpms_checklist(mode, checker) __register_dpms_checklist(mode, checker, __func__) #endif /* __DISPLAY_DPMS_H__ */ -- 2.7.4