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 <device-node.h>
35 #include "core/common.h"
36 #include "core/devices.h"
37 #include "dd-display.h"
38 #include "display-actor.h"
40 #define TELEPHONY_PATH "/org/tizen/telephony/SAMSUNG_QMI"
41 #define TELEPHONY_INTERFACE_SIM "org.tizen.telephony.Sim"
42 #define SIGNAL_SIM_STATUS "Status"
43 #define SIM_CARD_NOT_PRESENT (0x01)
45 #define VCONFKEY_LCD_BRIGHTNESS_INIT "db/private/deviced/lcd_brightness_init"
47 #define SIGNAL_HOMESCREEN "HomeScreen"
48 #define SIGNAL_EXTREME "Extreme"
49 #define SIGNAL_NOTEXTREME "NotExtreme"
51 #define BLIND_MASK(val) ((val) & 0xFFFF)
52 #define BLIND_RED(val) BLIND_MASK((val) >> 32)
53 #define BLIND_GREEN(val) BLIND_MASK((val) >> 16)
54 #define BLIND_BLUE(val) BLIND_MASK((val))
56 #define DISPLAY_DIM_BRIGHTNESS 0
57 #define DUMP_MODE_WATING_TIME 600000
59 static DBusMessage *edbus_start(E_DBus_Object *obj, DBusMessage *msg)
61 static const struct device_ops *display_device_ops = NULL;
63 if (!display_device_ops)
64 display_device_ops = find_device("display");
65 if (NOT_SUPPORT_OPS(display_device_ops))
66 return dbus_message_new_method_return(msg);
68 display_device_ops->start(CORE_LOGIC_MODE);
69 return dbus_message_new_method_return(msg);
72 static DBusMessage *edbus_stop(E_DBus_Object *obj, DBusMessage *msg)
74 static const struct device_ops *display_device_ops = NULL;
76 if (!display_device_ops)
77 display_device_ops = find_device("display");
78 if (NOT_SUPPORT_OPS(display_device_ops))
79 return dbus_message_new_method_return(msg);
81 display_device_ops->stop(CORE_LOGIC_MODE);
82 return dbus_message_new_method_return(msg);
85 static DBusMessage *edbus_lockstate(E_DBus_Object *obj, DBusMessage *msg)
100 dbus_error_init(&err);
102 if (!dbus_message_get_args(msg, &err,
103 DBUS_TYPE_STRING, &state_str,
104 DBUS_TYPE_STRING, &option1_str,
105 DBUS_TYPE_STRING, &option2_str,
106 DBUS_TYPE_INT32, &timeout, DBUS_TYPE_INVALID)) {
107 _E("there is no message");
112 if (!state_str || timeout < 0) {
113 _E("message is invalid!");
118 pid = get_edbus_sender_pid(msg);
119 if (kill(pid, 0) == -1) {
120 _E("%d process does not exist, dbus ignored!", pid);
125 if (!strcmp(state_str, PM_LCDON_STR))
127 else if (!strcmp(state_str, PM_LCDDIM_STR))
129 else if (!strcmp(state_str, PM_LCDOFF_STR))
132 _E("%s state is invalid, dbus ignored!", state_str);
137 if (!strcmp(option1_str, STAYCURSTATE_STR))
138 flag = STAY_CUR_STATE;
139 else if (!strcmp(option1_str, GOTOSTATENOW_STR))
140 flag = GOTO_STATE_NOW;
142 _E("%s option is invalid. set default option!", option1_str);
143 flag = STAY_CUR_STATE;
146 if (!strcmp(option2_str, HOLDKEYBLOCK_STR))
147 flag |= HOLD_KEY_BLOCK;
148 else if (!strcmp(option2_str, STANDBYMODE_STR))
149 flag |= STANDBY_MODE;
151 if (flag & GOTO_STATE_NOW) {
152 caps = display_get_caps(DISPLAY_ACTOR_API);
154 if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) &&
155 state == LCD_NORMAL) {
156 _D("No lcdon capability!");
160 if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) &&
162 _D("No lcdoff capability!");
168 if (check_dimstay(state, flag) == true) {
169 _E("LCD state can not be changed to OFF state now!");
170 flag &= ~GOTO_STATE_NOW;
171 flag |= STAY_CUR_STATE;
174 ret = pm_lock_internal(pid, state, flag, timeout);
176 reply = dbus_message_new_method_return(msg);
177 dbus_message_iter_init_append(reply, &iter);
178 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
183 static DBusMessage *edbus_unlockstate(E_DBus_Object *obj, DBusMessage *msg)
186 DBusMessageIter iter;
195 dbus_error_init(&err);
197 if (!dbus_message_get_args(msg, &err,
198 DBUS_TYPE_STRING, &state_str,
199 DBUS_TYPE_STRING, &option_str, DBUS_TYPE_INVALID)) {
200 _E("there is no message");
206 _E("message is invalid!");
211 pid = get_edbus_sender_pid(msg);
212 if (kill(pid, 0) == -1) {
213 _E("%d process does not exist, dbus ignored!", pid);
218 if (!strcmp(state_str, PM_LCDON_STR))
220 else if (!strcmp(state_str, PM_LCDDIM_STR))
222 else if (!strcmp(state_str, PM_LCDOFF_STR))
225 _E("%s state is invalid, dbus ignored!", state_str);
230 if (!strcmp(option_str, SLEEP_MARGIN_STR))
231 flag = PM_SLEEP_MARGIN;
232 else if (!strcmp(option_str, RESET_TIMER_STR))
233 flag = PM_RESET_TIMER;
234 else if (!strcmp(option_str, KEEP_TIMER_STR))
235 flag = PM_KEEP_TIMER;
237 _E("%s option is invalid. set default option!", option_str);
238 flag = PM_RESET_TIMER;
241 ret = pm_unlock_internal(pid, state, flag);
243 reply = dbus_message_new_method_return(msg);
244 dbus_message_iter_init_append(reply, &iter);
245 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
250 static DBusMessage *edbus_changestate(E_DBus_Object *obj, DBusMessage *msg)
253 DBusMessageIter iter;
261 dbus_error_init(&err);
263 if (!dbus_message_get_args(msg, &err,
264 DBUS_TYPE_STRING, &state_str, DBUS_TYPE_INVALID)) {
265 _E("there is no message");
271 _E("message is invalid!");
276 pid = get_edbus_sender_pid(msg);
277 if (kill(pid, 0) == -1) {
278 _E("%d process does not exist, dbus ignored!", pid);
283 if (!strcmp(state_str, PM_LCDON_STR))
285 else if (!strcmp(state_str, PM_LCDDIM_STR))
287 else if (!strcmp(state_str, PM_LCDOFF_STR))
289 else if (!strcmp(state_str, PM_SUSPEND_STR))
292 _E("%s state is invalid, dbus ignored!", state_str);
297 caps = display_get_caps(DISPLAY_ACTOR_API);
299 if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) &&
300 state == LCD_NORMAL) {
301 _D("No lcdon capability!");
305 if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) &&
307 _D("No lcdoff capability!");
312 if (check_dimstay(state, GOTO_STATE_NOW) == true) {
313 _E("LCD state can not be changed to OFF state!");
318 ret = pm_change_internal(pid, state);
320 if (!ret && state == LCD_OFF)
321 update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
323 reply = dbus_message_new_method_return(msg);
324 dbus_message_iter_init_append(reply, &iter);
325 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
330 static DBusMessage *edbus_getdisplaycount(E_DBus_Object *obj, DBusMessage *msg)
332 DBusMessageIter iter;
336 cmd = DISP_CMD(PROP_DISPLAY_DISPLAY_COUNT, DEFAULT_DISPLAY);
337 ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &cnt);
341 reply = dbus_message_new_method_return(msg);
342 dbus_message_iter_init_append(reply, &iter);
343 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
347 static DBusMessage *edbus_getmaxbrightness(E_DBus_Object *obj, DBusMessage *msg)
349 DBusMessageIter iter;
353 cmd = DISP_CMD(PROP_DISPLAY_MAX_BRIGHTNESS, DEFAULT_DISPLAY);
354 ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt);
358 reply = dbus_message_new_method_return(msg);
359 dbus_message_iter_init_append(reply, &iter);
360 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
364 static DBusMessage *edbus_setmaxbrightness(E_DBus_Object *obj, DBusMessage *msg)
366 DBusMessageIter iter;
370 dbus_message_iter_init(msg, &iter);
371 dbus_message_iter_get_basic(&iter, &brt);
373 cmd = DISP_CMD(PROP_DISPLAY_MAX_BRIGHTNESS, DEFAULT_DISPLAY);
374 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt);
376 reply = dbus_message_new_method_return(msg);
377 dbus_message_iter_init_append(reply, &iter);
378 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
382 static DBusMessage *edbus_getbrightness(E_DBus_Object *obj, DBusMessage *msg)
384 DBusMessageIter iter;
388 cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
389 ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt);
393 _I("get brightness %d, %d", brt, ret);
395 reply = dbus_message_new_method_return(msg);
396 dbus_message_iter_init_append(reply, &iter);
397 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &brt);
401 static DBusMessage *edbus_setbrightness(E_DBus_Object *obj, DBusMessage *msg)
403 DBusMessageIter iter;
405 int cmd, brt, powersaver, autobrt, ret, caps;
407 caps = display_get_caps(DISPLAY_ACTOR_API);
409 if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) {
410 _D("No brightness changing capability!");
415 dbus_message_iter_init(msg, &iter);
416 dbus_message_iter_get_basic(&iter, &brt);
418 if (brt == DISPLAY_DIM_BRIGHTNESS) {
419 _E("application can not set this value(DIM VALUE:%d)", brt);
424 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &powersaver) != 0) {
425 _E("Failed to get VCONFKEY_SETAPPL_PSMODE value");
426 powersaver = SETTING_PSMODE_NORMAL;
429 if (powersaver == SETTING_PSMODE_WEARABLE) {
430 _D("brightness is changed in powersaver mode!");
431 backlight_ops.set_force_brightness(0);
434 if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt) != 0) {
435 _E("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
436 autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF;
439 if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
440 _D("auto_brightness state is ON, can not change the brightness value");
445 cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
446 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt);
449 if (vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt) != 0)
450 _E("Failed to set VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
452 if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, brt) != 0)
453 _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
455 _I("set brightness %d, %d", brt, ret);
458 reply = dbus_message_new_method_return(msg);
459 dbus_message_iter_init_append(reply, &iter);
460 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
464 static DBusMessage *edbus_holdbrightness(E_DBus_Object *obj, DBusMessage *msg)
466 DBusMessageIter iter;
468 int cmd, brt, powersaver, autobrt, ret, caps;
470 caps = display_get_caps(DISPLAY_ACTOR_API);
472 if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) {
473 _D("No brightness changing capability!");
478 dbus_message_iter_init(msg, &iter);
479 dbus_message_iter_get_basic(&iter, &brt);
481 if (brt == DISPLAY_DIM_BRIGHTNESS) {
482 _E("application can not set this value(DIM VALUE:%d)", brt);
487 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &powersaver) != 0) {
488 _E("Failed to get VCONFKEY_SETAPPL_PSMODE value");
489 powersaver = SETTING_PSMODE_NORMAL;
492 if (powersaver == SETTING_PSMODE_WEARABLE) {
493 _D("Powersaver mode! brightness can not be changed!");
498 if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt) != 0) {
499 _E("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
500 autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF;
503 vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON);
505 cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
506 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt);
510 if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
511 _D("Auto brightness will be paused");
512 vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE);
515 if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, brt) != 0)
516 _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
518 _I("hold brightness %d, %d", brt, ret);
521 reply = dbus_message_new_method_return(msg);
522 dbus_message_iter_init_append(reply, &iter);
523 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
528 static DBusMessage *edbus_releasebrightness(E_DBus_Object *obj, DBusMessage *msg)
530 DBusMessageIter iter;
532 int cmd, bat, charger, changed, setting, brt, autobrt, ret = 0;
534 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat) != 0) {
535 _E("Failed to get VCONFKEY_SYSMAN_BATTERY_STATUS_LOW value");
540 if (vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger) != 0) {
541 _E("Failed to get VCONFKEY_SYSMAN_CHARGER_STATUS value");
546 if (vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed) != 0) {
547 _E("Failed to get VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM value");
552 if (vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting) != 0) {
553 _E("Failed to get VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
558 if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt) != 0) {
559 _E("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
564 vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF);
566 cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
567 ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt);
572 if (low_battery_state(bat) &&
573 charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) {
574 _D("batt warning low : brightness is not changed!");
576 device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, 0);
581 if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
582 if (brt != setting) {
583 device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, setting);
584 if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, setting) != 0) {
585 _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
588 } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) {
589 _D("Auto brightness will be enable");
590 vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON);
594 reply = dbus_message_new_method_return(msg);
595 dbus_message_iter_init_append(reply, &iter);
596 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
600 static DBusMessage *edbus_getaclstatus(E_DBus_Object *obj, DBusMessage *msg)
602 DBusMessageIter iter;
606 cmd = DISP_CMD(PROP_DISPLAY_ACL_CONTROL, DEFAULT_DISPLAY);
607 ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &st);
611 _I("get acl status %d, %d", st, ret);
613 reply = dbus_message_new_method_return(msg);
614 dbus_message_iter_init_append(reply, &iter);
615 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
619 static DBusMessage *edbus_setaclstatus(E_DBus_Object *ob, DBusMessage *msg)
621 DBusMessageIter iter;
625 dbus_message_iter_init(msg, &iter);
626 dbus_message_iter_get_basic(&iter, &st);
628 cmd = DISP_CMD(PROP_DISPLAY_ACL_CONTROL, DEFAULT_DISPLAY);
629 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, st);
631 _I("set acl status %d, %d", st, ret);
633 reply = dbus_message_new_method_return(msg);
634 dbus_message_iter_init_append(reply, &iter);
635 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
639 static DBusMessage *edbus_getautotone(E_DBus_Object *obj, DBusMessage *msg)
641 DBusMessageIter iter;
645 cmd = DISP_CMD(PROP_DISPLAY_AUTO_SCREEN_TONE, DEFAULT_DISPLAY);
646 ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &tone);
650 _I("get auto screen tone %d, %d", tone, ret);
652 reply = dbus_message_new_method_return(msg);
653 dbus_message_iter_init_append(reply, &iter);
654 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
658 static DBusMessage *edbus_setautotone(E_DBus_Object *obj, DBusMessage *msg)
660 DBusMessageIter iter;
664 dbus_message_iter_init(msg, &iter);
665 dbus_message_iter_get_basic(&iter, &tone);
667 cmd = DISP_CMD(PROP_DISPLAY_AUTO_SCREEN_TONE, DEFAULT_DISPLAY);
668 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, tone);
670 _I("set auto screen tone %d, %d", tone, ret);
672 reply = dbus_message_new_method_return(msg);
673 dbus_message_iter_init_append(reply, &iter);
674 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
678 static DBusMessage *edbus_setautotoneforce(E_DBus_Object *obj, DBusMessage *msg)
680 DBusMessageIter iter;
684 dbus_message_iter_init(msg, &iter);
685 dbus_message_iter_get_basic(&iter, &tone);
687 cmd = DISP_CMD(PROP_DISPLAY_AUTO_SCREEN_TONE_FORCE, DEFAULT_DISPLAY);
688 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, tone);
690 _I("set auto screen tone force %d, %d", tone, ret);
692 reply = dbus_message_new_method_return(msg);
693 dbus_message_iter_init_append(reply, &iter);
694 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
698 static DBusMessage *edbus_setrefreshrate(E_DBus_Object *obj, DBusMessage *msg)
700 DBusMessageIter iter;
702 int app, val, cmd, ret, control;
704 ret = dbus_message_get_args(msg, NULL,
705 DBUS_TYPE_INT32, &app,
706 DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
708 _I("there is no message");
713 if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) {
718 if (!display_conf.framerate_app[app]) {
719 _I("This case(%d) is not support in this target", app);
724 control = display_conf.control_display;
727 backlight_ops.off(NORMAL_MODE);
729 _D("app : %d, value : %d", app, val);
730 cmd = DISP_CMD(PROP_DISPLAY_FRAME_RATE, DEFAULT_DISPLAY);
731 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, val);
734 backlight_ops.on(NORMAL_MODE);
737 reply = dbus_message_new_method_return(msg);
738 dbus_message_iter_init_append(reply, &iter);
739 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
743 static DBusMessage *edbus_getcolorblind(E_DBus_Object *obj, DBusMessage *msg)
745 DBusMessageIter iter;
749 cmd = DISP_CMD(PROP_DISPLAY_IMAGE_ENHANCE_COLOR_BLIND, DEFAULT_DISPLAY);
750 ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &val);
754 _I("get color blind %d", val);
756 reply = dbus_message_new_method_return(msg);
757 dbus_message_iter_init_append(reply, &iter);
758 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
762 static DBusMessage *edbus_setcolorblind(E_DBus_Object *obj, DBusMessage *msg)
764 DBusMessageIter iter;
768 uint64_t red, grn, blu;
769 struct color_blind_info info;
771 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &power,
772 DBUS_TYPE_UINT64, &red, DBUS_TYPE_UINT64, &grn,
773 DBUS_TYPE_UINT64, &blu, DBUS_TYPE_INVALID);
775 _I("there is no message");
781 info.RrCr = BLIND_RED(red);
782 info.RgCg = BLIND_GREEN(red);
783 info.RbCb = BLIND_BLUE(red);
784 info.GrMr = BLIND_RED(grn);
785 info.GgMg = BLIND_GREEN(grn);
786 info.GbMb = BLIND_BLUE(grn);
787 info.BrYr = BLIND_RED(blu);
788 info.BgYg = BLIND_GREEN(blu);
789 info.BbYb = BLIND_BLUE(blu);
791 cmd = DISP_CMD(PROP_DISPLAY_IMAGE_ENHANCE_COLOR_BLIND, DEFAULT_DISPLAY);
792 ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, (int)&info);
794 _I("set color blind %d, %hu, %hu, %hu, %hu, %hu, %hu, %hu, %hu, %hu, %d",
795 info.power, info.RrCr, info.RgCg, info.RbCb, info.GrMr, info.GgMg,
796 info.GbMb, info.BrYr, info.BgYg, info.BbYb, ret);
799 reply = dbus_message_new_method_return(msg);
800 dbus_message_iter_init_append(reply, &iter);
801 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
805 static DBusMessage *edbus_gethbm(E_DBus_Object *obj, DBusMessage *msg)
807 DBusMessageIter iter;
816 /* check weak function symbol */
817 if (!hbm_get_state) {
822 hbm = hbm_get_state();
825 _E("failed to get high brightness mode %d", hbm);
827 _D("get high brightness mode %d", hbm);
829 reply = dbus_message_new_method_return(msg);
830 dbus_message_iter_init_append(reply, &iter);
831 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &hbm);
835 static DBusMessage *edbus_sethbm(E_DBus_Object *obj, DBusMessage *msg)
837 DBusMessageIter iter;
846 if (!dbus_message_get_args(msg, NULL,
847 DBUS_TYPE_INT32, &hbm,
848 DBUS_TYPE_INVALID)) {
849 _E("there is no message");
854 /* check weak function symbol */
855 if (!hbm_set_state) {
860 ret = hbm_set_state(hbm);
863 _E("failed to set high brightness mode (%d,%d)", ret, hbm);
865 _I("set high brightness mode (%d,%d)", ret, hbm);
867 reply = dbus_message_new_method_return(msg);
868 dbus_message_iter_init_append(reply, &iter);
869 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
873 static DBusMessage *edbus_sethbm_timeout(E_DBus_Object *obj, DBusMessage *msg)
875 DBusMessageIter iter;
877 int hbm, timeout, ret;
884 if (!dbus_message_get_args(msg, NULL,
885 DBUS_TYPE_INT32, &hbm,
886 DBUS_TYPE_INT32, &timeout, DBUS_TYPE_INVALID)) {
887 _E("there is no message");
892 /* check weak function symbol */
893 if (!hbm_set_state_with_timeout) {
898 ret = hbm_set_state_with_timeout(hbm, timeout);
901 _E("failed to set high brightness mode (%d,%d,%d)",
904 _I("set high brightness mode (%d,%d,%d)",
907 reply = dbus_message_new_method_return(msg);
908 dbus_message_iter_init_append(reply, &iter);
909 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
913 static DBusMessage *edbus_setautobrightnessmin(E_DBus_Object *obj, DBusMessage *msg)
915 DBusMessageIter iter;
921 sender = dbus_message_get_sender(msg);
923 _E("invalid sender name!");
927 if (!display_info.set_autobrightness_min) {
931 dbus_message_iter_init(msg, &iter);
932 dbus_message_iter_get_basic(&iter, &val);
934 pid = get_edbus_sender_pid(msg);
935 ret = display_info.set_autobrightness_min(val, (char *)sender);
937 _W("fail to set autobrightness min %d, %d by %d", val, ret, pid);
940 if (display_info.reset_autobrightness_min) {
941 register_edbus_watch(msg, WATCH_DISPLAY_AUTOBRIGHTNESS_MIN,
942 display_info.reset_autobrightness_min);
943 _I("set autobrightness min %d by %d", val, pid);
946 reply = dbus_message_new_method_return(msg);
947 dbus_message_iter_init_append(reply, &iter);
948 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
953 static DBusMessage *edbus_setlcdtimeout(E_DBus_Object *obj, DBusMessage *msg)
955 DBusMessageIter iter;
957 int on, dim, holdkey_block, ret;
961 sender = dbus_message_get_sender(msg);
963 _E("invalid sender name!");
968 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &on,
969 DBUS_TYPE_INT32, &dim, DBUS_TYPE_INT32, &holdkey_block,
972 pid = get_edbus_sender_pid(msg);
973 ret = set_lcd_timeout(on, dim, holdkey_block, sender);
975 _W("fail to set lcd timeout %d by %d", ret, pid);
977 register_edbus_watch(msg, WATCH_DISPLAY_LCD_TIMEOUT,
979 _I("set lcd timeout on %d, dim %d, holdblock %d by %d",
980 on, dim, holdkey_block, pid);
983 reply = dbus_message_new_method_return(msg);
984 dbus_message_iter_init_append(reply, &iter);
985 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
990 static DBusMessage *edbus_lockscreenbgon(E_DBus_Object *obj, DBusMessage *msg)
992 DBusMessageIter iter;
997 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &on,
1001 _E("fail to update lcdscreen bg on state %d", ret);
1006 if (!strcmp(on, "true"))
1007 update_pm_setting(SETTING_LOCK_SCREEN_BG, true);
1008 else if (!strcmp(on, "false"))
1009 update_pm_setting(SETTING_LOCK_SCREEN_BG, false);
1014 reply = dbus_message_new_method_return(msg);
1015 dbus_message_iter_init_append(reply, &iter);
1016 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1021 static DBusMessage *edbus_dumpmode(E_DBus_Object *obj, DBusMessage *msg)
1023 DBusMessageIter iter;
1028 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &on,
1032 _E("fail to get dumpmode state %d", ret);
1037 if (!strcmp(on, "on"))
1038 pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF,
1039 STAY_CUR_STATE, DUMP_MODE_WATING_TIME);
1040 else if (!strcmp(on, "off"))
1041 pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF,
1047 reply = dbus_message_new_method_return(msg);
1048 dbus_message_iter_init_append(reply, &iter);
1049 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1054 static DBusMessage *edbus_savelog(E_DBus_Object *obj, DBusMessage *msg)
1057 return dbus_message_new_method_return(msg);
1060 static DBusMessage *edbus_powerkeyignore(E_DBus_Object *obj, DBusMessage *msg)
1062 DBusMessageIter iter;
1067 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &on,
1071 _E("fail to get powerkey ignore %d", ret);
1076 if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore))
1077 keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false);
1079 reply = dbus_message_new_method_return(msg);
1080 dbus_message_iter_init_append(reply, &iter);
1081 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1086 static DBusMessage *edbus_powerkeylcdoff(E_DBus_Object *obj, DBusMessage *msg)
1088 DBusMessageIter iter;
1092 if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff))
1093 ret = keyfilter_ops->powerkey_lcdoff();
1097 reply = dbus_message_new_method_return(msg);
1098 dbus_message_iter_init_append(reply, &iter);
1099 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1104 static DBusMessage *edbus_customlcdon(E_DBus_Object *obj, DBusMessage *msg)
1106 DBusMessageIter iter;
1111 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &timeout,
1115 _E("fail to get custom lcd timeout %d", ret);
1120 ret = custom_lcdon(timeout);
1123 reply = dbus_message_new_method_return(msg);
1124 dbus_message_iter_init_append(reply, &iter);
1125 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1130 static DBusMessage *edbus_staytouchscreenoff(E_DBus_Object *obj, DBusMessage *msg)
1132 DBusMessageIter iter;
1137 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val,
1141 _E("fail to get stay touchscreen off state %d", ret);
1146 set_stay_touchscreen_off(val);
1148 reply = dbus_message_new_method_return(msg);
1149 dbus_message_iter_init_append(reply, &iter);
1150 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1155 static DBusMessage *edbus_lcdpaneloffmode(E_DBus_Object *obj, DBusMessage *msg)
1157 DBusMessageIter iter;
1162 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val,
1166 _E("fail to get lcd panel off mode %d", ret);
1171 set_lcd_paneloff_mode(val);
1173 reply = dbus_message_new_method_return(msg);
1174 dbus_message_iter_init_append(reply, &iter);
1175 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1180 static DBusMessage *edbus_actorcontrol(E_DBus_Object *obj, DBusMessage *msg)
1182 DBusMessageIter iter;
1184 int ret = 0, val, actor;
1187 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &op,
1188 DBUS_TYPE_INT32, &actor, DBUS_TYPE_INT32, &val,
1192 _E("fail to update actor control %d", ret);
1197 if (!strcmp(op, "set"))
1198 ret = display_set_caps(actor, val);
1199 else if (!strcmp(op, "reset"))
1200 ret = display_reset_caps(actor, val);
1205 reply = dbus_message_new_method_return(msg);
1206 dbus_message_iter_init_append(reply, &iter);
1207 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
1212 static const struct edbus_method edbus_methods[] = {
1213 { "start", NULL, NULL, edbus_start },
1214 { "stop", NULL, NULL, edbus_stop },
1215 { "lockstate", "sssi", "i", edbus_lockstate },
1216 { "unlockstate", "ss", "i", edbus_unlockstate },
1217 { "changestate", "s", "i", edbus_changestate },
1218 { "getbrightness", NULL, "i", edbus_getbrightness }, /* deprecated */
1219 { "setbrightness", "i", "i", edbus_setbrightness }, /* deprecated */
1220 { "getautotone", NULL, "i", edbus_getautotone }, /* deprecated */
1221 { "setautotone", "i", "i", edbus_setautotone }, /* deprecated */
1222 { "setframerate", "ii", "i", edbus_setrefreshrate }, /* deprecated */
1223 { "getcolorblind", NULL, "i", edbus_getcolorblind }, /* deprecated */
1224 { "setcolorblind", "uttt", "i", edbus_setcolorblind }, /* deprecated */
1225 { "setautobrightnessmin", "i", "i", edbus_setautobrightnessmin },
1226 { "setlcdtimeout", "iii", "i", edbus_setlcdtimeout },
1227 { "LockScreenBgOn", "s", "i", edbus_lockscreenbgon },
1228 { "GetDisplayCount", NULL, "i", edbus_getdisplaycount },
1229 { "GetMaxBrightness",NULL, "i", edbus_getmaxbrightness },
1230 { "SetMaxBrightness", "i", "i", edbus_setmaxbrightness },
1231 { "GetBrightness", NULL, "i", edbus_getbrightness },
1232 { "SetBrightness", "i", "i", edbus_setbrightness },
1233 { "HoldBrightness", "i", "i", edbus_holdbrightness },
1234 { "ReleaseBrightness", NULL, "i", edbus_releasebrightness },
1235 { "GetAclStatus", NULL, "i", edbus_getaclstatus },
1236 { "SetAclStatus", NULL, "i", edbus_setaclstatus },
1237 { "GetAutoTone", NULL, "i", edbus_getautotone },
1238 { "SetAutoTone", "i", "i", edbus_setautotone },
1239 { "SetAutoToneForce", "i", "i", edbus_setautotoneforce },
1240 { "SetRefreshRate", "ii", "i", edbus_setrefreshrate },
1241 { "GetColorBlind", NULL, "i", edbus_getcolorblind },
1242 { "SetColorBlind", "uttt", "i", edbus_setcolorblind },
1243 { "GetHBM", NULL, "i", edbus_gethbm },
1244 { "SetHBM", "i", "i", edbus_sethbm },
1245 { "SetHBMTimeout" ,"ii", "i", edbus_sethbm_timeout },
1246 { "Dumpmode", "s", "i", edbus_dumpmode },
1247 { "SaveLog", NULL, NULL, edbus_savelog },
1248 { "PowerKeyIgnore", "i", NULL, edbus_powerkeyignore },
1249 { "PowerKeyLCDOff", NULL, "i", edbus_powerkeylcdoff },
1250 { "CustomLCDOn", "i", "i", edbus_customlcdon },
1251 { "StayTouchScreenOff","i", "i", edbus_staytouchscreenoff },
1252 { "LCDPanelOffMode", "i", "i", edbus_lcdpaneloffmode },
1253 { "ActorControl", "sii", "i", edbus_actorcontrol },
1254 /* Add methods here */
1257 static void sim_signal_handler(void *data, DBusMessage *msg)
1261 static int state = false;
1263 if (!find_display_feature("auto-brightness")) {
1264 _D("auto brightness is not supported!");
1271 ret = dbus_message_is_signal(msg, TELEPHONY_INTERFACE_SIM,
1274 _E("there is no power off popup signal");
1278 ret = vconf_get_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, &state);
1279 if (ret < 0 || state)
1282 dbus_error_init(&err);
1284 ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val,
1287 _E("no message : [%s:%s]", err.name, err.message);
1288 dbus_error_free(&err);
1291 if (val != SIM_CARD_NOT_PRESENT) {
1292 /* change setting : autobrightness on */
1294 vconf_set_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, state);
1295 vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT,
1296 SETTING_BRIGHTNESS_AUTOMATIC_ON);
1297 vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
1298 PM_DEFAULT_BRIGHTNESS);
1299 _I("SIM card is inserted at first!");
1303 static void homescreen_signal_handler(void *data, DBusMessage *msg)
1310 ret = dbus_message_is_signal(msg, DEVICED_INTERFACE_NAME,
1313 _E("there is no homescreen signal");
1317 dbus_error_init(&err);
1319 ret = dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &screen,
1322 _E("no message : [%s:%s]", err.name, err.message);
1323 dbus_error_free(&err);
1326 _D("screen : %s", screen);
1328 if (set_alpm_screen) {
1329 pid = get_edbus_sender_pid(msg);
1330 set_alpm_screen(screen, pid);
1332 _E("alpm screen mode is not supported!");
1336 static void extreme_signal_handler(void *data, DBusMessage *msg)
1340 ret = dbus_message_is_signal(msg, POPUP_INTERFACE_LOWBAT,
1343 _E("there is no extreme signal");
1347 pm_status_flag &= ~BRTCH_FLAG;
1348 if (hbm_get_state != NULL && hbm_get_state() == true)
1349 hbm_set_state_with_timeout(false, 0);
1350 backlight_ops.update();
1351 _D("extreme mode : enter dim state!");
1352 if (vconf_set_int(VCONFKEY_PM_KEY_IGNORE, TRUE) != 0)
1353 _E("failed to set vconf status");
1356 static void not_extreme_signal_handler(void *data, DBusMessage *msg)
1360 ret = dbus_message_is_signal(msg, POPUP_INTERFACE_LOWBAT,
1363 _E("there is no extreme signal");
1367 _D("release extreme mode");
1368 if (vconf_set_int(VCONFKEY_PM_KEY_IGNORE, FALSE) != 0)
1369 _E("failed to set vconf status");
1373 * Default capability
1374 * api := LCDON | LCDOFF | BRIGHTNESS
1377 static struct display_actor_ops display_api_actor = {
1378 .id = DISPLAY_ACTOR_API,
1379 .caps = DISPLAY_CAPA_LCDON |
1380 DISPLAY_CAPA_LCDOFF |
1381 DISPLAY_CAPA_BRIGHTNESS,
1384 static struct display_actor_ops display_gesture_actor = {
1385 .id = DISPLAY_ACTOR_GESTURE,
1386 .caps = DISPLAY_CAPA_LCDON,
1389 int init_pm_dbus(void)
1393 display_add_actor(&display_api_actor);
1394 display_add_actor(&display_gesture_actor);
1396 ret = register_edbus_method(DEVICED_PATH_DISPLAY,
1397 edbus_methods, ARRAY_SIZE(edbus_methods));
1399 _E("Failed to register edbus method! %d", ret);
1403 * Auto-brightness feature has been implemented in wearable-device.
1404 * But UX is not determined, then Block sim-check-logic temporary.
1405 * This logic'll be re-enabled when UX concept related to sim is confirmed.
1408 ret = register_edbus_signal_handler(TELEPHONY_PATH,
1409 TELEPHONY_INTERFACE_SIM, SIGNAL_SIM_STATUS,
1410 sim_signal_handler);
1411 if (ret < 0 && ret != -EEXIST) {
1412 _E("Failed to register signal handler! %d", ret);
1416 ret = register_edbus_signal_handler(DEVICED_OBJECT_PATH,
1417 DEVICED_INTERFACE_NAME, SIGNAL_HOMESCREEN,
1418 homescreen_signal_handler);
1419 if (ret < 0 && ret != -EEXIST) {
1420 _E("Failed to register signal handler! %d", ret);
1424 ret = register_edbus_signal_handler(POPUP_PATH_LOWBAT,
1425 POPUP_INTERFACE_LOWBAT, SIGNAL_EXTREME,
1426 extreme_signal_handler);
1427 if (ret < 0 && ret != -EEXIST) {
1428 _E("Failed to register signal handler! %d", ret);
1431 ret = register_edbus_signal_handler(POPUP_PATH_LOWBAT,
1432 POPUP_INTERFACE_LOWBAT, SIGNAL_NOTEXTREME,
1433 not_extreme_signal_handler);
1434 if (ret < 0 && ret != -EEXIST) {
1435 _E("Failed to register signal handler! %d", ret);