• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "bundle_command_common.h"
16 
17 #include "app_log_wrapper.h"
18 #include "appexecfwk_errors.h"
19 #include "bundle_mgr_proxy.h"
20 #include "os_account_info.h"
21 #include "os_account_manager.h"
22 #include "if_system_ability_manager.h"
23 #include "iservice_registry.h"
24 #include "status_receiver_interface.h"
25 #include "system_ability_definition.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
GetBundleMgrProxy()29 sptr<IBundleMgr> BundleCommandCommon::GetBundleMgrProxy()
30 {
31     sptr<ISystemAbilityManager> systemAbilityManager =
32         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
33     if (systemAbilityManager == nullptr) {
34         APP_LOGE("failed to get system ability mgr.");
35         return nullptr;
36     }
37 
38     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
39     if (remoteObject == nullptr) {
40         APP_LOGE("failed to get bundle manager proxy.");
41         return nullptr;
42     }
43 
44     APP_LOGD("get bundle manager proxy success.");
45     return iface_cast<IBundleMgr>(remoteObject);
46 }
47 
GetCurrentUserId(int32_t userId)48 int32_t BundleCommandCommon::GetCurrentUserId(int32_t userId)
49 {
50     if (userId == Constants::UNSPECIFIED_USERID) {
51         std::vector<int> activeIds;
52         int32_t ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds);
53         if (ret != 0) {
54             APP_LOGW("QueryActiveOsAccountIds failed! ret = %{public}d.", ret);
55             return userId;
56         }
57         if (activeIds.empty()) {
58             APP_LOGW("QueryActiveOsAccountIds activeIds empty");
59             return userId;
60         }
61         return activeIds[0];
62     }
63     return userId;
64 }
65 
66 std::map<int32_t, std::string> BundleCommandCommon::bundleMessageMap_ = {
67     //  error + message
68     {
69         IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR,
70         "error: install internal error.",
71     },
72     {
73         IStatusReceiver::ERR_INSTALL_HOST_INSTALLER_FAILED,
74         "error: install host installer failed.",
75     },
76     {
77         IStatusReceiver::ERR_INSTALL_PARSE_FAILED,
78         "error: install parse failed.",
79     },
80     {
81         IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE,
82         "error: install version downgrade.",
83     },
84     {
85         IStatusReceiver::ERR_INSTALL_VERIFICATION_FAILED,
86         "error: install verification failed.",
87     },
88     {
89         IStatusReceiver::ERR_INSTALL_FAILED_INVALID_SIGNATURE_FILE_PATH,
90         "error: signature file path is invalid.",
91     },
92     {
93         IStatusReceiver::ERR_INSTALL_FAILED_BAD_BUNDLE_SIGNATURE_FILE,
94         "error: cannot open signature file.",
95     },
96     {
97         IStatusReceiver::ERR_INSTALL_FAILED_NO_BUNDLE_SIGNATURE,
98         "error: no signature file.",
99     },
100     {
101         IStatusReceiver::ERR_INSTALL_FAILED_VERIFY_APP_PKCS7_FAIL,
102         "error: fail to verify pkcs7 file.",
103     },
104     {
105         IStatusReceiver::ERR_INSTALL_FAILED_PROFILE_PARSE_FAIL,
106         "error: fail to parse signature file.",
107     },
108     {
109         IStatusReceiver::ERR_INSTALL_FAILED_APP_SOURCE_NOT_TRUESTED,
110         "error: signature verification failed due to not trusted app source.",
111     },
112     {
113         IStatusReceiver::ERR_INSTALL_FAILED_BAD_DIGEST,
114         "error: signature verification failed due to not bad digest.",
115     },
116     {
117         IStatusReceiver::ERR_INSTALL_FAILED_BUNDLE_INTEGRITY_VERIFICATION_FAILURE,
118         "error: signature verification failed due to out of integrity.",
119     },
120     {
121         IStatusReceiver::ERR_INSTALL_FAILED_FILE_SIZE_TOO_LARGE,
122         "error: signature verification failed due to oversize file.",
123     },
124     {
125         IStatusReceiver::ERR_INSTALL_FAILED_BAD_PUBLICKEY,
126         "error: signature verification failed due to bad public key.",
127     },
128     {
129         IStatusReceiver::ERR_INSTALL_FAILED_BAD_BUNDLE_SIGNATURE,
130         "error: signature verification failed due to bad bundle signature.",
131     },
132     {
133         IStatusReceiver::ERR_INSTALL_FAILED_NO_PROFILE_BLOCK_FAIL,
134         "error: signature verification failed due to no profile block.",
135     },
136     {
137         IStatusReceiver::ERR_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE,
138         "error: verify signature failed.",
139     },
140     {
141         IStatusReceiver::ERR_INSTALL_FAILED_VERIFY_SOURCE_INIT_FAIL,
142         "error: signature verification failed due to init source failed.",
143     },
144     {
145         IStatusReceiver::ERR_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE,
146         "error: install incompatible signature info.",
147     },
148     {
149         IStatusReceiver::ERR_INSTALL_FAILED_INCONSISTENT_SIGNATURE,
150         "error: install sign info inconsistent.",
151     },
152     {
153         IStatusReceiver::ERR_INSTALL_FAILED_MODULE_NAME_EMPTY,
154         "error: install failed due to hap moduleName is empty.",
155     },
156     {
157         IStatusReceiver::ERR_INSTALL_FAILED_MODULE_NAME_DUPLICATE,
158         "error: install failed due to hap moduleName duplicate.",
159     },
160     {
161         IStatusReceiver::ERR_INSTALL_FAILED_CHECK_HAP_HASH_PARAM,
162         "error: install failed due to check hap hash param failed.",
163     },
164     {
165         IStatusReceiver::ERR_INSTALL_PARAM_ERROR,
166         "error: install param error.",
167     },
168     {
169         IStatusReceiver::ERR_INSTALL_PERMISSION_DENIED,
170         "error: install permission denied.",
171     },
172     {
173         IStatusReceiver::ERR_INSTALL_ENTRY_ALREADY_EXIST,
174         "error: install entry already exist.",
175     },
176     {
177         IStatusReceiver::ERR_INSTALL_STATE_ERROR,
178         "error: install state error.",
179     },
180     {
181         IStatusReceiver::ERR_INSTALL_FILE_PATH_INVALID,
182         "error: install file path invalid.",
183     },
184     {
185         IStatusReceiver::ERR_INSTALL_INVALID_HAP_NAME,
186         "error: install invalid hap name.",
187     },
188     {
189         IStatusReceiver::ERR_INSTALL_INVALID_BUNDLE_FILE,
190         "error: install invalid bundle file.",
191     },
192     {
193         IStatusReceiver::ERR_INSTALL_INVALID_HAP_SIZE,
194         "error: install invalid hap size.",
195     },
196     {
197         IStatusReceiver::ERR_INSTALL_GENERATE_UID_ERROR,
198         "error: install generate uid error.",
199     },
200     {
201         IStatusReceiver::ERR_INSTALL_INSTALLD_SERVICE_ERROR,
202         "error: install installd service error.",
203     },
204     {
205         IStatusReceiver::ERR_INSTALL_BUNDLE_MGR_SERVICE_ERROR,
206         "error: install bundle mgr service error.",
207     },
208     {
209         IStatusReceiver::ERR_INSTALL_ALREADY_EXIST,
210         "error: install already exist.",
211     },
212     {
213         IStatusReceiver::ERR_INSTALL_BUNDLENAME_NOT_SAME,
214         "error: install bundle name not same",
215     },
216     {
217         IStatusReceiver::ERR_INSTALL_VERSIONCODE_NOT_SAME,
218         "error: install version code not same",
219     },
220     {
221         IStatusReceiver::ERR_INSTALL_VERSIONNAME_NOT_SAME,
222         "error: install version name not same",
223     },
224     {
225         IStatusReceiver::ERR_INSTALL_MINCOMPATIBLE_VERSIONCODE_NOT_SAME,
226         "error: install min compatible version code not same",
227     },
228     {
229         IStatusReceiver::ERR_INSTALL_VENDOR_NOT_SAME,
230         "error: install vendor not same",
231     },
232     {
233         IStatusReceiver::ERR_INSTALL_RELEASETYPE_TARGET_NOT_SAME,
234         "error: install releaseType target not same",
235     },
236     {
237         IStatusReceiver::ERR_INSTALL_RELEASETYPE_NOT_SAME,
238         "error: install releaseType not same",
239     },
240     {
241         IStatusReceiver::ERR_INSTALL_RELEASETYPE_COMPATIBLE_NOT_SAME,
242         "error: install releaseType compatible not same",
243     },
244     {
245         IStatusReceiver::ERR_INSTALL_VERSION_NOT_COMPATIBLE,
246         "error: install version not compatible",
247     },
248     {
249         IStatusReceiver::ERR_INSTALL_APP_DISTRIBUTION_TYPE_NOT_SAME,
250         "error: install distribution type not same",
251     },
252     {
253         IStatusReceiver::ERR_INSTALL_APP_PROVISION_TYPE_NOT_SAME,
254         "error: install provision type not same",
255     },
256     {
257         IStatusReceiver::ERR_INSTALL_INVALID_NUMBER_OF_ENTRY_HAP,
258         "error: install invalid number of entry hap",
259     },
260     {
261         IStatusReceiver::ERR_INSTALL_DISK_MEM_INSUFFICIENT,
262         "error: install failed due to insufficient disk memory",
263     },
264     {
265         IStatusReceiver::ERR_INSTALL_GRANT_REQUEST_PERMISSIONS_FAILED,
266         "error: install failed due to grant request permissions failed",
267     },
268     {
269         IStatusReceiver::ERR_INSTALL_UPDATE_HAP_TOKEN_FAILED,
270         "error: install failed due to update hap token failed",
271     },
272     {
273         IStatusReceiver::ERR_INSTALL_SINGLETON_NOT_SAME,
274         "error: install failed due to singleton not same",
275     },
276     {
277         IStatusReceiver::ERR_INSTALL_ZERO_USER_WITH_NO_SINGLETON,
278         "error: install failed due to zero user can only install singleton app",
279     },
280     {
281         IStatusReceiver::ERR_INSTALL_CHECK_SYSCAP_FAILED,
282         "error: install failed due to check syscap filed",
283     },
284     {
285         IStatusReceiver::ERR_INSTALL_APPTYPE_NOT_SAME,
286         "error: install failed due to apptype not same",
287     },
288     {
289         IStatusReceiver::ERR_INSTALL_TYPE_ERROR,
290         "error: install failed due to error bundle type"
291     },
292     {
293         IStatusReceiver::ERR_INSTALL_SDK_INCOMPATIBLE,
294         "error: install failed due to older sdk version in the device"
295     },
296     {
297         IStatusReceiver::ERR_INSTALL_SO_INCOMPATIBLE,
298         "error: install failed due to native so is incompatible"
299     },
300     {
301         IStatusReceiver::ERR_INSTALL_AN_INCOMPATIBLE,
302         "error: install failed due to ark native file is incompatible"
303     },
304     {
305         IStatusReceiver::ERR_INSTALL_URI_DUPLICATE,
306         "error: install failed due to uri prefix duplicate",
307     },
308     {
309         IStatusReceiver::ERR_INSTALL_PARSE_UNEXPECTED,
310         "error: install parse unexpected.",
311     },
312     {
313         IStatusReceiver::ERR_INSTALL_PARSE_MISSING_BUNDLE,
314         "error: install parse missing bundle.",
315     },
316     {
317         IStatusReceiver::ERR_INSTALL_PARSE_MISSING_ABILITY,
318         "error: install parse missing ability.",
319     },
320     {
321         IStatusReceiver::ERR_INSTALL_PARSE_NO_PROFILE,
322         "error: install parse no profile.",
323     },
324     {
325         IStatusReceiver::ERR_INSTALL_PARSE_BAD_PROFILE,
326         "error: install parse bad profile.",
327     },
328     {
329         IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_PROP_TYPE_ERROR,
330         "error: install parse profile prop type error.",
331     },
332     {
333         IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_MISSING_PROP,
334         "error: install parse profile missing prop.",
335     },
336     {
337         IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_PROP_CHECK_ERROR,
338         "error: install parse profile prop check error.",
339     },
340     {
341         IStatusReceiver::ERR_INSTALL_PARSE_PERMISSION_ERROR,
342         "error: install parse permission error.",
343     },
344     {
345         IStatusReceiver::ERR_INSTALL_PARSE_RPCID_FAILED,
346         "error: install parse syscap error.",
347     },
348     {
349         IStatusReceiver::ERR_INSTALL_PARSE_NATIVE_SO_FAILED,
350         "error: install parse native so failed.",
351     },
352     {
353         IStatusReceiver::ERR_INSTALL_PARSE_AN_FAILED,
354         "error: install parse ark native file failed.",
355     },
356     {
357         IStatusReceiver::ERR_INSTALLD_PARAM_ERROR,
358         "error: installd param error.",
359     },
360     {
361         IStatusReceiver::ERR_INSTALLD_GET_PROXY_ERROR,
362         "error: installd get proxy error.",
363     },
364     {
365         IStatusReceiver::ERR_INSTALLD_CREATE_DIR_FAILED,
366         "error: installd create dir failed.",
367     },
368     {
369         IStatusReceiver::ERR_INSTALLD_CREATE_DIR_EXIST,
370         "error: installd create dir exist.",
371     },
372     {
373         IStatusReceiver::ERR_INSTALLD_CHOWN_FAILED,
374         "error: installd chown failed.",
375     },
376     {
377         IStatusReceiver::ERR_INSTALLD_REMOVE_DIR_FAILED,
378         "error: installd remove dir failed.",
379     },
380     {
381         IStatusReceiver::ERR_INSTALLD_EXTRACT_FILES_FAILED,
382         "error: installd extract files failed.",
383     },
384     {
385         IStatusReceiver::ERR_INSTALLD_RNAME_DIR_FAILED,
386         "error: installd rename dir failed.",
387     },
388     {
389         IStatusReceiver::ERR_INSTALLD_CLEAN_DIR_FAILED,
390         "error: installd clean dir failed.",
391     },
392     {
393         IStatusReceiver::ERR_UNINSTALL_SYSTEM_APP_ERROR,
394         "error: uninstall system app error.",
395     },
396     {
397         IStatusReceiver::ERR_UNINSTALL_KILLING_APP_ERROR,
398         "error: uninstall killing app error.",
399     },
400     {
401         IStatusReceiver::ERR_UNINSTALL_INVALID_NAME,
402         "error: uninstall invalid name.",
403     },
404     {
405         IStatusReceiver::ERR_UNINSTALL_PARAM_ERROR,
406         "error: uninstall param error.",
407     },
408     {
409         IStatusReceiver::ERR_UNINSTALL_PERMISSION_DENIED,
410         "error: uninstall permission denied.",
411     },
412     {
413         IStatusReceiver::ERR_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR,
414         "error: uninstall bundle mgr service error.",
415     },
416     {
417         IStatusReceiver::ERR_UNINSTALL_MISSING_INSTALLED_BUNDLE,
418         "error: uninstall missing installed bundle.",
419     },
420     {
421         IStatusReceiver::ERR_UNINSTALL_MISSING_INSTALLED_MODULE,
422         "error: uninstall missing installed module.",
423     },
424     {
425         IStatusReceiver::ERR_FAILED_SERVICE_DIED,
426         "error: bundle manager service is died",
427     },
428     {
429         IStatusReceiver::ERR_FAILED_GET_INSTALLER_PROXY,
430         "error: failed to get installer proxy",
431     },
432     {
433         IStatusReceiver::ERR_USER_NOT_EXIST,
434         "error: user not exist.",
435     },
436     {
437         IStatusReceiver::ERR_USER_NOT_INSTALL_HAP,
438         "error: user does not install the hap.",
439     },
440     {
441         IStatusReceiver::ERR_OPERATION_TIME_OUT,
442         "error: operation time out.",
443     },
444     {
445         IStatusReceiver::ERR_INSTALL_NOT_UNIQUE_DISTRO_MODULE_NAME,
446         "error: moduleName is not unique.",
447     },
448     {
449         IStatusReceiver::ERR_INSTALL_INCONSISTENT_MODULE_NAME,
450         "error: moduleName is inconsistent.",
451     },
452     {
453         IStatusReceiver::ERR_INSTALL_SINGLETON_INCOMPATIBLE,
454         "error: singleton is incompatible with installed app.",
455     },
456     {
457         IStatusReceiver::ERR_INSTALL_DISALLOWED,
458         "error: disallowed install.",
459     },
460     {
461         IStatusReceiver::ERR_UNINSTALL_DISALLOWED,
462         "error: disallowed uninstall.",
463     },
464     {
465         IStatusReceiver::ERR_INSTALL_DEVICE_TYPE_NOT_SUPPORTED,
466         "error: device type is not supported"
467     },
468     {
469         IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_PROP_SIZE_CHECK_ERROR,
470         "error: too large size of string or array type element in the profile"
471     },
472     {
473         IStatusReceiver::ERR_INSTALL_DEPENDENT_MODULE_NOT_EXIST,
474         "error: dependent module does not exist.",
475     },
476     {
477         IStatusReceiver::ERR_INSTALL_ASAN_ENABLED_NOT_SAME,
478         "error: install asanEnabled not same",
479     },
480     {
481         IStatusReceiver::ERR_INSTALL_ASAN_ENABLED_NOT_SUPPORT,
482         "error, install asan enabled is not support",
483     },
484     {
485         IStatusReceiver::ERR_INSTALL_BUNDLE_TYPE_NOT_SAME,
486         "error, install bundleType not same",
487     },
488     {
489         IStatusReceiver::ERR_UNKNOWN,
490         "error: unknown.",
491     }
492 };
493 } // AppExecFwk
494 } // OHOS