2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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 * @file FShell_LockManagerImpl.cpp
19 * @brief This is the implementation for the _LockManagerImpl class.
22 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
27 #include <FShell_LockManagerImpl.h>
28 #include <FShell_LockManagerProxy.h>
30 namespace Tizen { namespace Shell
33 #define VCONFKEY_IDLE_LOCK_STATE "memory/idle_lock/state"
34 #define VCONFKEY_SETAPPL_PREFIX "db/setting"
35 #define VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT VCONFKEY_SETAPPL_PREFIX"/screen_lock_type"
39 VCONFKEY_IDLE_UNLOCK = 0x00,
45 SETTING_SCREEN_LOCK_TYPE_SWIPE = 0,
46 SETTING_SCREEN_LOCK_TYPE_MOTION,
47 SETTING_SCREEN_LOCK_TYPE_FACE_AND_VOICE,
48 SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD,
49 SETTING_SCREEN_LOCK_TYPE_PASSWORD,
50 SETTING_SCREEN_LOCK_TYPE_OTHER,
51 SETTING_SCREEN_LOCK_TYPE_MAX
55 _LockManagerImpl* _LockManagerImpl::__pTheInstance = null;
57 _LockManagerImpl::_LockManagerImpl(void)
61 _LockManagerImpl::~_LockManagerImpl(void)
66 _LockManagerImpl::InitSingleton(void)
68 std::unique_ptr<_LockManagerImpl> pInst(new (std::nothrow) _LockManagerImpl());
69 SysTryReturnVoidResult(NID_SHELL, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
71 result r = pInst->Construct();
72 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
74 __pTheInstance = pInst.release();
75 std::atexit(DestroySingleton);
79 _LockManagerImpl::DestroySingleton(void)
81 delete __pTheInstance;
85 _LockManagerImpl::GetInstance(void)
87 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
88 if (__pTheInstance == null)
91 pthread_once(&onceBlock, InitSingleton);
92 result r = GetLastResult();
95 onceBlock = PTHREAD_ONCE_INIT;
98 return __pTheInstance;
102 _LockManagerImpl::Construct(void)
108 _LockManagerImpl::IsLocked(void) const
110 int idleLockState = 0;
111 vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &idleLockState);
112 return (idleLockState == VCONFKEY_IDLE_LOCK);
116 _LockManagerImpl::IsSecureMode(void) const
118 int screenLockType = 0;
119 vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &screenLockType);
121 switch(screenLockType)
123 case SETTING_SCREEN_LOCK_TYPE_SWIPE:
124 case SETTING_SCREEN_LOCK_TYPE_MOTION:
127 case SETTING_SCREEN_LOCK_TYPE_FACE_AND_VOICE:
128 case SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD:
129 case SETTING_SCREEN_LOCK_TYPE_PASSWORD:
130 case SETTING_SCREEN_LOCK_TYPE_OTHER:
141 _LockManagerImpl::Unlock(void)
143 if( IsLocked() == false )
148 _LockManagerProxy* pLockManagerProxy = _LockManagerProxy::GetInstance();
149 SysTryReturnResult(NID_SHELL, pLockManagerProxy, E_SYSTEM, "Failed to _LockManagerProxy::GetInstance()!");
151 return pLockManagerProxy->Unlock();