2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <vconf-keys.h>
21 #include <glib-object.h>
28 #include <dd-deviced.h>
29 #include <dd-display.h>
31 #include <system_settings.h>
34 #include "package_mgr.h"
35 #include "process_mgr.h"
37 #include "dbus_util.h"
57 int lock_mgr_lcd_state_get(void)
59 return s_lock_mgr.lcd_state;
64 int lock_mgr_get_lock_pid(void)
66 return s_lock_mgr.lock_pid;
71 void lock_mgr_sound_play(lock_sound_type_e type)
73 int val = status_passive_get()->setappl_sound_lock_bool;
78 feedback_play_type(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_LOCK);
80 case LOCK_SOUND_UNLOCK:
81 feedback_play_type(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_UNLOCK);
83 case LOCK_SOUND_BTN_KEY:
84 feedback_play_type(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_SIP);
87 feedback_play_type(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP);
96 void lock_mgr_idle_lock_state_set(int lock_state)
98 _D("lock state : %d", lock_state);
102 ret = vconf_set_int(VCONFKEY_IDLE_LOCK_STATE, lock_state);
104 _E("Failed to set vconfkey : VCONFKEY_IDLE_LOCK_STATE");
107 ret = vconf_set_int(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, lock_state);
109 _E("Failed to set vconfkey : VCONFKEY_IDLE_LOCK_STATE_READ_ONLY");
115 static void _after_launch_lock(int pid)
117 int idle_lock_state = 0;
119 if (dbus_util_send_oomadj(pid, OOM_ADJ_VALUE_DEFAULT) < 0) {
120 _E("cannot send oomadj for pid[%d]", pid);
122 process_mgr_set_lock_priority(pid);
123 display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
124 s_lock_mgr.lock_pid = pid;
126 idle_lock_state = status_passive_get()->idle_lock_state;
127 if (idle_lock_state == VCONFKEY_IDLE_UNLOCK) {
128 lock_mgr_idle_lock_state_set(VCONFKEY_IDLE_LOCK);
129 lock_mgr_sound_play(LOCK_SOUND_LOCK);
135 static int _lock_changed_cb(const char *appid, const char *key, const char *value, void *cfn, void *afn)
144 static void _other_lockscreen_unlock(void)
146 _D("unlock other lock screen");
151 void lock_mgr_unlock(void)
153 int lock_type = status_active_get()->setappl_screen_lock_type_int;
154 _D("lock type(%d)", lock_type);
156 lock_mgr_idle_lock_state_set(VCONFKEY_IDLE_UNLOCK);
157 lock_mgr_sound_play(LOCK_SOUND_UNLOCK);
158 s_lock_mgr.lock_pid = 0;
160 if (lock_type == SETTING_SCREEN_LOCK_TYPE_OTHER) {
161 _other_lockscreen_unlock();
167 static void _on_lcd_changed_receive(void *data, DBusMessage *msg)
172 _D("LCD signal is received");
174 lcd_on = dbus_message_is_signal(msg, DEVICED_INTERFACE_DISPLAY, MEMBER_LCD_ON);
175 lcd_off = dbus_message_is_signal(msg, DEVICED_INTERFACE_DISPLAY, MEMBER_LCD_OFF);
179 s_lock_mgr.lcd_state = LCD_STATE_ON;
180 } else if (lcd_off) {
181 int idle_lock_state = 0;
182 Eina_Bool ret = EINA_FALSE;
183 s_lock_mgr.lcd_state = LCD_STATE_OFF;
185 idle_lock_state = status_passive_get()->idle_lock_state;
186 _D("idle_lock_state(%d)", idle_lock_state);
188 if (idle_lock_state == VCONFKEY_IDLE_UNLOCK) {
189 ret = lock_mgr_lockscreen_launch();
190 if (ret != EINA_TRUE) {
191 _E("Failed to launch lockscreen");
195 _E("%s dbus_message_is_signal error", DEVICED_INTERFACE_DISPLAY);
201 Eina_Bool lock_mgr_lockscreen_launch(void)
203 const char *lock_appid = NULL;
206 lock_type = status_active_get()->setappl_screen_lock_type_int;
207 _D("lock type : %d", lock_type);
209 //PM LOCK - don't go to sleep
210 display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
212 lock_appid = status_passive_get()->setappl_3rd_lock_pkg_name_str;
214 _E("set default lockscreen");
215 lock_appid = STATUS_DEFAULT_LOCK_PKG_NAME;
218 _I("lockscreen appid : %s", lock_appid);
221 case SETTING_SCREEN_LOCK_TYPE_NONE:
222 _D("Lockscreen type is NONE");
224 case SETTING_SCREEN_LOCK_TYPE_SWIPE:
225 case SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD:
226 case SETTING_SCREEN_LOCK_TYPE_PASSWORD:
227 case SETTING_SCREEN_LOCK_TYPE_OTHER:
228 process_mgr_must_launch(lock_appid, NULL, NULL, _lock_changed_cb, _after_launch_lock);
229 goto_if(s_lock_mgr.lock_pid < 0, ERROR);
232 _E("type error(%d)", lock_type);
236 _I("lock pid : %d", s_lock_mgr.lock_pid);
241 _E("Failed to launch lockscreen");
242 display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
248 static void _lock_daemon_init(void)
250 _SECURE_I("lockscreen : %s", status_passive_get()->setappl_3rd_lock_pkg_name_str);
252 /* register lcd changed cb */
253 dbus_util_receive_lcd_status(_on_lcd_changed_receive, NULL);
258 static int _lock_type_changed_cb(status_active_key_e key, void *data)
260 int lock_type = status_active_get()->setappl_screen_lock_type_int;
261 retv_if(lock_type == s_lock_mgr.old_lock_type, 1);
263 _D("lock type is changed : %d -> %d", s_lock_mgr.old_lock_type, lock_type);
265 s_lock_mgr.old_lock_type = lock_type;
271 int lock_mgr_daemon_start(void)
278 lock_type = status_active_get()->setappl_screen_lock_type_int;
279 _D("lock type : %d", lock_type);
281 status_active_register_cb(STATUS_ACTIVE_KEY_SETAPPL_SCREEN_LOCK_TYPE_INT, _lock_type_changed_cb, NULL);
283 ret = lock_mgr_lockscreen_launch();
284 if (ret != EINA_TRUE) {
285 _E("Failed to launch lockscreen");
288 if (feedback_initialize() != FEEDBACK_ERROR_NONE) {
289 _E("Failed to initialize feedback");
297 void lock_mgr_daemon_end(void)
299 status_active_unregister_cb(STATUS_ACTIVE_KEY_SETAPPL_SCREEN_LOCK_TYPE_INT, _lock_type_changed_cb);
301 feedback_deinitialize();