1/** 2 * Copyright (c) 2021-2024 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 Ability from '@ohos.app.ability.UIAbility'; 17import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData'; 18import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil'; 19import { GlobalContext } from '../../../../../../common/utils/src/main/ets/default/baseUtil/GlobalContext'; 20 21export default class MainAbility extends Ability { 22 private funcAbilityWant; 23 onCreate(want, launchParam) { 24 LogUtil.info(ConfigData.TAG + 'Application onCreate') 25 this.funcAbilityWant = want; 26 GlobalContext.getContext().setObject(GlobalContext.globalKeyAbilityWant, want); 27 GlobalContext.getContext().setObject(GlobalContext.globalKeySettingsAbilityContext, this.context); 28 } 29 30 onDestroy() { 31 AppStorage.SetOrCreate('settingsList', []); 32 LogUtil.info(ConfigData.TAG + 'Application onDestroy') 33 } 34 35 onWindowStageCreate(windowStage) { 36 // Main window is created, set main page for this ability 37 LogUtil.log("[Main] MainAbility onWindowStageCreate") 38 let url = 'pages/settingList'; 39 if (this.funcAbilityWant?.parameters?.router && this.funcAbilityWant.parameters.router === 'volumeControl') { 40 url = 'pages/volumeControl'; 41 } else if (this.funcAbilityWant?.uri === "wifi") { 42 url = 'pages/wifi'; 43 } else if (this.funcAbilityWant?.uri === "bluetooth") { 44 url = 'pages/bluetooth'; 45 } else if (this.funcAbilityWant?.uri === "volumeControl") { 46 url = 'pages/volumeControl'; 47 } else if (this.funcAbilityWant?.uri === "locationServices") { 48 url = 'pages/locationServices'; 49 } 50 windowStage.setUIContent(this.context, url, null); 51 GlobalContext.getContext().setObject(GlobalContext.globalKeySettingsAbilityContext, this.context); 52 } 53 54 onWindowStageDestroy() { 55 // Main window is destroyed, release UI related resources 56 LogUtil.log("[Main] MainAbility onWindowStageDestroy") 57 } 58 59 onForeground() { 60 // Ability has brought to foreground 61 LogUtil.log("[Main] MainAbility onForeground") 62 } 63 64 onBackground() { 65 // Ability has back to background 66 LogUtil.log("[Main] MainAbility onBackground") 67 } 68}; 69