4 * Copyright (c) 2019 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.
22 #include "shared/common.h"
28 #define LOCK_STR_MAX 20
29 #define DISP_LOCK_STR "displock"
30 #define MAIN_LOCK_STR "mainlock"
31 #define DIM_LOCK_STR "dimlock"
33 #define USER_WAKELOCK_NODE "/sys/power/slave_wake_lock"
34 #define USER_WAKEUNLOCK_NODE "/sys/power/slave_wake_unlock"
36 static bool userlock_saving_support;
38 int save_pmlock(enum state_t state, bool on, pid_t pid)
41 char *node, *state_str;
42 char str[LOCK_STR_MAX];
44 if (!userlock_saving_support)
49 state_str = DISP_LOCK_STR;
52 state_str = DIM_LOCK_STR;
55 state_str = MAIN_LOCK_STR;
61 node = (on ? USER_WAKELOCK_NODE : USER_WAKEUNLOCK_NODE);
63 snprintf(str, LOCK_STR_MAX, "%s %d", state_str, pid);
65 ret = sys_set_str(node, str);
67 _E("Failed to set disp userlock state!");
72 void init_save_userlock(void)
77 userlock_saving_support = false;
79 ret = sys_get_str(USER_WAKELOCK_NODE, str, sizeof(str));
81 _E("Failed to load userlock(lock)!");
85 ret = sys_get_str(USER_WAKEUNLOCK_NODE, str, sizeof(str));
87 _E("Failed to load userlock(unlock)!");
91 userlock_saving_support = true;
92 _I("userlock-saving is enabled!");