1/* 2 * Copyright (c) 2021-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 16import UIAbility from '@ohos.app.ability.UIAbility' 17import bundle from "@ohos.bundle"; 18 19var TAG = "PermissionManager_MainAbility:"; 20const PARMETER_BUNDLE_FLAG = 16; 21const USERID = 100; 22const noNeedDisplayApp: string[] = [ 23 "com.ohos.launcher" 24] 25 26export default class MainAbility extends UIAbility { 27 onCreate(want, launchParam) { 28 console.log(TAG + "MainAbility onCreate, ability name is " + want.abilityName + "."); 29 globalThis.context = this.context; 30 globalThis.allBundleInfo = []; 31 globalThis.allUserPermissions = [] 32 globalThis.allGroups = [] 33 globalThis.permissionLabels = {} 34 globalThis.initialGroups = [] 35 } 36 37 onWindowStageCreate(windowStage) { 38 // Main window is created, set main page for this ability 39 console.log(TAG + "MainAbility onWindowStageCreate."); 40 41 bundle.getAllBundleInfo(PARMETER_BUNDLE_FLAG).then(async(bundleInfos) => { 42 if (bundleInfos.length <= 0) { 43 console.info(TAG + 'bundle.getAllBundleInfo result.length less than or equal to zero'); 44 return; 45 } 46 for (let i = 0; i < bundleInfos.length; i++) { 47 var info = bundleInfos[i]; 48 // Filter blank icon icon and text label resources 49 try { 50 await bundle.queryAbilityByWant({ 51 bundleName: info.name, 52 action: "action.system.home", 53 entities: ["entity.system.home"] 54 }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_APPLICATION, USERID); 55 } catch(e) { 56 console.log(TAG + 'queryAbilityByWant catch error: ' + JSON.stringify(e)) 57 continue; 58 } 59 60 if (noNeedDisplayApp.indexOf(info.name) != -1) { 61 continue; 62 } 63 globalThis.initialGroups.push(info) 64 } 65 windowStage.setUIContent(this.context, "pages/authority-management", null); 66 }).catch((error) => { 67 console.error(TAG + 'bundle.getAllBundleInfo failed. Cause: ' + JSON.stringify(error)); 68 }) 69 } 70 71 onForeground() { 72 // Ability has brought to foreground 73 console.log(TAG + "MainAbility onForeground."); 74 } 75 76 onBackground() { 77 // Ability has back to background 78 console.log(TAG + "MainAbility onBackground."); 79 } 80 81 onDestroy() { 82 console.log(TAG + "MainAbility onDestroy."); 83 } 84 85 onWindowStageDestroy() { 86 // Main window is destroyed, release UI related resources 87 console.log(TAG + "MainAbility onWindowStageDestroy."); 88 } 89}; 90