1/* 2 * Copyright (c) 2023 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 Window from '@ohos.window' 18import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 19import Want from '@ohos.app.ability.Want'; 20 21import Logger from '../common/Logger' 22import { CurActiveAbility } from '../common/CurActiveAbility'; 23 24const TAG: string = 'SecondAbility'; 25 26export default class RecoveryAbility extends UIAbility { 27 storage: LocalStorage = new LocalStorage(); 28 29 onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { 30 Logger.info(TAG, 'onCreate'); 31 this.storage.setOrCreate<string>('launchReason', launchParam.launchReason.toString()); 32 this.storage.setOrCreate<string>('lastExitReason', launchParam.lastExitReason.toString()); 33 if (want.parameters !== undefined) { 34 AppStorage.SetOrCreate<string>('RecoverAbility', want.parameters['RecoverAbility'] as string); 35 } 36 } 37 38 onDestroy(): void { 39 Logger.info(TAG, 'onDestroy'); 40 } 41 42 onWindowStageCreate(windowStage: Window.WindowStage):void { 43 Logger.info(TAG, 'onWindowStageCreate'); 44 windowStage.loadContent('pages/RecoveryPage', this.storage, (err, data) => { 45 if (err.code) { 46 Logger.info(TAG, 'Failed to load the content. Cause:${JSON.stringify(err)}}'); 47 return; 48 } 49 }); 50 } 51 52 onWindowStageDestroy(): void { 53 Logger.info(TAG, 'onWindowStageDestroy'); 54 } 55 56 onForeground(): void { 57 Logger.info(TAG, 'onForeground'); 58 CurActiveAbility.GetInstance().SetGlobalAbility(this); 59 } 60 61 onSaveState(reason: AbilityConstant.StateType, wantParam: Record<string, Object>): AbilityConstant.OnSaveResult { 62 // No need to save state 63 Logger.info(TAG, 'onSaveState'); 64 return AbilityConstant.OnSaveResult.ALL_REJECT; 65 } 66 67 onBackground(): void { 68 // Ability has back to background 69 Logger.info(TAG, 'onBackground'); 70 } 71} 72