1 /*
2 * Copyright (c) 2022 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 "ability_info.h"
17 #include "bundle_info.h"
18 #include "bundle_manager_helper.h"
19
20 #include "continuous_task_log.h"
21 #include "include/ibundle_manager_helper.h"
22
23 namespace OHOS {
24 namespace BackgroundTaskMgr {
25 namespace {
26 static constexpr char TEST_DEFAULT_BUNDLE[] = "bundleName";
27 static constexpr uint32_t ALL_NEED_CHECK_BGMODE = 62;
28 static constexpr uint64_t NO_SYSTEM_APP_TOKEN_ID = -100;
29 std::shared_ptr<IBundleManagerHelper> bundleManagerHelperMock;
30 }
31
BundleManagerHelper()32 BundleManagerHelper::BundleManagerHelper() {}
33
~BundleManagerHelper()34 BundleManagerHelper::~BundleManagerHelper() {}
35
SetBundleManagerHelper(std::shared_ptr<IBundleManagerHelper> mock)36 void SetBundleManagerHelper(std::shared_ptr<IBundleManagerHelper> mock)
37 {
38 bundleManagerHelperMock = mock;
39 }
40
CleanBundleManagerHelper()41 void CleanBundleManagerHelper()
42 {
43 bundleManagerHelperMock.reset();
44 }
45
GetApplicationInfo(const std::string & appName,const AppExecFwk::ApplicationFlag flag,const int userId,AppExecFwk::ApplicationInfo & appInfo)46 bool BundleManagerHelper::GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag,
47 const int userId, AppExecFwk::ApplicationInfo &appInfo)
48 {
49 bool ret {true};
50 if (bundleManagerHelperMock) {
51 ret = bundleManagerHelperMock->GetApplicationInfo(appName, flag, userId, appInfo);
52 } else {
53 appInfo.resourcesApply = { 0 };
54 }
55 return ret;
56 }
57
GetClientBundleName(int32_t uid)58 std::string BundleManagerHelper::GetClientBundleName(int32_t uid)
59 {
60 return TEST_DEFAULT_BUNDLE;
61 }
62
CheckPermission(const std::string & permission)63 bool BundleManagerHelper::CheckPermission(const std::string &permission)
64 {
65 return true;
66 }
67
CheckACLPermission(const std::string & permission,uint64_t callingTokenId)68 bool BundleManagerHelper::CheckACLPermission(const std::string &permission, uint64_t callingTokenId)
69 {
70 return true;
71 }
72
IsSystemApp(uint64_t fullTokenId)73 bool BundleManagerHelper::IsSystemApp(uint64_t fullTokenId)
74 {
75 if (fullTokenId == NO_SYSTEM_APP_TOKEN_ID) {
76 return false;
77 }
78 return true;
79 }
80
GetBundleInfo(const std::string & bundleName,const AppExecFwk::BundleFlag flag,AppExecFwk::BundleInfo & bundleInfo,int32_t userId)81 bool BundleManagerHelper::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag,
82 AppExecFwk::BundleInfo &bundleInfo, int32_t userId)
83 {
84 if (bundleName == "false-test") {
85 return false;
86 }
87 if (bundleName == "empty-info") {
88 AppExecFwk::AbilityInfo abilityInfo;
89 abilityInfo.backgroundModes = 0;
90 bundleInfo.abilityInfos.emplace_back(abilityInfo);
91 return true;
92 }
93 AppExecFwk::AbilityInfo abilityInfo;
94 abilityInfo.name = "ability1";
95 abilityInfo.backgroundModes = ALL_NEED_CHECK_BGMODE;
96 bundleInfo.abilityInfos.emplace_back(abilityInfo);
97 bundleInfo.name = TEST_DEFAULT_BUNDLE;
98 return true;
99 }
100
QueryAbilityInfo(const AAFwk::Want & want,int32_t flags,int32_t userId,AppExecFwk::AbilityInfo & abilityInfo)101 bool BundleManagerHelper::QueryAbilityInfo(const AAFwk::Want &want, int32_t flags, int32_t userId,
102 AppExecFwk::AbilityInfo &abilityInfo)
103 {
104 abilityInfo.labelId = 1;
105 abilityInfo.label = "ability";
106 return true;
107 }
108
GetBundleResourceInfo(const std::string & bundleName,const AppExecFwk::ResourceFlag flags,AppExecFwk::BundleResourceInfo & bundleResourceInfo)109 bool BundleManagerHelper::GetBundleResourceInfo(const std::string &bundleName, const AppExecFwk::ResourceFlag flags,
110 AppExecFwk::BundleResourceInfo &bundleResourceInfo)
111 {
112 bundleResourceInfo.label = "label";
113 return true;
114 }
115
Connect()116 bool BundleManagerHelper::Connect()
117 {
118 return true;
119 }
120
Disconnect()121 void BundleManagerHelper::Disconnect() {}
122
OnRemoteDied(const wptr<IRemoteObject> & object)123 void BundleManagerHelper::OnRemoteDied(const wptr<IRemoteObject> &object) {}
124 } // namespace BackgroundTaskMgr
125 } // namespace OHOS