1/** 2 * Copyright (c) 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 */ 15import Ability from '@ohos.app.ability.UIAbility'; 16import Window from '@ohos.window'; 17 18import HiLog from '../utils/HiLog'; 19import MmsPreferences from '../utils/MmsPreferences'; 20import WorkFactory, { WorkerType } from '../workers/WorkFactory'; 21import simCardService from '../service/SimCardService'; 22 23const TAG = 'app'; 24 25export default class MainAbility extends Ability { 26 onCreate(want, launchParam): void { 27 HiLog.i(TAG, 'Ability onCreate com.ohos.mms version: 1.0.0.41'); 28 globalThis.mmsContext = this.context; 29 globalThis.abilityWant = want; 30 globalThis.needToUpdate = true; 31 MmsPreferences.getInstance().initPreferences(); 32 globalThis.DataWorker = WorkFactory.getWorker(WorkerType.DataWorker); 33 } 34 35 onNewWant(want, launchParam): void { 36 HiLog.i(TAG, 'Application onNewWant'); 37 globalThis.abilityWant = want; 38 } 39 40 onWindowStageCreate(windowStage: Window.WindowStage): void { 41 // Main window is created, set main page for this ability 42 windowStage.loadContent('pages/index', (err, data) => { 43 if (err.code) { 44 HiLog.e(TAG, 'testTag', 'Failed to load the content.'); 45 return; 46 } 47 HiLog.i(TAG, 'testTag', 'Succeeded in loading the content. Data: %{public}s'); 48 }); 49 } 50 51 onWindowStageDestroy(): void { 52 // Main window is destroyed, release UI related resources 53 HiLog.i(TAG, 'Ability onWindowStageDestroy'); 54 } 55 56 onForeground(): void { 57 // Ability has brought to foreground 58 HiLog.i(TAG, 'Ability onForeground'); 59 simCardService.init(); 60 } 61 62 onBackground(): void { 63 // Ability has back to background 64 HiLog.i(TAG, 'Ability onBackground'); 65 simCardService.deInit(); 66 } 67 68 onDestroy(): void { 69 HiLog.i(TAG, 'Ability onDestroy'); 70 if (globalThis.DataWorker == null || globalThis.DataWorker == undefined) { 71 return; 72 } 73 globalThis.DataWorker.close(); 74 } 75} 76