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 "interceptor/screen_unlock_interceptor.h"
17
18 #include "ability_util.h"
19 #include "parameters.h"
20 #include "start_ability_utils.h"
21 #ifdef SUPPORT_SCREEN
22 #include "screenlock_manager.h"
23 #endif
24
25 namespace OHOS {
26 namespace AAFwk {
27 namespace {
28 constexpr const char* SUPPORT_SCREEN_UNLOCK_STARTUP = "persist.sys.ability.support.screen_unlock_startup";
29 }
DoProcess(AbilityInterceptorParam param)30 ErrCode ScreenUnlockInterceptor::DoProcess(AbilityInterceptorParam param)
31 {
32 // xts reboot can still run
33 std::string supportStart = OHOS::system::GetParameter(SUPPORT_SCREEN_UNLOCK_STARTUP, "false");
34 if (supportStart == "true") {
35 TAG_LOGD(AAFwkTag::ABILITYMGR, "Abilityms support screen unlock startup.");
36 return ERR_OK;
37 }
38 // get target application info
39 AppExecFwk::AbilityInfo targetAbilityInfo;
40 if (StartAbilityUtils::startAbilityInfo != nullptr) {
41 targetAbilityInfo = StartAbilityUtils::startAbilityInfo->abilityInfo;
42 } else {
43 auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
44 if (bundleMgrHelper == nullptr) {
45 TAG_LOGD(AAFwkTag::ABILITYMGR, "The bundleMgrHelper is nullptr.");
46 return ERR_OK;
47 }
48 IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->QueryAbilityInfo(param.want,
49 AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, param.userId, targetAbilityInfo));
50 if (targetAbilityInfo.applicationInfo.name.empty() ||
51 targetAbilityInfo.applicationInfo.bundleName.empty()) {
52 TAG_LOGD(AAFwkTag::ABILITYMGR, "Cannot find targetAbilityInfo, element uri: %{public}s",
53 param.want.GetElement().GetURI().c_str());
54 return ERR_OK;
55 }
56 }
57
58 // temp add isSystemApp pass, remove after systemapp adjust
59 if (targetAbilityInfo.applicationInfo.isSystemApp ||
60 targetAbilityInfo.applicationInfo.allowAppRunWhenDeviceFirstLocked) {
61 return ERR_OK;
62 }
63 #ifdef SUPPORT_SCREEN
64 if (!OHOS::ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked()) {
65 return ERR_OK;
66 }
67 #endif
68 TAG_LOGE(AAFwkTag::ABILITYMGR, "Can not startup when device first locked.");
69 return ERR_BLOCK_START_FIRST_BOOT_SCREEN_UNLOCK;
70 }
71 } // namespace AAFwk
72 } // namespace OHOS