1/* 2 * Copyright (c) 2022 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 Ability from "./@ohos.app.ability.Ability"; 17import AbilityConstant from "./@ohos.app.ability.AbilityConstant"; 18import UIAbilityContext from "./application/UIAbilityContext"; 19import rpc from './@ohos.rpc'; 20import Want from './@ohos.app.ability.Want'; 21import window from './@ohos.window'; 22 23/** 24 * The prototype of the listener function interface registered by the Caller. 25 * @typedef OnReleaseCallback 26 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 27 * @StageModelOnly 28 * @since 9 29 */ 30export interface OnReleaseCallback { 31 (msg: string): void; 32} 33 34/** 35 * The prototype of the message listener function interface registered by the Callee. 36 * @typedef CalleeCallback 37 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 38 * @StageModelOnly 39 * @since 9 40 */ 41export interface CalleeCallback { 42 (indata: rpc.MessageSequence): rpc.Parcelable; 43} 44 45/** 46 * The interface of a Caller. 47 * @interface 48 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 49 * @StageModelOnly 50 * @since 9 51 */ 52export interface Caller { 53 /** 54 * Notify the server of Parcelable type data. 55 * @param { string } method - The notification event string listened to by the callee. 56 * @param { rpc.Parcelable } data - Notification data to the callee. 57 * @returns { Promise<void> } The promise returned by the function. 58 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 59 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 60 * @StageModelOnly 61 * @since 9 62 */ 63 call(method: string, data: rpc.Parcelable): Promise<void>; 64 65 /** 66 * Notify the server of Parcelable type data and return the notification result. 67 * @param { string } method - The notification event string listened to by the callee. 68 * @param { rpc.Parcelable } data - Notification data to the callee. 69 * @returns { Promise<rpc.MessageSequence> } Returns the callee's notification result data. 70 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 71 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 72 * @StageModelOnly 73 * @since 9 74 */ 75 callWithResult(method: string, data: rpc.Parcelable): Promise<rpc.MessageSequence>; 76 77 /** 78 * Clear service records. 79 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 80 * @StageModelOnly 81 * @since 9 82 */ 83 release(): void; 84 85 /** 86 * Register death listener notification callback. 87 * @param { OnReleaseCallback } callback - Register a callback function for listening for notifications. 88 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 89 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 90 * @StageModelOnly 91 * @since 9 92 */ 93 onRelease(callback: OnReleaseCallback): void; 94 95 /** 96 * Register death listener notification callback. 97 * @param { string } type - release. 98 * @param { OnReleaseCallback } callback - Register a callback function for listening for notifications. 99 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 100 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 101 * @StageModelOnly 102 * @since 9 103 */ 104 on(type: "release", callback: OnReleaseCallback): void; 105 106 /** 107 * Unregister death listener notification callback. 108 * @param { string } type - release. 109 * @param { OnReleaseCallback } callback - Unregister a callback function for listening for notifications. 110 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 111 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 112 * @StageModelOnly 113 * @since 9 114 */ 115 off(type: "release", callback: OnReleaseCallback): void; 116 117 /** 118 * Unregister all death listener notification callback. 119 * @param { string } type - release. 120 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 121 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 122 * @StageModelOnly 123 * @since 9 124 */ 125 off(type: "release"): void; 126} 127 128/** 129 * The interface of a Callee. 130 * @interface 131 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 132 * @StageModelOnly 133 * @since 9 134 */ 135export interface Callee { 136 /** 137 * Register data listener callback. 138 * @param { string } method - A string registered to listen for notification events. 139 * @param { CalleeCallback } callback - Register a callback function that listens for notification events. 140 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 141 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 142 * @StageModelOnly 143 * @since 9 144 */ 145 on(method: string, callback: CalleeCallback): void; 146 147 /** 148 * Unregister data listener callback. 149 * @param { string } method - A string registered to listen for notification events. 150 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 151 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 152 * @StageModelOnly 153 * @since 9 154 */ 155 off(method: string): void; 156} 157 158/** 159 * The class of a UI ability. 160 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 161 * @StageModelOnly 162 * @since 9 163 */ 164export default class UIAbility extends Ability { 165 /** 166 * Indicates configuration information about an ability context. 167 * @type { UIAbilityContext } 168 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 169 * @StageModelOnly 170 * @since 9 171 */ 172 context: UIAbilityContext; 173 174 /** 175 * Indicates ability launch want. 176 * @type { Want } 177 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 178 * @StageModelOnly 179 * @since 9 180 */ 181 launchWant: Want; 182 183 /** 184 * Indicates ability last request want. 185 * @type { Want } 186 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 187 * @StageModelOnly 188 * @since 9 189 */ 190 lastRequestWant: Want; 191 192 /** 193 * Call Service Stub Object. 194 * @type { Callee } 195 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 196 * @StageModelOnly 197 * @since 9 198 */ 199 callee: Callee; 200 201 /** 202 * Called back when an ability is started for initialization. 203 * @param { Want } want - Indicates the want info of the created ability. 204 * @param { AbilityConstant.LaunchParam } param - Indicates the launch param. 205 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 206 * @StageModelOnly 207 * @since 9 208 */ 209 onCreate(want: Want, param: AbilityConstant.LaunchParam): void; 210 211 /** 212 * Called back when an ability window stage is created. 213 * @param { window.WindowStage } windowStage - Indicates the created WindowStage. 214 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 215 * @StageModelOnly 216 * @since 9 217 */ 218 onWindowStageCreate(windowStage: window.WindowStage): void; 219 220 /** 221 * Called back when an ability window stage is destroyed. 222 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 223 * @StageModelOnly 224 * @since 9 225 */ 226 onWindowStageDestroy(): void; 227 228 /** 229 * Called back when an ability window stage is restored. 230 * @param { window.WindowStage } windowStage - window stage to restore 231 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 232 * @StageModelOnly 233 * @since 9 234 */ 235 onWindowStageRestore(windowStage: window.WindowStage): void; 236 237 /** 238 * Called back before an ability is destroyed. 239 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 240 * @StageModelOnly 241 * @since 9 242 */ 243 onDestroy(): void | Promise<void>; 244 245 /** 246 * Called back when the state of an ability changes to foreground. 247 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 248 * @StageModelOnly 249 * @since 9 250 */ 251 onForeground(): void; 252 253 /** 254 * Called back when the state of an ability changes to background. 255 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 256 * @StageModelOnly 257 * @since 9 258 */ 259 onBackground(): void; 260 261 /** 262 * Called back when an ability prepares to continue. 263 * @param { {[key: string]: Object} } wantParam - Indicates the want parameter. 264 * @returns { AbilityConstant.OnContinueResult } Return the result of onContinue. 265 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 266 * @StageModelOnly 267 * @since 9 268 */ 269 onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResult; 270 271 /** 272 * Called when the launch mode of an ability is set to singleton. 273 * This happens when you re-launch an ability that has been at the top of the ability stack. 274 * @param { Want } want - Indicates the want info of ability. 275 * @param { AbilityConstant.LaunchParam } launchParams - Indicates the launch parameters. 276 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 277 * @StageModelOnly 278 * @since 9 279 */ 280 onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; 281 282 /** 283 * Called when dump client information is required. 284 * It is recommended that developers don't DUMP sensitive information. 285 * @param { Array<string> } params - Indicates the params from command. 286 * @returns { Array<string> } Return the dump info array. 287 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 288 * @StageModelOnly 289 * @since 9 290 */ 291 onDump(params: Array<string>): Array<string>; 292 293 /** 294 * Called back when an ability prepares to save. 295 * @param reason state type when save. 296 * @param wantParam Indicates the want parameter. 297 * @returns 0 if ability agrees to save data successfully, otherwise errcode. 298 * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore 299 * @StageModelOnly 300 * @since 9 301 */ 302 onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Object}): AbilityConstant.OnSaveResult; 303} 304