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