1048147e0Sopenharmony_ci/** 2048147e0Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3048147e0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4048147e0Sopenharmony_ci * you may not use this file except in compliance with the License. 5048147e0Sopenharmony_ci * You may obtain a copy of the License at 6048147e0Sopenharmony_ci * 7048147e0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8048147e0Sopenharmony_ci * 9048147e0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10048147e0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11048147e0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12048147e0Sopenharmony_ci * See the License for the specific language governing permissions and 13048147e0Sopenharmony_ci * limitations under the License. 14048147e0Sopenharmony_ci */ 15048147e0Sopenharmony_ciimport Ability from '@ohos.app.ability.UIAbility'; 16048147e0Sopenharmony_ciimport Window from '@ohos.window'; 17048147e0Sopenharmony_ci 18048147e0Sopenharmony_ciimport HiLog from '../utils/HiLog'; 19048147e0Sopenharmony_ciimport MmsPreferences from '../utils/MmsPreferences'; 20048147e0Sopenharmony_ciimport WorkFactory, { WorkerType } from '../workers/WorkFactory'; 21048147e0Sopenharmony_ciimport simCardService from '../service/SimCardService'; 22048147e0Sopenharmony_ci 23048147e0Sopenharmony_ciconst TAG = 'app'; 24048147e0Sopenharmony_ci 25048147e0Sopenharmony_ciexport default class MainAbility extends Ability { 26048147e0Sopenharmony_ci onCreate(want, launchParam): void { 27048147e0Sopenharmony_ci HiLog.i(TAG, 'Ability onCreate com.ohos.mms version: 1.0.0.41'); 28048147e0Sopenharmony_ci globalThis.mmsContext = this.context; 29048147e0Sopenharmony_ci globalThis.abilityWant = want; 30048147e0Sopenharmony_ci globalThis.needToUpdate = true; 31048147e0Sopenharmony_ci MmsPreferences.getInstance().initPreferences(); 32048147e0Sopenharmony_ci globalThis.DataWorker = WorkFactory.getWorker(WorkerType.DataWorker); 33048147e0Sopenharmony_ci } 34048147e0Sopenharmony_ci 35048147e0Sopenharmony_ci onNewWant(want, launchParam): void { 36048147e0Sopenharmony_ci HiLog.i(TAG, 'Application onNewWant'); 37048147e0Sopenharmony_ci globalThis.abilityWant = want; 38048147e0Sopenharmony_ci } 39048147e0Sopenharmony_ci 40048147e0Sopenharmony_ci onWindowStageCreate(windowStage: Window.WindowStage): void { 41048147e0Sopenharmony_ci // Main window is created, set main page for this ability 42048147e0Sopenharmony_ci windowStage.loadContent('pages/index', (err, data) => { 43048147e0Sopenharmony_ci if (err.code) { 44048147e0Sopenharmony_ci HiLog.e(TAG, 'testTag', 'Failed to load the content.'); 45048147e0Sopenharmony_ci return; 46048147e0Sopenharmony_ci } 47048147e0Sopenharmony_ci HiLog.i(TAG, 'testTag', 'Succeeded in loading the content. Data: %{public}s'); 48048147e0Sopenharmony_ci }); 49048147e0Sopenharmony_ci } 50048147e0Sopenharmony_ci 51048147e0Sopenharmony_ci onWindowStageDestroy(): void { 52048147e0Sopenharmony_ci // Main window is destroyed, release UI related resources 53048147e0Sopenharmony_ci HiLog.i(TAG, 'Ability onWindowStageDestroy'); 54048147e0Sopenharmony_ci } 55048147e0Sopenharmony_ci 56048147e0Sopenharmony_ci onForeground(): void { 57048147e0Sopenharmony_ci // Ability has brought to foreground 58048147e0Sopenharmony_ci HiLog.i(TAG, 'Ability onForeground'); 59048147e0Sopenharmony_ci simCardService.init(); 60048147e0Sopenharmony_ci } 61048147e0Sopenharmony_ci 62048147e0Sopenharmony_ci onBackground(): void { 63048147e0Sopenharmony_ci // Ability has back to background 64048147e0Sopenharmony_ci HiLog.i(TAG, 'Ability onBackground'); 65048147e0Sopenharmony_ci simCardService.deInit(); 66048147e0Sopenharmony_ci } 67048147e0Sopenharmony_ci 68048147e0Sopenharmony_ci onDestroy(): void { 69048147e0Sopenharmony_ci HiLog.i(TAG, 'Ability onDestroy'); 70048147e0Sopenharmony_ci if (globalThis.DataWorker == null || globalThis.DataWorker == undefined) { 71048147e0Sopenharmony_ci return; 72048147e0Sopenharmony_ci } 73048147e0Sopenharmony_ci globalThis.DataWorker.close(); 74048147e0Sopenharmony_ci } 75048147e0Sopenharmony_ci} 76