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 Log from '../Log'; 17 18const TAG = 'AbilityManager'; 19 20export default class AbilityManager { 21 static ABILITY_NAME_ENTRY = 'SystemUi_Entry'; 22 static ABILITY_NAME_STATUS_BAR = 'SystemUi_StatusBar'; 23 static ABILITY_NAME_NAVIGATION_BAR = 'SystemUi_NavigationBar'; 24 static ABILITY_NAME_VOLUME_PANEL = 'SystemUi_VolumePanel'; 25 static ABILITY_NAME_NOTIFICATION_MANAGEMENT = 'SystemUi_NotificationManagement'; 26 static ABILITY_NAME_DROPDOWN_PANEL = 'SystemUi_DropdownPanel'; 27 static ABILITY_NAME_NOTIFICATION_PANEL = 'SystemUi_NotificationPanel'; 28 static ABILITY_NAME_CONTROL_PANEL = 'SystemUi_ControlPanel'; 29 static ABILITY_NAME_BANNER_NOTICE = 'SystemUi_BannerNotice'; 30 static ABILITY_NAME_SCREEN_LOCK = 'SystemUi_ScreenLock'; 31 32 static setContext(abilityName: string, context) { 33 Log.showDebug(TAG, `setContext, abilityName: ${abilityName}`); 34 globalThis[abilityName + '_Context'] = context; 35 } 36 37 static getContext(abilityName?: string) { 38 Log.showDebug(TAG, `getContext, abilityName: ${abilityName}`); 39 if (!abilityName) { 40 abilityName = AbilityManager.ABILITY_NAME_ENTRY; 41 } 42 return globalThis[abilityName + '_Context']; 43 } 44 45 static setAbilityData(abilityName, key, data) { 46 Log.showDebug(TAG, `setAbilityData, abilityName: ${abilityName} key: ${key} data: ${JSON.stringify(data)}`); 47 globalThis[abilityName + '_data_' + key] = data; 48 } 49 50 static getAbilityData(abilityName, key) { 51 Log.showDebug(TAG, `getAbilityData, abilityName: ${abilityName} key: ${key} `); 52 return globalThis[abilityName + '_data_' + key]; 53 } 54 55 static startAbility(want, callback?: Function) { 56 Log.showDebug(TAG, `startAbility, want: ${JSON.stringify(want)}`); 57 let context = AbilityManager.getContext(); 58 context.startAbility(want).then(() => { 59 Log.showInfo(TAG, `startAbility, then`); 60 if (callback) { 61 callback(null); 62 } 63 }).catch((error) => { 64 Log.showError(TAG, `startAbility, error: ${JSON.stringify(error)}`); 65 callback(error); 66 }) 67 } 68} 69