4 * Copyright (c) 2016 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.
20 #include <tzplatform_config.h>
21 #include <device/display-internal.h>
25 #define METHOD_DISPLAY_GETBRIGHTNESS "getbrightness"
26 #define METHOD_DISPLAY_SETBRIGHTNESS "setbrightness"
27 #define METHOD_DISPLAY_GETMAXBRIGHTNESS "GetMaxBrightness"
28 #define METHOD_DISPLAY_SETMAXBRIGHTNESS "SetMaxBrightness"
29 #define METHOD_DISPLAY_HOLDBRIGHTNESS "HoldBrightness"
30 #define METHOD_DISPLAY_RELEASEBRIGHTNESS "ReleaseBrightness"
31 #define METHOD_DISPLAY_CUSTOMBRIGHTNESS "CustomBrightness"
32 #define METHOD_DISPLAY_SETAUTOBRIGHTNESSMIN "setautobrightnessmin"
33 #define METHOD_DISPLAY_SETREFRESHRATE "SetRefreshRate"
34 #define METHOD_DISPLAY_GETDISPLAYCOUNT "GetDisplayCount"
35 #define METHOD_DISPLAY_CHANGESTATE "ChangeState"
36 #define METHOD_DISPLAY_LOCKSTATE_NOPT "lockstate_nopt"
37 #define METHOD_DISPLAY_UNLOCKSTATE "unlockstate"
38 #define METHOD_DISPLAY_SETLCDTIMEOUT "setlcdtimeout"
39 #define METHOD_DISPLAY_CUSTOMLCDON "CustomLCDOn"
40 #define METHOD_DISPLAY_LCDPANEL_OFFMODE "LCDPanelOffMode"
41 #define METHOD_DISPLAY_STAYTOUCHSCREEN_OFF "StayTouchScreenOff"
42 #define METHOD_DISPLAY_LOCKSCREENBGON "LockScreenBgOn"
43 #define METHOD_DISPLAY_DUMPMODE "Dumpmode"
44 #define METHOD_DISPLAY_SAVELOG "SaveLog"
45 #define METHOD_DISPLAY_POWERKEY_IGNORE "PowerKeyIgnore"
46 #define METHOD_DISPLAY_POWERKEY_LCDOFF "PowerKeyLCDOff"
47 #define METHOD_DISPLAY_LOCKTIMEOUT_EXPIRED "LockTimeoutExpired"
48 #define METHOD_DISPLAY_LOCKTIMEOUT_INPUT "LockTimeoutInput"
49 #define METHOD_DISPLAY_ACTORCONTROL "ActorControl"
50 #define METHOD_DISPLAY_START "start"
51 #define METHOD_DISPLAY_STOP "stop"
52 #define METHOD_CHANGE_STATE_BY_REASON "ChangeStateByReason"
54 #define PM_STATE_LOG_FILE "/var/log/pm_state.log"
55 #define PALM_STR "palm"
57 static bool get_display_method(const char *method, GVariant *param, int *value)
63 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
65 DEVICED_INTERFACE_DISPLAY,
68 _E("fail (%s): no reply", method);
71 if (!g_variant_get_safe(msg, "(i)", &val))
72 _E("fail (%s): no message", method);
74 _I("success (%s): %d", method, val);
84 static bool set_display_method(const char *method, GVariant *param)
90 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
92 DEVICED_INTERFACE_DISPLAY,
95 _E("fail (%s): no reply", method);
99 if (!g_variant_get_safe(msg, "(i)", &val))
100 _E("fail (%s): no message", method);
102 if ((val == -ENOTSUP) || (val == -ENOSYS)) {
103 _I("Not supported feature! (%s): %d", method, val);
105 } else if (val < 0) {
106 _E("fail (%s): returned fail (%d)", method, val);
108 _I("success (%s): %d", method, val);
113 g_variant_unref(msg);
117 static bool set_display_method_noreply(const char *method, GVariant *var)
122 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
123 DEVICED_PATH_DISPLAY,
124 DEVICED_INTERFACE_DISPLAY,
127 _E("fail (%s): no reply", method);
131 g_variant_unref(msg);
135 static bool set_display_maxbrightness(int brightness)
137 return set_display_method(METHOD_DISPLAY_SETMAXBRIGHTNESS, g_variant_new("(i)", brightness));
140 static bool set_display_holdbrightness(int brightness)
142 return set_display_method(METHOD_DISPLAY_HOLDBRIGHTNESS, g_variant_new("(i)", brightness));
145 static bool set_display_releasebrightness()
147 return set_display_method(METHOD_DISPLAY_RELEASEBRIGHTNESS, NULL);
150 static bool get_display_custombrightness()
152 return get_display_method(METHOD_DISPLAY_CUSTOMBRIGHTNESS, NULL, NULL);
155 static bool set_display_autobrightness_min(int min)
161 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
162 DEVICED_PATH_DISPLAY,
163 DEVICED_INTERFACE_DISPLAY,
164 METHOD_DISPLAY_SETAUTOBRIGHTNESSMIN,
165 g_variant_new("(i)", min),
168 _E("fail : no reply");
172 if (!g_variant_get_safe(msg, "(i)", &val)) {
173 _E("fail : no message");
175 if ((min < 1) || (min > 100)) {
177 _I("success : autobrightness min value should be 1~100. can't set (%d).", min);
180 _I("fail : can't set (%d). but returned success", min);
184 _E("fail : return fail (%d)", val);
186 _I("success : %d", val);
191 g_variant_unref(msg);
196 static bool set_display_refreshrate(int app, int rate)
198 return set_display_method(METHOD_DISPLAY_SETREFRESHRATE, g_variant_new("(ii)", app, rate));
202 static bool get_display_count()
204 return get_display_method(METHOD_DISPLAY_GETDISPLAYCOUNT, NULL, NULL);
207 static bool set_display_changestate(char *state)
209 return set_display_method(METHOD_DISPLAY_CHANGESTATE, g_variant_new("(s)", state));
213 static bool set_display_lockstate_nopt(char *state, char *option, char *ignore, int timeout)
216 char str_timeout[10];
218 snprintf(str_timeout, sizeof(str_timeout), "%d", timeout);
223 param[1] = str_timeout;
225 return set_display_method(METHOD_DISPLAY_LOCKSTATE_NOPT, "sssi", param);
228 static bool set_display_unlockstate(char *state, char *option)
235 return set_display_method(METHOD_DISPLAY_UNLOCKSTATE, "ss", param);
239 static bool set_display_lcdtimeout(int normal, int dim, int holdkey_block)
241 return set_display_method(METHOD_DISPLAY_SETLCDTIMEOUT, g_variant_new("(iii)", normal, dim, holdkey_block));
244 static bool set_display_customlcdon(int timeout_msec)
246 return set_display_method(METHOD_DISPLAY_CUSTOMLCDON, g_variant_new("(i)", timeout_msec));
249 static bool set_display_lcdpanel_offmode(int on)
251 return set_display_method(METHOD_DISPLAY_LCDPANEL_OFFMODE, g_variant_new("(i)", on));
254 static bool set_display_staytouchscreen_off(int on)
256 return set_display_method(METHOD_DISPLAY_STAYTOUCHSCREEN_OFF, g_variant_new("(i)", on));
259 static bool set_display_lockscreen_bg_on(char *on)
261 return set_display_method(METHOD_DISPLAY_LOCKSCREENBGON, g_variant_new("(s)", on));
264 static bool set_display_dumpmode(char *on)
266 return set_display_method(METHOD_DISPLAY_DUMPMODE, g_variant_new("(s)", on));
269 static bool set_display_savelog()
275 if (!stat(PM_STATE_LOG_FILE, &buf)) {
276 r = remove(PM_STATE_LOG_FILE);
278 _E("Remove file error : %d", r);
281 if (!set_display_method_noreply(METHOD_DISPLAY_SAVELOG, NULL))
286 if (!stat(PM_STATE_LOG_FILE, &buf)) {
287 _I("success : %s", PM_STATE_LOG_FILE);
294 static bool set_display_powerkey_ignore(int on)
296 return set_display_method(METHOD_DISPLAY_POWERKEY_IGNORE, g_variant_new("(i)", on));
299 static bool set_display_powerkey_lcdoff()
301 return set_display_method(METHOD_DISPLAY_POWERKEY_LCDOFF, NULL);
305 static bool set_display_locktimeout_expired(char *req_id)
312 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
313 DEVICED_PATH_DISPLAY,
314 DEVICED_INTERFACE_DISPLAY,
315 METHOD_DISPLAY_LOCKTIMEOUT_EXPIRED, g_variant_new("(s)", req_id),
318 _E("fail: no reply");
322 if (dbus_message_get_args(msg, NULL,
323 DBUS_TYPE_STRING, &ret_req_id, //request id
324 DBUS_TYPE_INT32, &val, //return value
325 DBUS_TYPE_INVALID) == 0)
326 _E("fail: no message");
328 if ((0 != strcmp(req_id, ret_req_id)) || (val < 0)) {
329 _E("fail: return fail");
331 _I("success: %s %d", ret_req_id, val);
336 dbus_message_unref(msg);
340 static bool set_display_locktimeout_input(char *req_id, int input)
345 snprintf(str_input, sizeof(str_input), "%d", input);
347 param[1] = str_input;
349 return set_display_method(METHOD_DISPLAY_LOCKTIMEOUT_INPUT, g_variant_new("(si)", req_id, input));
353 static bool set_display_actorcontrol(char *command, int actor, int caps)
355 return set_display_method(METHOD_DISPLAY_ACTORCONTROL, g_variant_new("(sii)", command, actor, caps));
358 static bool get_display_brightness_state(display_state_e state, int *brightness)
362 ret = device_display_get_brightness_state(0, state, brightness);
364 return capi_result(METHOD_DISPLAY_GETBRIGHTNESS, ret);
367 static bool get_display_max_brightness_state(display_state_e state, int *brightness)
371 ret = device_display_get_max_brightness_state(0, state, brightness);
373 return capi_result(METHOD_DISPLAY_GETMAXBRIGHTNESS, ret);
376 static bool set_display_brightness_state(display_state_e state, int brightness)
381 ret = device_display_set_brightness_state(0, state, brightness);
382 if (!capi_result(METHOD_DISPLAY_SETBRIGHTNESS, ret))
385 if (state == DISPLAY_STATE_NORMAL)
386 set_display_changestate("lcdon");
387 else if (state == DISPLAY_STATE_SCREEN_DIM)
388 set_display_changestate("lcddim");
390 _E("fail: unknown state(%d)", state);
394 ret = device_display_get_brightness_state(0, state, &getbrightness);
395 if (!capi_result(METHOD_DISPLAY_SETBRIGHTNESS, ret))
398 if (brightness != getbrightness)
404 static bool set_display_state_by_reason(display_state_e type, const char *reason, int timeout, dbus_pending_cb cb)
408 ret = device_display_change_state_by_reason(type, reason, timeout, cb);
410 return capi_result(METHOD_CHANGE_STATE_BY_REASON, ret);
413 static bool set_display_start()
415 return set_display_method_noreply(METHOD_DISPLAY_START, NULL);
418 static bool set_display_stop()
420 return set_display_method_noreply(METHOD_DISPLAY_STOP, NULL);
423 void display_test_all(int *success, int *fail)
429 (get_display_brightness_state(DISPLAY_STATE_NORMAL, &brt)) ? s++ : f++;
430 (get_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt)) ? s++ : f++;
431 (set_display_brightness_state(DISPLAY_STATE_NORMAL, 100)) ? s++ : f++;
432 (set_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, 1)) ? s++ : f++;
433 (get_display_max_brightness_state(DISPLAY_STATE_NORMAL, &brt)) ? s++ : f++;
434 (get_display_max_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt)) ? s++ : f++;
435 (set_display_maxbrightness(80)) ? s++ : f++; //not support, always success.
436 (set_display_holdbrightness(30)) ? s++ : f++;
437 (set_display_releasebrightness()) ? s++ : f++;
438 (get_display_custombrightness()) ? s++ : f++;
439 (set_display_autobrightness_min(15)) ? s++ : f++;
440 (set_display_autobrightness_min(0)) ? s++ : f++;
441 //(set_display_refreshrate(0, 30)) ? s++ : f++;
442 (get_display_count()) ? s++ : f++;
443 (set_display_changestate("lcdon")) ? s++ : f++;
444 //(set_display_lockstate_nopt("lcddim", "staycurstate", "", 3)) ? s++ : f++;
445 //(set_display_unlockstate("lcddim", "resettimer")) ? s++ : f++;
446 (set_display_lcdtimeout(5, 10, 1)) ? s++ : f++;
447 (set_display_customlcdon(6000)) ? s++ : f++;
448 (set_display_lcdpanel_offmode(1)) ? s++ : f++;
449 (set_display_lcdpanel_offmode(0)) ? s++ : f++;
450 (set_display_staytouchscreen_off(1)) ? s++ : f++;
451 (set_display_staytouchscreen_off(0)) ? s++ : f++;
452 (set_display_lockscreen_bg_on("true")) ? s++ : f++;
453 (set_display_dumpmode("on")) ? s++ : f++;
454 (set_display_dumpmode("off")) ? s++ : f++;
455 (set_display_savelog()) ? s++ : f++;
456 (set_display_powerkey_ignore(1)) ? s++ : f++; //not support, always success.
457 (set_display_powerkey_lcdoff()) ? s++ : f++; //not support, always success.
458 //(set_display_locktimeout_expired("auto_test")) ? s++ : f++;
459 //(set_display_locktimeout_input("auto_test", 1)) ? s++ : f++;
460 (set_display_actorcontrol("set", 4, 1<<3)) ? s++ : f++;
461 (set_display_actorcontrol("reset", 4, 1<<3)) ? s++ : f++;
462 (set_display_stop()) ? s++ : f++;
463 (set_display_start()) ? s++ : f++;
464 (set_display_state_by_reason(DISPLAY_STATE_SCREEN_OFF, PALM_STR, 0, __cb)) ? s++ : f++;
466 if (NULL != success) *success = s;
467 if (NULL != fail) *fail = f;
470 static void display_init(void *data)
477 display_test_all(&success, &fail);
479 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
482 static void display_exit(void *data)
488 static int display_unit(int argc, char **argv)
496 display_test_all(&success, &fail);
497 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
498 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_GETBRIGHTNESS)) {
499 get_display_brightness_state(DISPLAY_STATE_NORMAL, &brt);
500 get_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt);
501 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETBRIGHTNESS)) {
502 set_display_brightness_state(DISPLAY_STATE_NORMAL, 100);
503 set_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, 1);
504 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_GETMAXBRIGHTNESS)) {
505 get_display_max_brightness_state(DISPLAY_STATE_NORMAL, &brt);
506 get_display_max_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt);
507 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETMAXBRIGHTNESS)) {
508 set_display_maxbrightness(atoi(argv[4]));
509 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_HOLDBRIGHTNESS)) {
510 set_display_holdbrightness(atoi(argv[4]));
511 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_RELEASEBRIGHTNESS)) {
512 set_display_releasebrightness();
513 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_CUSTOMBRIGHTNESS)) {
514 get_display_custombrightness();
515 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETAUTOBRIGHTNESSMIN)) {
516 set_display_autobrightness_min(atoi(argv[4]));
517 // } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETREFRESHRATE)) {
518 // set_display_refreshrate(atoi(argv[4]), atoi(argv[5]));
519 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_GETDISPLAYCOUNT)) {
521 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_CHANGESTATE)) {
522 set_display_changestate(argv[4]);
523 // } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_LOCKSTATE_NOPT)) {
524 // set_display_lockstate_nopt(argv[4], argv[5], argv[6], atoi(argv[7]));
525 // } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_UNLOCKSTATE)) {
526 // set_display_lockstate_nopt(argv[4], argv[5]);
527 } else if (0 == strcasecmp(argv[3], METHOD_CHANGE_STATE_BY_REASON)) {
528 set_display_state_by_reason(DISPLAY_STATE_SCREEN_OFF, PALM_STR, 0, __cb);
529 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETLCDTIMEOUT)) {
530 set_display_lcdtimeout(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]));
531 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_CUSTOMLCDON)) {
532 set_display_customlcdon(atoi(argv[4]));
533 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_LCDPANEL_OFFMODE)) {
534 set_display_lcdpanel_offmode(atoi(argv[4]));
535 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_STAYTOUCHSCREEN_OFF)) {
536 set_display_staytouchscreen_off(atoi(argv[4]));
537 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_LOCKSCREENBGON)) {
538 set_display_lockscreen_bg_on(argv[4]);
539 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_DUMPMODE)) {
540 set_display_dumpmode(argv[4]);
541 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SAVELOG)) {
542 set_display_savelog();
543 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_POWERKEY_IGNORE)) {
544 set_display_powerkey_ignore(atoi(argv[4]));
545 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_POWERKEY_LCDOFF)) {
546 set_display_powerkey_lcdoff();
547 // } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_LOCKTIMEOUT_EXPIRED)) {
548 // set_display_locktimeout_expired(argv[4]);
549 // } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_LOCKTIMEOUT_INPUT)) {
550 // set_display_locktimeout_input(argv[4], atoi(argv[4]));
551 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_ACTORCONTROL)) {
552 set_display_actorcontrol(argv[4], atoi(argv[5]), atoi(argv[6]));
553 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_START)) {
555 } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_STOP)) {
558 _E("Unknown test case!!!");
564 static const struct test_ops display_test_ops = {
565 .priority = TEST_PRIORITY_NORMAL,
567 .init = display_init,
568 .exit = display_exit,
569 .unit = display_unit,
572 TEST_OPS_REGISTER(&display_test_ops)