1/* 2 * Copyright (c) 2022-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 16/** 17 * @file 18 * @kit AbilityKit 19 */ 20 21import AbilityConstant from './@ohos.app.ability.AbilityConstant'; 22import AbilityStageContext from './application/AbilityStageContext'; 23import Want from './@ohos.app.ability.Want'; 24import { Configuration } from './@ohos.app.ability.Configuration'; 25 26/** 27 * The class of an ability stage. 28 * 29 * @syscap SystemCapability.Ability.AbilityRuntime.Core 30 * @stagemodelonly 31 * @since 9 32 */ 33/** 34 * The class of an ability stage. 35 * 36 * @syscap SystemCapability.Ability.AbilityRuntime.Core 37 * @stagemodelonly 38 * @crossplatform 39 * @since 10 40 */ 41/** 42 * AbilityStage is a runtime class for HAP files. 43 * AbilityStage notifies you of when you can perform HAP initialization such as resource pre-loading and thread 44 * creation during the HAP loading. 45 * 46 * @syscap SystemCapability.Ability.AbilityRuntime.Core 47 * @stagemodelonly 48 * @crossplatform 49 * @atomicservice 50 * @since arkts {'1.1':'11', '1.2':'20'} 51 * @arkts 1.1&1.2 52 */ 53declare class AbilityStage { 54 /** 55 * Indicates configuration information about context. 56 * 57 * @type { AbilityStageContext } 58 * @syscap SystemCapability.Ability.AbilityRuntime.Core 59 * @stagemodelonly 60 * @since 9 61 */ 62 /** 63 * Indicates configuration information about context. 64 * 65 * @type { AbilityStageContext } 66 * @syscap SystemCapability.Ability.AbilityRuntime.Core 67 * @stagemodelonly 68 * @crossplatform 69 * @since 10 70 */ 71 /** 72 * Defines the context of AbilityStage. 73 * The context is obtained in the callback invoked when initialization is performed during ability startup. 74 * 75 * @type { AbilityStageContext } 76 * @syscap SystemCapability.Ability.AbilityRuntime.Core 77 * @stagemodelonly 78 * @crossplatform 79 * @atomicservice 80 * @since arkts {'1.1':'11', '1.2':'20'} 81 * @arkts 1.1&1.2 82 */ 83 context: AbilityStageContext; 84 85 /** 86 * Called back when an ability stage is started for initialization. 87 * 88 * @syscap SystemCapability.Ability.AbilityRuntime.Core 89 * @stagemodelonly 90 * @since 9 91 */ 92 /** 93 * Called back when an ability stage is started for initialization. 94 * 95 * @syscap SystemCapability.Ability.AbilityRuntime.Core 96 * @stagemodelonly 97 * @crossplatform 98 * @since 10 99 */ 100 /** 101 * Called when the application is created. 102 * 103 * <p>**NOTE**: 104 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 105 * </p> 106 * 107 * @syscap SystemCapability.Ability.AbilityRuntime.Core 108 * @stagemodelonly 109 * @crossplatform 110 * @atomicservice 111 * @since arkts {'1.1':'11', '1.2':'20'} 112 * @arkts 1.1&1.2 113 */ 114 onCreate(): void; 115 116 /** 117 * Called back when start specified ability. 118 * 119 * @param { Want } want - Indicates the want info of started ability. 120 * @returns { string } The user returns an ability string ID. If the ability of this ID has been started before, 121 * do not create a new instance and pull it back to the top of the stack. 122 * Otherwise, create a new instance and start it. 123 * @syscap SystemCapability.Ability.AbilityRuntime.Core 124 * @stagemodelonly 125 * @since 9 126 */ 127 /** 128 * Called when a specified ability is started. 129 * 130 * <p>**NOTE**: 131 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 132 * </p> 133 * 134 * @param { Want } want - Want information about the target ability, such as the ability name and bundle name. 135 * @returns { string } Ability ID. If the ability with this ID has been started, no new instance is created and the 136 * ability is placed at the top of the stack. Otherwise, a new instance is created and started. 137 * @syscap SystemCapability.Ability.AbilityRuntime.Core 138 * @stagemodelonly 139 * @atomicservice 140 * @since 11 141 */ 142 onAcceptWant(want: Want): string; 143 144 /** 145 * Called back asynchronously upon starting specified ability. 146 * 147 * @param { Want } want - Indicates the want info of the started ability. 148 * @returns { Promise<string> } The user returns an ability string ID. If the ability of this ID has been started before, 149 * do not create a new instance and pull it back to the top of the stack. 150 * Otherwise, create a new instance and start it. 151 * @syscap SystemCapability.Ability.AbilityRuntime.Core 152 * @stagemodelonly 153 * @atomicservice 154 * @since 20 155 */ 156 onAcceptWantAsync(want: Want): Promise<string>; 157 158 /** 159 * Called when the UIAbility is started in the specified process. 160 * 161 * <p>**NOTE**: 162 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 163 * </p> 164 * 165 * @param { Want } want - Want information about the target ability, such as the ability name and bundle name. 166 * @returns { string } Custom process identifier. If the process with this identifier has been created, the ability 167 * runs in the process. Otherwise, a new process is created and the ability runs in it. 168 * @syscap SystemCapability.Ability.AbilityRuntime.Core 169 * @stagemodelonly 170 * @since 11 171 */ 172 /** 173 * Called when UIAbility or configured with the isolationProcess field UIExtensionAbility in the specified process is started. 174 * 175 * <p>**NOTE**: 176 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 177 * </p> 178 * 179 * @param { Want } want - Want information about the target ability, such as the ability name and bundle name. 180 * @returns { string } Custom process identifier. If the process with this identifier has been created, the ability 181 * runs in the process. Otherwise, a new process is created and the ability runs in it. 182 * @syscap SystemCapability.Ability.AbilityRuntime.Core 183 * @stagemodelonly 184 * @since 20 185 */ 186 onNewProcessRequest(want: Want): string; 187 188 /** 189 * Called back asynchronously upon starting UIAbility or UIExtensionAbility in specified process. 190 * 191 * @param { Want } want - Indicates the want info of the started ability. 192 * @returns { Promise<string> } The user returns an ability string ID. If the ability of this ID has been started before, 193 * let the ability run in this process. Otherwise, create a new process. 194 * @syscap SystemCapability.Ability.AbilityRuntime.Core 195 * @stagemodelonly 196 * @atomicservice 197 * @since 20 198 */ 199 onNewProcessRequestAsync(want: Want): Promise<string>; 200 201 /** 202 * Called when the system configuration is updated. 203 * 204 * @param { Configuration } newConfig - Indicates the updated configuration. 205 * @syscap SystemCapability.Ability.AbilityRuntime.Core 206 * @stagemodelonly 207 * @since 9 208 */ 209 /** 210 * Called when the system configuration is updated. 211 * 212 * @param { Configuration } newConfig - Indicates the updated configuration. 213 * @syscap SystemCapability.Ability.AbilityRuntime.Core 214 * @stagemodelonly 215 * @crossplatform 216 * @since 10 217 */ 218 /** 219 * Called when the global configuration is updated. 220 * 221 * <p>**NOTE**: 222 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 223 * </p> 224 * 225 * @param { Configuration } newConfig - Callback invoked when the global configuration is updated. The global 226 * configuration indicates the configuration of the environment where the application is running and includes 227 * the language and color mode. 228 * @syscap SystemCapability.Ability.AbilityRuntime.Core 229 * @stagemodelonly 230 * @crossplatform 231 * @atomicservice 232 * @since arkts {'1.1':'11', '1.2':'20'} 233 * @arkts 1.1&1.2 234 */ 235 onConfigurationUpdate(newConfig: Configuration): void; 236 237 /** 238 * Called when the system has determined to trim the memory, for example, when the ability is running in the 239 * background and there is no enough memory for running as many background processes as possible. 240 * 241 * @param { AbilityConstant.MemoryLevel } level - Indicates the memory trim level, which shows the current memory usage status. 242 * @syscap SystemCapability.Ability.AbilityRuntime.Core 243 * @stagemodelonly 244 * @since 9 245 */ 246 /** 247 * Listens for changes in the system memory level status. 248 * When the system detects low memory resources, it will proactively invoke this callback. 249 * You can implement this callback to promptly release non-essential resources (such as cached data or temporary 250 * objects) upon receiving a memory shortage event, thereby preventing the application process from being forcibly 251 * terminated by the system. 252 * 253 * <p>**NOTE**: 254 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 255 * </p> 256 * 257 * @param { AbilityConstant.MemoryLevel } level - Memory level that indicates the memory usage status. When the 258 * specified memory level is reached, a callback will be invoked and the system will start adjustment. 259 * @syscap SystemCapability.Ability.AbilityRuntime.Core 260 * @stagemodelonly 261 * @atomicservice 262 * @since 11 263 */ 264 onMemoryLevel(level: AbilityConstant.MemoryLevel): void; 265 266 /** 267 * Called when the application is destroyed. This API is called during the normal lifecycle. 268 * If the application exits abnormally or is terminated, this API is not called. 269 * 270 * <p>**NOTE**: 271 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 272 * </p> 273 * 274 * @syscap SystemCapability.Ability.AbilityRuntime.Core 275 * @stagemodelonly 276 * @atomicservice 277 * @since arkts {'1.1':'12', '1.2':'20'} 278 * @arkts 1.1&1.2 279 */ 280 onDestroy(): void; 281 282 /** 283 * Called when the application is closed by the user, allowing the user to choose between immediate termination or 284 * cancellation. 285 * 286 * <p>**NOTE**: 287 * <br>This API returns the result synchronously and does not support asynchronous callbacks. 288 * <br>Currently, this API takes effect only on 2-in-1 devices. 289 * <br>This API is called only when the application exits normally. It is not called if the application is forcibly 290 * closed. 291 * <br>This API is not executed when {@link AbilityStage.onPrepareTerminationAsync} is implemented. 292 * </p> 293 * 294 * @permission ohos.permission.PREPARE_APP_TERMINATE 295 * @returns { AbilityConstant.PrepareTermination } The user's choice. 296 * @syscap SystemCapability.Ability.AbilityRuntime.Core 297 * @stagemodelonly 298 * @atomicservice 299 * @since 15 300 */ 301 onPrepareTermination(): AbilityConstant.PrepareTermination; 302 303 /** 304 * Called when the application is closed by the user, allowing the user to choose between immediate termination or 305 * cancellation. 306 * This API uses a promise to return the result. 307 * 308 * <p>**NOTE**: 309 * <br>Currently, this API takes effect only on 2-in-1 devices. 310 * <br>This API is called only when the application exits normally. It is not called if the application is forcibly 311 * closed. 312 * <br>If an asynchronous callback crashes, it will be handled as a timeout. If the application does not respond 313 * within 10 seconds, it will be terminated forcibly. 314 * </p> 315 * 316 * @permission ohos.permission.PREPARE_APP_TERMINATE 317 * @returns { Promise<AbilityConstant.PrepareTermination> } Promise used to return the user's choice. 318 * @syscap SystemCapability.Ability.AbilityRuntime.Core 319 * @stagemodelonly 320 * @atomicservice 321 * @since 15 322 */ 323 onPrepareTerminationAsync(): Promise<AbilityConstant.PrepareTermination>; 324} 325 326 327export default AbilityStage;