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 #ifdef SUPPORT_SCREEN
54     bool isScreenLocked = OHOS::ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked();
55     bool isScreenSecured = OHOS::ScreenLock::ScreenLockManager::GetInstance()->GetSecure();
56     TAG_LOGD(AAFwkTag::ABILITYMGR, "isScreenLocked: %{public}d, isScreenSecured: %{public}d",
57         isScreenLocked, isScreenSecured);
58     if (isScreenLocked && isScreenSecured) {
59         return false;
60     }
61 #endif
62 #endif
63 
64     TAG_LOGI(AAFwkTag::ABILITYMGR, "UnlockScreen begin");
65 #ifdef SUPPORT_POWER
66     bool isScreenOn = PowerMgr::PowerMgrClient::GetInstance().IsScreenOn();
67     TAG_LOGD(AAFwkTag::ABILITYMGR, "isScreenOn: %{public}d", isScreenOn);
68     if (!isScreenOn) {
69         PowerMgr::PowerMgrClient::GetInstance().WakeupDevice();
70     }
71 #endif
72 
73 #ifdef SUPPORT_GRAPHICS
74     if (isScreenLocked) {
75         sptr<UnlockScreenCallback> listener = sptr<UnlockScreenCallback>(new (std::nothrow) UnlockScreenCallback());
76         IN_PROCESS_CALL(OHOS::ScreenLock::ScreenLockManager::GetInstance()->Unlock(
77             OHOS::ScreenLock::Action::UNLOCKSCREEN, listener));
78     }
79 #endif
80     TAG_LOGI(AAFwkTag::ABILITYMGR, "UnlockScreen end");
81     return true;
82 }
83 } // namespace AbilityRuntime
84 } // namespace OHOS