From 6b27a38449547be0b64a521120e7012c0f35b0c7 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 9 May 2019 11:17:07 +0900 Subject: [PATCH 01/16] Remove unused function print_lowbat_state Change-Id: I43419bc75a0f3b7d2cc06592dce3fabb0585459b Signed-off-by: lokilee73 --- src/battery/lowbat-handler.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 9f37f39..21b51e5 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -162,15 +162,6 @@ static int lowbat_add_scenario(int old, int now, int (*func)(void *data)) return 0; } -static void print_lowbat_state(unsigned int bat_percent) -{ -#if 0 - int i; - for (i = 0; i < BAT_MON_SAMPLES; i++) - _D("\t%d", recent_bat_percent[i]); -#endif -} - static int power_execute(void *data) { static const struct device_ops *ops; @@ -733,7 +724,6 @@ static void lowbat_monitor(void *data) return; } else bat_percent = *(int *)data; - print_lowbat_state(bat_percent); lowbat_process(bat_percent, NULL); } -- 2.7.4 From c7081697c0a0469d75cb819e8465bdce9e92f143 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 9 May 2019 12:14:29 +0900 Subject: [PATCH 02/16] Move vconf setting for capacity from lowbat_process to process_power_supply Lowbat_process has to deal with low battery related parameters. It's better to set capcity related vconf in process_power_supply. Change-Id: I46d3feb977824e90bc32f74050382637af8b63d6 Signed-off-by: lokilee73 --- src/battery/lowbat-handler.c | 11 +---------- src/battery/power-supply.c | 7 +++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 21b51e5..354bbb6 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -585,16 +585,7 @@ static int lowbat_process(int bat_percent, void *ad) change_lowbat_level(new_bat_capacity); battery_level_send_system_event(new_bat_capacity); - if (new_bat_capacity != cur_bat_capacity) { - _D("[BAT_MON] cur=%d new=%d", cur_bat_capacity, new_bat_capacity); - ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, new_bat_capacity); - if (ret == 0) - cur_bat_capacity = new_bat_capacity; - else - _E("Failed to set vconf value for battery capacity: %d", vconf_get_ext_errno()); - - power_supply_broadcast(CHARGE_CAPACITY_SIGNAL, new_bat_capacity); - } + cur_bat_capacity = new_bat_capacity; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &vconf_state); if (ret < 0) { diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 9e0d54b..710599d 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -688,6 +688,13 @@ static void process_power_supply(void *data) power_supply_broadcast(CHARGE_NOW_SIGNAL, battery.charge_now); } + if (old_battery.capacity != battery.capacity) { + ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery.capacity); + if (ret < 0) + _E("Failed to set vconf value for battery capacity: %d", vconf_get_ext_errno()); + power_supply_broadcast(CHARGE_CAPACITY_SIGNAL, battery.capacity); + } + lowbat_execute(data); check_online(); if (old_battery.charge_full != battery.charge_full) -- 2.7.4 From 67d5f7157d53d6adcf73aa4a53dcc1e85ee52a50 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 9 May 2019 14:57:01 +0900 Subject: [PATCH 03/16] Change function name dbus_get_charge_level is used to get vconf value of VCONFKEY_SYSMAN_BATTERY_STATUS_LOW. It's not intuitive. So, change it. Change-Id: Ieb62b6fcd9baabbb7a746782f2146bc397d80432 Signed-off-by: lokilee73 --- src/battery/power-supply.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 710599d..c4eb7c8 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -856,7 +856,7 @@ static GVariant *dbus_get_charge_now(GDBusConnection *conn, return g_variant_new("(i)", ret); } -static GVariant *dbus_get_charge_level(GDBusConnection *conn, +static GVariant *dbus_get_status_low(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { @@ -1029,7 +1029,7 @@ static GVariant *dbus_get_battery_info(GDBusConnection *conn, static const dbus_method_s dbus_methods[] = { { CHARGER_STATUS_SIGNAL, NULL, "i", dbus_get_charger_status }, { CHARGE_NOW_SIGNAL, NULL, "i", dbus_get_charge_now }, - { CHARGE_LEVEL_SIGNAL, NULL, "i", dbus_get_charge_level }, + { CHARGE_LEVEL_SIGNAL, NULL, "i", dbus_get_status_low }, { CHARGE_CAPACITY_SIGNAL, NULL, "i", dbus_get_percent }, { CHARGE_CAPACITY_LAW_SIGNAL, NULL, "i", dbus_get_percent_raw }, { CHARGE_FULL_SIGNAL, NULL, "i", dbus_is_full }, -- 2.7.4 From 2633e05005bb79a9c5665781c84d68b63022831b Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 9 May 2019 17:00:27 +0900 Subject: [PATCH 04/16] Add low_bat_old to nofify when low_bat changes Currently, DEVICE_NOTIFIER_LOWBAT is notified periodically. So, add low_bat_old to notify when low_bat is changed. Change-Id: I70b1730a993f4f1783e20c719970223901b752b4 Signed-off-by: lokilee73 --- src/battery/lowbat-handler.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 354bbb6..0ba1ae1 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -570,6 +570,7 @@ static void change_lowbat_level(int bat_percent) static int lowbat_process(int bat_percent, void *ad) { static int online; + static bool low_bat_old; int new_bat_capacity; int new_bat_state; int vconf_state = -1; @@ -652,7 +653,10 @@ static int lowbat_process(int bat_percent, void *ad) if (new_bat_capacity <= battery_info.warning) low_bat = true; - device_notify(DEVICE_NOTIFIER_LOWBAT, (void *)low_bat); + if (low_bat_old != low_bat) { + device_notify(DEVICE_NOTIFIER_LOWBAT, (void *)&low_bat); + low_bat_old = low_bat; + } if (battery.online == POWER_SUPPLY_TYPE_UNKNOWN) { _E("Battery online is not initialized."); -- 2.7.4 From 15e715b79359974582b6e96338e922451fe2ff79 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 10 May 2019 14:20:03 +0900 Subject: [PATCH 05/16] Fix invalid return value of dbus Return value in dbus_locktimeout_expired has to be integer. So, fix it. Change-Id: Ie34853948852bca28f87bf0c984c59ea07a86fdd Signed-off-by: lokilee73 --- plugins/iot/display/display-dbus.c | 2 +- plugins/mobile/display/display-dbus.c | 2 +- plugins/tv/display/display-dbus.c | 2 +- plugins/wearable/display/display-dbus.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c index 12e1d0a..69ef153 100644 --- a/plugins/iot/display/display-dbus.c +++ b/plugins/iot/display/display-dbus.c @@ -963,7 +963,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, return NULL; out: - gvar = g_variant_new("(si)", req_id, ret); + gvar = g_variant_new("(i)", ret); g_free(req_id); if (ex) free(ex); diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c index 12e1d0a..69ef153 100644 --- a/plugins/mobile/display/display-dbus.c +++ b/plugins/mobile/display/display-dbus.c @@ -963,7 +963,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, return NULL; out: - gvar = g_variant_new("(si)", req_id, ret); + gvar = g_variant_new("(i)", ret); g_free(req_id); if (ex) free(ex); diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c index 12e1d0a..69ef153 100644 --- a/plugins/tv/display/display-dbus.c +++ b/plugins/tv/display/display-dbus.c @@ -963,7 +963,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, return NULL; out: - gvar = g_variant_new("(si)", req_id, ret); + gvar = g_variant_new("(i)", ret); g_free(req_id); if (ex) free(ex); diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c index 12e1d0a..69ef153 100644 --- a/plugins/wearable/display/display-dbus.c +++ b/plugins/wearable/display/display-dbus.c @@ -963,7 +963,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, return NULL; out: - gvar = g_variant_new("(si)", req_id, ret); + gvar = g_variant_new("(i)", ret); g_free(req_id); if (ex) free(ex); -- 2.7.4 From 5d18bc167445fd3f238ff13421963bbd4db393bd Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 13 May 2019 11:16:51 +0900 Subject: [PATCH 06/16] Fix dbus error by no reply timeout There is a dbus error, when dbus_lockTimeoutExpired is called. So, change it to reply. Change-Id: Ica0dda733d5b8e8da6fa45cc6328a6a1a2f5cd60 Signed-off-by: lokilee73 --- plugins/iot/display/display-dbus.c | 9 ++------- plugins/mobile/display/display-dbus.c | 9 ++------- plugins/tv/display/display-dbus.c | 9 ++------- plugins/wearable/display/display-dbus.c | 9 ++------- 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c index 69ef153..382dbed 100644 --- a/plugins/iot/display/display-dbus.c +++ b/plugins/iot/display/display-dbus.c @@ -911,7 +911,6 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -959,15 +958,11 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); - g_free(req_id); - return NULL; - out: - gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex) + if (ex && ret < 0) free(ex); - return gvar; + return g_variant_new("(i)", ret); } static gboolean app_term(gpointer data) diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c index 69ef153..382dbed 100644 --- a/plugins/mobile/display/display-dbus.c +++ b/plugins/mobile/display/display-dbus.c @@ -911,7 +911,6 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -959,15 +958,11 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); - g_free(req_id); - return NULL; - out: - gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex) + if (ex && ret < 0) free(ex); - return gvar; + return g_variant_new("(i)", ret); } static gboolean app_term(gpointer data) diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c index 69ef153..382dbed 100644 --- a/plugins/tv/display/display-dbus.c +++ b/plugins/tv/display/display-dbus.c @@ -911,7 +911,6 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -959,15 +958,11 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); - g_free(req_id); - return NULL; - out: - gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex) + if (ex && ret < 0) free(ex); - return gvar; + return g_variant_new("(i)", ret); } static gboolean app_term(gpointer data) diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c index 69ef153..382dbed 100644 --- a/plugins/wearable/display/display-dbus.c +++ b/plugins/wearable/display/display-dbus.c @@ -911,7 +911,6 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -959,15 +958,11 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); - g_free(req_id); - return NULL; - out: - gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex) + if (ex && ret < 0) free(ex); - return gvar; + return g_variant_new("(i)", ret); } static gboolean app_term(gpointer data) -- 2.7.4 From 0f59b98e8eae8cbf6b1f4e83228fb2f0c5c4d39c Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 13 May 2019 08:53:01 +0000 Subject: [PATCH 07/16] Revert "Fix dbus error by no reply timeout" This reverts commit 5d18bc167445fd3f238ff13421963bbd4db393bd. Change-Id: Ieb797fecd0230dea2d4558dd7ea629fdfded2ccb --- plugins/iot/display/display-dbus.c | 9 +++++++-- plugins/mobile/display/display-dbus.c | 9 +++++++-- plugins/tv/display/display-dbus.c | 9 +++++++-- plugins/wearable/display/display-dbus.c | 9 +++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c index 382dbed..69ef153 100644 --- a/plugins/iot/display/display-dbus.c +++ b/plugins/iot/display/display-dbus.c @@ -911,6 +911,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; + GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -958,11 +959,15 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); + g_free(req_id); + return NULL; + out: + gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex && ret < 0) + if (ex) free(ex); - return g_variant_new("(i)", ret); + return gvar; } static gboolean app_term(gpointer data) diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c index 382dbed..69ef153 100644 --- a/plugins/mobile/display/display-dbus.c +++ b/plugins/mobile/display/display-dbus.c @@ -911,6 +911,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; + GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -958,11 +959,15 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); + g_free(req_id); + return NULL; + out: + gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex && ret < 0) + if (ex) free(ex); - return g_variant_new("(i)", ret); + return gvar; } static gboolean app_term(gpointer data) diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c index 382dbed..69ef153 100644 --- a/plugins/tv/display/display-dbus.c +++ b/plugins/tv/display/display-dbus.c @@ -911,6 +911,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; + GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -958,11 +959,15 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); + g_free(req_id); + return NULL; + out: + gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex && ret < 0) + if (ex) free(ex); - return g_variant_new("(i)", ret); + return gvar; } static gboolean app_term(gpointer data) diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c index 382dbed..69ef153 100644 --- a/plugins/wearable/display/display-dbus.c +++ b/plugins/wearable/display/display-dbus.c @@ -911,6 +911,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, char pid_str[16]; char comm[NAME_MAX]; struct pmlock_expired_s *ex = NULL; + GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -958,11 +959,15 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, DD_LIST_APPEND(expired_req_list, ex); + g_free(req_id); + return NULL; + out: + gvar = g_variant_new("(i)", ret); g_free(req_id); - if (ex && ret < 0) + if (ex) free(ex); - return g_variant_new("(i)", ret); + return gvar; } static gboolean app_term(gpointer data) -- 2.7.4 From 2faf677d8748503f6d540e4f9a30b74e52f1d28f Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Fri, 10 May 2019 20:39:01 +0900 Subject: [PATCH 08/16] usbhost: dbus: modified to reply error type message if failed gdbus method handler should reply g_variant with valid signature or error type message. Change-Id: I7acf504685fd37db343ad756e06b5446f426c264 Signed-off-by: sanghyeok.oh --- src/usbhost/usb-host.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 6ef9bfe..0e419b7 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -458,38 +458,51 @@ static GVariant *get_device_list(GDBusConnection *conn, const char *str; int baseclass; GVariantBuilder *builder = NULL; + const char *error = NULL; + int item_cnt = 0; g_variant_get(param, "(i)", &baseclass); builder = g_variant_builder_new(G_VARIANT_TYPE("a(siiiiisss)")); if (!builder) { - _E("Failed to new builder."); + _E("Failed to alloc memory for g_variant_builder."); + error = "Failed to alloc memory for g_variant_builder."; goto out; } DD_LIST_FOREACH(usbhost_list, elem, usbhost) { if (baseclass != USB_CLASS_ALL && usbhost->baseclass != baseclass) continue; - g_variant_builder_add(builder, "s", &str); - g_variant_builder_add(builder, "i", &usbhost->baseclass); - g_variant_builder_add(builder, "i", &usbhost->subclass); - g_variant_builder_add(builder, "i", &usbhost->protocol); - g_variant_builder_add(builder, "i", &usbhost->vendorid); - g_variant_builder_add(builder, "i", &usbhost->productid); - str = (!usbhost->manufacturer ? "" : usbhost->manufacturer); - g_variant_builder_add(builder, "s", &str); - str = (!usbhost->product ? "" : usbhost->product); - g_variant_builder_add(builder, "s", &str); - str = (!usbhost->serial ? "" : usbhost->serial); - g_variant_builder_add(builder, "s", &str); + + g_variant_builder_add(builder, "(siiiiisss)", + nullstr(NULL), + usbhost->baseclass, + usbhost->subclass, + usbhost->protocol, + usbhost->vendorid, + usbhost->productid, + nullstr(usbhost->manufacturer), + nullstr(usbhost->product), + nullstr(usbhost->serial)); + ++item_cnt; + } + + if (item_cnt == 0) { + _E("Not found matched item"); + error = "Not found matched item"; + goto out; } - gvar = g_variant_builder_end(builder); - // todo: make format and fill it as 0; - g_variant_builder_unref(builder); + gvar = g_variant_new("(a(siiiiisss))", builder); out: - return (gvar ? gvar : dbus_handle_new_g_variant_tuple()); + if (builder) + g_variant_builder_unref(builder); + if (!gvar) + g_dbus_method_invocation_return_error(invocation, + G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, + "%s", error); + return gvar; } static GVariant *get_device_list_count(GDBusConnection *conn, -- 2.7.4 From 41a137a4b4ef1d18fc518c480ddce65869229205 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 14 May 2019 14:15:15 +0900 Subject: [PATCH 09/16] Fix signature mis-match in expired_deliver_result Expected signature is 'i', but returned value is 'si'. So, fix it. Change-Id: I9e476983a7bef55dcc94fd8bd1fc83b98563bbcd Signed-off-by: lokilee73 --- plugins/iot/display/display-dbus.c | 2 +- plugins/mobile/display/display-dbus.c | 2 +- plugins/tv/display/display-dbus.c | 2 +- plugins/wearable/display/display-dbus.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/iot/display/display-dbus.c +++ b/plugins/iot/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/mobile/display/display-dbus.c +++ b/plugins/mobile/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/tv/display/display-dbus.c +++ b/plugins/tv/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/wearable/display/display-dbus.c +++ b/plugins/wearable/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); -- 2.7.4 From d6a3b3fe3b088edf094711e4eb1e34f82609720f Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 14 May 2019 21:29:07 +0900 Subject: [PATCH 10/16] Fix segment fault in control_handler and get_control_handler There are segment fault because of argc. Buffer size of argv is 2 or 3, but it can exceed limitation by argc. So, change conditions as below. 1. Check conditions and return -EINAL when it's not satisfied ex) if argc is 3 in dbus_control_handler if argc is 2 in dbus_get_control_handler 2. Remove argc check in control_handler and get_control_handler, because it's wrong Change-Id: I22c4c89d59deeeb5181dd7787ed9ca60ea2af50d Signed-off-by: lokilee73 --- src/control/control.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/control/control.c b/src/control/control.c index d410134..6112898 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -55,12 +55,6 @@ static int control_handler(int argc, char **argv) for (i = 0; i < argc; ++i) _I("argv[%2d]=%s", i, argv[i]); - if (argc > 5) { - _E("Invalid argument."); - errno = EINVAL; - return -1; - } - pid = atoi(argv[0]); device = atoi(argv[1]); enable = atoi(argv[2]); @@ -102,12 +96,6 @@ static int get_control_handler(int argc, char **argv) for (i = 0; i < argc; ++i) _I("argv[%2d]=%s", i, argv[i]); - if (argc > 4) { - _E("Invalid argument."); - errno = EINVAL; - return -1; - } - pid = atoi(argv[0]); device = atoi(argv[1]); _I("pid=%d device=%d", pid, device); @@ -136,9 +124,8 @@ GVariant *dbus_control_handler(GDBusConnection *conn, char *argv[3]; g_variant_get(param, "(sisss)", NULL, &argc, &argv[0], &argv[1], &argv[2]); - - if (argc < 0) { - _E("Message is invalid."); + if (argc != 3) { + _E("Invalid argument."); ret = -EINVAL; goto out; } @@ -169,8 +156,8 @@ GVariant *dbus_get_control_handler(GDBusConnection *conn, char *argv[2]; g_variant_get(param, "(siss)", NULL, &argc, &argv[0], &argv[1]); - if (argc < 0) { - _E("Message is invalid."); + if (argc != 2) { + _E("Invalid argument."); ret = -EINVAL; goto out; } -- 2.7.4 From 08666c3c9dab1d68399a0e888cf669222d09a739 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 17 May 2019 16:55:06 +0900 Subject: [PATCH 11/16] Change lcd control method from dbus-send to using internal APIs supported by dpms Change-Id: I69e62ebbc8083a40fc383d2c2f36a63d7c975ebe Signed-off-by: lokilee73 --- CMakeLists.txt | 3 + packaging/deviced.spec | 3 + plugins/iot/display/CMakeLists.txt | 7 +- plugins/iot/display/core.c | 16 +-- plugins/iot/display/device-interface.c | 56 ++------- plugins/iot/display/dpms-wayland-none.c | 100 ---------------- plugins/mobile/display/CMakeLists.txt | 7 +- plugins/mobile/display/core.c | 16 +-- plugins/mobile/display/device-interface.c | 56 ++------- plugins/mobile/display/dpms-wayland-none.c | 100 ---------------- plugins/tv/display/CMakeLists.txt | 7 +- plugins/tv/display/core.c | 15 +-- plugins/tv/display/device-interface.c | 56 ++------- plugins/tv/display/dpms-wayland-none.c | 100 ---------------- plugins/wearable/display/CMakeLists.txt | 7 +- plugins/wearable/display/core.c | 15 +-- plugins/wearable/display/device-interface.c | 56 ++------- plugins/wearable/display/dpms-wayland-none.c | 100 ---------------- src/display/device-interface.h | 4 - src/display/display-dpms.c | 173 +++++++++++++++++++++++++++ src/display/display-dpms.h | 28 +++++ systemd/deviced.service | 1 + 22 files changed, 284 insertions(+), 642 deletions(-) delete mode 100644 plugins/iot/display/dpms-wayland-none.c delete mode 100644 plugins/mobile/display/dpms-wayland-none.c delete mode 100644 plugins/tv/display/dpms-wayland-none.c delete mode 100644 plugins/wearable/display/dpms-wayland-none.c create mode 100644 src/display/display-dpms.c create mode 100644 src/display/display-dpms.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 151bf1b..a90dec1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,9 @@ SET(PKG_MODULES capi-system-device libsystemd libsyscommon + wayland-client + tizen-extension-client + tizen-dpms-client ) IF(DISPLAY_MODULE STREQUAL on) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 52e7605..b895131 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -37,6 +37,9 @@ BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(libusbgx) BuildRequires: pkgconfig(libsyscommon) BuildRequires: pkgconfig(capi-system-device) +BuildRequires: pkgconfig(wayland-client) +BuildRequires: pkgconfig(tizen-extension-client) +BuildRequires: pkgconfig(tizen-dpms-client) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} diff --git a/plugins/iot/display/CMakeLists.txt b/plugins/iot/display/CMakeLists.txt index 95ccb0d..206e95a 100644 --- a/plugins/iot/display/CMakeLists.txt +++ b/plugins/iot/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(iot-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 7f26941..fe4d69b 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1456,7 +1456,6 @@ static gboolean lcd_on_expired(void *data) /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) return G_SOURCE_REMOVE; else if (ret < 0) @@ -2168,17 +2167,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 201a33e..c4c9c7d 100755 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -691,6 +655,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -700,6 +665,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/iot/display/dpms-wayland-none.c b/plugins/iot/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/iot/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "device-interface.h" -#include "util.h" -#include "core.h" - -#define ENLIGHTENMENT_BUS_NAME "org.enlightenment.wm" -#define ENLIGHTENMENT_OBJECT_PATH "/org/enlightenment/wm" -#define ENLIGHTENMENT_INTERFACE_NAME ENLIGHTENMENT_BUS_NAME".dpms" - -static void dpms_set_cb(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/plugins/mobile/display/CMakeLists.txt b/plugins/mobile/display/CMakeLists.txt index 7aad0f4..071f366 100644 --- a/plugins/mobile/display/CMakeLists.txt +++ b/plugins/mobile/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(mobile-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 7f26941..fe4d69b 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1456,7 +1456,6 @@ static gboolean lcd_on_expired(void *data) /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) return G_SOURCE_REMOVE; else if (ret < 0) @@ -2168,17 +2167,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 201a33e..c4c9c7d 100755 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -691,6 +655,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -700,6 +665,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/mobile/display/dpms-wayland-none.c b/plugins/mobile/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/mobile/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "device-interface.h" -#include "util.h" -#include "core.h" - -#define ENLIGHTENMENT_BUS_NAME "org.enlightenment.wm" -#define ENLIGHTENMENT_OBJECT_PATH "/org/enlightenment/wm" -#define ENLIGHTENMENT_INTERFACE_NAME ENLIGHTENMENT_BUS_NAME".dpms" - -static void dpms_set_cb(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/plugins/tv/display/CMakeLists.txt b/plugins/tv/display/CMakeLists.txt index 317ab00..f996126 100644 --- a/plugins/tv/display/CMakeLists.txt +++ b/plugins/tv/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(tv-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 95ebe4f..5bf09f7 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2169,17 +2169,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 201a33e..c4c9c7d 100755 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -691,6 +655,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -700,6 +665,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/tv/display/dpms-wayland-none.c b/plugins/tv/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/tv/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "device-interface.h" -#include "util.h" -#include "core.h" - -#define ENLIGHTENMENT_BUS_NAME "org.enlightenment.wm" -#define ENLIGHTENMENT_OBJECT_PATH "/org/enlightenment/wm" -#define ENLIGHTENMENT_INTERFACE_NAME ENLIGHTENMENT_BUS_NAME".dpms" - -static void dpms_set_cb(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/plugins/wearable/display/CMakeLists.txt b/plugins/wearable/display/CMakeLists.txt index 0dcccb1..391ec59 100644 --- a/plugins/wearable/display/CMakeLists.txt +++ b/plugins/wearable/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(wearable-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 4fe0fc7..4823071 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2171,17 +2171,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index a362b6e..69fd7d5 100755 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -732,6 +696,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -741,6 +706,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/wearable/display/dpms-wayland-none.c b/plugins/wearable/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/wearable/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "device-interface.h" -#include "util.h" -#include "core.h" - -#define ENLIGHTENMENT_BUS_NAME "org.enlightenment.wm" -#define ENLIGHTENMENT_OBJECT_PATH "/org/enlightenment/wm" -#define ENLIGHTENMENT_INTERFACE_NAME ENLIGHTENMENT_BUS_NAME".dpms" - -static void dpms_set_cb(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/src/display/device-interface.h b/src/display/device-interface.h index b277c2d..81e8150 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -98,9 +98,5 @@ enum dpms_state { DPMS_SUSPEND, /* Blanked, lower power */ DPMS_OFF, /* Shut off, awaiting activity */ }; - -int dpms_set_power(enum dpms_state state); -int dpms_get_power(enum dpms_state *state); - #endif diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c new file mode 100644 index 0000000..37f5d1b --- /dev/null +++ b/src/display/display-dpms.c @@ -0,0 +1,173 @@ + /* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include +#include +#include "core/log.h" +#include "display/util.h" +#include +#include +#include + +struct wl_display *display; +struct wl_output *wl_out; +struct tizen_dpms_manager *tz_dpms_mng = NULL; +int lcd_state = -1; +bool wm_is_ready; + +bool check_wm_ready(void) +{ + if (access("/run/.wm_ready", F_OK) == 0) { + _I("Window manager is ready."); + wm_is_ready = true; + return true; + } + + _I("Window manager is not ready."); + return false; +} + +void disconnect_interface_with_dpms(void) +{ + if (tz_dpms_mng) { + tizen_dpms_manager_destroy(tz_dpms_mng); + tz_dpms_mng = NULL; + } + + if (wl_out) { + wl_output_destroy(wl_out); + wl_out = NULL; + } + + if (display) { + wl_display_disconnect(display); + display = NULL; + } +} + +static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) +{ + _D("dpms_state_cb - mode:%d, error:%d", mode, error); + lcd_state = mode; +} + +static const struct tizen_dpms_manager_listener dpms_listener = { + dpms_handle_state +}; + +static void handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + if (strcmp(interface, "wl_output") == 0) { + wl_out = wl_registry_bind(registry, name, &wl_output_interface, 2); + if (!wl_out) { + _E("Handle wl_output bind failed."); + disconnect_interface_with_dpms(); + } + _D("Get wl_output."); + } else if (strcmp(interface, "tizen_dpms_manager") == 0) { + tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); + if (!tz_dpms_mng) { + _E("Handle tizen_dpms_manager bind failed."); + disconnect_interface_with_dpms(); + } + tizen_dpms_manager_add_listener(tz_dpms_mng, &dpms_listener, NULL); + + _D("Get dpms manager."); + } +} + +static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) +{ + +} + +static const struct wl_registry_listener registry_listener = { + handle_global, + handle_global_remove +}; + +bool connect_interface_with_dpms(void) +{ + struct wl_registry *registry = NULL; + + display = wl_display_connect(NULL); + if (display == NULL) { + _E("Display is NULL."); + goto error; + } + + registry = wl_display_get_registry(display); + if (registry == NULL) { + _E("Registry is NULL."); + goto error; + } + + wl_registry_add_listener(registry, ®istry_listener, NULL); + wl_display_roundtrip(display); + + if (!wl_out || !tz_dpms_mng) { + _E("Roundtrip failed."); + goto error; + } + + wl_registry_destroy(registry); + _D("Setup with dpms is done."); + return true; + +error: + if (registry) + wl_registry_destroy(registry); + disconnect_interface_with_dpms(); + return false; +} + +bool dpms_is_available(void) +{ + static bool dpms_connected; + + /* Check window manager */ + if (!wm_is_ready) { + _E("Window manager is not ready"); + return false; + } + /* Try to connect interface with dpms, because window manager is ready */ + if (!dpms_connected) { + _D("call connect_interface_with_dpms()"); + dpms_connected = connect_interface_with_dpms(); + return dpms_connected; + } + + return true; +} + +void dpms_set_state(int on) +{ + tizen_dpms_manager_set_dpms(tz_dpms_mng, wl_out, on); + wl_display_roundtrip(display); +} + +int dpms_get_state(void) +{ + tizen_dpms_manager_get_dpms(tz_dpms_mng, wl_out); + wl_display_roundtrip(display); + + return lcd_state; +} diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h new file mode 100644 index 0000000..3b4e2ae --- /dev/null +++ b/src/display/display-dpms.h @@ -0,0 +1,28 @@ + /* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 __DISPLAY_DPMS_H__ +#define __DISPLAY_DPMS_H__ + +bool check_wm_ready(void); +bool dpms_is_available(void); +bool connect_interface_with_dpms(void); +void disconnect_interface_with_dpms(void); +void dpms_set_state(int on); +int dpms_get_state(void); +#endif /* __DISPLAY_DPMS_H__ */ diff --git a/systemd/deviced.service b/systemd/deviced.service index 5d5ce63..3a286d9 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -4,6 +4,7 @@ Description=System device daemon [Service] Type=notify SmackProcessLabel=System::Privileged +Environment=XDG_RUNTIME_DIR=/run ExecStart=/usr/bin/deviced Restart=always RestartSec=0 -- 2.7.4 From fe795aab3a42407e858bcaf90f9785994c91d276 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 22 May 2019 18:23:29 +0900 Subject: [PATCH 12/16] Move same files in each profile to display folder Change-Id: I8dac3442da66e23dfb3ce53b925c2af45bb8395d Signed-off-by: lokilee73 --- plugins/iot/display/ambient-mode.c | 210 ---- plugins/iot/display/auto-brightness.c | 681 ------------ plugins/iot/display/display-actor.c | 102 -- plugins/iot/display/display-dbus.c | 1168 --------------------- plugins/iot/display/display-ops.c | 74 -- plugins/iot/display/input.c | 224 ---- plugins/iot/display/lock-detector.c | 232 ---- plugins/iot/display/poll.c | 174 --- plugins/iot/display/setting.c | 271 ----- plugins/mobile/display/ambient-mode.c | 210 ---- plugins/mobile/display/display-actor.c | 102 -- plugins/mobile/display/display-dbus.c | 1168 --------------------- plugins/mobile/display/display-ops.c | 74 -- plugins/mobile/display/input.c | 224 ---- plugins/mobile/display/lock-detector.c | 232 ---- plugins/mobile/display/poll.c | 174 --- plugins/mobile/display/setting.c | 271 ----- plugins/tv/display/ambient-mode.c | 210 ---- plugins/tv/display/auto-brightness.c | 682 ------------ plugins/tv/display/display-actor.c | 102 -- plugins/tv/display/display-dbus.c | 1168 --------------------- plugins/tv/display/display-ops.c | 74 -- plugins/tv/display/input.c | 224 ---- plugins/tv/display/lock-detector.c | 232 ---- plugins/tv/display/poll.c | 174 --- plugins/tv/display/setting.c | 271 ----- plugins/wearable/display/auto-brightness.c | 681 ------------ {plugins/wearable => src}/display/ambient-mode.c | 0 {plugins/mobile => src}/display/auto-brightness.c | 0 {plugins/wearable => src}/display/display-actor.c | 0 {plugins/wearable => src}/display/display-dbus.c | 0 {plugins/wearable => src}/display/display-ops.c | 0 {plugins/wearable => src}/display/input.c | 0 {plugins/wearable => src}/display/lock-detector.c | 0 {plugins/wearable => src}/display/poll.c | 0 {plugins/wearable => src}/display/setting.c | 0 36 files changed, 9409 deletions(-) delete mode 100644 plugins/iot/display/ambient-mode.c delete mode 100644 plugins/iot/display/auto-brightness.c delete mode 100644 plugins/iot/display/display-actor.c delete mode 100644 plugins/iot/display/display-dbus.c delete mode 100644 plugins/iot/display/display-ops.c delete mode 100644 plugins/iot/display/input.c delete mode 100644 plugins/iot/display/lock-detector.c delete mode 100644 plugins/iot/display/poll.c delete mode 100644 plugins/iot/display/setting.c delete mode 100644 plugins/mobile/display/ambient-mode.c delete mode 100644 plugins/mobile/display/display-actor.c delete mode 100644 plugins/mobile/display/display-dbus.c delete mode 100644 plugins/mobile/display/display-ops.c delete mode 100644 plugins/mobile/display/input.c delete mode 100644 plugins/mobile/display/lock-detector.c delete mode 100644 plugins/mobile/display/poll.c delete mode 100644 plugins/mobile/display/setting.c delete mode 100644 plugins/tv/display/ambient-mode.c delete mode 100644 plugins/tv/display/auto-brightness.c delete mode 100644 plugins/tv/display/display-actor.c delete mode 100644 plugins/tv/display/display-dbus.c delete mode 100644 plugins/tv/display/display-ops.c delete mode 100644 plugins/tv/display/input.c delete mode 100644 plugins/tv/display/lock-detector.c delete mode 100644 plugins/tv/display/poll.c delete mode 100644 plugins/tv/display/setting.c delete mode 100644 plugins/wearable/display/auto-brightness.c rename {plugins/wearable => src}/display/ambient-mode.c (100%) rename {plugins/mobile => src}/display/auto-brightness.c (100%) rename {plugins/wearable => src}/display/display-actor.c (100%) rename {plugins/wearable => src}/display/display-dbus.c (100%) rename {plugins/wearable => src}/display/display-ops.c (100%) rename {plugins/wearable => src}/display/input.c (100%) rename {plugins/wearable => src}/display/lock-detector.c (100%) rename {plugins/wearable => src}/display/poll.c (100%) rename {plugins/wearable => src}/display/setting.c (100%) diff --git a/plugins/iot/display/ambient-mode.c b/plugins/iot/display/ambient-mode.c deleted file mode 100644 index b15fd56..0000000 --- a/plugins/iot/display/ambient-mode.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "core/device-notifier.h" -#include "core/devices.h" - -#define ON "on" -#define OFF "off" - -#define SIGNAL_AMBIENT_MODE "AmbientMode" -#define CLOCK_START "clockstart" -#define CLOCK_END "clockend" -#define TIMEOUT_NONE (-1) -#define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ - -static int ambient_state; -static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; -static unsigned int update_count; - -void broadcast_ambient_state(int state) -{ - int ret; - - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); - if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); -} - -int ambient_get_condition(void) -{ - return ambient_condition; -} - -int ambient_get_state(void) -{ - return ambient_state; -} - -static void ambient_set_condition(keynode_t *key_nodes, void *data) -{ - int state; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - ambient_condition = vconf_keynode_get_bool(key_nodes); - _I("Ambient mode condition is %d.", ambient_condition); - - state = (ambient_condition == 0 ? 0 : 1); - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION, (void *)&state); - - set_dim_state(state); -} - -int ambient_set_state(int on) -{ - if (!ambient_condition) - return 0; - - broadcast_ambient_state(on); - - update_count = 0; - - if (!on) - ambient_pid = 0; - - _D("AMBIENT is %s.", (on ? ON : OFF)); - - ambient_state = on; - - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE, (void *)&ambient_state); - - return 0; -} - -void ambient_check_invalid_state(pid_t pid) -{ - if (pid != INTERNAL_LOCK_AMBIENT) - return; - - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - - if (is_emulator()) { - /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) - return; - } - - if (ambient_get_state() == false) - return; - - _E("Invalid state. Ambient state is change to off."); - - /* If lcd_power is on and ambient state is true - * when pm state is changed to sleep, - * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ - - ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); -} - -static void start_clock(void) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, - AMBIENT_CLOCK_WAITING_TIME); -} - -static void end_clock(pid_t pid) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); - - update_count++; - if (update_count == UINT_MAX) - update_count = 1; - ambient_pid = pid; - - _I("Enter real ambient state by process(%d).", - ambient_pid); -} - -int ambient_set_screen(char *screen, pid_t pid) -{ - if (!screen) - return -EINVAL; - - if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); - else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); - - return 0; -} - -static void ambient_init(void *data) -{ - int ret; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); - if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); -} - -static void ambient_exit(void *data) -{ - ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); -} - -static const struct display_ops ambient_ops = { - .name = "ambient", - .init = ambient_init, - .exit = ambient_exit, -}; - -DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/plugins/iot/display/auto-brightness.c b/plugins/iot/display/auto-brightness.c deleted file mode 100644 index 88ff66a..0000000 --- a/plugins/iot/display/auto-brightness.c +++ /dev/null @@ -1,681 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "device-node.h" -#include "setting.h" -#include "core/device-notifier.h" -#include "core/config-parser.h" - -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ -#define MAX_SAMPLING_COUNT 3 -#define MAX_FAULT 5 -#define DEFAULT_AUTOMATIC_BRT 5 -#define AUTOMATIC_DEVIDE_VAL 10 -#define AUTOMATIC_DELAY_TIME 500 /* 0.5 sec */ - -#define RADIAN_VALUE (57.2957) -#define ROTATION_90 90 -#define WORKING_ANGLE_MIN 0 -#define WORKING_ANGLE_MAX 20 - -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - -static int (*_default_action) (int); -static guint alc_timeout_id = 0; -static guint update_timeout; -static sensor_listener_h light_listener; -static sensor_listener_h accel_listener; -static int fault_count; -static int automatic_brt = DEFAULT_AUTOMATIC_BRT; -static int min_brightness = PM_MIN_BRIGHTNESS; -static char *min_brightness_name = 0; - -/* light sensor */ -static float lmax, lmin; - -static bool update_working_position(void) -{ - sensor_event_s data; - int ret; - float x, y, z, pitch, realg; - - if (!display_conf.accel_sensor_on) - return false; - - ret = sensor_listener_read_data(accel_listener, &data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get accelerometer data: %d", ret); - return true; - } - - x = data.values[0]; - y = data.values[1]; - z = data.values[2]; - - realg = (float)sqrt((x * x) + (y * y) + (z * z)); - pitch = ROTATION_90 - abs((int) (asin(z / realg) * RADIAN_VALUE)); - - _D("Accel data x=%f y=%f z=%f pitch=%f", x, y, z, pitch); - - if (pitch >= WORKING_ANGLE_MIN && pitch <= WORKING_ANGLE_MAX) - return true; - return false; -} - -static void alc_set_brightness(int setting, int value, float light) -{ - static float old; - int position, tmp_value = 0, ret; - - ret = backlight_ops.get_brightness(&tmp_value); - if (ret < 0) { - _E("Failed to get display brightness."); - return; - } - - if (value < min_brightness) - value = min_brightness; - - if (tmp_value != value) { - if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { - position = update_working_position(); - if (!position && (old > light)) { - _D("It's not working position, " - "LCD isn't getting dark."); - return; - } - } - int diff, step; - - diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) - step = (diff > 0 ? 1 : -1); - else - step = (int)ceil(diff / - (float)display_conf.brightness_change_step); - - _D("%d", step); - while (tmp_value != value) { - if (step == 0) break; - - tmp_value += step; - if ((step > 0 && tmp_value > value) || - (step < 0 && tmp_value < value)) - tmp_value = value; - - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); - } - _I("Load light data(%f). auto brt=%d min brightness=%d " - "brightness=%d", light, automatic_brt, min_brightness, value); - old = light; - } -} - -static bool check_brightness_changed(int value) -{ - int i; - static int values[MAX_SAMPLING_COUNT], count = 0; - - if (count >= MAX_SAMPLING_COUNT || count < 0) - count = 0; - - values[count++] = value; - - for (i = 0; i < MAX_SAMPLING_COUNT - 1; i++) - if (values[i] != values[i+1]) - return false; - return true; -} - -static bool alc_update_brt(bool setting) -{ - int value = 0; - int ret = -1; - sensor_event_s light_data; - int index; - float light; - - ret = sensor_listener_read_data(light_listener, &light_data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to read light sensor data: %d", ret); - goto out; - } - - index = light_data.value_count - 1; - if (index < 0 || light_data.values[index] < 0) { - _E("Invalid light sensor data."); - goto out; - } - - light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( - lmax, lmin, light, &value); - if (ret == -ENOTSUP) { - _E("Not supported to handle the light data."); - goto out; - } - - if (ret < 0 || value < PM_MIN_BRIGHTNESS || value > PM_MAX_BRIGHTNESS) { - _E("Failed to load light data. light=%f value=%d: %d", light, value, ret); - goto out; - } - - fault_count = 0; - - if (display_conf.continuous_sampling && - !check_brightness_changed(value) && - !setting) - return true; - - alc_set_brightness(setting, value, light); - - return true; - -out: - fault_count++; - - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { - if (alc_timeout_id) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - SETTING_BRIGHTNESS_AUTOMATIC_OFF); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - _E("Fault counts is over %d, disable automatic brightness.", MAX_FAULT); - return false; - } - return true; -} - -static gboolean alc_handler(void *data) -{ - if (pm_cur_state != S_NORMAL) { - if (alc_timeout_id > 0) - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - return G_SOURCE_REMOVE; - } - - if (!alc_update_brt(false)) - return G_SOURCE_REMOVE; - - if (alc_timeout_id != 0) - return G_SOURCE_CONTINUE; - - return G_SOURCE_REMOVE; -} - -static int alc_action(int timeout) -{ - /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } - - if (_default_action != NULL) - return _default_action(timeout); - - /* unreachable code */ - return -1; -} - -static int connect_sensor(void) -{ - int ret; - sensor_h sensor; - sensor_h *list = NULL; - int cnt = 0; - - _I("Connect with sensor fw."); - /* light sensor */ - ret = sensor_get_sensor_list(SENSOR_LIGHT, &list, &cnt); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor list: %d", ret); - goto error; - } - - /* TODO - * Sensor apis will be fixed - * to provide which sensor is effective among sensors */ - if (cnt == 3) /* three light sensors exist */ - sensor = list[2]; - else - sensor = list[0]; - - free(list); - - ret = sensor_get_min_range(sensor, &lmin); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor min range: %d", ret); - goto error; - } - ret = sensor_get_max_range(sensor, &lmax); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor max range: %d", ret); - goto error; - } - _I("Light sensor min=%f max=%f", lmin, lmax); - - ret = sensor_create_listener(sensor, &light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(light)."); - goto error; - } - sensor_listener_set_option(light_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start light sensor."); - sensor_destroy_listener(light_listener); - light_listener = 0; - goto error; - } - - if (!display_conf.accel_sensor_on) - goto success; - - /* accelerometer sensor */ - ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &sensor); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get default accel sensor."); - goto error; - } - ret = sensor_create_listener(&sensor, &accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(accel)."); - goto error; - } - sensor_listener_set_option(accel_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start accel sensor."); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - goto error; - } - -success: - fault_count = 0; - return 0; - -error: - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - return -EIO; -} - -static int disconnect_sensor(void) -{ - _I("Disconnect with sensor fw."); - /* light sensor*/ - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - - /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - - if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; - _default_action = NULL; - } - if (alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -void set_brightness_changed_state(void) -{ - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; - _D("Brightness changed in low battery," - "escape dim state (light)."); - } -} - -static int set_autobrightness_state(int status) -{ - int ret = -1; - int brt = -1; - int default_brt = -1; - - if (status == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (connect_sensor() < 0) - return -1; - - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - /* change alc action func */ - if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; - - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _I("Auto brightness paused."); - disconnect_sensor(); - } else { - disconnect_sensor(); - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - ret = get_setting_brightness(&default_brt); - if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { - _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; - if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } - default_brt = brt; - } - - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); - } - - return 0; -} - -static void set_alc_function(keynode_t *key_nodes, void *data) -{ - int status, ret; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - status = vconf_keynode_get_int(key_nodes); - - switch (status) { - case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - case SETTING_BRIGHTNESS_AUTOMATIC_ON: - case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - ret = set_autobrightness_state(status); - _D("Set auto brightness: %d", ret); - break; - default: - _E("Invalid value(%d)", status); - } -} - -static void set_alc_automatic_brt(keynode_t *key_nodes, void *data) -{ - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - automatic_brt = vconf_keynode_get_int(key_nodes) / AUTOMATIC_DEVIDE_VAL; - _D("Automatic brt(%d)", automatic_brt); - - alc_update_brt(true); -} - -static gboolean update_handler(void *data) -{ - int ret, on; - - update_timeout = 0; - - if (pm_cur_state != S_NORMAL) - return G_SOURCE_REMOVE; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); - if (ret < 0 || on != SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - return G_SOURCE_REMOVE; - } - - _D("Auto brightness is working."); - alc_update_brt(true); - - return G_SOURCE_REMOVE; -} - -static void update_auto_brightness(bool update) -{ - if (update_timeout) { - g_source_remove(update_timeout); - update_timeout = 0; - } - - if (update) { - update_timeout = g_timeout_add(AUTOMATIC_DELAY_TIME, - update_handler, NULL); - } -} - -static int prepare_lsensor(void *data) -{ - int status, ret; - int brt = -1; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - set_autobrightness_state(status); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - - /* add auto_brt_setting change handler */ - vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function, NULL); - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - - if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { - _E("Failed to get automatic brightness."); - } else { - automatic_brt = brt / AUTOMATIC_DEVIDE_VAL; - _I("Automatic brt(%d) init success.", automatic_brt); - } - - vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt, NULL); - - return 0; -} - -static void update_brightness_direct(void) -{ - int ret, status; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - alc_update_brt(true); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); -} - -static int set_autobrightness_min(int val, char *name) -{ - if (!name) - return -EINVAL; - - if (val < PM_MIN_BRIGHTNESS || val > PM_MAX_BRIGHTNESS) - return -EINVAL; - - min_brightness = val; - - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - min_brightness_name = strndup(name, strlen(name)); - - update_brightness_direct(); - - _I("Auto brightness min value changed. min_brightness=%d min_brightness_name=%s", - min_brightness, min_brightness_name); - - return 0; -} - -static void reset_autobrightness_min(GDBusConnection *conn, - const gchar *sender, - const gchar *unique_name, - gpointer data) -{ - if (!sender) - return; - - if (!min_brightness_name) - return; - - if (strcmp(sender, min_brightness_name)) - return; - - _I("Change to default min brightness. before=%d changed=%d brightness_name=%s", min_brightness, - PM_MIN_BRIGHTNESS, min_brightness_name); - min_brightness = PM_MIN_BRIGHTNESS; - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - - update_brightness_direct(); -} - -static int lcd_changed_cb(void *data) -{ - int lcd_state; - - if (!data) - return 0; - lcd_state = *(int *)data; - if (lcd_state == S_LCDOFF && alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -static int booting_done_cb(void *data) -{ - int state; - - if (!data) - return 0; - - state = *(int *)data; - if (state != true) - return 0; - - /* get light data from sensor fw */ - prepare_lsensor(NULL); - - return 0; -} - -static void exit_lsensor(void) -{ - vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt); - - set_autobrightness_state(SETTING_BRIGHTNESS_AUTOMATIC_OFF); -} - -static void auto_brightness_init(void *data) -{ - display_info.update_auto_brightness = update_auto_brightness; - display_info.set_autobrightness_min = set_autobrightness_min; - display_info.reset_autobrightness_min = reset_autobrightness_min; - - register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static void auto_brightness_exit(void *data) -{ - exit_lsensor(); - - unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static const struct display_ops display_autobrightness_ops = { - .name = "auto-brightness", - .init = auto_brightness_init, - .exit = auto_brightness_exit, -}; - -DISPLAY_OPS_REGISTER(&display_autobrightness_ops) - diff --git a/plugins/iot/display/display-actor.c b/plugins/iot/display/display-actor.c deleted file mode 100644 index bab8630..0000000 --- a/plugins/iot/display/display-actor.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-actor.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *actor_head; - -void display_add_actor(struct display_actor_ops *actor) -{ - DD_LIST_APPEND(actor_head, actor); -} - -static struct display_actor_ops *display_find_actor(enum display_actor_id id) -{ - dd_list *elem; - struct display_actor_ops *actor; - - DD_LIST_FOREACH(actor_head, elem, actor) { - if (actor->id == id) - return actor; - } - return NULL; -} - -int display_set_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps |= caps; - - return 0; -} - -int display_reset_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps &= ~caps; - - return 0; -} - -unsigned int display_get_caps(enum display_actor_id id) -{ - struct display_actor_ops *actor; - - if (id <= 0) - return 0; - - actor = display_find_actor(id); - if (!actor) - return 0; - - return actor->caps; -} - -int display_has_caps(unsigned int total_caps, unsigned int caps) -{ - if (!total_caps || !caps) - return false; - - if ((total_caps & caps) == caps) - return true; - - return false; -} - diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c deleted file mode 100644 index 308d665..0000000 --- a/plugins/iot/display/display-dbus.c +++ /dev/null @@ -1,1168 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file display-dbus.c - * @brief dbus interface - * - */ - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core/log.h" -#include "util.h" -#include "core.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-idler.h" -#include "apps/apps.h" -#include "dd-display.h" -#include "display-actor.h" -#include "display-ops.h" -#include - -#define SIGNAL_HOMESCREEN "HomeScreen" - -#define DUMP_MODE_WATING_TIME 600000 - -#define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" -#define EXPIRED_POPUP_PID "_APP_PID_" -#define EXPIRED_POPUP_COMM "_APP_COMM_" -#define EXPIRED_POPUP_ID "_REQUEST_ID_" - -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - -GVariant *dbus_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->start(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->stop(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_lockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option1_str; - char *option2_str; - int timeout; - pid_t pid; - int state; - int flag; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); - - if (!state_str || timeout < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option1_str, STAYCURSTATE_STR)) - flag = STAY_CUR_STATE; - else if (!strcmp(option1_str, GOTOSTATENOW_STR)) - flag = GOTO_STATE_NOW; - else { - _E("%s option is invalid. set default option!", option1_str); - flag = STAY_CUR_STATE; - } - - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - - if (flag & GOTO_STATE_NOW) { - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - } - - if (check_dimstay(state, flag) == true) { - _E("LCD state can not be changed to OFF state now!"); - flag &= ~GOTO_STATE_NOW; - flag |= STAY_CUR_STATE; - } - - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); -out: - g_free(state_str); - g_free(option1_str); - g_free(option2_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_unlockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option_str; - pid_t pid; - int state; - int flag; - int ret = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ss)", &state_str, &option_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option_str, SLEEP_MARGIN_STR)) - flag = PM_SLEEP_MARGIN; - else if (!strcmp(option_str, RESET_TIMER_STR)) - flag = PM_RESET_TIMER; - else if (!strcmp(option_str, KEEP_TIMER_STR)) - flag = PM_KEEP_TIMER; - else { - _E("%s option is invalid. set default option!", option_str); - flag = PM_RESET_TIMER; - } - - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); -out: - g_free(state_str); - g_free(option_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_changestate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - pid_t pid; - int state; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &state_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else if (!strcmp(state_str, PM_STANDBY_STR)) - state = STANDBY; - else if (!strcmp(state_str, PM_SUSPEND_STR)) - state = SUSPEND; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - - if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); - ret = -EBUSY; - goto out; - } - - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); - - if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); -out: - g_free(state_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getdisplaycount(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = DEFAULT_DISPLAY_COUNT; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret, state; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - if (state == DISPLAY_STATE_NORMAL) - ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - else if (state == DISPLAY_STATE_SCREEN_DIM) - ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS; - else - ret = -EINVAL; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = -ENOTSUP; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt = -1, state, ret; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - - if (state == DISPLAY_STATE_NORMAL) - ret = backlight_ops.get_brightness(&brt); - else if (state == DISPLAY_STATE_SCREEN_DIM) { - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - if (ret >= 0) - ret = brt; - - _I("get brightness %d, %d", brt, ret); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int state, brt, autobrt, ret = 0, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(ii)", &state, &brt); - - //Check if brt is same with DIM - if (brt == 0) { - _E("application can not set this value(DIM VALUE:%d)", brt); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _E("auto_brightness state is ON, can not change the brightness value"); - ret = -EPERM; - goto error; - } - - if (state == DISPLAY_STATE_NORMAL) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } else if (state == DISPLAY_STATE_SCREEN_DIM) { - if (pm_cur_state == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - } - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - _I("set brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_holdbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt, autobrt, ret, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(i)", &brt); - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _D("Auto brightness will be paused"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - - _I("hold brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_releasebrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int bat, charger, changed, setting, brt, autobrt, ret = 0; - - CHECK_POWEROFF(); - - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); - if (ret < 0) { - _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger); - if (ret < 0) { - _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed); - if (ret < 0) { - _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting); - if (ret < 0) { - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.get_brightness(&brt); - if (ret < 0) - brt = ret; - - // check dim state - if (low_battery_state(bat) && - charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { - _D("batt warning low : brightness is not changed!"); - if (brt != 0) - backlight_ops.set_brightness(0); - goto error; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); - } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _D("Auto brightness will be enable"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setrefreshrate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int app, val, ret, control; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ii)", &app, &val); - - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { - ret = -EINVAL; - goto error; - } - - if (!display_conf.framerate_app[app]) { - _I("This case(%d) is not support in this target", app); - ret = -EPERM; - goto error; - } - - control = display_conf.control_display; - - if (control) - backlight_ops.off(NORMAL_MODE); - - _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); - if (ret < 0) - _E("Failed to set frame rate (%d)", ret); - - if (control) - backlight_ops.on(NORMAL_MODE); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int val, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - if (!display_info.set_autobrightness_min) { - ret = -EIO; - goto error; - } - g_variant_get(param, "(i)", &val); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = display_info.set_autobrightness_min(val, (char *)sender); - if (ret) { - _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); - goto error; - } - if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set autobrightness min %d by %d", val, pid); - } -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setlcdtimeout(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int on, dim, holdkey_block, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = set_lcd_timeout(on, dim, holdkey_block, sender); - if (ret) { - _W("fail to set lcd timeout %d by %d", ret, pid); - } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); - } - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lockscreenbgon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); - } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_dumpmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "on")) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, - STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_savelog(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - if (!device_poweroff(NULL)) - save_display_log(); - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_powerkeyignore(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &on); - - if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) - keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) - ret = keyfilter_ops->powerkey_lcdoff(); - else - ret = -ENOSYS; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_customlcdon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int timeout; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &timeout); - - ret = custom_lcdon(timeout); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_stay_touchscreen_off(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_lcd_paneloff_mode(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_actorcontrol(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0, val, actor; - char *op; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sii)", &op, &actor, &val); - - if (!strcmp(op, "set")) - ret = display_set_caps(actor, val); - else if (!strcmp(op, "reset")) - ret = display_reset_caps(actor, val); - else - ret = -EINVAL; - - g_free(op); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getcustombrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int status = 0; - - CHECK_POWEROFF(); - - status = backlight_ops.get_custom_status(); - - return g_variant_new("(i)", status); -} - -struct pmlock_expired_s { - char req_id[32]; - GDBusMethodInvocation *invocation; - int value; - pid_t pid; -}; - -static dd_list *expired_req_list; - -static int get_command(pid_t pid, char *comm, size_t len) -{ - FILE *fp; - char path[PATH_MAX]; - char name[NAME_MAX]; - char *tmp; - int ret; - - snprintf(path, sizeof(path), "/proc/%d/comm", pid); - - fp = fopen(path, "r"); - if (!fp) { - _E("Failed to open file %s, errno:%d", path, errno); - return -errno; - } - - ret = fread(name, 1, sizeof(name) - 1, fp); - name[ret] = '\0'; - fclose(fp); - - tmp = name; - while (*tmp != '\0') { - if (*tmp == '\n' || - *tmp == '\r') { - *tmp = '\0'; - break; - } - tmp++; - } - - snprintf(comm, len, "%s", name); - - return 0; -} - -GVariant *dbus_locktimeout_expired(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - pid_t pid; - char pid_str[16]; - char comm[NAME_MAX]; - struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &req_id); - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = get_command(pid, comm, sizeof(comm)); - if (ret < 0) { - _E("Failed to get command (%d)", ret); - goto out; - } - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(pid_str, sizeof(pid_str), "%d", pid); - ret = launch_system_app(APP_DEFAULT, 8, - APP_KEY_TYPE, - EXPIRED_POPUP_TYPE_POWER, - EXPIRED_POPUP_PID, - pid_str, - EXPIRED_POPUP_COMM, - comm, - EXPIRED_POPUP_ID, - req_id); - if (ret < 0) { - _E("Failed to launch pmlock expired popup(%d)", ret); - goto out; - } - - ex->pid = pid; - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - - ex->invocation = invocation; - - DD_LIST_APPEND(expired_req_list, ex); - - g_free(req_id); - return NULL; - -out: - gvar = g_variant_new("(i)", ret); - g_free(req_id); - if (ex) - free(ex); - return gvar; -} - -static gboolean app_term(gpointer data) -{ - struct pmlock_expired_s *ex = data; - - if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); - free(ex); - } - return G_SOURCE_REMOVE; -} - -static void expired_deliver_result(void *data) -{ - struct pmlock_expired_s *ex = data; - struct pmlock_expired_s *item = NULL; - dd_list *l; - size_t len; - int value; - char *id; - - if (!ex) - return; - - len = strlen(ex->req_id) + 1; - DD_LIST_FOREACH(expired_req_list, l, item) { - if (!strncmp(item->req_id, ex->req_id, len)) { - DD_LIST_REMOVE(expired_req_list, item); - break; - } - } - if (!item) - goto out; - - id = ex->req_id; - value = ex->value; - - _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" : - (value == 2) ? "KILL app" : "Release power lock"); - - if (!item->invocation) { - _E("item->invocation is null"); - goto out; - } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); - - if (value == 2) { - kill(item->pid, SIGTERM); - g_timeout_add(3000, app_term, (gpointer)item); - item = NULL; - } - -out: - free(ex); - free(item); -} - -GVariant *dbus_locktimeout_input(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - struct pmlock_expired_s *ex; - int value; - - CHECK_POWEROFF(); - - g_variant_get(param, "(si)", &req_id, &value); - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - ex->value = value; - - _I("req_id(%s), value(%d)", ex->req_id, ex->value); - - add_idle_request(expired_deliver_result, ex); - - ret = 0; - -out: - g_free(req_id); - return g_variant_new("(i)", ret); -} - -static const dbus_method_s dbus_methods[] = { - { "start", NULL, NULL, dbus_start }, - { "stop", NULL, NULL, dbus_stop }, - { "lockstate", "sssi", "i", dbus_lockstate }, - { "unlockstate", "ss", "i", dbus_unlockstate }, - { "changestate", "s", "i", dbus_changestate }, - { "ChangeState", "s", "i", dbus_changestate }, - { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */ - { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */ - { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */ - { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin }, - { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout }, - { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon }, - { "GetDisplayCount", NULL, "i", dbus_getdisplaycount }, - { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness }, - { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness }, - { "GetBrightness", "i", "i", dbus_getbrightness }, - { "SetBrightness", "ii", "i", dbus_setbrightness }, - { "HoldBrightness", "i", "i", dbus_holdbrightness }, - { "ReleaseBrightness", NULL, "i", dbus_releasebrightness }, - { "SetRefreshRate", "ii", "i", dbus_setrefreshrate }, - { "Dumpmode", "s", "i", dbus_dumpmode }, - { "SaveLog", NULL, NULL, dbus_savelog }, - { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, - { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, - { "CustomLCDOn", "i", "i", dbus_customlcdon }, - { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, - { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, - { "ActorControl", "sii", "i", dbus_actorcontrol }, - { "CustomBrightness", NULL, "i", dbus_getcustombrightness }, - { "CurrentBrightness", NULL, "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */ - { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, - { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_DISPLAY, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void homescreen_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - char *screen; - pid_t pid; - - g_variant_get(param, "(s)", &screen); - - _D("screen : %s", screen); - - pid = dbus_connection_get_sender_pid(conn, sender); - ambient_set_screen(screen, pid); - g_free(screen); -} - -/* - * Default capability - * api := LCDON | LCDOFF | BRIGHTNESS - * gesture := LCDON - */ -static struct display_actor_ops display_api_actor = { - .id = DISPLAY_ACTOR_API, - .caps = DISPLAY_CAPA_LCDON | - DISPLAY_CAPA_LCDOFF | - DISPLAY_CAPA_BRIGHTNESS, -}; - -static struct display_actor_ops display_gesture_actor = { - .id = DISPLAY_ACTOR_GESTURE, - .caps = DISPLAY_CAPA_LCDON, -}; - -int init_pm_dbus(void) -{ - int ret; - - display_add_actor(&display_api_actor); - display_add_actor(&display_gesture_actor); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - ret = subscribe_dbus_signal(NULL, - DEVICED_OBJECT_PATH, - DEVICED_INTERFACE_NAME, - SIGNAL_HOMESCREEN, - homescreen_signal_handler, - NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } - - return 0; -} - diff --git a/plugins/iot/display/display-ops.c b/plugins/iot/display/display-ops.c deleted file mode 100644 index 22b9137..0000000 --- a/plugins/iot/display/display-ops.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-ops.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *disp_head; - -void add_display(const struct display_ops *disp) -{ - DD_LIST_APPEND(disp_head, disp); -} - -void remove_display(const struct display_ops *disp) -{ - DD_LIST_REMOVE(disp_head, disp); -} - -const struct display_ops *find_display_feature(const char *name) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - if (!strcmp(disp->name, name)) - return disp; - } - return NULL; -} - -void display_ops_init(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] initialize", disp->name); - if (disp->init) - disp->init(data); - } -} - -void display_ops_exit(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] deinitialize", disp->name); - if (disp->exit) - disp->exit(data); - } -} - diff --git a/plugins/iot/display/input.c b/plugins/iot/display/input.c deleted file mode 100644 index a986504..0000000 --- a/plugins/iot/display/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "poll.h" - -#define SEAT_NAME "seat0" - -static struct udev *udev; -static struct libinput *li; -static guint efd; - -int (*pm_callback) (int, PMMsg *); - -static inline void process_event(struct libinput_event *ev) -{ - static const struct device_ops *display_device_ops; - struct input_event input; - struct libinput *li; - struct libinput_event_keyboard *k; - unsigned int time; - int fd; - - if (!pm_callback) - return; - - if (!display_device_ops) { - display_device_ops = find_device("display"); - if (!display_device_ops) - return; - } - - /* do not operate when display stops */ - if (device_get_status(display_device_ops) - != DEVICE_OPS_STATUS_START) { - _E("display status is stop"); - return; - } - - switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; - case LIBINPUT_EVENT_KEYBOARD_KEY: - k = libinput_event_get_keyboard_event(ev); - time = libinput_event_keyboard_get_time(k); - li = libinput_event_get_context(ev); - - input.time.tv_sec = MSEC_TO_SEC(time); - input.time.tv_usec = MSEC_TO_USEC(time % 1000); - input.type = EV_KEY; - input.code = libinput_event_keyboard_get_key(k); - input.value = libinput_event_keyboard_get_key_state(k); - - fd = libinput_get_fd(li); - _D("time %ld.%06ld type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); - input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - case LIBINPUT_EVENT_TOUCH_UP: - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; - break; - default: - break; - } - - /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); -} - -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -int init_input(void) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return -EPERM; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return -EPERM; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return -EPERM; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return -EPERM; - } - - return 0; -} - -int exit_input(void) -{ - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ - - if (li) - libinput_unref(li); - - if (udev) - udev_unref(udev); - - return 0; -} diff --git a/plugins/iot/display/lock-detector.c b/plugins/iot/display/lock-detector.c deleted file mode 100644 index 0560ef4..0000000 --- a/plugins/iot/display/lock-detector.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file lock-detector.c - * @brief - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "core/list.h" - -struct lock_info { - unsigned long hash; - char *name; - int state; - int count; - long locktime; - long unlocktime; - long time; -}; - -#define LIMIT_COUNT 128 - -static dd_list *lock_info_list; - -static long get_time(void) -{ - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); -} - -static void shrink_lock_info_list(void) -{ - dd_list *l, *l_prev; - struct lock_info *info; - unsigned int count; - - count = DD_LIST_LENGTH(lock_info_list); - if (count <= LIMIT_COUNT) - return; - _D("list is shrink : count %d", count); - - DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { - if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); - if (info->name) - free(info->name); - free(info); - count--; - } - if (count <= (LIMIT_COUNT / 2)) - break; - } -} - -int set_lock_time(const char *pname, int state) -{ - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - info->count += 1; - if (info->locktime == 0) - info->locktime = get_time(); - info->unlocktime = 0; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } - - info = malloc(sizeof(struct lock_info)); - if (!info) { - _E("Malloc is failed for lock_info!"); - return -ENOMEM; - } - - info->hash = val; - info->name = strndup(pname, strlen(pname)); - info->state = state; - info->count = 1; - info->locktime = get_time(); - info->unlocktime = 0; - info->time = 0; - - DD_LIST_APPEND(lock_info_list, info); - - return 0; -} - -int set_unlock_time(const char *pname, int state) -{ - bool find = false; - long diff; - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - find = true; - break; - } - - if (!find) - return -EINVAL; - - if (info->locktime == 0) - return -EINVAL; - - /* update time */ - info->unlocktime = get_time(); - diff = info->unlocktime - info->locktime; - if (diff > 0) - info->time += diff; - info->locktime = 0; - - if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) - shrink_lock_info_list(); - - return 0; -} - -void free_lock_info_list(void) -{ - dd_list *l, *l_next; - struct lock_info *info; - - if (!lock_info_list) - return; - - DD_LIST_FOREACH_SAFE(lock_info_list, l, l_next, info) { - DD_LIST_REMOVE(lock_info_list, info); - if (info->name) - free(info->name); - free(info); - } - lock_info_list = NULL; -} - -void print_lock_info_list(int fd) -{ - struct lock_info *info; - dd_list *l; - char buf[255]; - int ret; - - if (!lock_info_list) - return; - - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; - if (info->locktime != 0 && info->unlocktime == 0) - time = get_time() - info->locktime; - snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - } -} - diff --git a/plugins/iot/display/poll.c b/plugins/iot/display/poll.c deleted file mode 100644 index ee0471d..0000000 --- a/plugins/iot/display/poll.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include -#include "util.h" -#include "core.h" -#include "poll.h" -#include "display/display-ops.h" - -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(pm_status_flag & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static bool state_supported(enum state_t st) -{ - if (states[st].trans) - return true; - return false; -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -void init_pm_internal() -{ - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; -} diff --git a/plugins/iot/display/setting.c b/plugins/iot/display/setting.c deleted file mode 100644 index 1f2f1c7..0000000 --- a/plugins/iot/display/setting.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core.h" -#include "util.h" -#include "setting.h" -#include "display-ops.h" - -#define LCD_DIM_RATIO 0.3 -#define LCD_MAX_DIM_TIMEOUT 7000 -#define LCD_MIN_DIM_TIMEOUT 500 - -static const char *setting_keys[SETTING_GET_END] = { - [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, - [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS, - [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE, - [SETTING_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, -}; - -static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; -static bool lock_screen_bg_state = false; -static int force_lcdtimeout = 0; -static int custom_on_timeout = 0; -static int custom_normal_timeout = 0; -static int custom_dim_timeout = 0; - -static void display_state_send_system_event(int state) -{ - bundle *b; - const char *str; - - if (state == S_NORMAL) - str = EVT_VAL_DISPLAY_NORMAL; - else if (state == S_LCDDIM) - str = EVT_VAL_DISPLAY_DIM; - else if (state == S_LCDOFF) - str = EVT_VAL_DISPLAY_OFF; - else - return; - - _I("eventsystem (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); -} - -int set_force_lcdtimeout(int timeout) -{ - if (timeout < 0) - return -EINVAL; - - force_lcdtimeout = timeout; - - return 0; -} - -int __get_lock_screen_state(void) -{ - return lock_screen_state; -} - -void set_lock_screen_state(int state) -{ - switch (state) { - case VCONFKEY_IDLE_LOCK: - case VCONFKEY_IDLE_UNLOCK: - lock_screen_state = state; - break; - default: - lock_screen_state = VCONFKEY_IDLE_UNLOCK; - } -} - -int get_lock_screen_bg_state(void) -{ - return lock_screen_bg_state; -} - -void set_lock_screen_bg_state(bool state) -{ - _I("state is %d", state); - lock_screen_bg_state = state; -} - -int set_setting_pmstate(int val) -{ - static int old = -1; - int ret; - - if (old == val) - return 0; - old = val; - - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); - - return ret; -} - -int get_setting_brightness(int *level) -{ - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; -} - -void get_dim_timeout(int *dim_timeout) -{ - int vconf_timeout, on_timeout, val, ret; - - if (custom_dim_timeout > 0) { - *dim_timeout = custom_dim_timeout; - return; - } - - if (ambient_get_condition() == true) { - *dim_timeout = LCD_MIN_DIM_TIMEOUT; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - val = (double)on_timeout * LCD_DIM_RATIO; - if (val > LCD_MAX_DIM_TIMEOUT) - val = LCD_MAX_DIM_TIMEOUT; - - *dim_timeout = val; -} - -void get_run_timeout(int *timeout) -{ - int dim_timeout = -1; - int vconf_timeout = -1; - int on_timeout; - int ret; - - if (custom_normal_timeout > 0) { - *timeout = custom_normal_timeout; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - if (on_timeout == 0) { - *timeout = on_timeout; - return; - } - - get_dim_timeout(&dim_timeout); - *timeout = on_timeout - dim_timeout; -} - -int set_custom_lcdon_timeout(int timeout) -{ - int changed = (custom_on_timeout == timeout ? false : true); - - custom_on_timeout = timeout; - - if (timeout <= 0) { - custom_normal_timeout = 0; - custom_dim_timeout = 0; - return changed; - } - - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; - custom_normal_timeout = timeout - custom_dim_timeout; - - _I("custom normal(%d), dim(%d)", custom_normal_timeout, - custom_dim_timeout); - - return changed; -} - -static int setting_cb(keynode_t *key_nodes, void *data) -{ - keynode_t *tmp = key_nodes; - int index; - - index = (int)((intptr_t)data); - if (index > SETTING_END) { - _E("Unknown setting key: %s, idx=%d", - vconf_keynode_get_name(tmp), index); - return -1; - } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); - - return 0; -} - -int init_setting(int (*func) (int key_idx, int val)) -{ - int i; - - if (func != NULL) - disp_plgn.update_pm_setting = func; - - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { - /* - * To pass an index data through the vconf infratstructure - * without memory allocation, an index data becomes typecast - * to proper pointer size on each architecture. - */ - vconf_notify_key_changed(setting_keys[i], (void *)setting_cb, - (void *)((intptr_t)i)); - } - - disp_plgn.get_lock_screen_state = __get_lock_screen_state; - - return 0; -} - -int exit_setting(void) -{ - int i; - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) - vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb); - - return 0; -} - diff --git a/plugins/mobile/display/ambient-mode.c b/plugins/mobile/display/ambient-mode.c deleted file mode 100644 index b15fd56..0000000 --- a/plugins/mobile/display/ambient-mode.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "core/device-notifier.h" -#include "core/devices.h" - -#define ON "on" -#define OFF "off" - -#define SIGNAL_AMBIENT_MODE "AmbientMode" -#define CLOCK_START "clockstart" -#define CLOCK_END "clockend" -#define TIMEOUT_NONE (-1) -#define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ - -static int ambient_state; -static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; -static unsigned int update_count; - -void broadcast_ambient_state(int state) -{ - int ret; - - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); - if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); -} - -int ambient_get_condition(void) -{ - return ambient_condition; -} - -int ambient_get_state(void) -{ - return ambient_state; -} - -static void ambient_set_condition(keynode_t *key_nodes, void *data) -{ - int state; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - ambient_condition = vconf_keynode_get_bool(key_nodes); - _I("Ambient mode condition is %d.", ambient_condition); - - state = (ambient_condition == 0 ? 0 : 1); - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION, (void *)&state); - - set_dim_state(state); -} - -int ambient_set_state(int on) -{ - if (!ambient_condition) - return 0; - - broadcast_ambient_state(on); - - update_count = 0; - - if (!on) - ambient_pid = 0; - - _D("AMBIENT is %s.", (on ? ON : OFF)); - - ambient_state = on; - - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE, (void *)&ambient_state); - - return 0; -} - -void ambient_check_invalid_state(pid_t pid) -{ - if (pid != INTERNAL_LOCK_AMBIENT) - return; - - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - - if (is_emulator()) { - /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) - return; - } - - if (ambient_get_state() == false) - return; - - _E("Invalid state. Ambient state is change to off."); - - /* If lcd_power is on and ambient state is true - * when pm state is changed to sleep, - * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ - - ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); -} - -static void start_clock(void) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, - AMBIENT_CLOCK_WAITING_TIME); -} - -static void end_clock(pid_t pid) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); - - update_count++; - if (update_count == UINT_MAX) - update_count = 1; - ambient_pid = pid; - - _I("Enter real ambient state by process(%d).", - ambient_pid); -} - -int ambient_set_screen(char *screen, pid_t pid) -{ - if (!screen) - return -EINVAL; - - if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); - else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); - - return 0; -} - -static void ambient_init(void *data) -{ - int ret; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); - if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); -} - -static void ambient_exit(void *data) -{ - ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); -} - -static const struct display_ops ambient_ops = { - .name = "ambient", - .init = ambient_init, - .exit = ambient_exit, -}; - -DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/plugins/mobile/display/display-actor.c b/plugins/mobile/display/display-actor.c deleted file mode 100644 index bab8630..0000000 --- a/plugins/mobile/display/display-actor.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-actor.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *actor_head; - -void display_add_actor(struct display_actor_ops *actor) -{ - DD_LIST_APPEND(actor_head, actor); -} - -static struct display_actor_ops *display_find_actor(enum display_actor_id id) -{ - dd_list *elem; - struct display_actor_ops *actor; - - DD_LIST_FOREACH(actor_head, elem, actor) { - if (actor->id == id) - return actor; - } - return NULL; -} - -int display_set_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps |= caps; - - return 0; -} - -int display_reset_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps &= ~caps; - - return 0; -} - -unsigned int display_get_caps(enum display_actor_id id) -{ - struct display_actor_ops *actor; - - if (id <= 0) - return 0; - - actor = display_find_actor(id); - if (!actor) - return 0; - - return actor->caps; -} - -int display_has_caps(unsigned int total_caps, unsigned int caps) -{ - if (!total_caps || !caps) - return false; - - if ((total_caps & caps) == caps) - return true; - - return false; -} - diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c deleted file mode 100644 index 308d665..0000000 --- a/plugins/mobile/display/display-dbus.c +++ /dev/null @@ -1,1168 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file display-dbus.c - * @brief dbus interface - * - */ - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core/log.h" -#include "util.h" -#include "core.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-idler.h" -#include "apps/apps.h" -#include "dd-display.h" -#include "display-actor.h" -#include "display-ops.h" -#include - -#define SIGNAL_HOMESCREEN "HomeScreen" - -#define DUMP_MODE_WATING_TIME 600000 - -#define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" -#define EXPIRED_POPUP_PID "_APP_PID_" -#define EXPIRED_POPUP_COMM "_APP_COMM_" -#define EXPIRED_POPUP_ID "_REQUEST_ID_" - -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - -GVariant *dbus_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->start(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->stop(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_lockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option1_str; - char *option2_str; - int timeout; - pid_t pid; - int state; - int flag; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); - - if (!state_str || timeout < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option1_str, STAYCURSTATE_STR)) - flag = STAY_CUR_STATE; - else if (!strcmp(option1_str, GOTOSTATENOW_STR)) - flag = GOTO_STATE_NOW; - else { - _E("%s option is invalid. set default option!", option1_str); - flag = STAY_CUR_STATE; - } - - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - - if (flag & GOTO_STATE_NOW) { - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - } - - if (check_dimstay(state, flag) == true) { - _E("LCD state can not be changed to OFF state now!"); - flag &= ~GOTO_STATE_NOW; - flag |= STAY_CUR_STATE; - } - - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); -out: - g_free(state_str); - g_free(option1_str); - g_free(option2_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_unlockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option_str; - pid_t pid; - int state; - int flag; - int ret = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ss)", &state_str, &option_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option_str, SLEEP_MARGIN_STR)) - flag = PM_SLEEP_MARGIN; - else if (!strcmp(option_str, RESET_TIMER_STR)) - flag = PM_RESET_TIMER; - else if (!strcmp(option_str, KEEP_TIMER_STR)) - flag = PM_KEEP_TIMER; - else { - _E("%s option is invalid. set default option!", option_str); - flag = PM_RESET_TIMER; - } - - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); -out: - g_free(state_str); - g_free(option_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_changestate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - pid_t pid; - int state; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &state_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else if (!strcmp(state_str, PM_STANDBY_STR)) - state = STANDBY; - else if (!strcmp(state_str, PM_SUSPEND_STR)) - state = SUSPEND; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - - if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); - ret = -EBUSY; - goto out; - } - - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); - - if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); -out: - g_free(state_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getdisplaycount(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = DEFAULT_DISPLAY_COUNT; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret, state; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - if (state == DISPLAY_STATE_NORMAL) - ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - else if (state == DISPLAY_STATE_SCREEN_DIM) - ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS; - else - ret = -EINVAL; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = -ENOTSUP; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt = -1, state, ret; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - - if (state == DISPLAY_STATE_NORMAL) - ret = backlight_ops.get_brightness(&brt); - else if (state == DISPLAY_STATE_SCREEN_DIM) { - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - if (ret >= 0) - ret = brt; - - _I("get brightness %d, %d", brt, ret); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int state, brt, autobrt, ret = 0, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(ii)", &state, &brt); - - //Check if brt is same with DIM - if (brt == 0) { - _E("application can not set this value(DIM VALUE:%d)", brt); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _E("auto_brightness state is ON, can not change the brightness value"); - ret = -EPERM; - goto error; - } - - if (state == DISPLAY_STATE_NORMAL) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } else if (state == DISPLAY_STATE_SCREEN_DIM) { - if (pm_cur_state == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - } - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - _I("set brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_holdbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt, autobrt, ret, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(i)", &brt); - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _D("Auto brightness will be paused"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - - _I("hold brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_releasebrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int bat, charger, changed, setting, brt, autobrt, ret = 0; - - CHECK_POWEROFF(); - - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); - if (ret < 0) { - _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger); - if (ret < 0) { - _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed); - if (ret < 0) { - _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting); - if (ret < 0) { - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.get_brightness(&brt); - if (ret < 0) - brt = ret; - - // check dim state - if (low_battery_state(bat) && - charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { - _D("batt warning low : brightness is not changed!"); - if (brt != 0) - backlight_ops.set_brightness(0); - goto error; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); - } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _D("Auto brightness will be enable"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setrefreshrate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int app, val, ret, control; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ii)", &app, &val); - - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { - ret = -EINVAL; - goto error; - } - - if (!display_conf.framerate_app[app]) { - _I("This case(%d) is not support in this target", app); - ret = -EPERM; - goto error; - } - - control = display_conf.control_display; - - if (control) - backlight_ops.off(NORMAL_MODE); - - _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); - if (ret < 0) - _E("Failed to set frame rate (%d)", ret); - - if (control) - backlight_ops.on(NORMAL_MODE); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int val, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - if (!display_info.set_autobrightness_min) { - ret = -EIO; - goto error; - } - g_variant_get(param, "(i)", &val); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = display_info.set_autobrightness_min(val, (char *)sender); - if (ret) { - _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); - goto error; - } - if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set autobrightness min %d by %d", val, pid); - } -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setlcdtimeout(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int on, dim, holdkey_block, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = set_lcd_timeout(on, dim, holdkey_block, sender); - if (ret) { - _W("fail to set lcd timeout %d by %d", ret, pid); - } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); - } - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lockscreenbgon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); - } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_dumpmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "on")) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, - STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_savelog(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - if (!device_poweroff(NULL)) - save_display_log(); - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_powerkeyignore(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &on); - - if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) - keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) - ret = keyfilter_ops->powerkey_lcdoff(); - else - ret = -ENOSYS; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_customlcdon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int timeout; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &timeout); - - ret = custom_lcdon(timeout); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_stay_touchscreen_off(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_lcd_paneloff_mode(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_actorcontrol(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0, val, actor; - char *op; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sii)", &op, &actor, &val); - - if (!strcmp(op, "set")) - ret = display_set_caps(actor, val); - else if (!strcmp(op, "reset")) - ret = display_reset_caps(actor, val); - else - ret = -EINVAL; - - g_free(op); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getcustombrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int status = 0; - - CHECK_POWEROFF(); - - status = backlight_ops.get_custom_status(); - - return g_variant_new("(i)", status); -} - -struct pmlock_expired_s { - char req_id[32]; - GDBusMethodInvocation *invocation; - int value; - pid_t pid; -}; - -static dd_list *expired_req_list; - -static int get_command(pid_t pid, char *comm, size_t len) -{ - FILE *fp; - char path[PATH_MAX]; - char name[NAME_MAX]; - char *tmp; - int ret; - - snprintf(path, sizeof(path), "/proc/%d/comm", pid); - - fp = fopen(path, "r"); - if (!fp) { - _E("Failed to open file %s, errno:%d", path, errno); - return -errno; - } - - ret = fread(name, 1, sizeof(name) - 1, fp); - name[ret] = '\0'; - fclose(fp); - - tmp = name; - while (*tmp != '\0') { - if (*tmp == '\n' || - *tmp == '\r') { - *tmp = '\0'; - break; - } - tmp++; - } - - snprintf(comm, len, "%s", name); - - return 0; -} - -GVariant *dbus_locktimeout_expired(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - pid_t pid; - char pid_str[16]; - char comm[NAME_MAX]; - struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &req_id); - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = get_command(pid, comm, sizeof(comm)); - if (ret < 0) { - _E("Failed to get command (%d)", ret); - goto out; - } - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(pid_str, sizeof(pid_str), "%d", pid); - ret = launch_system_app(APP_DEFAULT, 8, - APP_KEY_TYPE, - EXPIRED_POPUP_TYPE_POWER, - EXPIRED_POPUP_PID, - pid_str, - EXPIRED_POPUP_COMM, - comm, - EXPIRED_POPUP_ID, - req_id); - if (ret < 0) { - _E("Failed to launch pmlock expired popup(%d)", ret); - goto out; - } - - ex->pid = pid; - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - - ex->invocation = invocation; - - DD_LIST_APPEND(expired_req_list, ex); - - g_free(req_id); - return NULL; - -out: - gvar = g_variant_new("(i)", ret); - g_free(req_id); - if (ex) - free(ex); - return gvar; -} - -static gboolean app_term(gpointer data) -{ - struct pmlock_expired_s *ex = data; - - if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); - free(ex); - } - return G_SOURCE_REMOVE; -} - -static void expired_deliver_result(void *data) -{ - struct pmlock_expired_s *ex = data; - struct pmlock_expired_s *item = NULL; - dd_list *l; - size_t len; - int value; - char *id; - - if (!ex) - return; - - len = strlen(ex->req_id) + 1; - DD_LIST_FOREACH(expired_req_list, l, item) { - if (!strncmp(item->req_id, ex->req_id, len)) { - DD_LIST_REMOVE(expired_req_list, item); - break; - } - } - if (!item) - goto out; - - id = ex->req_id; - value = ex->value; - - _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" : - (value == 2) ? "KILL app" : "Release power lock"); - - if (!item->invocation) { - _E("item->invocation is null"); - goto out; - } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); - - if (value == 2) { - kill(item->pid, SIGTERM); - g_timeout_add(3000, app_term, (gpointer)item); - item = NULL; - } - -out: - free(ex); - free(item); -} - -GVariant *dbus_locktimeout_input(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - struct pmlock_expired_s *ex; - int value; - - CHECK_POWEROFF(); - - g_variant_get(param, "(si)", &req_id, &value); - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - ex->value = value; - - _I("req_id(%s), value(%d)", ex->req_id, ex->value); - - add_idle_request(expired_deliver_result, ex); - - ret = 0; - -out: - g_free(req_id); - return g_variant_new("(i)", ret); -} - -static const dbus_method_s dbus_methods[] = { - { "start", NULL, NULL, dbus_start }, - { "stop", NULL, NULL, dbus_stop }, - { "lockstate", "sssi", "i", dbus_lockstate }, - { "unlockstate", "ss", "i", dbus_unlockstate }, - { "changestate", "s", "i", dbus_changestate }, - { "ChangeState", "s", "i", dbus_changestate }, - { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */ - { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */ - { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */ - { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin }, - { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout }, - { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon }, - { "GetDisplayCount", NULL, "i", dbus_getdisplaycount }, - { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness }, - { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness }, - { "GetBrightness", "i", "i", dbus_getbrightness }, - { "SetBrightness", "ii", "i", dbus_setbrightness }, - { "HoldBrightness", "i", "i", dbus_holdbrightness }, - { "ReleaseBrightness", NULL, "i", dbus_releasebrightness }, - { "SetRefreshRate", "ii", "i", dbus_setrefreshrate }, - { "Dumpmode", "s", "i", dbus_dumpmode }, - { "SaveLog", NULL, NULL, dbus_savelog }, - { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, - { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, - { "CustomLCDOn", "i", "i", dbus_customlcdon }, - { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, - { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, - { "ActorControl", "sii", "i", dbus_actorcontrol }, - { "CustomBrightness", NULL, "i", dbus_getcustombrightness }, - { "CurrentBrightness", NULL, "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */ - { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, - { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_DISPLAY, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void homescreen_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - char *screen; - pid_t pid; - - g_variant_get(param, "(s)", &screen); - - _D("screen : %s", screen); - - pid = dbus_connection_get_sender_pid(conn, sender); - ambient_set_screen(screen, pid); - g_free(screen); -} - -/* - * Default capability - * api := LCDON | LCDOFF | BRIGHTNESS - * gesture := LCDON - */ -static struct display_actor_ops display_api_actor = { - .id = DISPLAY_ACTOR_API, - .caps = DISPLAY_CAPA_LCDON | - DISPLAY_CAPA_LCDOFF | - DISPLAY_CAPA_BRIGHTNESS, -}; - -static struct display_actor_ops display_gesture_actor = { - .id = DISPLAY_ACTOR_GESTURE, - .caps = DISPLAY_CAPA_LCDON, -}; - -int init_pm_dbus(void) -{ - int ret; - - display_add_actor(&display_api_actor); - display_add_actor(&display_gesture_actor); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - ret = subscribe_dbus_signal(NULL, - DEVICED_OBJECT_PATH, - DEVICED_INTERFACE_NAME, - SIGNAL_HOMESCREEN, - homescreen_signal_handler, - NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } - - return 0; -} - diff --git a/plugins/mobile/display/display-ops.c b/plugins/mobile/display/display-ops.c deleted file mode 100644 index 22b9137..0000000 --- a/plugins/mobile/display/display-ops.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-ops.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *disp_head; - -void add_display(const struct display_ops *disp) -{ - DD_LIST_APPEND(disp_head, disp); -} - -void remove_display(const struct display_ops *disp) -{ - DD_LIST_REMOVE(disp_head, disp); -} - -const struct display_ops *find_display_feature(const char *name) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - if (!strcmp(disp->name, name)) - return disp; - } - return NULL; -} - -void display_ops_init(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] initialize", disp->name); - if (disp->init) - disp->init(data); - } -} - -void display_ops_exit(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] deinitialize", disp->name); - if (disp->exit) - disp->exit(data); - } -} - diff --git a/plugins/mobile/display/input.c b/plugins/mobile/display/input.c deleted file mode 100644 index a986504..0000000 --- a/plugins/mobile/display/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "poll.h" - -#define SEAT_NAME "seat0" - -static struct udev *udev; -static struct libinput *li; -static guint efd; - -int (*pm_callback) (int, PMMsg *); - -static inline void process_event(struct libinput_event *ev) -{ - static const struct device_ops *display_device_ops; - struct input_event input; - struct libinput *li; - struct libinput_event_keyboard *k; - unsigned int time; - int fd; - - if (!pm_callback) - return; - - if (!display_device_ops) { - display_device_ops = find_device("display"); - if (!display_device_ops) - return; - } - - /* do not operate when display stops */ - if (device_get_status(display_device_ops) - != DEVICE_OPS_STATUS_START) { - _E("display status is stop"); - return; - } - - switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; - case LIBINPUT_EVENT_KEYBOARD_KEY: - k = libinput_event_get_keyboard_event(ev); - time = libinput_event_keyboard_get_time(k); - li = libinput_event_get_context(ev); - - input.time.tv_sec = MSEC_TO_SEC(time); - input.time.tv_usec = MSEC_TO_USEC(time % 1000); - input.type = EV_KEY; - input.code = libinput_event_keyboard_get_key(k); - input.value = libinput_event_keyboard_get_key_state(k); - - fd = libinput_get_fd(li); - _D("time %ld.%06ld type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); - input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - case LIBINPUT_EVENT_TOUCH_UP: - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; - break; - default: - break; - } - - /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); -} - -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -int init_input(void) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return -EPERM; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return -EPERM; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return -EPERM; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return -EPERM; - } - - return 0; -} - -int exit_input(void) -{ - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ - - if (li) - libinput_unref(li); - - if (udev) - udev_unref(udev); - - return 0; -} diff --git a/plugins/mobile/display/lock-detector.c b/plugins/mobile/display/lock-detector.c deleted file mode 100644 index 0560ef4..0000000 --- a/plugins/mobile/display/lock-detector.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file lock-detector.c - * @brief - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "core/list.h" - -struct lock_info { - unsigned long hash; - char *name; - int state; - int count; - long locktime; - long unlocktime; - long time; -}; - -#define LIMIT_COUNT 128 - -static dd_list *lock_info_list; - -static long get_time(void) -{ - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); -} - -static void shrink_lock_info_list(void) -{ - dd_list *l, *l_prev; - struct lock_info *info; - unsigned int count; - - count = DD_LIST_LENGTH(lock_info_list); - if (count <= LIMIT_COUNT) - return; - _D("list is shrink : count %d", count); - - DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { - if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); - if (info->name) - free(info->name); - free(info); - count--; - } - if (count <= (LIMIT_COUNT / 2)) - break; - } -} - -int set_lock_time(const char *pname, int state) -{ - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - info->count += 1; - if (info->locktime == 0) - info->locktime = get_time(); - info->unlocktime = 0; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } - - info = malloc(sizeof(struct lock_info)); - if (!info) { - _E("Malloc is failed for lock_info!"); - return -ENOMEM; - } - - info->hash = val; - info->name = strndup(pname, strlen(pname)); - info->state = state; - info->count = 1; - info->locktime = get_time(); - info->unlocktime = 0; - info->time = 0; - - DD_LIST_APPEND(lock_info_list, info); - - return 0; -} - -int set_unlock_time(const char *pname, int state) -{ - bool find = false; - long diff; - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - find = true; - break; - } - - if (!find) - return -EINVAL; - - if (info->locktime == 0) - return -EINVAL; - - /* update time */ - info->unlocktime = get_time(); - diff = info->unlocktime - info->locktime; - if (diff > 0) - info->time += diff; - info->locktime = 0; - - if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) - shrink_lock_info_list(); - - return 0; -} - -void free_lock_info_list(void) -{ - dd_list *l, *l_next; - struct lock_info *info; - - if (!lock_info_list) - return; - - DD_LIST_FOREACH_SAFE(lock_info_list, l, l_next, info) { - DD_LIST_REMOVE(lock_info_list, info); - if (info->name) - free(info->name); - free(info); - } - lock_info_list = NULL; -} - -void print_lock_info_list(int fd) -{ - struct lock_info *info; - dd_list *l; - char buf[255]; - int ret; - - if (!lock_info_list) - return; - - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; - if (info->locktime != 0 && info->unlocktime == 0) - time = get_time() - info->locktime; - snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - } -} - diff --git a/plugins/mobile/display/poll.c b/plugins/mobile/display/poll.c deleted file mode 100644 index ee0471d..0000000 --- a/plugins/mobile/display/poll.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include -#include "util.h" -#include "core.h" -#include "poll.h" -#include "display/display-ops.h" - -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(pm_status_flag & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static bool state_supported(enum state_t st) -{ - if (states[st].trans) - return true; - return false; -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -void init_pm_internal() -{ - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; -} diff --git a/plugins/mobile/display/setting.c b/plugins/mobile/display/setting.c deleted file mode 100644 index b109d8c..0000000 --- a/plugins/mobile/display/setting.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core.h" -#include "util.h" -#include "setting.h" -#include "display-ops.h" - -#define LCD_DIM_RATIO 0.3 -#define LCD_MAX_DIM_TIMEOUT 7000 -#define LCD_MIN_DIM_TIMEOUT 500 - -static const char *setting_keys[SETTING_GET_END] = { - [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, - [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS, - [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE, - [SETTING_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, -}; - -static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; -static bool lock_screen_bg_state = false; -static int force_lcdtimeout = 0; -static int custom_on_timeout = 0; -static int custom_normal_timeout = 0; -static int custom_dim_timeout = 0; - -static void display_state_send_system_event(int state) -{ - bundle *b; - const char *str; - - if (state == S_NORMAL) - str = EVT_VAL_DISPLAY_NORMAL; - else if (state == S_LCDDIM) - str = EVT_VAL_DISPLAY_DIM; - else if (state == S_LCDOFF) - str = EVT_VAL_DISPLAY_OFF; - else - return; - - _I("eventsystem (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); -} - -int set_force_lcdtimeout(int timeout) -{ - if (timeout < 0) - return -EINVAL; - - force_lcdtimeout = timeout; - - return 0; -} - -int __get_lock_screen_state(void) -{ - return lock_screen_state; -} - -void set_lock_screen_state(int state) -{ - switch (state) { - case VCONFKEY_IDLE_LOCK: - case VCONFKEY_IDLE_UNLOCK: - lock_screen_state = state; - break; - default: - lock_screen_state = VCONFKEY_IDLE_UNLOCK; - } -} - -int get_lock_screen_bg_state(void) -{ - return lock_screen_bg_state; -} - -void set_lock_screen_bg_state(bool state) -{ - _I("state is %d", state); - lock_screen_bg_state = state; -} - -int set_setting_pmstate(int val) -{ - static int old = -1; - int ret; - - if (old == val) - return 0; - old = val; - - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); - - return ret; -} - -int get_setting_brightness(int *level) -{ - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; -} - -void get_dim_timeout(int *dim_timeout) -{ - int vconf_timeout, on_timeout, val, ret; - - if (custom_dim_timeout > 0) { - *dim_timeout = custom_dim_timeout; - return; - } - - if (ambient_get_condition() == true) { - *dim_timeout = LCD_MIN_DIM_TIMEOUT; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - val = (double)on_timeout * LCD_DIM_RATIO; - if (val > LCD_MAX_DIM_TIMEOUT) - val = LCD_MAX_DIM_TIMEOUT; - - *dim_timeout = val; -} - -void get_run_timeout(int *timeout) -{ - int dim_timeout = -1; - int vconf_timeout = -1; - int on_timeout; - int ret; - - if (custom_normal_timeout > 0) { - *timeout = custom_normal_timeout; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - if (on_timeout == 0) { - *timeout = on_timeout; - return; - } - - get_dim_timeout(&dim_timeout); - *timeout = on_timeout - dim_timeout; -} - -int set_custom_lcdon_timeout(int timeout) -{ - int changed = (custom_on_timeout == timeout ? false : true); - - custom_on_timeout = timeout; - - if (timeout <= 0) { - custom_normal_timeout = 0; - custom_dim_timeout = 0; - return changed; - } - - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; - custom_normal_timeout = timeout - custom_dim_timeout; - - _I("custom normal(%d), dim(%d)", custom_normal_timeout, - custom_dim_timeout); - - return changed; -} - -static int setting_cb(keynode_t *key_nodes, void *data) -{ - keynode_t *tmp = key_nodes; - int index; - - index = (int)((intptr_t)data); - if (index > SETTING_END) { - _E("Unknown setting key: %s, idx=%d", - vconf_keynode_get_name(tmp), index); - return -1; - } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); - - return 0; -} - -int init_setting(int (*func) (int key_idx, int val)) -{ - int i; - - if (func != NULL) - disp_plgn.update_pm_setting = func; - - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { - /* - * To pass an index data through the vconf infratstructure - * without memory allocation, an index data becomes typecast - * to proper pointer size on each architecture. - */ - vconf_notify_key_changed(setting_keys[i], (void *)setting_cb, - (void *)((intptr_t)i)); - } - - disp_plgn.get_lock_screen_state = __get_lock_screen_state; - - return 0; -} - -int exit_setting(void) -{ - int i; - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) - vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb); - - return 0; -} - diff --git a/plugins/tv/display/ambient-mode.c b/plugins/tv/display/ambient-mode.c deleted file mode 100644 index b15fd56..0000000 --- a/plugins/tv/display/ambient-mode.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "core/device-notifier.h" -#include "core/devices.h" - -#define ON "on" -#define OFF "off" - -#define SIGNAL_AMBIENT_MODE "AmbientMode" -#define CLOCK_START "clockstart" -#define CLOCK_END "clockend" -#define TIMEOUT_NONE (-1) -#define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ - -static int ambient_state; -static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; -static unsigned int update_count; - -void broadcast_ambient_state(int state) -{ - int ret; - - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); - if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); -} - -int ambient_get_condition(void) -{ - return ambient_condition; -} - -int ambient_get_state(void) -{ - return ambient_state; -} - -static void ambient_set_condition(keynode_t *key_nodes, void *data) -{ - int state; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - ambient_condition = vconf_keynode_get_bool(key_nodes); - _I("Ambient mode condition is %d.", ambient_condition); - - state = (ambient_condition == 0 ? 0 : 1); - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION, (void *)&state); - - set_dim_state(state); -} - -int ambient_set_state(int on) -{ - if (!ambient_condition) - return 0; - - broadcast_ambient_state(on); - - update_count = 0; - - if (!on) - ambient_pid = 0; - - _D("AMBIENT is %s.", (on ? ON : OFF)); - - ambient_state = on; - - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE, (void *)&ambient_state); - - return 0; -} - -void ambient_check_invalid_state(pid_t pid) -{ - if (pid != INTERNAL_LOCK_AMBIENT) - return; - - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - - if (is_emulator()) { - /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) - return; - } - - if (ambient_get_state() == false) - return; - - _E("Invalid state. Ambient state is change to off."); - - /* If lcd_power is on and ambient state is true - * when pm state is changed to sleep, - * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ - - ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); -} - -static void start_clock(void) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, - AMBIENT_CLOCK_WAITING_TIME); -} - -static void end_clock(pid_t pid) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); - - update_count++; - if (update_count == UINT_MAX) - update_count = 1; - ambient_pid = pid; - - _I("Enter real ambient state by process(%d).", - ambient_pid); -} - -int ambient_set_screen(char *screen, pid_t pid) -{ - if (!screen) - return -EINVAL; - - if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); - else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); - - return 0; -} - -static void ambient_init(void *data) -{ - int ret; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); - if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); -} - -static void ambient_exit(void *data) -{ - ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); -} - -static const struct display_ops ambient_ops = { - .name = "ambient", - .init = ambient_init, - .exit = ambient_exit, -}; - -DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/plugins/tv/display/auto-brightness.c b/plugins/tv/display/auto-brightness.c deleted file mode 100644 index ed957cd..0000000 --- a/plugins/tv/display/auto-brightness.c +++ /dev/null @@ -1,682 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "device-node.h" -#include "setting.h" -#include "core/device-notifier.h" -#include "core/config-parser.h" - -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ -#define MAX_SAMPLING_COUNT 3 -#define MAX_FAULT 5 -#define DEFAULT_AUTOMATIC_BRT 5 -#define AUTOMATIC_DEVIDE_VAL 10 -#define AUTOMATIC_DELAY_TIME 500 /* 0.5 sec */ - -#define RADIAN_VALUE (57.2957) -#define ROTATION_90 90 -#define WORKING_ANGLE_MIN 0 -#define WORKING_ANGLE_MAX 20 - -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - -static int (*_default_action) (int); -static guint alc_timeout_id = 0; -static guint update_timeout; -static sensor_listener_h light_listener; -static sensor_listener_h accel_listener; -static int fault_count; -static int automatic_brt = DEFAULT_AUTOMATIC_BRT; -static int min_brightness = PM_MIN_BRIGHTNESS; -static char *min_brightness_name = 0; - -/* light sensor */ -static float lmax, lmin; - -static bool update_working_position(void) -{ - sensor_event_s data; - int ret; - float x, y, z, pitch, realg; - - if (!display_conf.accel_sensor_on) - return false; - - ret = sensor_listener_read_data(accel_listener, &data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get accelerometer data: %d", ret); - return true; - } - - x = data.values[0]; - y = data.values[1]; - z = data.values[2]; - - realg = (float)sqrt((x * x) + (y * y) + (z * z)); - pitch = ROTATION_90 - abs((int) (asin(z / realg) * RADIAN_VALUE)); - - _D("Accel data x=%f y=%f z=%f pitch=%f", x, y, z, pitch); - - if (pitch >= WORKING_ANGLE_MIN && pitch <= WORKING_ANGLE_MAX) - return true; - return false; -} - -static void alc_set_brightness(int setting, int value, float light) -{ - static float old; - int position, tmp_value = 0, ret; - - ret = backlight_ops.get_brightness(&tmp_value); - if (ret < 0) { - _E("Failed to get display brightness."); - return; - } - - if (value < min_brightness) - value = min_brightness; - - if (tmp_value != value) { - if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { - position = update_working_position(); - if (!position && (old > light)) { - _D("It's not working position, " - "LCD isn't getting dark."); - return; - } - } - int diff, step; - - diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) - step = (diff > 0 ? 1 : -1); - else - step = (int)ceil(diff / - (float)display_conf.brightness_change_step); - - _D("%d", step); - while (tmp_value != value) { - if (step == 0) break; - - tmp_value += step; - if ((step > 0 && tmp_value > value) || - (step < 0 && tmp_value < value)) - tmp_value = value; - - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); - } - _I("Load light data(%f). auto brt=%d min brightness=%d " - "brightness=%d", light, automatic_brt, min_brightness, value); - old = light; - } -} - -static bool check_brightness_changed(int value) -{ - int i; - static int values[MAX_SAMPLING_COUNT], count = 0; - - if (count >= MAX_SAMPLING_COUNT || count < 0) - count = 0; - - values[count++] = value; - - for (i = 0; i < MAX_SAMPLING_COUNT - 1; i++) - if (values[i] != values[i+1]) - return false; - return true; -} - -static bool alc_update_brt(bool setting) -{ - int value = 0; - int ret = -1; - sensor_event_s light_data; - int index; - float light; - - ret = sensor_listener_read_data(light_listener, &light_data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to read light sensor data: %d", ret); - goto out; - } - - index = light_data.value_count - 1; - if (index < 0 || light_data.values[index] < 0) { - _E("Invalid light sensor data."); - goto out; - } - - light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( - lmax, lmin, light, &value); - if (ret == -ENOTSUP) { - _E("Not supported to handle the light data."); - goto out; - } - - if (ret < 0 || value < PM_MIN_BRIGHTNESS || value > PM_MAX_BRIGHTNESS) { - _E("Failed to load light data. light=%f value=%d: %d", light, value, ret); - goto out; - } - - fault_count = 0; - - if (display_conf.continuous_sampling && - !check_brightness_changed(value) && - !setting) - return true; - - alc_set_brightness(setting, value, light); - - return true; - -out: - fault_count++; - - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { - if (alc_timeout_id) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - SETTING_BRIGHTNESS_AUTOMATIC_OFF); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - _E("Fault counts is over %d, disable automatic brightness.", MAX_FAULT); - return false; - } - return true; -} - -static gboolean alc_handler(void *data) -{ - if (pm_cur_state != S_NORMAL) { - if (alc_timeout_id > 0) - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - return G_SOURCE_REMOVE; - } - - if (!alc_update_brt(false)) - return G_SOURCE_REMOVE; - - if (alc_timeout_id != 0) - return G_SOURCE_CONTINUE; - - return G_SOURCE_REMOVE; -} - -static int alc_action(int timeout) -{ - /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } - - if (_default_action != NULL) - return _default_action(timeout); - - /* unreachable code */ - return -1; -} - -static int connect_sensor(void) -{ - int ret; - sensor_h sensor; - sensor_h *list = NULL; - int cnt = 0; - - _I("Connect with sensor fw."); - /* light sensor */ - ret = sensor_get_sensor_list(SENSOR_LIGHT, &list, &cnt); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor list: %d", ret); - goto error; - } - - /* TODO - * Sensor apis will be fixed - * to provide which sensor is effective among sensors */ - if (cnt == 3) /* three light sensors exist */ - sensor = list[2]; - else - sensor = list[0]; - - free(list); - - ret = sensor_get_min_range(sensor, &lmin); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor min range: %d", ret); - goto error; - } - ret = sensor_get_max_range(sensor, &lmax); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor max range: %d", ret); - goto error; - } - _I("Light sensor min=%f max=%f", lmin, lmax); - - ret = sensor_create_listener(sensor, &light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(light)."); - goto error; - } - sensor_listener_set_option(light_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start light sensor."); - sensor_destroy_listener(light_listener); - light_listener = 0; - goto error; - } - - if (!display_conf.accel_sensor_on) - goto success; - - /* accelerometer sensor */ - ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &sensor); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get default accel sensor."); - goto error; - } - ret = sensor_create_listener(&sensor, &accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(accel)."); - goto error; - } - sensor_listener_set_option(accel_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start accel sensor."); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - goto error; - } - -success: - fault_count = 0; - return 0; - -error: - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - return -EIO; -} - -static int disconnect_sensor(void) -{ - _I("Disconnect with sensor fw."); - /* light sensor*/ - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - - /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - - if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; - _default_action = NULL; - } - if (alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -void set_brightness_changed_state(void) -{ - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; - _D("Brightness changed in low battery," - "escape dim state (light)."); - } -} - -static int set_autobrightness_state(int status) -{ - int ret = -1; - int brt = -1; - int default_brt = -1; - - if (status == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (connect_sensor() < 0) - return -1; - - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - /* change alc action func */ - if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; - - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _I("Auto brightness paused."); - disconnect_sensor(); - } else { - disconnect_sensor(); - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - ret = get_setting_brightness(&default_brt); - if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { - _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; - if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } - default_brt = brt; - } - - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); - } - - return 0; -} - -static void set_alc_function(keynode_t *key_nodes, void *data) -{ - int status, ret; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - status = vconf_keynode_get_int(key_nodes); - - switch (status) { - case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - case SETTING_BRIGHTNESS_AUTOMATIC_ON: - case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - ret = set_autobrightness_state(status); - _D("Set auto brightness: %d", ret); - break; - default: - _E("Invalid value(%d)", status); - } -} - -static void set_alc_automatic_brt(keynode_t *key_nodes, void *data) -{ - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - automatic_brt = vconf_keynode_get_int(key_nodes) / AUTOMATIC_DEVIDE_VAL; - _D("Automatic brt(%d)", automatic_brt); - - alc_update_brt(true); -} - -static gboolean update_handler(void *data) -{ - int ret, on; - - update_timeout = 0; - - if (pm_cur_state != S_NORMAL) - return G_SOURCE_REMOVE; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); - if (ret < 0 || on != SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - return G_SOURCE_REMOVE; - } - - _D("Auto brightness is working."); - alc_update_brt(true); - - return G_SOURCE_REMOVE; -} - -static void update_auto_brightness(bool update) -{ - if (update_timeout) { - g_source_remove(update_timeout); - update_timeout = 0; - } - - if (update) { - update_timeout = g_timeout_add(AUTOMATIC_DELAY_TIME, - update_handler, NULL); - } -} - -static int prepare_lsensor(void *data) -{ - int status, ret; - int brt = -1; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - set_autobrightness_state(status); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - - /* add auto_brt_setting change handler */ - vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function, NULL); - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - - if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { - _E("Failed to get automatic brightness."); - } else { - automatic_brt = brt / AUTOMATIC_DEVIDE_VAL; - _I("Automatic brt(%d) init success." , automatic_brt); - } - - vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt, NULL); - - return 0; -} - -static void update_brightness_direct(void) -{ - int ret, status; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - alc_update_brt(true); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); -} - -static int set_autobrightness_min(int val, char *name) -{ - if (!name) - return -EINVAL; - - if (val < PM_MIN_BRIGHTNESS || val > PM_MAX_BRIGHTNESS) - return -EINVAL; - - min_brightness = val; - - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - min_brightness_name = strndup(name, strlen(name)); - - update_brightness_direct(); - - _I("Auto brightness min value changed. min_brightness=%d min_brightness_name=%s", - min_brightness, min_brightness_name); - - return 0; -} - -static void reset_autobrightness_min(GDBusConnection *conn, - const gchar *sender, - const gchar *unique_name, - gpointer data) -{ - if (!sender) - return; - - if (!min_brightness_name) - return; - - if (strcmp(sender, min_brightness_name)) - return; - - _I("Change to default min brightness. before=%d changed=%d brightness_name=%s", min_brightness, - PM_MIN_BRIGHTNESS, min_brightness_name); - min_brightness = PM_MIN_BRIGHTNESS; - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - - update_brightness_direct(); -} - -static int lcd_changed_cb(void *data) -{ - int lcd_state; - - if (!data) - return 0; - lcd_state = *(int *)data; - if (lcd_state == S_LCDOFF && alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -static int booting_done_cb(void *data) -{ - int state; - - if (!data) - return 0; - - state = *(int *)data; - if (state != true) - return 0; - - /* get light data from sensor fw */ - prepare_lsensor(NULL); - - return 0; -} - -static void exit_lsensor(void) -{ - vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt); - - set_autobrightness_state(SETTING_BRIGHTNESS_AUTOMATIC_OFF); -} - -static void auto_brightness_init(void *data) -{ - display_info.update_auto_brightness = update_auto_brightness; - display_info.set_autobrightness_min = set_autobrightness_min; - display_info.reset_autobrightness_min = reset_autobrightness_min; - - register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static void auto_brightness_exit(void *data) -{ - exit_lsensor(); - - unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static const struct display_ops display_autobrightness_ops = { - .name = "auto-brightness", - .init = auto_brightness_init, - .exit = auto_brightness_exit, -}; - -DISPLAY_OPS_REGISTER(&display_autobrightness_ops) - diff --git a/plugins/tv/display/display-actor.c b/plugins/tv/display/display-actor.c deleted file mode 100644 index bab8630..0000000 --- a/plugins/tv/display/display-actor.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-actor.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *actor_head; - -void display_add_actor(struct display_actor_ops *actor) -{ - DD_LIST_APPEND(actor_head, actor); -} - -static struct display_actor_ops *display_find_actor(enum display_actor_id id) -{ - dd_list *elem; - struct display_actor_ops *actor; - - DD_LIST_FOREACH(actor_head, elem, actor) { - if (actor->id == id) - return actor; - } - return NULL; -} - -int display_set_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps |= caps; - - return 0; -} - -int display_reset_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps &= ~caps; - - return 0; -} - -unsigned int display_get_caps(enum display_actor_id id) -{ - struct display_actor_ops *actor; - - if (id <= 0) - return 0; - - actor = display_find_actor(id); - if (!actor) - return 0; - - return actor->caps; -} - -int display_has_caps(unsigned int total_caps, unsigned int caps) -{ - if (!total_caps || !caps) - return false; - - if ((total_caps & caps) == caps) - return true; - - return false; -} - diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c deleted file mode 100644 index 308d665..0000000 --- a/plugins/tv/display/display-dbus.c +++ /dev/null @@ -1,1168 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file display-dbus.c - * @brief dbus interface - * - */ - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core/log.h" -#include "util.h" -#include "core.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-idler.h" -#include "apps/apps.h" -#include "dd-display.h" -#include "display-actor.h" -#include "display-ops.h" -#include - -#define SIGNAL_HOMESCREEN "HomeScreen" - -#define DUMP_MODE_WATING_TIME 600000 - -#define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" -#define EXPIRED_POPUP_PID "_APP_PID_" -#define EXPIRED_POPUP_COMM "_APP_COMM_" -#define EXPIRED_POPUP_ID "_REQUEST_ID_" - -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - -GVariant *dbus_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->start(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->stop(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_lockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option1_str; - char *option2_str; - int timeout; - pid_t pid; - int state; - int flag; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); - - if (!state_str || timeout < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option1_str, STAYCURSTATE_STR)) - flag = STAY_CUR_STATE; - else if (!strcmp(option1_str, GOTOSTATENOW_STR)) - flag = GOTO_STATE_NOW; - else { - _E("%s option is invalid. set default option!", option1_str); - flag = STAY_CUR_STATE; - } - - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - - if (flag & GOTO_STATE_NOW) { - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - } - - if (check_dimstay(state, flag) == true) { - _E("LCD state can not be changed to OFF state now!"); - flag &= ~GOTO_STATE_NOW; - flag |= STAY_CUR_STATE; - } - - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); -out: - g_free(state_str); - g_free(option1_str); - g_free(option2_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_unlockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option_str; - pid_t pid; - int state; - int flag; - int ret = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ss)", &state_str, &option_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option_str, SLEEP_MARGIN_STR)) - flag = PM_SLEEP_MARGIN; - else if (!strcmp(option_str, RESET_TIMER_STR)) - flag = PM_RESET_TIMER; - else if (!strcmp(option_str, KEEP_TIMER_STR)) - flag = PM_KEEP_TIMER; - else { - _E("%s option is invalid. set default option!", option_str); - flag = PM_RESET_TIMER; - } - - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); -out: - g_free(state_str); - g_free(option_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_changestate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - pid_t pid; - int state; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &state_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else if (!strcmp(state_str, PM_STANDBY_STR)) - state = STANDBY; - else if (!strcmp(state_str, PM_SUSPEND_STR)) - state = SUSPEND; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - - if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); - ret = -EBUSY; - goto out; - } - - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); - - if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); -out: - g_free(state_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getdisplaycount(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = DEFAULT_DISPLAY_COUNT; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret, state; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - if (state == DISPLAY_STATE_NORMAL) - ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - else if (state == DISPLAY_STATE_SCREEN_DIM) - ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS; - else - ret = -EINVAL; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = -ENOTSUP; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt = -1, state, ret; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - - if (state == DISPLAY_STATE_NORMAL) - ret = backlight_ops.get_brightness(&brt); - else if (state == DISPLAY_STATE_SCREEN_DIM) { - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - if (ret >= 0) - ret = brt; - - _I("get brightness %d, %d", brt, ret); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int state, brt, autobrt, ret = 0, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(ii)", &state, &brt); - - //Check if brt is same with DIM - if (brt == 0) { - _E("application can not set this value(DIM VALUE:%d)", brt); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _E("auto_brightness state is ON, can not change the brightness value"); - ret = -EPERM; - goto error; - } - - if (state == DISPLAY_STATE_NORMAL) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } else if (state == DISPLAY_STATE_SCREEN_DIM) { - if (pm_cur_state == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - } - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - _I("set brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_holdbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt, autobrt, ret, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(i)", &brt); - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _D("Auto brightness will be paused"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - - _I("hold brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_releasebrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int bat, charger, changed, setting, brt, autobrt, ret = 0; - - CHECK_POWEROFF(); - - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); - if (ret < 0) { - _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger); - if (ret < 0) { - _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed); - if (ret < 0) { - _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting); - if (ret < 0) { - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.get_brightness(&brt); - if (ret < 0) - brt = ret; - - // check dim state - if (low_battery_state(bat) && - charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { - _D("batt warning low : brightness is not changed!"); - if (brt != 0) - backlight_ops.set_brightness(0); - goto error; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); - } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _D("Auto brightness will be enable"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setrefreshrate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int app, val, ret, control; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ii)", &app, &val); - - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { - ret = -EINVAL; - goto error; - } - - if (!display_conf.framerate_app[app]) { - _I("This case(%d) is not support in this target", app); - ret = -EPERM; - goto error; - } - - control = display_conf.control_display; - - if (control) - backlight_ops.off(NORMAL_MODE); - - _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); - if (ret < 0) - _E("Failed to set frame rate (%d)", ret); - - if (control) - backlight_ops.on(NORMAL_MODE); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int val, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - if (!display_info.set_autobrightness_min) { - ret = -EIO; - goto error; - } - g_variant_get(param, "(i)", &val); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = display_info.set_autobrightness_min(val, (char *)sender); - if (ret) { - _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); - goto error; - } - if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set autobrightness min %d by %d", val, pid); - } -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setlcdtimeout(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int on, dim, holdkey_block, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = set_lcd_timeout(on, dim, holdkey_block, sender); - if (ret) { - _W("fail to set lcd timeout %d by %d", ret, pid); - } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); - } - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lockscreenbgon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); - } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_dumpmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "on")) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, - STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_savelog(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - if (!device_poweroff(NULL)) - save_display_log(); - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_powerkeyignore(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &on); - - if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) - keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) - ret = keyfilter_ops->powerkey_lcdoff(); - else - ret = -ENOSYS; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_customlcdon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int timeout; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &timeout); - - ret = custom_lcdon(timeout); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_stay_touchscreen_off(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_lcd_paneloff_mode(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_actorcontrol(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0, val, actor; - char *op; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sii)", &op, &actor, &val); - - if (!strcmp(op, "set")) - ret = display_set_caps(actor, val); - else if (!strcmp(op, "reset")) - ret = display_reset_caps(actor, val); - else - ret = -EINVAL; - - g_free(op); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getcustombrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int status = 0; - - CHECK_POWEROFF(); - - status = backlight_ops.get_custom_status(); - - return g_variant_new("(i)", status); -} - -struct pmlock_expired_s { - char req_id[32]; - GDBusMethodInvocation *invocation; - int value; - pid_t pid; -}; - -static dd_list *expired_req_list; - -static int get_command(pid_t pid, char *comm, size_t len) -{ - FILE *fp; - char path[PATH_MAX]; - char name[NAME_MAX]; - char *tmp; - int ret; - - snprintf(path, sizeof(path), "/proc/%d/comm", pid); - - fp = fopen(path, "r"); - if (!fp) { - _E("Failed to open file %s, errno:%d", path, errno); - return -errno; - } - - ret = fread(name, 1, sizeof(name) - 1, fp); - name[ret] = '\0'; - fclose(fp); - - tmp = name; - while (*tmp != '\0') { - if (*tmp == '\n' || - *tmp == '\r') { - *tmp = '\0'; - break; - } - tmp++; - } - - snprintf(comm, len, "%s", name); - - return 0; -} - -GVariant *dbus_locktimeout_expired(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - pid_t pid; - char pid_str[16]; - char comm[NAME_MAX]; - struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &req_id); - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = get_command(pid, comm, sizeof(comm)); - if (ret < 0) { - _E("Failed to get command (%d)", ret); - goto out; - } - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(pid_str, sizeof(pid_str), "%d", pid); - ret = launch_system_app(APP_DEFAULT, 8, - APP_KEY_TYPE, - EXPIRED_POPUP_TYPE_POWER, - EXPIRED_POPUP_PID, - pid_str, - EXPIRED_POPUP_COMM, - comm, - EXPIRED_POPUP_ID, - req_id); - if (ret < 0) { - _E("Failed to launch pmlock expired popup(%d)", ret); - goto out; - } - - ex->pid = pid; - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - - ex->invocation = invocation; - - DD_LIST_APPEND(expired_req_list, ex); - - g_free(req_id); - return NULL; - -out: - gvar = g_variant_new("(i)", ret); - g_free(req_id); - if (ex) - free(ex); - return gvar; -} - -static gboolean app_term(gpointer data) -{ - struct pmlock_expired_s *ex = data; - - if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); - free(ex); - } - return G_SOURCE_REMOVE; -} - -static void expired_deliver_result(void *data) -{ - struct pmlock_expired_s *ex = data; - struct pmlock_expired_s *item = NULL; - dd_list *l; - size_t len; - int value; - char *id; - - if (!ex) - return; - - len = strlen(ex->req_id) + 1; - DD_LIST_FOREACH(expired_req_list, l, item) { - if (!strncmp(item->req_id, ex->req_id, len)) { - DD_LIST_REMOVE(expired_req_list, item); - break; - } - } - if (!item) - goto out; - - id = ex->req_id; - value = ex->value; - - _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" : - (value == 2) ? "KILL app" : "Release power lock"); - - if (!item->invocation) { - _E("item->invocation is null"); - goto out; - } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); - - if (value == 2) { - kill(item->pid, SIGTERM); - g_timeout_add(3000, app_term, (gpointer)item); - item = NULL; - } - -out: - free(ex); - free(item); -} - -GVariant *dbus_locktimeout_input(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - struct pmlock_expired_s *ex; - int value; - - CHECK_POWEROFF(); - - g_variant_get(param, "(si)", &req_id, &value); - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - ex->value = value; - - _I("req_id(%s), value(%d)", ex->req_id, ex->value); - - add_idle_request(expired_deliver_result, ex); - - ret = 0; - -out: - g_free(req_id); - return g_variant_new("(i)", ret); -} - -static const dbus_method_s dbus_methods[] = { - { "start", NULL, NULL, dbus_start }, - { "stop", NULL, NULL, dbus_stop }, - { "lockstate", "sssi", "i", dbus_lockstate }, - { "unlockstate", "ss", "i", dbus_unlockstate }, - { "changestate", "s", "i", dbus_changestate }, - { "ChangeState", "s", "i", dbus_changestate }, - { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */ - { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */ - { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */ - { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin }, - { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout }, - { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon }, - { "GetDisplayCount", NULL, "i", dbus_getdisplaycount }, - { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness }, - { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness }, - { "GetBrightness", "i", "i", dbus_getbrightness }, - { "SetBrightness", "ii", "i", dbus_setbrightness }, - { "HoldBrightness", "i", "i", dbus_holdbrightness }, - { "ReleaseBrightness", NULL, "i", dbus_releasebrightness }, - { "SetRefreshRate", "ii", "i", dbus_setrefreshrate }, - { "Dumpmode", "s", "i", dbus_dumpmode }, - { "SaveLog", NULL, NULL, dbus_savelog }, - { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, - { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, - { "CustomLCDOn", "i", "i", dbus_customlcdon }, - { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, - { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, - { "ActorControl", "sii", "i", dbus_actorcontrol }, - { "CustomBrightness", NULL, "i", dbus_getcustombrightness }, - { "CurrentBrightness", NULL, "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */ - { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, - { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_DISPLAY, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void homescreen_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - char *screen; - pid_t pid; - - g_variant_get(param, "(s)", &screen); - - _D("screen : %s", screen); - - pid = dbus_connection_get_sender_pid(conn, sender); - ambient_set_screen(screen, pid); - g_free(screen); -} - -/* - * Default capability - * api := LCDON | LCDOFF | BRIGHTNESS - * gesture := LCDON - */ -static struct display_actor_ops display_api_actor = { - .id = DISPLAY_ACTOR_API, - .caps = DISPLAY_CAPA_LCDON | - DISPLAY_CAPA_LCDOFF | - DISPLAY_CAPA_BRIGHTNESS, -}; - -static struct display_actor_ops display_gesture_actor = { - .id = DISPLAY_ACTOR_GESTURE, - .caps = DISPLAY_CAPA_LCDON, -}; - -int init_pm_dbus(void) -{ - int ret; - - display_add_actor(&display_api_actor); - display_add_actor(&display_gesture_actor); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - ret = subscribe_dbus_signal(NULL, - DEVICED_OBJECT_PATH, - DEVICED_INTERFACE_NAME, - SIGNAL_HOMESCREEN, - homescreen_signal_handler, - NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } - - return 0; -} - diff --git a/plugins/tv/display/display-ops.c b/plugins/tv/display/display-ops.c deleted file mode 100644 index 22b9137..0000000 --- a/plugins/tv/display/display-ops.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-ops.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *disp_head; - -void add_display(const struct display_ops *disp) -{ - DD_LIST_APPEND(disp_head, disp); -} - -void remove_display(const struct display_ops *disp) -{ - DD_LIST_REMOVE(disp_head, disp); -} - -const struct display_ops *find_display_feature(const char *name) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - if (!strcmp(disp->name, name)) - return disp; - } - return NULL; -} - -void display_ops_init(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] initialize", disp->name); - if (disp->init) - disp->init(data); - } -} - -void display_ops_exit(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] deinitialize", disp->name); - if (disp->exit) - disp->exit(data); - } -} - diff --git a/plugins/tv/display/input.c b/plugins/tv/display/input.c deleted file mode 100644 index a986504..0000000 --- a/plugins/tv/display/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "poll.h" - -#define SEAT_NAME "seat0" - -static struct udev *udev; -static struct libinput *li; -static guint efd; - -int (*pm_callback) (int, PMMsg *); - -static inline void process_event(struct libinput_event *ev) -{ - static const struct device_ops *display_device_ops; - struct input_event input; - struct libinput *li; - struct libinput_event_keyboard *k; - unsigned int time; - int fd; - - if (!pm_callback) - return; - - if (!display_device_ops) { - display_device_ops = find_device("display"); - if (!display_device_ops) - return; - } - - /* do not operate when display stops */ - if (device_get_status(display_device_ops) - != DEVICE_OPS_STATUS_START) { - _E("display status is stop"); - return; - } - - switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; - case LIBINPUT_EVENT_KEYBOARD_KEY: - k = libinput_event_get_keyboard_event(ev); - time = libinput_event_keyboard_get_time(k); - li = libinput_event_get_context(ev); - - input.time.tv_sec = MSEC_TO_SEC(time); - input.time.tv_usec = MSEC_TO_USEC(time % 1000); - input.type = EV_KEY; - input.code = libinput_event_keyboard_get_key(k); - input.value = libinput_event_keyboard_get_key_state(k); - - fd = libinput_get_fd(li); - _D("time %ld.%06ld type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); - input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - case LIBINPUT_EVENT_TOUCH_UP: - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; - break; - default: - break; - } - - /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); -} - -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -int init_input(void) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return -EPERM; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return -EPERM; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return -EPERM; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return -EPERM; - } - - return 0; -} - -int exit_input(void) -{ - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ - - if (li) - libinput_unref(li); - - if (udev) - udev_unref(udev); - - return 0; -} diff --git a/plugins/tv/display/lock-detector.c b/plugins/tv/display/lock-detector.c deleted file mode 100644 index 0560ef4..0000000 --- a/plugins/tv/display/lock-detector.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file lock-detector.c - * @brief - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "core/list.h" - -struct lock_info { - unsigned long hash; - char *name; - int state; - int count; - long locktime; - long unlocktime; - long time; -}; - -#define LIMIT_COUNT 128 - -static dd_list *lock_info_list; - -static long get_time(void) -{ - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); -} - -static void shrink_lock_info_list(void) -{ - dd_list *l, *l_prev; - struct lock_info *info; - unsigned int count; - - count = DD_LIST_LENGTH(lock_info_list); - if (count <= LIMIT_COUNT) - return; - _D("list is shrink : count %d", count); - - DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { - if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); - if (info->name) - free(info->name); - free(info); - count--; - } - if (count <= (LIMIT_COUNT / 2)) - break; - } -} - -int set_lock_time(const char *pname, int state) -{ - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - info->count += 1; - if (info->locktime == 0) - info->locktime = get_time(); - info->unlocktime = 0; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } - - info = malloc(sizeof(struct lock_info)); - if (!info) { - _E("Malloc is failed for lock_info!"); - return -ENOMEM; - } - - info->hash = val; - info->name = strndup(pname, strlen(pname)); - info->state = state; - info->count = 1; - info->locktime = get_time(); - info->unlocktime = 0; - info->time = 0; - - DD_LIST_APPEND(lock_info_list, info); - - return 0; -} - -int set_unlock_time(const char *pname, int state) -{ - bool find = false; - long diff; - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - find = true; - break; - } - - if (!find) - return -EINVAL; - - if (info->locktime == 0) - return -EINVAL; - - /* update time */ - info->unlocktime = get_time(); - diff = info->unlocktime - info->locktime; - if (diff > 0) - info->time += diff; - info->locktime = 0; - - if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) - shrink_lock_info_list(); - - return 0; -} - -void free_lock_info_list(void) -{ - dd_list *l, *l_next; - struct lock_info *info; - - if (!lock_info_list) - return; - - DD_LIST_FOREACH_SAFE(lock_info_list, l, l_next, info) { - DD_LIST_REMOVE(lock_info_list, info); - if (info->name) - free(info->name); - free(info); - } - lock_info_list = NULL; -} - -void print_lock_info_list(int fd) -{ - struct lock_info *info; - dd_list *l; - char buf[255]; - int ret; - - if (!lock_info_list) - return; - - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; - if (info->locktime != 0 && info->unlocktime == 0) - time = get_time() - info->locktime; - snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - } -} - diff --git a/plugins/tv/display/poll.c b/plugins/tv/display/poll.c deleted file mode 100644 index ee0471d..0000000 --- a/plugins/tv/display/poll.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include -#include "util.h" -#include "core.h" -#include "poll.h" -#include "display/display-ops.h" - -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(pm_status_flag & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static bool state_supported(enum state_t st) -{ - if (states[st].trans) - return true; - return false; -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -void init_pm_internal() -{ - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; -} diff --git a/plugins/tv/display/setting.c b/plugins/tv/display/setting.c deleted file mode 100644 index b109d8c..0000000 --- a/plugins/tv/display/setting.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core.h" -#include "util.h" -#include "setting.h" -#include "display-ops.h" - -#define LCD_DIM_RATIO 0.3 -#define LCD_MAX_DIM_TIMEOUT 7000 -#define LCD_MIN_DIM_TIMEOUT 500 - -static const char *setting_keys[SETTING_GET_END] = { - [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, - [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS, - [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE, - [SETTING_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, -}; - -static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; -static bool lock_screen_bg_state = false; -static int force_lcdtimeout = 0; -static int custom_on_timeout = 0; -static int custom_normal_timeout = 0; -static int custom_dim_timeout = 0; - -static void display_state_send_system_event(int state) -{ - bundle *b; - const char *str; - - if (state == S_NORMAL) - str = EVT_VAL_DISPLAY_NORMAL; - else if (state == S_LCDDIM) - str = EVT_VAL_DISPLAY_DIM; - else if (state == S_LCDOFF) - str = EVT_VAL_DISPLAY_OFF; - else - return; - - _I("eventsystem (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); -} - -int set_force_lcdtimeout(int timeout) -{ - if (timeout < 0) - return -EINVAL; - - force_lcdtimeout = timeout; - - return 0; -} - -int __get_lock_screen_state(void) -{ - return lock_screen_state; -} - -void set_lock_screen_state(int state) -{ - switch (state) { - case VCONFKEY_IDLE_LOCK: - case VCONFKEY_IDLE_UNLOCK: - lock_screen_state = state; - break; - default: - lock_screen_state = VCONFKEY_IDLE_UNLOCK; - } -} - -int get_lock_screen_bg_state(void) -{ - return lock_screen_bg_state; -} - -void set_lock_screen_bg_state(bool state) -{ - _I("state is %d", state); - lock_screen_bg_state = state; -} - -int set_setting_pmstate(int val) -{ - static int old = -1; - int ret; - - if (old == val) - return 0; - old = val; - - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); - - return ret; -} - -int get_setting_brightness(int *level) -{ - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; -} - -void get_dim_timeout(int *dim_timeout) -{ - int vconf_timeout, on_timeout, val, ret; - - if (custom_dim_timeout > 0) { - *dim_timeout = custom_dim_timeout; - return; - } - - if (ambient_get_condition() == true) { - *dim_timeout = LCD_MIN_DIM_TIMEOUT; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - val = (double)on_timeout * LCD_DIM_RATIO; - if (val > LCD_MAX_DIM_TIMEOUT) - val = LCD_MAX_DIM_TIMEOUT; - - *dim_timeout = val; -} - -void get_run_timeout(int *timeout) -{ - int dim_timeout = -1; - int vconf_timeout = -1; - int on_timeout; - int ret; - - if (custom_normal_timeout > 0) { - *timeout = custom_normal_timeout; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - if (on_timeout == 0) { - *timeout = on_timeout; - return; - } - - get_dim_timeout(&dim_timeout); - *timeout = on_timeout - dim_timeout; -} - -int set_custom_lcdon_timeout(int timeout) -{ - int changed = (custom_on_timeout == timeout ? false : true); - - custom_on_timeout = timeout; - - if (timeout <= 0) { - custom_normal_timeout = 0; - custom_dim_timeout = 0; - return changed; - } - - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; - custom_normal_timeout = timeout - custom_dim_timeout; - - _I("custom normal(%d), dim(%d)", custom_normal_timeout, - custom_dim_timeout); - - return changed; -} - -static int setting_cb(keynode_t *key_nodes, void *data) -{ - keynode_t *tmp = key_nodes; - int index; - - index = (int)((intptr_t)data); - if (index > SETTING_END) { - _E("Unknown setting key: %s, idx=%d", - vconf_keynode_get_name(tmp), index); - return -1; - } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); - - return 0; -} - -int init_setting(int (*func) (int key_idx, int val)) -{ - int i; - - if (func != NULL) - disp_plgn.update_pm_setting = func; - - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { - /* - * To pass an index data through the vconf infratstructure - * without memory allocation, an index data becomes typecast - * to proper pointer size on each architecture. - */ - vconf_notify_key_changed(setting_keys[i], (void *)setting_cb, - (void *)((intptr_t)i)); - } - - disp_plgn.get_lock_screen_state = __get_lock_screen_state; - - return 0; -} - -int exit_setting(void) -{ - int i; - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) - vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb); - - return 0; -} - diff --git a/plugins/wearable/display/auto-brightness.c b/plugins/wearable/display/auto-brightness.c deleted file mode 100644 index efc415c..0000000 --- a/plugins/wearable/display/auto-brightness.c +++ /dev/null @@ -1,681 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "util.h" -#include "core.h" -#include "display-ops.h" -#include "device-node.h" -#include "setting.h" -#include "core/device-notifier.h" -#include "core/config-parser.h" - -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ -#define MAX_SAMPLING_COUNT 3 -#define MAX_FAULT 5 -#define DEFAULT_AUTOMATIC_BRT 5 -#define AUTOMATIC_DEVIDE_VAL 10 -#define AUTOMATIC_DELAY_TIME 500 /* 0.5 sec */ - -#define RADIAN_VALUE (57.2957) -#define ROTATION_90 90 -#define WORKING_ANGLE_MIN 0 -#define WORKING_ANGLE_MAX 20 - -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - -static int (*_default_action) (int); -static guint alc_timeout_id = 0; -static guint update_timeout; -static sensor_listener_h light_listener; -static sensor_listener_h accel_listener; -static int fault_count; -static int automatic_brt = DEFAULT_AUTOMATIC_BRT; -static int min_brightness = PM_MIN_BRIGHTNESS; -static char *min_brightness_name = 0; - -/* light sensor */ -static float lmax, lmin; - -static bool update_working_position(void) -{ - sensor_event_s data; - int ret; - float x, y, z, pitch, realg; - - if (!display_conf.accel_sensor_on) - return false; - - ret = sensor_listener_read_data(accel_listener, &data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get accelerometer data: %d", ret); - return true; - } - - x = data.values[0]; - y = data.values[1]; - z = data.values[2]; - - realg = (float)sqrt((x * x) + (y * y) + (z * z)); - pitch = ROTATION_90 - abs((int) (asin(z / realg) * RADIAN_VALUE)); - - _D("Accel data x=%f y=%f z=%f pitch=%f", x, y, z, pitch); - - if (pitch >= WORKING_ANGLE_MIN && pitch <= WORKING_ANGLE_MAX) - return true; - return false; -} - -static void alc_set_brightness(int setting, int value, float light) -{ - static float old; - int position, tmp_value = 0, ret; - - ret = backlight_ops.get_brightness(&tmp_value); - if (ret < 0) { - _E("Failed to get display brightness."); - return; - } - - if (value < min_brightness) - value = min_brightness; - - if (tmp_value != value) { - if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { - position = update_working_position(); - if (!position && (old > light)) { - _D("It's not working position, " - "LCD isn't getting dark."); - return; - } - } - int diff, step; - - diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) - step = (diff > 0 ? 1 : -1); - else - step = (int)ceil(diff / - (float)display_conf.brightness_change_step); - - _D("%d", step); - while (tmp_value != value) { - if (step == 0) break; - - tmp_value += step; - if ((step > 0 && tmp_value > value) || - (step < 0 && tmp_value < value)) - tmp_value = value; - - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); - } - _I("Load light data(%f). auto brt=%d min brightness=%d " - "brightness=%d", light, automatic_brt, min_brightness, value); - old = light; - } -} - -static bool check_brightness_changed(int value) -{ - int i; - static int values[MAX_SAMPLING_COUNT], count = 0; - - if (count >= MAX_SAMPLING_COUNT || count < 0) - count = 0; - - values[count++] = value; - - for (i = 0; i < MAX_SAMPLING_COUNT - 1; i++) - if (values[i] != values[i+1]) - return false; - return true; -} - -static bool alc_update_brt(bool setting) -{ - int value = 0; - int ret = -1; - sensor_event_s light_data; - int index; - float light; - - ret = sensor_listener_read_data(light_listener, &light_data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to read light sensor data: %d", ret); - goto out; - } - - index = light_data.value_count - 1; - if (index < 0 || light_data.values[index] < 0) { - _E("Invalid light sensor data."); - goto out; - } - - light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( - lmax, lmin, light, &value); - if (ret == -ENOTSUP) { - _E("Not supported to handle the light data."); - goto out; - } - - if (ret < 0 || value < PM_MIN_BRIGHTNESS || value > PM_MAX_BRIGHTNESS) { - _E("Failed to load light data. light=%f value=%d: %d", light, value, ret); - goto out; - } - - fault_count = 0; - - if (display_conf.continuous_sampling && - !check_brightness_changed(value) && - !setting) - return true; - - alc_set_brightness(setting, value, light); - - return true; - -out: - fault_count++; - - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { - if (alc_timeout_id) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - SETTING_BRIGHTNESS_AUTOMATIC_OFF); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - _E("Fault counts is over %d, disable automatic brightness.", MAX_FAULT); - return false; - } - return true; -} - -static gboolean alc_handler(void *data) -{ - if (pm_cur_state != S_NORMAL) { - if (alc_timeout_id > 0) - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - return G_SOURCE_REMOVE; - } - - if (!alc_update_brt(false)) - return G_SOURCE_REMOVE; - - if (alc_timeout_id != 0) - return G_SOURCE_CONTINUE; - - return G_SOURCE_REMOVE; -} - -static int alc_action(int timeout) -{ - /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } - - if (_default_action != NULL) - return _default_action(timeout); - - /* unreachable code */ - return -1; -} - -static int connect_sensor(void) -{ - int ret; - sensor_h sensor; - sensor_h *list = NULL; - int cnt = 0; - - _I("Connect with sensor fw."); - /* light sensor */ - ret = sensor_get_sensor_list(SENSOR_LIGHT, &list, &cnt); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor list: %d", ret); - goto error; - } - - /* TODO - * Sensor apis will be fixed - * to provide which sensor is effective among sensors */ - if (cnt == 3) /* three light sensors exist */ - sensor = list[2]; - else - sensor = list[0]; - - free(list); - - ret = sensor_get_min_range(sensor, &lmin); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor min range: %d", ret); - goto error; - } - ret = sensor_get_max_range(sensor, &lmax); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor max range: %d", ret); - goto error; - } - _I("Light sensor min(%f), max(%f)", lmin, lmax); - - ret = sensor_create_listener(sensor, &light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(light)."); - goto error; - } - sensor_listener_set_option(light_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start light sensor."); - sensor_destroy_listener(light_listener); - light_listener = 0; - goto error; - } - - if (!display_conf.accel_sensor_on) - goto success; - - /* accelerometer sensor */ - ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &sensor); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get default accel sensor."); - goto error; - } - ret = sensor_create_listener(&sensor, &accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(accel)."); - goto error; - } - sensor_listener_set_option(accel_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start accel sensor."); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - goto error; - } - -success: - fault_count = 0; - return 0; - -error: - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - return -EIO; -} - -static int disconnect_sensor(void) -{ - _I("Disconnect with sensor fw."); - /* light sensor*/ - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - - /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - - if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; - _default_action = NULL; - } - if (alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -void set_brightness_changed_state(void) -{ - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; - _D("Brightness changed in low battery," - "escape dim state (light)."); - } -} - -static int set_autobrightness_state(int status) -{ - int ret = -1; - int brt = -1; - int default_brt = -1; - - if (status == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (connect_sensor() < 0) - return -1; - - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - /* change alc action func */ - if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; - - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _I("Auto brightness paused."); - disconnect_sensor(); - } else { - disconnect_sensor(); - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - ret = get_setting_brightness(&default_brt); - if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { - _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; - if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } - default_brt = brt; - } - - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); - } - - return 0; -} - -static void set_alc_function(keynode_t *key_nodes, void *data) -{ - int status, ret; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - status = vconf_keynode_get_int(key_nodes); - - switch (status) { - case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - case SETTING_BRIGHTNESS_AUTOMATIC_ON: - case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - ret = set_autobrightness_state(status); - _D("Set auto brightness: %d", ret); - break; - default: - _E("Invalid value(%d)", status); - } -} - -static void set_alc_automatic_brt(keynode_t *key_nodes, void *data) -{ - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - automatic_brt = vconf_keynode_get_int(key_nodes) / AUTOMATIC_DEVIDE_VAL; - _D("Automatic brt(%d)", automatic_brt); - - alc_update_brt(true); -} - -static gboolean update_handler(void *data) -{ - int ret, on; - - update_timeout = 0; - - if (pm_cur_state != S_NORMAL) - return G_SOURCE_REMOVE; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); - if (ret < 0 || on != SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - return G_SOURCE_REMOVE; - } - - _D("Auto brightness is working."); - alc_update_brt(true); - - return G_SOURCE_REMOVE; -} - -static void update_auto_brightness(bool update) -{ - if (update_timeout) { - g_source_remove(update_timeout); - update_timeout = 0; - } - - if (update) { - update_timeout = g_timeout_add(AUTOMATIC_DELAY_TIME, - update_handler, NULL); - } -} - -static int prepare_lsensor(void *data) -{ - int status, ret; - int brt = -1; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - set_autobrightness_state(status); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - - /* add auto_brt_setting change handler */ - vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function, NULL); - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - - if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { - _E("Failed to get automatic brightness."); - } else { - automatic_brt = brt / AUTOMATIC_DEVIDE_VAL; - _I("Automatic brt(%d) init success.", automatic_brt); - } - - vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt, NULL); - - return 0; -} - -static void update_brightness_direct(void) -{ - int ret, status; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - alc_update_brt(true); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); -} - -static int set_autobrightness_min(int val, char *name) -{ - if (!name) - return -EINVAL; - - if (val < PM_MIN_BRIGHTNESS || val > PM_MAX_BRIGHTNESS) - return -EINVAL; - - min_brightness = val; - - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - min_brightness_name = strndup(name, strlen(name)); - - update_brightness_direct(); - - _I("Auto brightness min value changed. min_brightness=%d min_brightness_name=%s", - min_brightness, min_brightness_name); - - return 0; -} - -static void reset_autobrightness_min(GDBusConnection *conn, - const gchar *sender, - const gchar *unique_name, - gpointer data) -{ - if (!sender) - return; - - if (!min_brightness_name) - return; - - if (strcmp(sender, min_brightness_name)) - return; - - _I("Change to default min brightness. before=%d changed=%d brightness_name=%s", min_brightness, - PM_MIN_BRIGHTNESS, min_brightness_name); - min_brightness = PM_MIN_BRIGHTNESS; - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - - update_brightness_direct(); -} - -static int lcd_changed_cb(void *data) -{ - int lcd_state; - - if (!data) - return 0; - lcd_state = *(int *)data; - if (lcd_state == S_LCDOFF && alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -static int booting_done_cb(void *data) -{ - int state; - - if (!data) - return 0; - - state = *(int *)data; - if (state != true) - return 0; - - /* get light data from sensor fw */ - prepare_lsensor(NULL); - - return 0; -} - -static void exit_lsensor(void) -{ - vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt); - - set_autobrightness_state(SETTING_BRIGHTNESS_AUTOMATIC_OFF); -} - -static void auto_brightness_init(void *data) -{ - display_info.update_auto_brightness = update_auto_brightness; - display_info.set_autobrightness_min = set_autobrightness_min; - display_info.reset_autobrightness_min = reset_autobrightness_min; - - register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static void auto_brightness_exit(void *data) -{ - exit_lsensor(); - - unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static const struct display_ops display_autobrightness_ops = { - .name = "auto-brightness", - .init = auto_brightness_init, - .exit = auto_brightness_exit, -}; - -DISPLAY_OPS_REGISTER(&display_autobrightness_ops) - diff --git a/plugins/wearable/display/ambient-mode.c b/src/display/ambient-mode.c similarity index 100% rename from plugins/wearable/display/ambient-mode.c rename to src/display/ambient-mode.c diff --git a/plugins/mobile/display/auto-brightness.c b/src/display/auto-brightness.c similarity index 100% rename from plugins/mobile/display/auto-brightness.c rename to src/display/auto-brightness.c diff --git a/plugins/wearable/display/display-actor.c b/src/display/display-actor.c similarity index 100% rename from plugins/wearable/display/display-actor.c rename to src/display/display-actor.c diff --git a/plugins/wearable/display/display-dbus.c b/src/display/display-dbus.c similarity index 100% rename from plugins/wearable/display/display-dbus.c rename to src/display/display-dbus.c diff --git a/plugins/wearable/display/display-ops.c b/src/display/display-ops.c similarity index 100% rename from plugins/wearable/display/display-ops.c rename to src/display/display-ops.c diff --git a/plugins/wearable/display/input.c b/src/display/input.c similarity index 100% rename from plugins/wearable/display/input.c rename to src/display/input.c diff --git a/plugins/wearable/display/lock-detector.c b/src/display/lock-detector.c similarity index 100% rename from plugins/wearable/display/lock-detector.c rename to src/display/lock-detector.c diff --git a/plugins/wearable/display/poll.c b/src/display/poll.c similarity index 100% rename from plugins/wearable/display/poll.c rename to src/display/poll.c diff --git a/plugins/wearable/display/setting.c b/src/display/setting.c similarity index 100% rename from plugins/wearable/display/setting.c rename to src/display/setting.c -- 2.7.4 From 3b0750f7bd653a394c8bd48ff92389098add32c3 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Mon, 27 May 2019 15:41:21 +0900 Subject: [PATCH 13/16] dbus-policy: modified to use default deny - allow signal Change-Id: Ic9eeb5a7df8b35dacad0d2a8488efc249cd12104 Signed-off-by: sanghyeok.oh --- conf/org.tizen.system.deviced.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 49877ee..709c909 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -26,8 +26,7 @@ - - + -- 2.7.4 From 498493b3915e95fa7f78cc26914ffa1dd8b31646 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 11 Jun 2019 18:11:14 +0900 Subject: [PATCH 14/16] Update battery.health_s in check_health_status battery.health_s is not synchronized with battery.health. So, update battery.health_s in check_health_status to synchronize them. Change-Id: I779b1c91e202198be62ef858d2fa774a067a2c7d Signed-off-by: lokilee73 --- src/battery/power-supply.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index c4eb7c8..2b092d6 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -636,6 +636,9 @@ static void check_health_status(const char *env_value) battery.health = HEALTH_GOOD; return; } + + snprintf(battery.health_s, sizeof(battery.health_s), "%s", env_value); + if (strncmp(env_value, OVERHEAT_NAME, sizeof(OVERHEAT_NAME)) == 0) battery.health = HEALTH_HIGH; -- 2.7.4 From b82336785cdd7abda7212b930c72e1521960bed5 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 14 Jun 2019 19:35:24 +0900 Subject: [PATCH 15/16] Initialize dpms_connected in disconnect_interface_with_dpms to protect crash Display can be controlled by devicectl command. ex) devicectl display stop/start After disconnect_interface_with_dpms is called by devicectl command, LCD_ON can be requested via dbus-send. At this time, dpms related functions and variables are initialized. So, crash can occur. Change-Id: I9fdbc0c27e612bbdc9d11309f2a0be6102112d66 Signed-off-by: lokilee73 --- src/display/display-dpms.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/display/display-dpms.c diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c old mode 100644 new mode 100755 index 37f5d1b..54127de --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -31,6 +31,7 @@ struct wl_output *wl_out; struct tizen_dpms_manager *tz_dpms_mng = NULL; int lcd_state = -1; bool wm_is_ready; +static bool dpms_connected; bool check_wm_ready(void) { @@ -60,6 +61,8 @@ void disconnect_interface_with_dpms(void) wl_display_disconnect(display); display = NULL; } + + dpms_connected = false; } static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) @@ -141,8 +144,6 @@ error: bool dpms_is_available(void) { - static bool dpms_connected; - /* Check window manager */ if (!wm_is_ready) { _E("Window manager is not ready"); -- 2.7.4 From 3ced9b5f3d7f92aa3cf44cdafac51d334907c85b Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 17 Jun 2019 13:33:31 +0900 Subject: [PATCH 16/16] Temporarily allow org.tizen.system.deviced.Board in dbus policy Change-Id: I5ce697624c93a03bc8ae9af5184ec2456c21ee7a Signed-off-by: Hyotaek Shim --- conf/org.tizen.system.deviced.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 709c909..58737c0 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -59,5 +59,6 @@ + -- 2.7.4