4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * @file display-dbus.c
22 * @brief dbus interface
29 #include <libsyscommon/libgdbus.h>
30 #include <libsyscommon/proc.h>
31 #include <system/syscommon-plugin-deviced-common-interface.h>
32 #include <device/display.h>
33 #include <device/power.h>
35 #include "ambient-mode.h"
38 #include "lock-detector.h"
39 #include "shared/common.h"
40 #include "shared/devices.h"
41 #include "shared/device-notifier.h"
42 #include "shared/apps.h"
43 #include "dd-display.h"
44 #include "device-interface.h"
45 #include "display-actor.h"
46 #include "display-ops.h"
47 #include "shared/plugin.h"
48 #include "display-lock.h"
49 #include "display-panel.h"
50 #include "display-config.h"
51 #include "display-state-transition.h"
52 //#include "display/display.h"
53 #include "display-backlight.h"
54 #include "display-misc.h"
55 #include "display-util.h"
57 #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus"
58 #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus"
59 #define APP_CHANGE_STATE "AppStatusChange"
60 #define APP_TERMINATED "AppTerminated"
62 #ifndef VCONFKEY_LCD_BRIGHTNESS_INIT
63 #define VCONFKEY_LCD_BRIGHTNESS_INIT "db/private/deviced/lcd_brightness_init"
66 #define DISPLAY_DIM_BRIGHTNESS 0
67 #define DUMP_MODE_WATING_TIME 600000
69 #define LCDOFF_PROXI_STR "proximity"
70 #define LCDOFF_GESTURE_STR "gesture"
72 #define EXPIRED_POPUP_TYPE_POWER "power_lock_expired"
73 #define EXPIRED_POPUP_PID "_APP_PID_"
74 #define EXPIRED_POPUP_COMM "_APP_COMM_"
75 #define EXPIRED_POPUP_ID "_REQUEST_ID_"
77 static struct display_plugin *disp_plgn;
78 static char *custom_change_name;
80 static GVariant *dbus_start(GDBusConnection *conn,
81 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
82 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
84 static const struct device_ops *display_device_ops = NULL;
86 if (!display_device_ops)
87 display_device_ops = find_device("display");
88 if (NOT_SUPPORT_OPS(display_device_ops))
91 display_device_ops->start(CORE_LOGIC_MODE);
93 return gdbus_new_g_variant_tuple();
96 static GVariant *dbus_stop(GDBusConnection *conn,
97 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
98 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
100 static const struct device_ops *display_device_ops = NULL;
102 if (!display_device_ops)
103 display_device_ops = find_device("display");
104 if (NOT_SUPPORT_OPS(display_device_ops))
107 display_state_transition_request_state_transition_with_option(DEVICED_EVENT_DISPLAY, LCD_NORMAL);
109 display_device_ops->stop(CORE_LOGIC_MODE);
111 return gdbus_new_g_variant_tuple();
114 static int check_dimstay(int next_state, int flag)
116 if (next_state != LCD_OFF)
119 if (!(flag & GOTO_STATE_NOW))
122 if (!(get_pm_status_flag() & DIMSTAY_FLAG))
128 static GVariant *dbus_lockstate(GDBusConnection *conn,
129 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
130 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
142 assert(g_display_plugin.config);
144 g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout);
146 if (!state_str || timeout < 0) {
147 _E("message is invalid!");
152 if (!strcmp(state_str, "privilege check"))
155 pid = gdbus_connection_get_sender_pid(conn, sender);
156 if (pid == -1 || kill(pid, 0) == -1) {
157 _E("%d process does not exist, dbus ignored!", pid);
162 if (!strcmp(state_str, PM_LCDON_STR))
164 else if (!strcmp(state_str, PM_LCDDIM_STR)) {
165 if (!g_display_plugin.config->dimming) {
166 _E("LCD_DIM lock is not supported.");
171 } else if (!strcmp(state_str, PM_LCDOFF_STR))
174 _E("%s state is invalid, dbus ignored.", state_str);
179 if (!strcmp(option1_str, STAYCURSTATE_STR))
180 flag = STAY_CUR_STATE;
181 else if (!strcmp(option1_str, GOTOSTATENOW_STR))
182 flag = GOTO_STATE_NOW;
184 _E("%s option is invalid. set default option!", option1_str);
185 flag = STAY_CUR_STATE;
188 if (flag & GOTO_STATE_NOW) {
189 caps = display_get_caps(DISPLAY_ACTOR_API);
191 if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) &&
192 state == LCD_NORMAL) {
193 _D("No lcdon capability!");
197 if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) &&
199 _D("No lcdoff capability!");
205 if (check_dimstay(state, flag) == true) {
206 _E("LCD state can not be changed to OFF state now!");
207 flag &= ~GOTO_STATE_NOW;
208 flag |= STAY_CUR_STATE;
211 display_lock_request_lock_with_option(pid, state, flag, timeout);
216 return g_variant_new("(i)", ret);
219 static GVariant *dbus_unlockstate(GDBusConnection *conn,
220 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
221 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
230 assert(g_display_plugin.config);
232 g_variant_get(param, "(ss)", &state_str, &option_str);
235 _E("message is invalid!");
240 if (!strcmp(state_str, "privilege check"))
243 pid = gdbus_connection_get_sender_pid(conn, sender);
244 if (pid == -1 || kill(pid, 0) == -1) {
245 _E("%d process does not exist, dbus ignored!", pid);
250 if (!strcmp(state_str, PM_LCDON_STR))
252 else if (!strcmp(state_str, PM_LCDDIM_STR)) {
253 if (!g_display_plugin.config->dimming) {
254 _E("LCD_DIM unlock is not supported.");
259 } else if (!strcmp(state_str, PM_LCDOFF_STR))
262 _E("%s state is invalid, dbus ignored!", state_str);
267 if (!strcmp(option_str, SLEEP_MARGIN_STR))
268 flag = PM_SLEEP_MARGIN;
269 else if (!strcmp(option_str, RESET_TIMER_STR))
270 flag = PM_RESET_TIMER;
271 else if (!strcmp(option_str, KEEP_TIMER_STR))
272 flag = PM_KEEP_TIMER;
274 _E("%s option is invalid. set default option!", option_str);
275 flag = PM_RESET_TIMER;
278 display_lock_request_unlock_with_option(pid, state, flag);
282 return g_variant_new("(i)", ret);
285 static GVariant *dbus_changestate(GDBusConnection *conn,
286 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
287 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
292 int ret = 0, len, lcdon_blocked;
295 assert(g_display_plugin.config);
297 g_variant_get(param, "(s)", &state_str);
300 _E("message is invalid!");
305 if (!strcmp(state_str, "privilege check"))
308 pid = gdbus_connection_get_sender_pid(conn, sender);
309 if (pid == -1 || kill(pid, 0) == -1) {
310 _E("%d process does not exist, dbus ignored!", pid);
315 len = strlen(state_str);
321 if (!strcmp(state_str, PM_LCDON_STR))
323 else if (!strcmp(state_str, PM_LCDDIM_STR)) {
324 if (!g_display_plugin.config->dimming) {
325 _E("LCD_DIM state is not supported.");
330 } else if (!strcmp(state_str, PM_LCDOFF_STR))
332 else if (!strcmp(state_str, PM_STANDBY_STR))
334 else if (!strcmp(state_str, PM_SUSPEND_STR))
337 _E("%s state is invalid, dbus ignored!", state_str);
342 caps = display_get_caps(DISPLAY_ACTOR_API);
344 if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) &&
345 state == LCD_NORMAL) {
346 _D("No lcdon capability!");
350 if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) &&
352 _D("No lcdoff capability!");
357 lcdon_blocked = display_plugin_is_lcd_on_blocked();
358 if (lcdon_blocked != LCDON_BLOCK_NONE) {
359 if (state == LCD_NORMAL || state == LCD_DIM) {
360 _W("LCDON is blocked, %d.", lcdon_blocked);
366 if (check_dimstay(state, GOTO_STATE_NOW) == true) {
367 _E("LCD state can not be changed to OFF state! by %d", pid);
372 display_state_transition_request_state_transition_with_option(pid, state);
374 if (!ret && state == LCD_OFF)
375 display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
378 return g_variant_new("(i)", ret);
381 static GVariant *dbus_getdisplaycount(GDBusConnection *conn,
382 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
383 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
387 ret = DEFAULT_DISPLAY_COUNT;
389 return g_variant_new("(i)", ret);
392 static GVariant *dbus_getmaxbrightness(GDBusConnection *conn,
393 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
394 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
398 g_variant_get(param, "(i)", &state);
399 if (state == DISPLAY_STATE_NORMAL)
400 ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS;
401 else if (state == DISPLAY_STATE_SCREEN_DIM)
402 ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS;
406 return g_variant_new("(i)", ret);
409 static GVariant *dbus_setmaxbrightness(GDBusConnection *conn,
410 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
411 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
417 return g_variant_new("(i)", ret);
420 static GVariant *dbus_getbrightness(GDBusConnection *conn,
421 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
422 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
424 enum deviced_display_state current;
425 int brt = -1, ret, result;
427 if (display_state_get_current(¤t) < 0) {
432 if (current == DEVICED_DISPLAY_STATE_ON) {
433 ret = display_backlight_get_brightness(&brt);
438 } else if (current == DEVICED_DISPLAY_STATE_DIM) {
439 ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt);
441 _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno());
447 display_backlight_get_default_brightness(&result);
451 _I("get brightness %d, %d", brt, result);
454 return g_variant_new("(i)", result);
457 static GVariant *dbus_setbrightness(GDBusConnection *conn,
458 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
459 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
461 int state, brt, autobrt, ret = 0, caps;
464 caps = display_get_caps(DISPLAY_ACTOR_API);
466 if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) {
467 _D("No brightness changing capability!");
472 g_variant_get(param, "(ii)", &state, &brt);
474 //Check if brt is same with DIM
475 if (brt == DISPLAY_DIM_BRIGHTNESS) {
476 _E("application can not set this value(DIM VALUE:%d)", brt);
481 ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt);
483 _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno());
484 autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF;
487 if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
488 _E("auto_brightness state is ON, can not change the brightness value");
493 clear_pm_status_flag(DIM_MASK);
494 if (state == DISPLAY_STATE_NORMAL) {
495 if (disp_plgn->auto_brightness_control) {
496 ret = disp_plgn->auto_brightness_control(BR_SET_BRIGHTNESS, brt);
498 display_backlight_set_default_brightness(brt);
499 ret = display_backlight_set_brightness(brt);
502 ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt);
504 _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno());
506 } else if (state == DISPLAY_STATE_SCREEN_DIM) {
507 enum deviced_display_state current;
508 ret = display_state_get_current(¤t);
512 if (current == DEVICED_DISPLAY_STATE_DIM) {
513 ret = display_backlight_set_brightness(brt);
518 ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt);
520 _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno());
524 pid = gdbus_connection_get_sender_pid(conn, sender);
525 _I("Set brightness pid=%d brt=%d ret=%d", pid, brt, ret);
528 return g_variant_new("(i)", ret);
531 static GVariant *dbus_holdbrightness(GDBusConnection *conn,
532 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
533 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
535 int brt, autobrt, ret, caps;
538 caps = display_get_caps(DISPLAY_ACTOR_API);
540 if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) {
541 _D("No brightness changing capability!");
546 g_variant_get(param, "(i)", &brt);
548 if (brt == DISPLAY_DIM_BRIGHTNESS) {
549 _E("application can not set this value(DIM VALUE:%d)", brt);
554 ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt);
556 _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno());
557 autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF;
560 ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON);
562 _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno());
564 if (disp_plgn->auto_brightness_control)
565 ret = disp_plgn->auto_brightness_control(BR_HOLD_BRIGHTNESS, brt);
567 ret = display_backlight_set_brightness(brt);
572 if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
573 _D("Auto brightness will be paused");
574 ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE);
576 _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno());
579 pid = gdbus_connection_get_sender_pid(conn, sender);
580 _I("Hold brightness pid=%d brt=%d ret=%d", pid, brt, ret);
583 return g_variant_new("(i)", ret);
586 static GVariant *dbus_releasebrightness(GDBusConnection *conn,
587 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
588 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
590 int bat, charger, changed, setting, brt, autobrt, ret = 0;
593 pid = gdbus_connection_get_sender_pid(conn, sender);
594 _I("Release brightness pid=%d", pid);
596 ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat);
598 _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno());
603 ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger);
605 _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno());
610 ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed);
612 _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno());
617 ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting);
619 _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno());
624 ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt);
626 _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno());
631 ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF);
633 _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno());
635 ret = display_backlight_get_brightness(&brt);
640 if (!disp_plgn->auto_brightness_control && display_misc_is_low_battery_state(bat) &&
641 charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) {
642 _D("batt warning low : brightness is not changed!");
644 display_backlight_set_brightness(0);
648 if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
649 if (disp_plgn->auto_brightness_control) {
650 disp_plgn->auto_brightness_control(BR_RELEASE_BRIGHTNESS, BR_IMPLICIT);
653 display_backlight_set_brightness(setting);
655 } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) {
656 _D("Auto brightness will be enable");
657 ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON);
659 _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno());
663 return g_variant_new("(i)", ret);
666 static GVariant *dbus_setrefreshrate(GDBusConnection *conn,
667 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
668 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
670 int app, val, ret, control;
672 assert(g_display_plugin.config);
674 g_variant_get(param, "(ii)", &app, &val);
676 if (app < 0 || app >= ARRAY_SIZE(g_display_plugin.config->framerate_app) || val < 0) {
681 if (!g_display_plugin.config->framerate_app[app]) {
682 _I("This case(%d) is not support in this target", app);
687 control = g_display_plugin.config->control_display;
690 display_panel_set_panel_state_by_off_state(NORMAL_MODE);
692 _D("app : %d, value : %d", app, val);
693 ret = display_panel_set_frame_rate(val);
695 _E("Failed to set frame rate (%d)", ret);
698 display_panel_set_panel_state_by_on_state(NORMAL_MODE);
701 return g_variant_new("(i)", ret);
704 static GVariant *dbus_setautobrightnessmin(GDBusConnection *conn,
705 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
706 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
712 if (!g_display_plugin.set_autobrightness_min) {
716 g_variant_get(param, "(i)", &val);
718 pid = gdbus_connection_get_sender_pid(conn, sender);
719 if (pid == -1 || kill(pid, 0) == -1) {
720 _E("%d process does not exist, dbus ignored!", pid);
724 ret = g_display_plugin.set_autobrightness_min(val, (char *)sender);
726 _W("fail to set autobrightness min %d, %d by %d", val, ret, pid);
729 if (g_display_plugin.reset_autobrightness_min) {
730 id = gdbus_watch_name(sender, g_display_plugin.reset_autobrightness_min, NULL, NULL, NULL);
732 _E("failed to watch name %s, id %d", sender, id);
733 //todo: set return value
735 _I("set autobrightness min %d by %d", val, pid);
738 return g_variant_new("(i)", ret);
741 /* FIXME: these functions should be removed or refactored after discussion */
742 static int set_lcd_timeout(int on, int dim, const char *name)
744 unsigned int custom_normal_timeout = 0;
745 unsigned int custom_dim_timeout = 0;
747 enum deviced_display_state current;
749 if (on == 0 && dim == 0) {
750 _I("LCD timeout changed: default setting");
751 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_ON, 0);
752 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_DIM, 0);
753 } else if (on < 0 || dim < 0) {
754 _E("Failed to set value(on=%d dim=%d).", on, dim);
757 _I("LCD timeout changed: on=%ds dim=%ds", on, dim);
758 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_ON, SEC_TO_MSEC(on));
759 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_DIM, SEC_TO_MSEC(dim));
762 ret = display_state_get_current(¤t);
766 /* Apply new backlight time */
767 display_state_transition_update_display_state_timeout_by_priority();
768 if (current == DEVICED_DISPLAY_STATE_ON)
769 display_state_transition_do_state_transition(current, EVENT_INPUT);
771 if (custom_change_name) {
772 free(custom_change_name);
773 custom_change_name = 0;
776 display_state_transition_get_custom_timeout(DEVICED_DISPLAY_STATE_ON, &custom_normal_timeout);
777 display_state_transition_get_custom_timeout(DEVICED_DISPLAY_STATE_DIM, &custom_dim_timeout);
778 if (custom_normal_timeout == 0 && custom_dim_timeout == 0)
781 custom_change_name = strndup(name, strlen(name));
782 if (!custom_change_name) {
783 _E("Failed to malloc.");
784 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_ON, 0);
785 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_DIM, 0);
792 static void reset_lcd_timeout(GDBusConnection *conn,
794 const gchar *unique_name,
797 enum deviced_display_state current;
803 if (!custom_change_name)
806 if (strcmp(sender, custom_change_name))
809 _I("reset lcd timeout: Set default timeout. sender=%s", sender);
811 free(custom_change_name);
812 custom_change_name = 0;
813 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_ON, 0);
814 display_state_transition_set_custom_timeout(DEVICED_DISPLAY_STATE_DIM, 0);
816 ret = display_state_get_current(¤t);
820 display_state_transition_update_display_state_timeout_by_priority();
821 if (current == DEVICED_DISPLAY_STATE_ON)
822 display_state_transition_do_state_transition(current, EVENT_INPUT);
825 static GVariant *dbus_setlcdtimeout(GDBusConnection *conn,
826 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
827 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
829 int on, dim, dummy, ret; // dummy: holdkeyblock, unused
833 g_variant_get(param, "(iii)", &on, &dim, &dummy);
835 pid = gdbus_connection_get_sender_pid(conn, sender);
836 if (pid == -1 || kill(pid, 0) == -1) {
837 _E("%d process does not exist, dbus ignored!", pid);
842 ret = set_lcd_timeout(on, dim, sender);
844 _W("fail to set lcd timeout %d by %d", ret, pid);
846 id = gdbus_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL);
848 _E("failed to watch name %s, id %d", sender, id);
849 //todo: set return value
851 _I("set lcd timeout on %d, dim %d, by %d",
856 return g_variant_new("(i)", ret);
859 static GVariant *dbus_lockscreenbgon(GDBusConnection *conn,
860 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
861 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
866 g_variant_get(param, "(s)", &on);
868 if (!strcmp(on, "true"))
869 display_setting_update_pm_setting(SETTING_LOCK_SCREEN_BG, true);
870 else if (!strcmp(on, "false"))
871 display_setting_update_pm_setting(SETTING_LOCK_SCREEN_BG, false);
876 return g_variant_new("(i)", ret);
879 static GVariant *dbus_dumpmode(GDBusConnection *conn,
880 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
881 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
886 g_variant_get(param, "(s)", &on);
888 if (!strcmp(on, "on")) {
890 display_lock_request_lock_with_option(DEVICED_EVENT_MISC_DUMPMODE, LCD_OFF,
891 STAY_CUR_STATE, DUMP_MODE_WATING_TIME);
892 display_backlight_unset_blink();
893 } else if (!strcmp(on, "off")) {
894 display_lock_request_unlock_with_option(DEVICED_EVENT_MISC_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN);
895 display_backlight_set_blink(0);
896 } else if (!strcmp(on, "blink")) {
897 display_backlight_set_blink(500);
903 return g_variant_new("(i)", ret);
906 static GVariant *dbus_savelog(GDBusConnection *conn,
907 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
908 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
911 return gdbus_new_g_variant_tuple();
914 static GVariant *dbus_powerkeyignore(GDBusConnection *conn,
915 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
916 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
918 return g_variant_new("(i)", 0);
921 static GVariant *dbus_powerkeylcdoff(GDBusConnection *conn,
922 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
923 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
925 return g_variant_new("(i)", -ENOSYS);
928 static GVariant *dbus_customlcdon(GDBusConnection *conn,
929 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
930 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
933 int timeout, lcdon_blocked;
936 pid = gdbus_connection_get_sender_pid(conn, sender);
937 _I("Change state to DEVICED_DISPLAY_STATE_ON pid=%d", pid);
939 g_variant_get(param, "(i)", &timeout);
941 lcdon_blocked = display_plugin_is_lcd_on_blocked();
942 if (lcdon_blocked != LCDON_BLOCK_NONE) {
943 _W("LCDON is blocked, %d.", lcdon_blocked);
944 return g_variant_new("(i)", -ENOTSUP);
947 ret = display_panel_custom_lcd_on(timeout);
949 return g_variant_new("(i)", ret);
952 static GVariant *dbus_customlcdoff(GDBusConnection *conn,
953 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
954 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
957 enum device_flags flag;
958 char *reason_str = NULL;
961 pid = gdbus_connection_get_sender_pid(conn, sender);
962 _I("Change state to DEVICED_DISPLAY_STATE_OFF pid=%d", pid);
964 g_variant_get(param, "(s)", &reason_str);
966 if (!strcmp(reason_str, LCDOFF_PROXI_STR))
967 flag = LCD_OFF_BY_PROXIMITY;
968 else if (!strcmp(reason_str, LCDOFF_GESTURE_STR))
969 flag = LCD_OFF_BY_GESTURE;
971 _E("%s resean is invalid, dbus ignored!", reason_str);
976 ret = display_panel_custom_lcd_off(flag);
981 return g_variant_new("(i)", ret);
984 static GVariant *dbus_changestatebyreason(GDBusConnection *conn,
985 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
986 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
989 int next_state, timeout;
990 char *reason = NULL, *state = NULL;
993 g_variant_get(param, "(isi)", &next_state, &reason, &timeout);
995 if (next_state == DISPLAY_STATE_NORMAL) {
996 state = "DEVICED_DISPLAY_STATE_ON";
997 ret = display_panel_display_turn_on_by_reason(reason, timeout);
998 } else if (next_state == DISPLAY_STATE_SCREEN_OFF) {
999 state = "DEVICED_DISPLAY_STATE_OFF";
1000 ret = display_panel_display_turn_off_by_reason(reason);
1001 } else if (next_state == DISPLAY_STATE_SCREEN_DIM) {
1002 state = "DEVICED_DISPLAY_STATE_DIM";
1009 pid = gdbus_connection_get_sender_pid(conn, sender);
1010 _I("Change state pid=%d state=%s reason=%s ret=%d", pid, state, reason, ret);
1013 return g_variant_new("(i)", ret);
1016 static GVariant *dbus_staytouchscreenoff(GDBusConnection *conn,
1017 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1018 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1024 pid = gdbus_connection_get_sender_pid(conn, sender);
1025 _I("Stay touchscreen off pid=%d", pid);
1027 g_variant_get(param, "(i)", &val);
1029 display_misc_set_stay_touchscreen_off((bool)val);
1031 return g_variant_new("(i)", ret);
1034 static GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn,
1035 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1036 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1042 pid = gdbus_connection_get_sender_pid(conn, sender);
1043 _I("Set lcd panel off mode pid=%d", pid);
1045 g_variant_get(param, "(i)", &val);
1047 display_panel_set_lcd_paneloff_mode((bool)val);
1049 return g_variant_new("(i)", ret);
1052 static GVariant *dbus_actorcontrol(GDBusConnection *conn,
1053 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1054 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1056 int ret = 0, val, actor;
1059 g_variant_get(param, "(sii)", &op, &actor, &val);
1061 if (!strcmp(op, "set"))
1062 ret = display_set_caps(actor, val);
1063 else if (!strcmp(op, "reset"))
1064 ret = display_reset_caps(actor, val);
1069 return g_variant_new("(i)", ret);
1072 static GVariant *dbus_getcustombrightness(GDBusConnection *conn,
1073 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1074 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1079 display_backlight_get_custom_status(&custom_status);
1080 status = custom_status;
1082 return g_variant_new("(i)", status);
1085 struct pmlock_expired_s {
1087 GDBusMethodInvocation *invocation;
1092 static GList *expired_req_list;
1094 static GVariant *dbus_locktimeout_expired(GDBusConnection *conn,
1095 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1096 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1102 char comm[NAME_MAX];
1103 struct pmlock_expired_s *ex = NULL;
1104 GVariant *gvar = NULL;
1106 g_variant_get(param, "(s)", &req_id);
1108 pid = gdbus_connection_get_sender_pid(conn, sender);
1109 if (pid == -1 || kill(pid, 0) == -1) {
1110 _E("%d process does not exist, dbus ignored!", pid);
1115 ret = syscommon_proc_get_comm(pid, comm, sizeof(comm));
1117 _E("Failed to get command (%d)", ret);
1121 ex = calloc(1, sizeof(struct pmlock_expired_s));
1123 _E("calloc() failed");
1128 snprintf(pid_str, sizeof(pid_str), "%d", pid);
1129 ret = launch_system_app(APP_DEFAULT, 8,
1131 EXPIRED_POPUP_TYPE_POWER,
1139 _E("Failed to launch pmlock expired popup(%d)", ret);
1144 snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id);
1146 ex->invocation = invocation;
1148 SYS_G_LIST_APPEND(expired_req_list, ex);
1154 gvar = g_variant_new("(i)", ret);
1161 static gboolean app_term(gpointer data)
1163 struct pmlock_expired_s *ex = data;
1166 if (ex->pid > 0 && kill(ex->pid, 0) != -1) {
1167 if (kill(ex->pid, SIGKILL) == -1)
1168 _E("failed to kill pid(%d), err(%m)", ex->pid);
1172 return G_SOURCE_REMOVE;
1175 static gboolean expired_deliver_result(gpointer data)
1177 struct pmlock_expired_s *ex = data;
1178 struct pmlock_expired_s *item = NULL;
1185 return G_SOURCE_REMOVE;
1187 len = strlen(ex->req_id) + 1;
1188 SYS_G_LIST_FOREACH(expired_req_list, l, item) {
1189 if (!strncmp(item->req_id, ex->req_id, len)) {
1190 SYS_G_LIST_REMOVE(expired_req_list, item);
1200 _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" :
1201 (value == 2) ? "KILL app" : "Release power lock");
1203 if (!item->invocation) {
1204 _E("item->invocation is null");
1207 g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0));
1210 if (item->pid > 0 && kill(item->pid, SIGTERM) == -1)
1211 _E("failed to kill pid(%d), err(%m)", item->pid);
1212 g_timeout_add(3000, app_term, (gpointer)item);
1220 return G_SOURCE_REMOVE;
1223 static GVariant *dbus_locktimeout_input(GDBusConnection *conn,
1224 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1225 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1229 struct pmlock_expired_s *ex;
1232 g_variant_get(param, "(si)", &req_id, &value);
1234 ex = calloc(1, sizeof(struct pmlock_expired_s));
1236 _E("calloc() failed");
1241 snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id);
1244 _I("req_id(%s), value(%d)", ex->req_id, ex->value);
1246 g_idle_add(expired_deliver_result, (gpointer)ex);
1252 return g_variant_new("(i)", ret);
1255 static GVariant *dbus_dimstay_control(GDBusConnection *conn,
1256 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1257 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1259 int dimstay, ret = 0;
1260 enum deviced_display_state current;
1263 g_variant_get(param, "(i)", &dimstay);
1266 _E("Invalid dimstay set value %d.", dimstay);
1271 pid = gdbus_connection_get_sender_pid(conn, sender);
1273 _I("Set DIM_FLAG pid=%d", pid);
1274 set_pm_status_flag(DIM_FLAG);
1276 _I("Unset DIM_FLAG pid=%d", pid);
1277 clear_pm_status_flag(DIM_FLAG);
1280 ret = display_state_get_current(¤t);
1284 if (current == DEVICED_DISPLAY_STATE_ON)
1285 display_backlight_update_by_default_brightness();
1288 return g_variant_new("(i)", ret);
1291 static GVariant *dbus_getbrightnessinfo(GDBusConnection *conn,
1292 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1293 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1295 int default_brightness;
1296 int current_brightness;
1298 display_backlight_get_default_brightness(&default_brightness);
1299 display_backlight_get_brightness(¤t_brightness);
1301 return g_variant_new("(ii)", default_brightness, current_brightness);
1304 static GVariant *dbus_setwhitebalance(GDBusConnection *conn,
1305 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1306 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1308 int white_balance_type, value;
1309 int ret = 0, ret_val;
1312 g_variant_get(param, "(ii)", &white_balance_type, &value);
1314 ret_val = display_panel_set_white_balance(white_balance_type, value);
1316 _E("Failed to set white balance");
1320 pid = gdbus_connection_get_sender_pid(conn, sender);
1321 _I("Set white balance pid=%d white balance type=%d value=%d", pid, white_balance_type, value);
1323 return g_variant_new("(i)", ret);
1326 static GVariant *dbus_getwhitebalance(GDBusConnection *conn,
1327 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1328 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1330 int white_balance_type;
1331 int ret = 0, ret_val;
1334 g_variant_get(param, "(i)", &white_balance_type);
1336 ret = display_panel_get_white_balance(white_balance_type, &ret_val);
1338 _E("Failed to get white balance");
1344 pid = gdbus_connection_get_sender_pid(conn, sender);
1345 _I("Get white balance pid=%d white balance type=%d", pid, white_balance_type);
1347 return g_variant_new("(i)", ret);
1350 static GVariant *dbus_getrotationangle(GDBusConnection *conn,
1351 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1352 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1356 enum hal_device_display_rotation_angle angle;
1357 enum display_init_direction_e init_direction;
1359 g_variant_get(param, "(i)", &display_index);
1360 ret = hal_device_display_get_rotation_angle(display_index, &angle);
1362 angle = HAL_DEVICE_DISPLAY_ROTATION_ANGLE_UNKNOWN;
1364 init_direction = get_display_init_direction();
1366 return g_variant_new("(iii)", ret, angle, init_direction);
1369 static GVariant *dbus_setrotationangle(GDBusConnection *conn,
1370 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1371 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1375 enum hal_device_display_rotation_angle angle;
1376 enum hal_device_display_rotation_direction direction;
1378 g_variant_get(param, "(iii)", &display_index, &angle, &direction);
1379 ret = hal_device_display_set_rotation_angle(display_index, angle, direction);
1381 return g_variant_new("(i)", ret);
1384 static GVariant *dbus_pmlockgetlockstate(GDBusConnection *conn,
1385 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
1386 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
1388 power_lock_e power_lock_type;
1389 bool pmlock_state = false;
1390 enum deviced_display_state pmlock_type;
1393 g_variant_get(param, "(i)", &power_lock_type);
1395 if (power_lock_type < POWER_LOCK_CPU || power_lock_type > POWER_LOCK_DISPLAY_DIM)
1396 _W("Invalid parameter power lock type=(%d)", power_lock_type);
1398 pmlock_type = power_lock_type_to_pmlock(power_lock_type);
1400 pmlock_state = display_lock_is_state_locked(pmlock_type);
1402 pid = gdbus_connection_get_sender_pid(conn, sender);
1403 _D("Pmlock get lock state pid=%d power lock state=%d", pid, pmlock_state);
1405 return g_variant_new("(i)", (int)pmlock_state);
1408 static const dbus_method_s dbus_methods[] = {
1409 { "start", NULL, NULL, dbus_start },
1410 { "stop", NULL, NULL, dbus_stop },
1411 { "lockstate", "sssi", "i", dbus_lockstate },
1412 { "unlockstate", "ss", "i", dbus_unlockstate },
1413 { "changestate", "s", "i", dbus_changestate },
1414 { "ChangeState", "s", "i", dbus_changestate },
1415 { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */
1416 { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */
1417 { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */
1418 { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin },
1419 { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout },
1420 { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon },
1421 { "GetDisplayCount", NULL, "i", dbus_getdisplaycount },
1422 { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness },
1423 { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness },
1424 { "GetBrightness", "i", "i", dbus_getbrightness },
1425 { "SetBrightness", "ii", "i", dbus_setbrightness },
1426 { "HoldBrightness", "i", "i", dbus_holdbrightness },
1427 { "ReleaseBrightness", NULL, "i", dbus_releasebrightness },
1428 { "SetRefreshRate", "ii", "i", dbus_setrefreshrate },
1429 { "Dumpmode", "s", "i", dbus_dumpmode },
1430 { "SaveLog", NULL, NULL, dbus_savelog },
1431 { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore },
1432 { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff },
1433 { "CustomLCDOn", "i", "i", dbus_customlcdon },
1434 { "CustomLCDOff", "s", "i", dbus_customlcdoff },
1435 { "ChangeStateByReason", "isi", "i", dbus_changestatebyreason },
1436 { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff },
1437 { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode },
1438 { "ActorControl", "sii", "i", dbus_actorcontrol },
1439 { "CustomBrightness", NULL, "i", dbus_getcustombrightness },
1440 { "CurrentBrightness", "i", "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */
1441 { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired },
1442 { "LockTimeoutInput", "si", "i", dbus_locktimeout_input },
1443 { "DimStayControl", "i", "i", dbus_dimstay_control },
1444 { "GetBrightnessInfo", NULL, "ii", dbus_getbrightnessinfo},
1445 { "SetWhiteBalance", "ii", "i", dbus_setwhitebalance},
1446 { "GetWhiteBalance", "i", "i", dbus_getwhitebalance},
1447 { "GetRotationAngle", "i", "iii", dbus_getrotationangle},
1448 { "SetRotationAngle", "iii", "i", dbus_setrotationangle},
1449 { "PmlockGetLockState", "i", "i", dbus_pmlockgetlockstate},
1450 /* Add methods here */
1453 static const dbus_interface_u dbus_interface = {
1455 .name = DEVICED_INTERFACE_DISPLAY,
1456 .methods = dbus_methods,
1457 .nr_methods = ARRAY_SIZE(dbus_methods),
1460 static void changestate_signal_handler(GDBusConnection *conn,
1461 const gchar *sender,
1472 if (!g_variant_get_safe(param, "(issss)", &val, NULL, NULL, &state, NULL)) {
1473 _E("failed to get params from gvariant. expected:%s, type:%s", "(issss)", g_variant_get_type_string(param));
1477 if (state == NULL) {
1478 _E("state is null.");
1483 if (!strcmp(state, "bg")) {
1484 _D("process(%d) was going background.", pid);
1485 set_app_state(pid, APPLICATION_BACKGROUND);
1486 syscommon_notifier_emit_notify(DEVICED_NOTIFIER_APPLICATION_BACKGROUND, &pid);
1487 } else if (!strcmp(state, "fg")) {
1488 _D("process(%d) was going foreground.", pid);
1489 set_app_state(pid, APPLICATION_FOREGROUND);
1490 syscommon_notifier_emit_notify(DEVICED_NOTIFIER_APPLICATION_FOREGROUND, &pid);
1498 static void app_terminate_signal_handler(GDBusConnection *conn,
1499 const gchar *sender,
1508 if (!g_variant_get_safe(param, "(i)", &pid)) {
1509 _E("failed to get params from gvariant. expected:%s, type:%s", "(i)", g_variant_get_type_string(param));
1513 set_app_state(pid, APPLICATION_TERMINATED);
1514 syscommon_notifier_emit_notify(DEVICED_NOTIFIER_APPLICATION_TERMINATED, &pid);
1518 * Default capability
1519 * api := LCDON | LCDOFF | BRIGHTNESS
1522 static struct display_actor_ops display_api_actor = {
1523 .id = DISPLAY_ACTOR_API,
1524 .caps = DISPLAY_CAPA_LCDON |
1525 DISPLAY_CAPA_LCDOFF |
1526 DISPLAY_CAPA_BRIGHTNESS,
1529 static struct display_actor_ops display_gesture_actor = {
1530 .id = DISPLAY_ACTOR_GESTURE,
1531 .caps = DISPLAY_CAPA_LCDON,
1534 int init_pm_dbus(void)
1538 display_add_actor(&display_api_actor);
1539 display_add_actor(&display_gesture_actor);
1541 ret = gdbus_add_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface);
1543 _E("fail to init dbus method(%d)", ret);
1546 ret = gdbus_signal_subscribe(NULL,
1548 AUL_APPSTATUS_INTERFACE,
1550 changestate_signal_handler,
1553 _E("Failed to register signal handler: %d", ret);
1555 ret = gdbus_signal_subscribe(NULL,
1557 AUL_APPSTATUS_INTERFACE,
1559 app_terminate_signal_handler,
1562 _E("Failed to register signal handler: %d", ret);
1567 static void __CONSTRUCTOR__ initialize(void)
1569 disp_plgn = get_var_display_plugin();
1571 _E("Failed to get display plugin variable.");