1/** 2 * Copyright (c) 2022-2023 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 16import bundleManager from '@ohos.bundle.bundleManager'; 17import bundleResManager from '@ohos.bundle.bundleResourceManager'; 18import { CMModelErrorCode } from '../model/CertMangerModel'; 19import { AppInfoVo } from './CertManagerVo/AppInfoVo'; 20import { BusinessError } from '@ohos.base'; 21 22const TAG = 'certManager BUNDLE:'; 23 24export class BundleNameModel { 25 async getAppInfoList(appUid: number, callback: Function): Promise<void> { 26 console.info(TAG + 'getAppInfoList enter uid: ' + appUid); 27 try { 28 let appInfo: AppInfoVo = { 29 appImage: '', 30 appName: '', 31 }; 32 33 let appCloneIdentity = await bundleManager.getAppCloneIdentity(appUid); 34 console.info(TAG + 'appBundleName: ' + appCloneIdentity.bundleName + ', appIndex: ' + appCloneIdentity.appIndex); 35 36 let bundleFlags = bundleResManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 37 let resourceInfo = bundleResManager.getBundleResourceInfo(appCloneIdentity.bundleName, bundleFlags, 38 appCloneIdentity.appIndex); 39 appInfo.appName = resourceInfo.label; 40 appInfo.appImage = resourceInfo.icon; 41 console.info(TAG + 'get bundle info success'); 42 43 callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, appInfo); 44 } catch (err) { 45 let e: BusinessError = err as BusinessError; 46 console.error(TAG + 'getAppInfoList failed, message: ' + e.message + ', code: ' + e.code); 47 callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); 48 } 49 } 50} 51 52let bundleNameModel = new BundleNameModel(); 53 54export default bundleNameModel as BundleNameModel; 55