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 "mock_ability_manager_service.h"
17
18 #include "ability_manager_errors.h"
19 #include "app_utils.h"
20 #include "hilog_tag_wrapper.h"
21 #include "permission_verification.h"
22 #include "process_options.h"
23
24 namespace OHOS {
25 namespace AAFwk {
CheckProcessOptions(const Want & want,const StartOptions & startOptions,int32_t userId)26 int32_t AbilityManagerService::CheckProcessOptions(const Want &want, const StartOptions &startOptions, int32_t userId)
27 {
28 if (startOptions.processOptions == nullptr ||
29 !ProcessOptions::IsValidProcessMode(startOptions.processOptions->processMode)) {
30 return ERR_OK;
31 }
32
33 TAG_LOGI(AAFwkTag::ABILITYMGR, "start ability with process options");
34
35 bool isStartupVisibilityHide =
36 (startOptions.processOptions->startupVisibility == StartupVisibility::STARTUP_HIDE);
37 bool hasStartBackgroundAbilityPermission = PermissionVerification::GetInstance()->
38 VerifyStartUIAbilityToHiddenPermission();
39 bool canStartupHide = (ProcessOptions::IsNoAttachmentMode(startOptions.processOptions->processMode) &&
40 isStartupVisibilityHide && hasStartBackgroundAbilityPermission);
41 if (!canStartupHide) {
42 TAG_LOGE(AAFwkTag::ABILITYMGR, "not self application and has no start background ability permission");
43 return ERR_NOT_SELF_APPLICATION;
44 }
45
46 return ERR_OK;
47 }
48
BlockAllAppStart(bool flag)49 int32_t AbilityManagerService::BlockAllAppStart(bool flag)
50 {
51 TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
52
53 if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) {
54 TAG_LOGE(AAFwkTag::ABILITYMGR, "not supported device");
55 return ERR_PERMISSION_DENIED;
56 }
57
58 if (!PermissionVerification::GetInstance()->VerifyBlockAllAppStartPermission()) {
59 TAG_LOGE(AAFwkTag::ABILITYMGR, "Permission verification failed");
60 return ERR_PERMISSION_DENIED;
61 }
62
63 std::unique_lock<ffrt::mutex> lock(shouldBlockAllAppStartMutex_);
64 shouldBlockAllAppStart_ = flag;
65 return ERR_OK;
66 }
67
ShouldBlockAllAppStart()68 bool AbilityManagerService::ShouldBlockAllAppStart()
69 {
70 if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) {
71 return false;
72 }
73
74 std::unique_lock<ffrt::mutex> lock(shouldBlockAllAppStartMutex_);
75 return shouldBlockAllAppStart_;
76 }
77 } // namespace AAFwk
78 } // namespace OHOS
79