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 "mock_bundle_manager.h"
17 #include "ability_config.h"
18 #include "ability_info.h"
19 #include "application_info.h"
20 #include "hilog_wrapper.h"
21
22 using namespace OHOS::AAFwk;
23
24 namespace OHOS {
25 namespace AppExecFwk {
BundleMgrService()26 BundleMgrService::BundleMgrService()
27 {}
28
~BundleMgrService()29 BundleMgrService::~BundleMgrService()
30 {}
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int BundleMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
33 {
34 (void)code;
35 (void)data;
36 (void)reply;
37 (void)option;
38 return 0;
39 }
40
GetBundleInfo(const std::string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo,int32_t userId)41 bool BundleMgrService::GetBundleInfo(
42 const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId)
43 {
44 (void)bundleName;
45 (void)flag;
46 (void)bundleInfo;
47 (void)userId;
48 return true;
49 }
50
QueryAbilityInfo(const AAFwk::Want & want,AbilityInfo & abilityInfo)51 bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want& want, AbilityInfo& abilityInfo)
52 {
53 HILOG_DEBUG(" mock BundleMgrService QueryAbilityInfo ------------ start");
54 if (CheckWantEntity(want, abilityInfo)) {
55 HILOG_DEBUG(" mock BundleMgrService CheckWantEntity true ------------ start");
56 return true;
57 }
58
59 ElementName elementTemp = want.GetElement();
60 std::string abilityNameTemp = elementTemp.GetAbilityName();
61 std::string bundleNameTemp = elementTemp.GetBundleName();
62 abilityInfo.deviceId = elementTemp.GetDeviceID();
63
64 if (bundleNameTemp.empty() || abilityNameTemp.empty()) {
65 return false;
66 }
67
68 auto fun = abilityInfoMap_.find(bundleNameTemp);
69 if (fun != abilityInfoMap_.end()) {
70 auto call = fun->second;
71 if (call) {
72 call(bundleNameTemp, abilityInfo, elementTemp);
73 return true;
74 }
75 }
76 if (std::string::npos != elementTemp.GetBundleName().find("service")) {
77 abilityInfo.type = AppExecFwk::AbilityType::SERVICE;
78 }
79 abilityInfo.name = elementTemp.GetAbilityName();
80 abilityInfo.bundleName = elementTemp.GetBundleName();
81 abilityInfo.applicationName = elementTemp.GetBundleName();
82 abilityInfo.deviceId = elementTemp.GetDeviceID();
83 abilityInfo.applicationInfo.bundleName = elementTemp.GetBundleName();
84 abilityInfo.applicationInfo.name = "hello";
85 if (want.HasEntity(Want::ENTITY_HOME) && want.GetAction() == Want::ACTION_HOME) {
86 abilityInfo.applicationInfo.isLauncherApp = true;
87 } else {
88 abilityInfo.applicationInfo.isLauncherApp = false;
89 abilityInfo.applicationInfo.iconPath = "icon path";
90 abilityInfo.applicationInfo.label = "app label";
91 }
92 HILOG_DEBUG(" mock BundleMgrService QueryAbilityInfo ------------ end");
93 return true;
94 }
95
QueryAbilityInfo(const Want & want,int32_t flags,int32_t userId,AbilityInfo & abilityInfo)96 bool BundleMgrService::QueryAbilityInfo(const Want& want, int32_t flags, int32_t userId, AbilityInfo& abilityInfo)
97 {
98 (void)want;
99 (void)flags;
100 (void)userId;
101 (void)abilityInfo;
102 return true;
103 }
104
GetUidByBundleName(const std::string & bundleName,const int userId)105 int BundleMgrService::GetUidByBundleName(const std::string& bundleName, const int userId)
106 {
107 (void)bundleName;
108 (void)userId;
109 return 0;
110 }
111
CheckIsSystemAppByUid(const int uid)112 bool BundleMgrService::CheckIsSystemAppByUid(const int uid)
113 {
114 (void)uid;
115 return true;
116 }
117
QueryAbilityInfoByUri(const std::string & uri,AbilityInfo & abilityInfo)118 bool BundleMgrService::QueryAbilityInfoByUri(const std::string& uri, AbilityInfo& abilityInfo)
119 {
120 (void)uri;
121 (void)abilityInfo;
122 return false;
123 }
124
GetApplicationInfo(const std::string & appName,const ApplicationFlag flag,const int userId,ApplicationInfo & appInfo)125 bool BundleMgrService::GetApplicationInfo(
126 const std::string& appName, const ApplicationFlag flag, const int userId, ApplicationInfo& appInfo)
127 {
128 (void)flag;
129 (void)userId;
130 (void)appInfo;
131 if (appName.empty()) {
132 return false;
133 }
134 return true;
135 }
136
CheckWantEntity(const AAFwk::Want & want,AbilityInfo & abilityInfo)137 bool BundleMgrService::CheckWantEntity(const AAFwk::Want& want, AbilityInfo& abilityInfo)
138 {
139 (void)abilityInfo;
140 HILOG_DEBUG(" mock BundleMgrService QueryAbilityInfo CheckWantEntity ------------ start---------1");
141 auto entityVector = want.GetEntities();
142 ElementName element = want.GetElement();
143 if (entityVector.empty()) {
144 return false;
145 }
146
147 auto find = false;
148 HILOG_DEBUG(" mock BundleMgrService QueryAbilityInfo CheckWantEntity ------------ start---------2");
149 for (const auto& entity : entityVector) {
150 if (entity == Want::FLAG_HOME_INTENT_FROM_SYSTEM && element.GetAbilityName().empty() &&
151 element.GetBundleName().empty()) {
152 find = true;
153 break;
154 }
155 }
156 HILOG_DEBUG(" mock BundleMgrService QueryAbilityInfo CheckWantEntity ------------ start---------3");
157 auto bundleName = element.GetBundleName();
158 auto abilityName = element.GetAbilityName();
159 if (find || (bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME &&
160 (abilityName == AbilityConfig::SYSTEM_UI_STATUS_BAR ||
161 abilityName == AbilityConfig::SYSTEM_UI_NAVIGATION_BAR))) {
162 GTEST_LOG_(INFO) << "QueryAbilityInfo ++> system luncher, find :" << find;
163 HILOG_DEBUG(" mock BundleMgrService QueryAbilityInfo CheckWantEntity ------------ start-----4");
164 return true;
165 }
166 HILOG_DEBUG(" mock BundleMgrService QueryAbilityInfo CheckWantEntity ------------ start---------5");
167 return false;
168 }
169 } // namespace AppExecFwk
170 } // namespace OHOS
171