tizen 2.3 release
[framework/system/deviced.git] / src / display / display-dbus.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19
20 /**
21  * @file        display-dbus.c
22  * @brief       dbus interface
23  *
24  */
25
26 #include <error.h>
27 #include <stdbool.h>
28 #include <Ecore.h>
29 #include <device-node.h>
30
31 #include "core/log.h"
32 #include "util.h"
33 #include "core.h"
34 #include "weaks.h"
35 #include "core/common.h"
36 #include "core/devices.h"
37 #include "dd-display.h"
38 #include "display-actor.h"
39
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)
44
45 #define VCONFKEY_LCD_BRIGHTNESS_INIT "db/private/deviced/lcd_brightness_init"
46
47 #define SIGNAL_HOMESCREEN               "HomeScreen"
48 #define SIGNAL_EXTREME                  "Extreme"
49 #define SIGNAL_NOTEXTREME               "NotExtreme"
50
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))
55
56 #define DISPLAY_DIM_BRIGHTNESS  0
57 #define DUMP_MODE_WATING_TIME   600000
58
59 static DBusMessage *edbus_start(E_DBus_Object *obj, DBusMessage *msg)
60 {
61         static const struct device_ops *display_device_ops = NULL;
62
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);
67
68         display_device_ops->start(CORE_LOGIC_MODE);
69         return dbus_message_new_method_return(msg);
70 }
71
72 static DBusMessage *edbus_stop(E_DBus_Object *obj, DBusMessage *msg)
73 {
74         static const struct device_ops *display_device_ops = NULL;
75
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);
80
81         display_device_ops->stop(CORE_LOGIC_MODE);
82         return dbus_message_new_method_return(msg);
83 }
84
85 static DBusMessage *edbus_lockstate(E_DBus_Object *obj, DBusMessage *msg)
86 {
87         DBusError err;
88         DBusMessageIter iter;
89         DBusMessage *reply;
90         char *state_str;
91         char *option1_str;
92         char *option2_str;
93         int timeout;
94         pid_t pid;
95         int state;
96         int flag;
97         int ret;
98         unsigned int caps;
99
100         dbus_error_init(&err);
101
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");
108                 ret = -EINVAL;
109                 goto out;
110         }
111
112         if (!state_str || timeout < 0) {
113                 _E("message is invalid!");
114                 ret = -EINVAL;
115                 goto out;
116         }
117
118         pid = get_edbus_sender_pid(msg);
119         if (kill(pid, 0) == -1) {
120                 _E("%d process does not exist, dbus ignored!", pid);
121                 ret = -ESRCH;
122                 goto out;
123         }
124
125         if (!strcmp(state_str, PM_LCDON_STR))
126                 state = LCD_NORMAL;
127         else if (!strcmp(state_str, PM_LCDDIM_STR))
128                 state = LCD_DIM;
129         else if (!strcmp(state_str, PM_LCDOFF_STR))
130                 state = LCD_OFF;
131         else {
132                 _E("%s state is invalid, dbus ignored!", state_str);
133                 ret = -EINVAL;
134                 goto out;
135         }
136
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;
141         else {
142                 _E("%s option is invalid. set default option!", option1_str);
143                 flag = STAY_CUR_STATE;
144         }
145
146         if (!strcmp(option2_str, HOLDKEYBLOCK_STR))
147                 flag |= HOLD_KEY_BLOCK;
148         else if (!strcmp(option2_str, STANDBYMODE_STR))
149                 flag |= STANDBY_MODE;
150
151         if (flag & GOTO_STATE_NOW) {
152                 caps = display_get_caps(DISPLAY_ACTOR_API);
153
154                 if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) &&
155                     state == LCD_NORMAL) {
156                         _D("No lcdon capability!");
157                         ret = -EPERM;
158                         goto out;
159                 }
160                 if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) &&
161                     state == LCD_OFF) {
162                         _D("No lcdoff capability!");
163                         ret = -EPERM;
164                         goto out;
165                 }
166         }
167
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;
172         }
173
174         ret = pm_lock_internal(pid, state, flag, timeout);
175 out:
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);
179
180         return reply;
181 }
182
183 static DBusMessage *edbus_unlockstate(E_DBus_Object *obj, DBusMessage *msg)
184 {
185         DBusError err;
186         DBusMessageIter iter;
187         DBusMessage *reply;
188         char *state_str;
189         char *option_str;
190         pid_t pid;
191         int state;
192         int flag;
193         int ret;
194
195         dbus_error_init(&err);
196
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");
201                 ret = -EINVAL;
202                 goto out;
203         }
204
205         if (!state_str) {
206                 _E("message is invalid!");
207                 ret = -EINVAL;
208                 goto out;
209         }
210
211         pid = get_edbus_sender_pid(msg);
212         if (kill(pid, 0) == -1) {
213                 _E("%d process does not exist, dbus ignored!", pid);
214                 ret = -ESRCH;
215                 goto out;
216         }
217
218         if (!strcmp(state_str, PM_LCDON_STR))
219                 state = LCD_NORMAL;
220         else if (!strcmp(state_str, PM_LCDDIM_STR))
221                 state = LCD_DIM;
222         else if (!strcmp(state_str, PM_LCDOFF_STR))
223                 state = LCD_OFF;
224         else {
225                 _E("%s state is invalid, dbus ignored!", state_str);
226                 ret = -EINVAL;
227                 goto out;
228         }
229
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;
236         else {
237                 _E("%s option is invalid. set default option!", option_str);
238                 flag = PM_RESET_TIMER;
239         }
240
241         ret = pm_unlock_internal(pid, state, flag);
242 out:
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);
246
247         return reply;
248 }
249
250 static DBusMessage *edbus_changestate(E_DBus_Object *obj, DBusMessage *msg)
251 {
252         DBusError err;
253         DBusMessageIter iter;
254         DBusMessage *reply;
255         char *state_str;
256         pid_t pid;
257         int state;
258         int ret;
259         unsigned int caps;
260
261         dbus_error_init(&err);
262
263         if (!dbus_message_get_args(msg, &err,
264                     DBUS_TYPE_STRING, &state_str, DBUS_TYPE_INVALID)) {
265                 _E("there is no message");
266                 ret = -EINVAL;
267                 goto out;
268         }
269
270         if (!state_str) {
271                 _E("message is invalid!");
272                 ret = -EINVAL;
273                 goto out;
274         }
275
276         pid = get_edbus_sender_pid(msg);
277         if (kill(pid, 0) == -1) {
278                 _E("%d process does not exist, dbus ignored!", pid);
279                 ret = -ESRCH;
280                 goto out;
281         }
282
283         if (!strcmp(state_str, PM_LCDON_STR))
284                 state = LCD_NORMAL;
285         else if (!strcmp(state_str, PM_LCDDIM_STR))
286                 state = LCD_DIM;
287         else if (!strcmp(state_str, PM_LCDOFF_STR))
288                 state = LCD_OFF;
289         else if (!strcmp(state_str, PM_SUSPEND_STR))
290                 state = SUSPEND;
291         else {
292                 _E("%s state is invalid, dbus ignored!", state_str);
293                 ret = -EINVAL;
294                 goto out;
295         }
296
297         caps = display_get_caps(DISPLAY_ACTOR_API);
298
299         if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) &&
300             state == LCD_NORMAL) {
301                 _D("No lcdon capability!");
302                 ret = -EPERM;
303                 goto out;
304         }
305         if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) &&
306             state == LCD_OFF) {
307                 _D("No lcdoff capability!");
308                 ret = -EPERM;
309                 goto out;
310         }
311
312         if (check_dimstay(state, GOTO_STATE_NOW) == true) {
313                 _E("LCD state can not be changed to OFF state!");
314                 ret = -EBUSY;
315                 goto out;
316         }
317
318         ret = pm_change_internal(pid, state);
319
320         if (!ret && state == LCD_OFF)
321                 update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
322 out:
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);
326
327         return reply;
328 }
329
330 static DBusMessage *edbus_getdisplaycount(E_DBus_Object *obj, DBusMessage *msg)
331 {
332         DBusMessageIter iter;
333         DBusMessage *reply;
334         int cmd, cnt, ret;
335
336         cmd = DISP_CMD(PROP_DISPLAY_DISPLAY_COUNT, DEFAULT_DISPLAY);
337         ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &cnt);
338         if (ret >= 0)
339                 ret = cnt;
340
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);
344         return reply;
345 }
346
347 static DBusMessage *edbus_getmaxbrightness(E_DBus_Object *obj, DBusMessage *msg)
348 {
349         DBusMessageIter iter;
350         DBusMessage *reply;
351         int cmd, brt, ret;
352
353         cmd = DISP_CMD(PROP_DISPLAY_MAX_BRIGHTNESS, DEFAULT_DISPLAY);
354         ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt);
355         if (ret >= 0)
356                 ret = brt;
357
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);
361         return reply;
362 }
363
364 static DBusMessage *edbus_setmaxbrightness(E_DBus_Object *obj, DBusMessage *msg)
365 {
366         DBusMessageIter iter;
367         DBusMessage *reply;
368         int cmd, brt, ret;
369
370         dbus_message_iter_init(msg, &iter);
371         dbus_message_iter_get_basic(&iter, &brt);
372
373         cmd = DISP_CMD(PROP_DISPLAY_MAX_BRIGHTNESS, DEFAULT_DISPLAY);
374         ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt);
375
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);
379         return reply;
380 }
381
382 static DBusMessage *edbus_getbrightness(E_DBus_Object *obj, DBusMessage *msg)
383 {
384         DBusMessageIter iter;
385         DBusMessage *reply;
386         int cmd, brt, ret;
387
388         cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
389         ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt);
390         if (ret >= 0)
391                 ret = brt;
392
393         _I("get brightness %d, %d", brt, ret);
394
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);
398         return reply;
399 }
400
401 static DBusMessage *edbus_setbrightness(E_DBus_Object *obj, DBusMessage *msg)
402 {
403         DBusMessageIter iter;
404         DBusMessage *reply;
405         int cmd, brt, powersaver, autobrt, ret, caps;
406
407         caps = display_get_caps(DISPLAY_ACTOR_API);
408
409         if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) {
410                 _D("No brightness changing capability!");
411                 ret = -EPERM;
412                 goto error;
413         }
414
415         dbus_message_iter_init(msg, &iter);
416         dbus_message_iter_get_basic(&iter, &brt);
417
418         if (brt == DISPLAY_DIM_BRIGHTNESS) {
419                 _E("application can not set this value(DIM VALUE:%d)", brt);
420                 ret = -EPERM;
421                 goto error;
422         }
423
424         if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &powersaver) != 0) {
425                 _E("Failed to get VCONFKEY_SETAPPL_PSMODE value");
426                 powersaver = SETTING_PSMODE_NORMAL;
427         }
428
429         if (powersaver == SETTING_PSMODE_WEARABLE) {
430                 _D("brightness is changed in powersaver mode!");
431                 backlight_ops.set_force_brightness(0);
432         }
433
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;
437         }
438
439         if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
440                 _D("auto_brightness state is ON, can not change the brightness value");
441                 ret = 0;
442                 goto error;
443         }
444
445         cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
446         ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt);
447         if (ret < 0)
448                 goto error;
449         if (vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt) != 0)
450                 _E("Failed to set VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
451
452         if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, brt) != 0)
453                 _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
454
455         _I("set brightness %d, %d", brt, ret);
456
457 error:
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);
461         return reply;
462 }
463
464 static DBusMessage *edbus_holdbrightness(E_DBus_Object *obj, DBusMessage *msg)
465 {
466         DBusMessageIter iter;
467         DBusMessage *reply;
468         int cmd, brt, powersaver, autobrt, ret, caps;
469
470         caps = display_get_caps(DISPLAY_ACTOR_API);
471
472         if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) {
473                 _D("No brightness changing capability!");
474                 ret = -EPERM;
475                 goto error;
476         }
477
478         dbus_message_iter_init(msg, &iter);
479         dbus_message_iter_get_basic(&iter, &brt);
480
481         if (brt == DISPLAY_DIM_BRIGHTNESS) {
482                 _E("application can not set this value(DIM VALUE:%d)", brt);
483                 ret = -EPERM;
484                 goto error;
485         }
486
487         if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &powersaver) != 0) {
488                 _E("Failed to get VCONFKEY_SETAPPL_PSMODE value");
489                 powersaver = SETTING_PSMODE_NORMAL;
490         }
491
492         if (powersaver == SETTING_PSMODE_WEARABLE) {
493                 _D("Powersaver mode! brightness can not be changed!");
494                 ret = -EPERM;
495                 goto error;
496         }
497
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;
501         }
502
503         vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON);
504
505         cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
506         ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt);
507         if (ret < 0)
508                 goto error;
509
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);
513         }
514
515         if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, brt) != 0)
516                 _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
517
518         _I("hold brightness %d, %d", brt, ret);
519
520 error:
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);
524         return reply;
525
526 }
527
528 static DBusMessage *edbus_releasebrightness(E_DBus_Object *obj, DBusMessage *msg)
529 {
530         DBusMessageIter iter;
531         DBusMessage *reply;
532         int cmd, bat, charger, changed, setting, brt, autobrt, ret = 0;
533
534         if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat) != 0) {
535                 _E("Failed to get VCONFKEY_SYSMAN_BATTERY_STATUS_LOW value");
536                 ret = -EPERM;
537                 goto error;
538         }
539
540         if (vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger) != 0) {
541                 _E("Failed to get VCONFKEY_SYSMAN_CHARGER_STATUS value");
542                 ret = -EPERM;
543                 goto error;
544         }
545
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");
548                 ret = -EPERM;
549                 goto error;
550         }
551
552         if (vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting) != 0) {
553                 _E("Failed to get VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
554                 ret = -EPERM;
555                 goto error;
556         }
557
558         if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt) != 0) {
559                 _E("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
560                 ret = -EPERM;
561                 goto error;
562         }
563
564         vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF);
565
566         cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY);
567         ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt);
568         if (ret < 0)
569                 brt = ret;
570
571         // check dim state
572         if (low_battery_state(bat) &&
573             charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) {
574                 _D("batt warning low : brightness is not changed!");
575                 if (brt != 0) {
576                         device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, 0);
577                 }
578                 goto error;
579         }
580
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");
586                         }
587                 }
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);
591         }
592
593 error:
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);
597         return reply;
598 }
599
600 static DBusMessage *edbus_getaclstatus(E_DBus_Object *obj, DBusMessage *msg)
601 {
602         DBusMessageIter iter;
603         DBusMessage *reply;
604         int cmd, st, ret;
605
606         cmd = DISP_CMD(PROP_DISPLAY_ACL_CONTROL, DEFAULT_DISPLAY);
607         ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &st);
608         if (ret >= 0)
609                 ret = st;
610
611         _I("get acl status %d, %d", st, ret);
612
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);
616         return reply;
617 }
618
619 static DBusMessage *edbus_setaclstatus(E_DBus_Object *ob, DBusMessage *msg)
620 {
621         DBusMessageIter iter;
622         DBusMessage *reply;
623         int cmd, st, ret;
624
625         dbus_message_iter_init(msg, &iter);
626         dbus_message_iter_get_basic(&iter, &st);
627
628         cmd = DISP_CMD(PROP_DISPLAY_ACL_CONTROL, DEFAULT_DISPLAY);
629         ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, st);
630
631         _I("set acl status %d, %d", st, ret);
632
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);
636         return reply;
637 }
638
639 static DBusMessage *edbus_getautotone(E_DBus_Object *obj, DBusMessage *msg)
640 {
641         DBusMessageIter iter;
642         DBusMessage *reply;
643         int cmd, tone, ret;
644
645         cmd = DISP_CMD(PROP_DISPLAY_AUTO_SCREEN_TONE, DEFAULT_DISPLAY);
646         ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &tone);
647         if (ret >= 0)
648                 ret = tone;
649
650         _I("get auto screen tone %d, %d", tone, ret);
651
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);
655         return reply;
656 }
657
658 static DBusMessage *edbus_setautotone(E_DBus_Object *obj, DBusMessage *msg)
659 {
660         DBusMessageIter iter;
661         DBusMessage *reply;
662         int cmd, tone, ret;
663
664         dbus_message_iter_init(msg, &iter);
665         dbus_message_iter_get_basic(&iter, &tone);
666
667         cmd = DISP_CMD(PROP_DISPLAY_AUTO_SCREEN_TONE, DEFAULT_DISPLAY);
668         ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, tone);
669
670         _I("set auto screen tone %d, %d", tone, ret);
671
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);
675         return reply;
676 }
677
678 static DBusMessage *edbus_setautotoneforce(E_DBus_Object *obj, DBusMessage *msg)
679 {
680         DBusMessageIter iter;
681         DBusMessage *reply;
682         int cmd, tone, ret;
683
684         dbus_message_iter_init(msg, &iter);
685         dbus_message_iter_get_basic(&iter, &tone);
686
687         cmd = DISP_CMD(PROP_DISPLAY_AUTO_SCREEN_TONE_FORCE, DEFAULT_DISPLAY);
688         ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, tone);
689
690         _I("set auto screen tone force %d, %d", tone, ret);
691
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);
695         return reply;
696 }
697
698 static DBusMessage *edbus_setrefreshrate(E_DBus_Object *obj, DBusMessage *msg)
699 {
700         DBusMessageIter iter;
701         DBusMessage *reply;
702         int app, val, cmd, ret, control;
703
704         ret = dbus_message_get_args(msg, NULL,
705                         DBUS_TYPE_INT32, &app,
706                         DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
707         if (!ret) {
708                 _I("there is no message");
709                 ret = -EINVAL;
710                 goto error;
711         }
712
713         if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) {
714                 ret = -EINVAL;
715                 goto error;
716         }
717
718         if (!display_conf.framerate_app[app]) {
719                 _I("This case(%d) is not support in this target", app);
720                 ret = -EPERM;
721                 goto error;
722         }
723
724         control = display_conf.control_display;
725
726         if (control)
727                 backlight_ops.off(NORMAL_MODE);
728
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);
732
733         if (control)
734                 backlight_ops.on(NORMAL_MODE);
735
736 error:
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);
740         return reply;
741 }
742
743 static DBusMessage *edbus_getcolorblind(E_DBus_Object *obj, DBusMessage *msg)
744 {
745         DBusMessageIter iter;
746         DBusMessage *reply;
747         int cmd, val, ret;
748
749         cmd = DISP_CMD(PROP_DISPLAY_IMAGE_ENHANCE_COLOR_BLIND, DEFAULT_DISPLAY);
750         ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &val);
751         if (ret >= 0)
752                 ret = val;
753
754         _I("get color blind %d", val);
755
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);
759         return reply;
760 }
761
762 static DBusMessage *edbus_setcolorblind(E_DBus_Object *obj, DBusMessage *msg)
763 {
764         DBusMessageIter iter;
765         DBusMessage *reply;
766         int cmd, val, ret;
767         unsigned int power;
768         uint64_t red, grn, blu;
769         struct color_blind_info info;
770
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);
774         if (!ret) {
775                 _I("there is no message");
776                 ret = -EINVAL;
777                 goto error;
778         }
779
780         info.power = power;
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);
790
791         cmd = DISP_CMD(PROP_DISPLAY_IMAGE_ENHANCE_COLOR_BLIND, DEFAULT_DISPLAY);
792         ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, (int)&info);
793
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);
797
798 error:
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);
802         return reply;
803 }
804
805 static DBusMessage *edbus_gethbm(E_DBus_Object *obj, DBusMessage *msg)
806 {
807         DBusMessageIter iter;
808         DBusMessage *reply;
809         int hbm;
810
811         if (!msg) {
812                 _E("msg is empty!");
813                 return NULL;
814         }
815
816         /* check weak function symbol */
817         if (!hbm_get_state) {
818                 hbm = -ENOSYS;
819                 goto error;
820         }
821
822         hbm = hbm_get_state();
823
824         if (hbm < 0)
825                 _E("failed to get high brightness mode %d", hbm);
826         else
827                 _D("get high brightness mode %d", hbm);
828 error:
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);
832         return reply;
833 }
834
835 static DBusMessage *edbus_sethbm(E_DBus_Object *obj, DBusMessage *msg)
836 {
837         DBusMessageIter iter;
838         DBusMessage *reply;
839         int hbm, ret;
840
841         if (!msg) {
842                 _E("msg is empty!");
843                 return NULL;
844         }
845
846         if (!dbus_message_get_args(msg, NULL,
847                     DBUS_TYPE_INT32, &hbm,
848                     DBUS_TYPE_INVALID)) {
849                 _E("there is no message");
850                 ret = -EINVAL;
851                 goto error;
852         }
853
854         /* check weak function symbol */
855         if (!hbm_set_state) {
856                 ret = -ENOSYS;
857                 goto error;
858         }
859
860         ret = hbm_set_state(hbm);
861
862         if (ret < 0)
863                 _E("failed to set high brightness mode (%d,%d)", ret, hbm);
864         else
865                 _I("set high brightness mode (%d,%d)", ret, hbm);
866 error:
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);
870         return reply;
871 }
872
873 static DBusMessage *edbus_sethbm_timeout(E_DBus_Object *obj, DBusMessage *msg)
874 {
875         DBusMessageIter iter;
876         DBusMessage *reply;
877         int hbm, timeout, ret;
878
879         if (!msg) {
880                 _E("msg is empty!");
881                 return NULL;
882         }
883
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");
888                 ret = -EINVAL;
889                 goto error;
890         }
891
892         /* check weak function symbol */
893         if (!hbm_set_state_with_timeout) {
894                 ret = -ENOSYS;
895                 goto error;
896         }
897
898         ret = hbm_set_state_with_timeout(hbm, timeout);
899
900         if (ret < 0)
901                 _E("failed to set high brightness mode (%d,%d,%d)",
902                     ret, hbm, timeout);
903         else
904                 _I("set high brightness mode (%d,%d,%d)",
905                     ret, hbm, timeout);
906 error:
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);
910         return reply;
911 }
912
913 static DBusMessage *edbus_setautobrightnessmin(E_DBus_Object *obj, DBusMessage *msg)
914 {
915         DBusMessageIter iter;
916         DBusMessage *reply;
917         int val, ret;
918         pid_t pid;
919         const char *sender;
920
921         sender = dbus_message_get_sender(msg);
922         if (!sender) {
923                 _E("invalid sender name!");
924                 ret = -EINVAL;
925                 goto error;
926         }
927         if (!display_info.set_autobrightness_min) {
928                 ret = -EIO;
929                 goto error;
930         }
931         dbus_message_iter_init(msg, &iter);
932         dbus_message_iter_get_basic(&iter, &val);
933
934         pid = get_edbus_sender_pid(msg);
935         ret = display_info.set_autobrightness_min(val, (char *)sender);
936         if (ret) {
937                 _W("fail to set autobrightness min %d, %d by %d", val, ret, pid);
938                 goto error;
939         }
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);
944         }
945 error:
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);
949
950         return reply;
951 }
952
953 static DBusMessage *edbus_setlcdtimeout(E_DBus_Object *obj, DBusMessage *msg)
954 {
955         DBusMessageIter iter;
956         DBusMessage *reply;
957         int on, dim, holdkey_block, ret;
958         pid_t pid;
959         const char *sender;
960
961         sender = dbus_message_get_sender(msg);
962         if (!sender) {
963                 _E("invalid sender name!");
964                 ret = -EINVAL;
965                 goto error;
966         }
967
968         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &on,
969                     DBUS_TYPE_INT32, &dim, DBUS_TYPE_INT32, &holdkey_block,
970                     DBUS_TYPE_INVALID);
971
972         pid = get_edbus_sender_pid(msg);
973         ret = set_lcd_timeout(on, dim, holdkey_block, sender);
974         if (ret) {
975                 _W("fail to set lcd timeout %d by %d", ret, pid);
976         } else {
977                 register_edbus_watch(msg, WATCH_DISPLAY_LCD_TIMEOUT,
978                     reset_lcd_timeout);
979                 _I("set lcd timeout on %d, dim %d, holdblock %d by %d",
980                     on, dim, holdkey_block, pid);
981         }
982 error:
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);
986
987         return reply;
988 }
989
990 static DBusMessage *edbus_lockscreenbgon(E_DBus_Object *obj, DBusMessage *msg)
991 {
992         DBusMessageIter iter;
993         DBusMessage *reply;
994         int ret = 0;
995         char *on;
996
997         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &on,
998                     DBUS_TYPE_INVALID);
999
1000         if (!ret) {
1001                 _E("fail to update lcdscreen bg on state %d", ret);
1002                 ret = -EINVAL;
1003                 goto error;
1004         }
1005
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);
1010         else
1011                 ret = -EINVAL;
1012
1013 error:
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);
1017
1018         return reply;
1019 }
1020
1021 static DBusMessage *edbus_dumpmode(E_DBus_Object *obj, DBusMessage *msg)
1022 {
1023         DBusMessageIter iter;
1024         DBusMessage *reply;
1025         int ret = 0;
1026         char *on;
1027
1028         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &on,
1029                     DBUS_TYPE_INVALID);
1030
1031         if (!ret) {
1032                 _E("fail to get dumpmode state %d", ret);
1033                 ret = -EINVAL;
1034                 goto error;
1035         }
1036
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,
1042                     PM_SLEEP_MARGIN);
1043         else
1044                 ret = -EINVAL;
1045
1046 error:
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);
1050
1051         return reply;
1052 }
1053
1054 static DBusMessage *edbus_savelog(E_DBus_Object *obj, DBusMessage *msg)
1055 {
1056         save_display_log();
1057         return dbus_message_new_method_return(msg);
1058 }
1059
1060 static DBusMessage *edbus_powerkeyignore(E_DBus_Object *obj, DBusMessage *msg)
1061 {
1062         DBusMessageIter iter;
1063         DBusMessage *reply;
1064         int ret = 0;
1065         int on;
1066
1067         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &on,
1068                     DBUS_TYPE_INVALID);
1069
1070         if (!ret) {
1071                 _E("fail to get powerkey ignore %d", ret);
1072                 ret = -EINVAL;
1073                 goto error;
1074         }
1075
1076         if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore))
1077                 keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false);
1078 error:
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);
1082
1083         return reply;
1084 }
1085
1086 static DBusMessage *edbus_powerkeylcdoff(E_DBus_Object *obj, DBusMessage *msg)
1087 {
1088         DBusMessageIter iter;
1089         DBusMessage *reply;
1090         int ret;
1091
1092         if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff))
1093                 ret = keyfilter_ops->powerkey_lcdoff();
1094         else
1095                 ret = -ENOSYS;
1096
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);
1100
1101         return reply;
1102 }
1103
1104 static DBusMessage *edbus_customlcdon(E_DBus_Object *obj, DBusMessage *msg)
1105 {
1106         DBusMessageIter iter;
1107         DBusMessage *reply;
1108         int ret = 0;
1109         int timeout;
1110
1111         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &timeout,
1112                     DBUS_TYPE_INVALID);
1113
1114         if (!ret) {
1115                 _E("fail to get custom lcd timeout %d", ret);
1116                 ret = -EINVAL;
1117                 goto error;
1118         }
1119
1120         ret = custom_lcdon(timeout);
1121
1122 error:
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);
1126
1127         return reply;
1128 }
1129
1130 static DBusMessage *edbus_staytouchscreenoff(E_DBus_Object *obj, DBusMessage *msg)
1131 {
1132         DBusMessageIter iter;
1133         DBusMessage *reply;
1134         int ret = 0;
1135         int val;
1136
1137         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val,
1138                     DBUS_TYPE_INVALID);
1139
1140         if (!ret) {
1141                 _E("fail to get stay touchscreen off state %d", ret);
1142                 ret = -EINVAL;
1143                 goto error;
1144         }
1145
1146         set_stay_touchscreen_off(val);
1147 error:
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);
1151
1152         return reply;
1153 }
1154
1155 static DBusMessage *edbus_lcdpaneloffmode(E_DBus_Object *obj, DBusMessage *msg)
1156 {
1157         DBusMessageIter iter;
1158         DBusMessage *reply;
1159         int ret = 0;
1160         int val;
1161
1162         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val,
1163                     DBUS_TYPE_INVALID);
1164
1165         if (!ret) {
1166                 _E("fail to get lcd panel off mode %d", ret);
1167                 ret = -EINVAL;
1168                 goto error;
1169         }
1170
1171         set_lcd_paneloff_mode(val);
1172 error:
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);
1176
1177         return reply;
1178 }
1179
1180 static DBusMessage *edbus_actorcontrol(E_DBus_Object *obj, DBusMessage *msg)
1181 {
1182         DBusMessageIter iter;
1183         DBusMessage *reply;
1184         int ret = 0, val, actor;
1185         char *op;
1186
1187         ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &op,
1188                     DBUS_TYPE_INT32, &actor, DBUS_TYPE_INT32, &val,
1189                     DBUS_TYPE_INVALID);
1190
1191         if (!ret) {
1192                 _E("fail to update actor control %d", ret);
1193                 ret = -EINVAL;
1194                 goto error;
1195         }
1196
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);
1201         else
1202                 ret = -EINVAL;
1203
1204 error:
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);
1208
1209         return reply;
1210 }
1211
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 */
1255 };
1256
1257 static void sim_signal_handler(void *data, DBusMessage *msg)
1258 {
1259         DBusError err;
1260         int ret, val;
1261         static int state = false;
1262
1263         if (!find_display_feature("auto-brightness")) {
1264                 _D("auto brightness is not supported!");
1265                 return;
1266         }
1267
1268         if (state)
1269                 return;
1270
1271         ret = dbus_message_is_signal(msg, TELEPHONY_INTERFACE_SIM,
1272             SIGNAL_SIM_STATUS);
1273         if (!ret) {
1274                 _E("there is no power off popup signal");
1275                 return;
1276         }
1277
1278         ret = vconf_get_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, &state);
1279         if (ret < 0 || state)
1280                 return;
1281
1282         dbus_error_init(&err);
1283
1284         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val,
1285             DBUS_TYPE_INVALID);
1286         if (!ret) {
1287                 _E("no message : [%s:%s]", err.name, err.message);
1288                 dbus_error_free(&err);
1289         }
1290
1291         if (val != SIM_CARD_NOT_PRESENT) {
1292                 /* change setting : autobrightness on */
1293                 state = true;
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!");
1300         }
1301 }
1302
1303 static void homescreen_signal_handler(void *data, DBusMessage *msg)
1304 {
1305         DBusError err;
1306         int ret;
1307         char *screen;
1308         pid_t pid;
1309
1310         ret = dbus_message_is_signal(msg, DEVICED_INTERFACE_NAME,
1311             SIGNAL_HOMESCREEN);
1312         if (!ret) {
1313                 _E("there is no homescreen signal");
1314                 return;
1315         }
1316
1317         dbus_error_init(&err);
1318
1319         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &screen,
1320             DBUS_TYPE_INVALID);
1321         if (!ret) {
1322                 _E("no message : [%s:%s]", err.name, err.message);
1323                 dbus_error_free(&err);
1324         }
1325
1326         _D("screen : %s", screen);
1327
1328         if (set_alpm_screen) {
1329                 pid = get_edbus_sender_pid(msg);
1330                 set_alpm_screen(screen, pid);
1331         } else {
1332                 _E("alpm screen mode is not supported!");
1333         }
1334 }
1335
1336 static void extreme_signal_handler(void *data, DBusMessage *msg)
1337 {
1338         int ret;
1339
1340         ret = dbus_message_is_signal(msg, POPUP_INTERFACE_LOWBAT,
1341             SIGNAL_EXTREME);
1342         if (!ret) {
1343                 _E("there is no extreme signal");
1344                 return;
1345         }
1346
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");
1354 }
1355
1356 static void not_extreme_signal_handler(void *data, DBusMessage *msg)
1357 {
1358         int ret;
1359
1360         ret = dbus_message_is_signal(msg, POPUP_INTERFACE_LOWBAT,
1361             SIGNAL_NOTEXTREME);
1362         if (!ret) {
1363                 _E("there is no extreme signal");
1364                 return;
1365         }
1366
1367         _D("release extreme mode");
1368         if (vconf_set_int(VCONFKEY_PM_KEY_IGNORE, FALSE) != 0)
1369                 _E("failed to set vconf status");
1370 }
1371
1372 /*
1373  * Default capability
1374  * api      := LCDON | LCDOFF | BRIGHTNESS
1375  * gesture  := LCDON
1376  */
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,
1382 };
1383
1384 static struct display_actor_ops display_gesture_actor = {
1385         .id     = DISPLAY_ACTOR_GESTURE,
1386         .caps   = DISPLAY_CAPA_LCDON,
1387 };
1388
1389 int init_pm_dbus(void)
1390 {
1391         int ret;
1392
1393         display_add_actor(&display_api_actor);
1394         display_add_actor(&display_gesture_actor);
1395
1396         ret = register_edbus_method(DEVICED_PATH_DISPLAY,
1397                     edbus_methods, ARRAY_SIZE(edbus_methods));
1398         if (ret < 0) {
1399                 _E("Failed to register edbus method! %d", ret);
1400                 return ret;
1401         }
1402 /*
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.
1406  */
1407 /*
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);
1413                 return ret;
1414         }
1415 */
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);
1421                 return ret;
1422         }
1423
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);
1429                 return ret;
1430         }
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);
1436                 return ret;
1437         }
1438         return 0;
1439 }
1440