• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 "extension_config.h"
20 #include "event_report.h"
21 #include "parameters.h"
22 #include "start_ability_utils.h"
23 #include "startup_util.h"
24 #ifdef SUPPORT_SCREEN
25 #ifdef ABILITY_RUNTIME_SCREENLOCK_ENABLE
26 #include "screenlock_manager.h"
27 #endif // ABILITY_RUNTIME_SCREENLOCK_ENABLE
28 #endif
29 
30 namespace OHOS {
31 namespace AAFwk {
DoProcess(AbilityInterceptorParam param)32 ErrCode ScreenUnlockInterceptor::DoProcess(AbilityInterceptorParam param)
33 {
34     // get target application info
35     AppExecFwk::AbilityInfo targetAbilityInfo;
36     if (StartAbilityUtils::startAbilityInfo != nullptr) {
37         targetAbilityInfo = StartAbilityUtils::startAbilityInfo->abilityInfo;
38     } else {
39         QueryTargetAbilityInfo(param, targetAbilityInfo);
40         if (targetAbilityInfo.applicationInfo.name.empty() ||
41             targetAbilityInfo.applicationInfo.bundleName.empty()) {
42             TAG_LOGD(AAFwkTag::ABILITYMGR, "Cannot find targetAbilityInfo, element uri: %{public}s",
43                 param.want.GetElement().GetURI().c_str());
44             return ERR_OK;
45         }
46     }
47     if (targetAbilityInfo.applicationInfo.allowAppRunWhenDeviceFirstLocked) {
48         return ERR_OK;
49     }
50 #ifdef SUPPORT_SCREEN
51 #ifdef ABILITY_RUNTIME_SCREENLOCK_ENABLE
52     if (!OHOS::ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked()) {
53         return ERR_OK;
54     }
55 #endif // ABILITY_RUNTIME_SCREENLOCK_ENABLE
56 #endif
57     if (targetAbilityInfo.applicationInfo.isSystemApp &&
58         targetAbilityInfo.type != AppExecFwk::AbilityType::EXTENSION) {
59         EventInfo eventInfo;
60         eventInfo.bundleName = targetAbilityInfo.applicationInfo.bundleName;
61         eventInfo.moduleName = "StartScreenUnlock";
62         EventReport::SendStartAbilityOtherExtensionEvent(EventName::START_ABILITY_OTHER_EXTENSION, eventInfo);
63         return ERR_OK;
64     }
65     if (targetAbilityInfo.type == AppExecFwk::AbilityType::EXTENSION &&
66         !DelayedSingleton<ExtensionConfig>::GetInstance()->IsScreenUnlockIntercept(
67             targetAbilityInfo.extensionTypeName, targetAbilityInfo.applicationInfo.isSystemApp)) {
68         return ERR_OK;
69     }
70     TAG_LOGE(AAFwkTag::ABILITYMGR, "no startup before device first unlock");
71     return ERR_BLOCK_START_FIRST_BOOT_SCREEN_UNLOCK;
72 }
73 
QueryTargetAbilityInfo(const AbilityInterceptorParam & param,AppExecFwk::AbilityInfo & targetAbilityInfo)74 void ScreenUnlockInterceptor::QueryTargetAbilityInfo(const AbilityInterceptorParam &param,
75     AppExecFwk::AbilityInfo &targetAbilityInfo)
76 {
77     auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
78     if (bundleMgrHelper == nullptr) {
79         TAG_LOGD(AAFwkTag::ABILITYMGR, "The bundleMgrHelper is nullptr.");
80         return;
81     }
82     IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->QueryAbilityInfo(param.want,
83         AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, param.userId, targetAbilityInfo));
84     if (!targetAbilityInfo.applicationInfo.name.empty() && !targetAbilityInfo.applicationInfo.bundleName.empty()) {
85         return;
86     }
87 
88     std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
89     IN_PROCESS_CALL(bundleMgrHelper->QueryExtensionAbilityInfos(param.want,
90         AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, param.userId, extensionInfos));
91     if (extensionInfos.size() <= 0) {
92         TAG_LOGD(AAFwkTag::ABILITYMGR, "extensionInfo empty");
93         return;
94     }
95     AbilityRuntime::StartupUtil::InitAbilityInfoFromExtension(extensionInfos.front(), targetAbilityInfo);
96 }
97 } // namespace AAFwk
98 } // namespace OHOS