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 backgroundTaskManager from '@ohos.backgroundTaskManager' 19import quickFixManager from '@ohos.app.ability.quickFixManager' 20import Logger from '../util/Logger' 21 22const TAG: string = 'MainAbility' 23const PATH: string = '/data/storage/el2/base/haps/entry-signed-release.hqf' 24 25let demandId 26 27// cancel suspend delay 28function cancelSuspendDelay() { 29 backgroundTaskManager.cancelSuspendDelay(demandId) 30} 31 32// quick fix 33async function applyQuickFix() { 34 try { 35 await quickFixManager.applyQuickFix([PATH]) 36 Logger.info(TAG, `applyQuickFix success`) 37 } catch (error) { 38 Logger.info(TAG, `applyQuickFix err: + ${JSON.stringify(error)}`) 39 } 40} 41 42export default class MainAbility extends UIAbility { 43 onCreate(want, launchParam) { 44 Logger.info(TAG, `onCreate`) 45 let status = want.parameters 46 AppStorage.SetOrCreate('status', status) 47 AppStorage.SetOrCreate('filePath', this.context.filesDir) 48 } 49 50 onDestroy() { 51 Logger.info(TAG, `onDestroy`) 52 } 53 54 onWindowStageCreate(windowStage: Window.WindowStage) { 55 // Main window is created, set main page for this ability 56 Logger.info(TAG, `onWindowStageCreate`) 57 windowStage.loadContent('pages/Index', (err, data) => { 58 if (err.code) { 59 Logger.info(TAG, `Failed to load the content. Cause: ${JSON.stringify(err)}`) 60 return 61 } 62 Logger.info(TAG, `Succeeded in loading the content. Data: ${JSON.stringify(data)}`) 63 }) 64 } 65 66 onWindowStageDestroy() { 67 // Main window is destroyed, release UI related resources 68 Logger.info(TAG, `onWindowStageDestroy`) 69 } 70 71 onForeground() { 72 // Ability has brought to foreground 73 Logger.info(TAG, `onForeground`) 74 } 75 76 onBackground() { 77 // Ability has back to background 78 Logger.info(TAG, `onBackground`) 79 // quick fix 80 Logger.info(TAG, `onBackground applyQuickFix`) 81 applyQuickFix() 82 // cancel suspend delay 83 cancelSuspendDelay() 84 } 85} 86