From 6c664b9026ee46b31e41b0d13ac1715319150e2e Mon Sep 17 00:00:00 2001 From: yangxuguang-huawei Date: Tue, 20 May 2025 11:47:58 +0800 Subject: [PATCH] feat: add StaticAbilityLifecycleCallback Signed-off-by: yangxuguang-huawei --- ...bility.StaticAbilityLifecycleCallback.d.ts | 284 ++++++++++++++++++ api/@ohos.app.ability.common.d.ts | 12 + api/application/ApplicationContext.d.ts | 27 ++ 3 files changed, 323 insertions(+) create mode 100644 api/@ohos.app.ability.StaticAbilityLifecycleCallback.d.ts diff --git a/api/@ohos.app.ability.StaticAbilityLifecycleCallback.d.ts b/api/@ohos.app.ability.StaticAbilityLifecycleCallback.d.ts new file mode 100644 index 0000000000..d5610584b5 --- /dev/null +++ b/api/@ohos.app.ability.StaticAbilityLifecycleCallback.d.ts @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @kit AbilityKit + */ + +import UIAbility from './@ohos.app.ability.UIAbility'; +import window from './@ohos.window'; + +/** + * The static ability lifecycle callback. + * + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ +declare class StaticAbilityLifecycleCallback { + /** + * Called back when the ability is started for initialization. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityCreate(ability: UIAbility): void; + + /** + * Called back before the ability is started for initialization. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityWillCreate?: (ability: UIAbility) => void; + + /** + * Called back when the window stage is created. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageCreate(ability: UIAbility, windowStage: window.WindowStage): void; + + /** + * Called back before the window stage is created. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageWillCreate?: (ability: UIAbility, windowStage: window.WindowStage) => void; + + /** + * Called back before the UIAbility calls onNewWant. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWillNewWant?: (ability: UIAbility) => void; + + /** + * Called back after the UIAbility calls onNewWant. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onNewWant?: (ability: UIAbility) => void; + + /** + * Called back when the window stage is active. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageActive(ability: UIAbility, windowStage: window.WindowStage): void; + + /** + * Called back when the window stage is inactive. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageInactive(ability: UIAbility, windowStage: window.WindowStage): void; + + /** + * Called back when the window stage is destroyed. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageDestroy(ability: UIAbility, windowStage: window.WindowStage): void; + + /** + * Called back before the window stage is destroyed. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageWillDestroy?: (ability: UIAbility, windowStage: window.WindowStage) => void; + + /** + * Called back when the ability is destroyed. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityDestroy(ability: UIAbility): void; + + /** + * Called back before the ability is destroyed. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityWillDestroy?: (ability: UIAbility) => void; + + /** + * Called back when the state of the ability changes to foreground. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityForeground(ability: UIAbility): void; + + /** + * Called back before the state of the ability changes to foreground. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityWillForeground?: (ability: UIAbility) => void; + + /** + * Called back when the state of the ability changes to background. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityBackground(ability: UIAbility): void; + + /** + * Called back before the state of the ability changes to background. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityWillBackground?: (ability: UIAbility) => void; + + /** + * Called back when the ability prepares to continue. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityContinue(ability: UIAbility): void; + + /** + * Called back before the ability prepares to continue. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityWillContinue?: (ability: UIAbility) => void; + + /** + * Called back when the abilty has called the onWindowStageRestore. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageRestore?: (ability: UIAbility, windowStage: window.WindowStage) => void; + + /** + * Called back when the abilty prepares to call the onWindowStageRestore. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @param { window.WindowStage } windowStage - Window stage to be created. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onWindowStageWillRestore?: (ability: UIAbility, windowStage: window.WindowStage) => void; + + /** + * Called back when the ability has called onSaveState. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilitySaveState?: (ability: UIAbility) => void; + + /** + * Called back when the ability prepares to call onSaveState. + * + * @param { UIAbility } ability - Indicates the ability to register for listening. + * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + onAbilityWillSaveState?: (ability: UIAbility) => void; +} + +export default StaticAbilityLifecycleCallback; \ No newline at end of file diff --git a/api/@ohos.app.ability.common.d.ts b/api/@ohos.app.ability.common.d.ts index f26a6a6e5f..7cd6533899 100644 --- a/api/@ohos.app.ability.common.d.ts +++ b/api/@ohos.app.ability.common.d.ts @@ -45,6 +45,7 @@ import * as _UIServiceExtensionConnectCallback from './application/UIServiceExte import * as _AppServiceExtensionContext from './application/AppServiceExtensionContext'; /*** endif */ import { AbilityResult as _AbilityResult } from './ability/abilityResult'; +import type _StaticAbilityLifecycleCallback from './@ohos.app.ability.StaticAbilityLifecycleCallback'; /*** if arkts 1.2 */ import _UIAbilityContext from './application/UIAbilityContext'; import type _UIExtensionContext from './application/UIExtensionContext'; @@ -577,6 +578,17 @@ declare namespace common { * @since 20 */ export type AppServiceExtensionContext = _AppServiceExtensionContext.default; + + /** + * The static ability lifecycle callback. + * + * @typedef { _StaticAbilityLifecycleCallback } + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @stagemodelonly + * @since arkts {'1.1':'20', '1.2':'20'} + * @arkts 1.1&1.2 + */ + export type StaticAbilityLifecycleCallback = _StaticAbilityLifecycleCallback; } export default common; diff --git a/api/application/ApplicationContext.d.ts b/api/application/ApplicationContext.d.ts index b90f46c56a..777769328c 100644 --- a/api/application/ApplicationContext.d.ts +++ b/api/application/ApplicationContext.d.ts @@ -29,6 +29,7 @@ import { ProcessInformation } from './ProcessInformation'; import type ConfigurationConstant from '../@ohos.app.ability.ConfigurationConstant'; import Want from '../@ohos.app.ability.Want'; /*** endif */ +import type StaticAbilityLifecycleCallback from '../@ohos.app.ability.StaticAbilityLifecycleCallback'; /** * The context of an application. It allows access to application-specific resources. @@ -60,6 +61,32 @@ import Want from '../@ohos.app.ability.Want'; * @arkts 1.1&1.2 */ declare class ApplicationContext extends Context { + /** + * Register static ability lifecycle callback. + * + * @param { 'staticAbilityLifecycle' } type - Event type. + * @param { StaticAbilityLifecycleCallback } callback - The static ability lifecycle callback. + * @returns { number } Returns the number code of the callback. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + on(type: 'staticAbilityLifecycle', callback: StaticAbilityLifecycleCallback): number; + + /** + * Unregister static ability lifecycle callback. + * + * @param { 'staticAbilityLifecycle' } type - Event type. + * @param { number } callbackId - ID of the listener to unregister. + * @returns { Promise } The promise returned by the function. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @stagemodelonly + * @since arkts{ '1.1':'20', '1.2':'20' } + * @arkts 1.1&1.2 + */ + off(type: 'staticAbilityLifecycle', callbackId: number): Promise; + /** * Register ability lifecycle callback. * -- Gitee