1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "unlock_screen_manager.h"
17 
18 #include "hilog_tag_wrapper.h"
19 #include "in_process_call_wrapper.h"
20 #include "parameters.h"
21 #include "permission_verification.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 namespace {
26 constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state";
27 }
28 
~UnlockScreenManager()29 UnlockScreenManager::~UnlockScreenManager() {}
30 
UnlockScreenManager()31 UnlockScreenManager::UnlockScreenManager() {}
32 
GetInstance()33 UnlockScreenManager &UnlockScreenManager::GetInstance()
34 {
35     static UnlockScreenManager instance;
36     return instance;
37 }
38 
UnlockScreen()39 bool UnlockScreenManager::UnlockScreen()
40 {
41     bool isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall();
42     bool isDeveloperMode = system::GetBoolParameter(DEVELOPER_MODE_STATE, false);
43     if (!isShellCall) {
44         TAG_LOGD(AAFwkTag::ABILITYMGR, "not aa start call, just start ability");
45         return true;
46     }
47     if (!isDeveloperMode) {
48         TAG_LOGD(AAFwkTag::ABILITYMGR, "not devlop mode, just start ability");
49         return true;
50     }
51 
52 #ifdef SUPPORT_GRAPHICS
53     bool isScreenLocked = OHOS::ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked();
54     bool isScreenSecured = OHOS::ScreenLock::ScreenLockManager::GetInstance()->GetSecure();
55     TAG_LOGD(AAFwkTag::ABILITYMGR, "isScreenLocked: %{public}d, isScreenSecured: %{public}d",
56         isScreenLocked, isScreenSecured);
57     if (isScreenLocked && isScreenSecured) {
58         return false;
59     }
60 #endif
61 
62 #ifdef SUPPORT_POWER
63     bool isScreenOn = PowerMgr::PowerMgrClient::GetInstance().IsScreenOn();
64     TAG_LOGD(AAFwkTag::ABILITYMGR, "isScreenOn: %{public}d", isScreenOn);
65     if (!isScreenOn) {
66         PowerMgr::PowerMgrClient::GetInstance().WakeupDevice();
67     }
68 #endif
69 
70 #ifdef SUPPORT_GRAPHICS
71     if (isScreenLocked) {
72         sptr<UnlockScreenCallback> listener = sptr<UnlockScreenCallback>(new (std::nothrow) UnlockScreenCallback());
73         IN_PROCESS_CALL(OHOS::ScreenLock::ScreenLockManager::GetInstance()->Unlock(
74             OHOS::ScreenLock::Action::UNLOCKSCREEN, listener));
75     }
76 #endif
77     return true;
78 }
79 } // namespace AbilityRuntime
80 } // namespace OHOS