• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "bundle_manager_internal_mock.h"
17 
18 using namespace std;
19 using namespace OHOS;
20 using namespace OHOS::DistributedSchedule;
21 
22 IMPLEMENT_SINGLE_INSTANCE(BundleManagerInternal);
23 
GetCallerAppIdFromBms(int32_t callingUid,std::string & appId)24 bool BundleManagerInternal::GetCallerAppIdFromBms(int32_t callingUid, std::string& appId)
25 {
26     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
27         return false;
28     }
29     return IBundleManagerInternal::bundleMgrMock->GetCallerAppIdFromBms(callingUid, appId);
30 }
31 
GetCallerAppIdFromBms(const std::string & bundleName,std::string & appId)32 bool BundleManagerInternal::GetCallerAppIdFromBms(const std::string& bundleName, std::string& appId)
33 {
34     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
35         return false;
36     }
37     return IBundleManagerInternal::bundleMgrMock->GetCallerAppIdFromBms(bundleName, appId);
38 }
39 
GetSpecifyBundleNameFromBms(int32_t callingUid,std::string & bundleName)40 bool BundleManagerInternal::GetSpecifyBundleNameFromBms(int32_t callingUid, std::string& bundleName)
41 {
42     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
43         return false;
44     }
45     return IBundleManagerInternal::bundleMgrMock->GetSpecifyBundleNameFromBms(callingUid, bundleName);
46 }
47 
GetBundleNameListFromBms(int32_t callingUid,std::vector<std::string> & bundleNameList)48 bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid, std::vector<std::string>& bundleNameList)
49 {
50     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
51         return false;
52     }
53     return IBundleManagerInternal::bundleMgrMock->GetBundleNameListFromBms(callingUid, bundleNameList);
54 }
55 
GetBundleNameListFromBms(int32_t callingUid,std::vector<std::u16string> & u16BundleNameList)56 bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid,
57     std::vector<std::u16string>& u16BundleNameList)
58 {
59     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
60         return false;
61     }
62     return IBundleManagerInternal::bundleMgrMock->GetBundleNameListFromBms(callingUid, u16BundleNameList);
63 }
64 
QueryAbilityInfo(const AAFwk::Want & want,AppExecFwk::AbilityInfo & abilityInfo)65 bool BundleManagerInternal::QueryAbilityInfo(const AAFwk::Want& want, AppExecFwk::AbilityInfo& abilityInfo)
66 {
67     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
68         return false;
69     }
70     return IBundleManagerInternal::bundleMgrMock->QueryAbilityInfo(want, abilityInfo);
71 }
72 
QueryExtensionAbilityInfo(const AAFwk::Want & want,AppExecFwk::ExtensionAbilityInfo & extensionInfo)73 bool BundleManagerInternal::QueryExtensionAbilityInfo(const AAFwk::Want& want,
74     AppExecFwk::ExtensionAbilityInfo& extensionInfo)
75 {
76     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
77         return false;
78     }
79     return IBundleManagerInternal::bundleMgrMock->QueryExtensionAbilityInfo(want, extensionInfo);
80 }
81 
InitAbilityInfoFromExtension(const AppExecFwk::ExtensionAbilityInfo & extensionAbilityInfo,AppExecFwk::AbilityInfo & abilityInfo)82 void BundleManagerInternal::InitAbilityInfoFromExtension(const AppExecFwk::ExtensionAbilityInfo &extensionAbilityInfo,
83     AppExecFwk::AbilityInfo &abilityInfo)
84 {
85     abilityInfo.bundleName = extensionAbilityInfo.bundleName;
86     abilityInfo.name = extensionAbilityInfo.name;
87     abilityInfo.permissions = extensionAbilityInfo.permissions;
88     abilityInfo.visible = extensionAbilityInfo.visible;
89 }
90 
IsSameAppId(const std::string & callerAppId,const std::string & targetBundleName)91 bool BundleManagerInternal::IsSameAppId(const std::string& callerAppId, const std::string& targetBundleName)
92 {
93     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
94         return false;
95     }
96     return IBundleManagerInternal::bundleMgrMock->IsSameAppId(callerAppId, targetBundleName);
97 }
98 
IsSameDeveloperId(const std::string & bundleNameInCurrentSide,const std::string & developerId4OtherSide)99 bool BundleManagerInternal::IsSameDeveloperId(const std::string &bundleNameInCurrentSide,
100     const std::string &developerId4OtherSide)
101 {
102     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
103         return false;
104     }
105     return IBundleManagerInternal::bundleMgrMock->IsSameDeveloperId(bundleNameInCurrentSide, developerId4OtherSide);
106 }
107 
GetLocalBundleInfo(const std::string & bundleName,AppExecFwk::BundleInfo & localBundleInfo)108 int32_t BundleManagerInternal::GetLocalBundleInfo(const std::string& bundleName,
109     AppExecFwk::BundleInfo &localBundleInfo)
110 {
111     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
112         return ERR_OK;
113     }
114     return IBundleManagerInternal::bundleMgrMock->GetLocalBundleInfo(bundleName, localBundleInfo);
115 }
116 
GetLocalBundleInfoV9(const std::string & bundleName,AppExecFwk::BundleInfo & bundleInfo)117 int32_t BundleManagerInternal::GetLocalBundleInfoV9(const std::string& bundleName,
118     AppExecFwk::BundleInfo &bundleInfo)
119 {
120     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
121         return ERR_OK;
122     }
123     return IBundleManagerInternal::bundleMgrMock->GetLocalBundleInfoV9(bundleName, bundleInfo);
124 }
125 
GetLocalAbilityInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,AppExecFwk::AbilityInfo & abilityInfo)126 int32_t BundleManagerInternal::GetLocalAbilityInfo(const std::string& bundleName,
127     const std::string& moduleName, const std::string& abilityName, AppExecFwk::AbilityInfo &abilityInfo)
128 {
129     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
130         return ERR_OK;
131     }
132     return IBundleManagerInternal::bundleMgrMock->GetLocalAbilityInfo(bundleName, moduleName, abilityName, abilityInfo);
133 }
134 
GetContinueBundle4Src(const std::string & srcBundleName,std::vector<std::string> & bundleNameList)135 bool BundleManagerInternal::GetContinueBundle4Src(const std::string &srcBundleName,
136     std::vector<std::string> &bundleNameList)
137 {
138     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
139         return false;
140     }
141     return IBundleManagerInternal::bundleMgrMock->GetContinueBundle4Src(srcBundleName, bundleNameList);
142 }
143 
GetAppProvisionInfo4CurrentUser(const std::string & bundleName,AppExecFwk::AppProvisionInfo & appProvisionInfo)144 bool BundleManagerInternal::GetAppProvisionInfo4CurrentUser(const std::string &bundleName,
145     AppExecFwk::AppProvisionInfo &appProvisionInfo)
146 {
147     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
148         return false;
149     }
150     return IBundleManagerInternal::bundleMgrMock->GetAppProvisionInfo4CurrentUser(bundleName, appProvisionInfo);
151 }
152 
CheckRemoteBundleInfoForContinuation(const std::string & dstDeviceId,const std::string & bundleName,AppExecFwk::DistributedBundleInfo & remoteBundleInfo)153 int32_t BundleManagerInternal::CheckRemoteBundleInfoForContinuation(const std::string& dstDeviceId,
154     const std::string& bundleName, AppExecFwk::DistributedBundleInfo& remoteBundleInfo)
155 {
156     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
157         return ERR_OK;
158     }
159     return IBundleManagerInternal::bundleMgrMock->CheckRemoteBundleInfoForContinuation(dstDeviceId, bundleName,
160         remoteBundleInfo);
161 }
162 
GetBundleManager()163 sptr<AppExecFwk::IBundleMgr> BundleManagerInternal::GetBundleManager()
164 {
165     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
166         return nullptr;
167     }
168     return IBundleManagerInternal::bundleMgrMock->GetBundleManager();
169 }
170 
GetDistributedBundleManager()171 sptr<AppExecFwk::IDistributedBms> BundleManagerInternal::GetDistributedBundleManager()
172 {
173     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
174         return nullptr;
175     }
176     return IBundleManagerInternal::bundleMgrMock->GetDistributedBundleManager();
177 }
178 
GetUidFromBms(const std::string & bundleName)179 int32_t BundleManagerInternal::GetUidFromBms(const std::string& bundleName)
180 {
181     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
182         return ERR_OK;
183     }
184     return IBundleManagerInternal::bundleMgrMock->GetUidFromBms(bundleName);
185 }
186 
GetContinueType(const std::string & networkId,std::string & bundleName,uint8_t continueTypeId)187 std::string BundleManagerInternal::GetContinueType(const std::string &networkId,
188     std::string &bundleName, uint8_t continueTypeId)
189 {
190     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
191         return "";
192     }
193     return IBundleManagerInternal::bundleMgrMock->GetContinueType(networkId, bundleName,
194         continueTypeId);
195 }
196 
GetContinueTypeId(const std::string & bundleName,const std::string & abilityName,uint8_t & continueTypeId)197 int32_t BundleManagerInternal::GetContinueTypeId(const std::string &bundleName,
198     const std::string &abilityName, uint8_t &continueTypeId)
199 {
200     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
201         return ERR_OK;
202     }
203     return IBundleManagerInternal::bundleMgrMock->GetContinueTypeId(bundleName, abilityName, continueTypeId);
204 }
205 
GetBundleNameById(const std::string & networkId,const uint16_t & bundleNameId,std::string & bundleName)206 int32_t BundleManagerInternal::GetBundleNameById(const std::string& networkId,
207     const uint16_t& bundleNameId, std::string& bundleName)
208 {
209     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
210         return ERR_OK;
211     }
212     return IBundleManagerInternal::bundleMgrMock->GetBundleNameById(networkId, bundleNameId, bundleName);
213 }
214 
GetApplicationInfoFromBms(const std::string & bundleName,const AppExecFwk::BundleFlag flag,const int32_t userId,AppExecFwk::ApplicationInfo & appInfo)215 int32_t BundleManagerInternal::GetApplicationInfoFromBms(const std::string& bundleName,
216     const AppExecFwk::BundleFlag flag, const int32_t userId, AppExecFwk::ApplicationInfo &appInfo)
217 {
218     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
219         return ERR_OK;
220     }
221     return IBundleManagerInternal::bundleMgrMock->GetApplicationInfoFromBms(bundleName, flag, userId, appInfo);
222 }
223 
QueryOsAccount(int32_t & activeAccountId)224 ErrCode BundleManagerInternal::QueryOsAccount(int32_t& activeAccountId)
225 {
226     if (IBundleManagerInternal::bundleMgrMock == nullptr) {
227         return ERR_OK;
228     }
229     return IBundleManagerInternal::bundleMgrMock->QueryOsAccount(activeAccountId);
230 }
231