1/* 2 * Copyright (c) 2021-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 { AsyncCallback, Callback } from './@ohos.base'; 17import Want from './@ohos.app.ability.Want'; 18import { WantAgentInfo } from './wantAgent/wantAgentInfo'; 19import { TriggerInfo } from './wantAgent/triggerInfo'; 20 21/** 22 * Provide the method obtain trigger, cancel, and compare and to obtain 23 * the bundle name, UID of an {@link WantAgent} object. 24 * 25 * @namespace wantAgent 26 * @syscap SystemCapability.Ability.AbilityRuntime.Core 27 * @since 7 28 * @deprecated since 9 29 * @useinstead ohos.app.ability.wantAgent/wantAgent 30 */ 31declare namespace wantAgent { 32 /** 33 * Obtains the bundle name of a WantAgent. 34 * 35 * @param { WantAgent } agent - whose bundle name to obtain. 36 * @param { AsyncCallback<string> } callback - A callback method to obtain the package name of the WantAgent instance. 37 * @syscap SystemCapability.Ability.AbilityRuntime.Core 38 * @since 7 39 * @deprecated since 9 40 * @useinstead ohos.app.ability.wantAgent/wantAgent#getBundleName 41 */ 42 function getBundleName(agent: WantAgent, callback: AsyncCallback<string>): void; 43 44 /** 45 * Obtains the bundle name of a WantAgent. 46 * 47 * @param { WantAgent } agent - whose bundle name to obtain. 48 * @returns { Promise<string> } Returns the bundle name of the {@link WantAgent} if any. 49 * @syscap SystemCapability.Ability.AbilityRuntime.Core 50 * @since 7 51 * @deprecated since 9 52 * @useinstead ohos.app.ability.wantAgent/wantAgent#getBundleName 53 */ 54 function getBundleName(agent: WantAgent): Promise<string>; 55 56 /** 57 * Obtains the UID of a WantAgent. 58 * 59 * @param { WantAgent } agent - whose UID to obtain. 60 * @param { AsyncCallback<number> } callback - Create a callback method for WantAgent. 61 * @syscap SystemCapability.Ability.AbilityRuntime.Core 62 * @since 7 63 * @deprecated since 9 64 * @useinstead ohos.app.ability.wantAgent/wantAgent#getUid 65 */ 66 function getUid(agent: WantAgent, callback: AsyncCallback<number>): void; 67 68 /** 69 * Obtains the UID of a WantAgent. 70 * 71 * @param { WantAgent } agent - whose UID to obtain. 72 * @returns { Promise<number> } Returns the UID of the {@link WantAgent} if any; returns {@code -1} otherwise. 73 * @syscap SystemCapability.Ability.AbilityRuntime.Core 74 * @since 7 75 * @deprecated since 9 76 * @useinstead ohos.app.ability.wantAgent/wantAgent#getUid 77 */ 78 function getUid(agent: WantAgent): Promise<number>; 79 80 /** 81 * Obtains the {@link Want} of an {@link WantAgent}. 82 * 83 * @param { WantAgent } agent - Indicates the {@link WantAgent} whose UID is to be obtained. 84 * @param { AsyncCallback<Want> } callback - Obtain the callback method for Want in WantAgent. 85 * @syscap SystemCapability.Ability.AbilityRuntime.Core 86 * @systemapi 87 * @since 7 88 * @deprecated since 9 89 * @useinstead ohos.app.ability.wantAgent/wantAgent#getWant 90 */ 91 function getWant(agent: WantAgent, callback: AsyncCallback<Want>): void; 92 93 /** 94 * Obtains the {@link Want} of an {@link WantAgent}. 95 * 96 * @param { WantAgent } agent - Indicates the {@link WantAgent} whose UID is to be obtained. 97 * @returns { Promise<Want> } Returns the {@link Want} of the {@link WantAgent}. 98 * @syscap SystemCapability.Ability.AbilityRuntime.Core 99 * @systemapi 100 * @since 7 101 * @deprecated since 9 102 * @useinstead ohos.app.ability.wantAgent/wantAgent#getWant 103 */ 104 function getWant(agent: WantAgent): Promise<Want>; 105 106 /** 107 * Cancel a WantAgent. Only the application that creates the WantAgent can cancel it. 108 * 109 * @param { WantAgent } agent - to cancel. 110 * @param { AsyncCallback<void> } callback - Cancel the callback method for Want in WantAgent. 111 * @syscap SystemCapability.Ability.AbilityRuntime.Core 112 * @since 7 113 * @deprecated since 9 114 * @useinstead ohos.app.ability.wantAgent/wantAgent#cancel 115 */ 116 function cancel(agent: WantAgent, callback: AsyncCallback<void>): void; 117 118 /** 119 * Cancel a WantAgent. Only the application that creates the WantAgent can cancel it. 120 * 121 * @param { WantAgent } agent - to cancel. 122 * @returns { Promise<void> } The promise returned by the function. 123 * @syscap SystemCapability.Ability.AbilityRuntime.Core 124 * @since 7 125 * @deprecated since 9 126 * @useinstead ohos.app.ability.wantAgent/wantAgent#cancel 127 */ 128 function cancel(agent: WantAgent): Promise<void>; 129 130 /** 131 * Triggers a WantAgent. 132 * 133 * @param { WantAgent } agent - to trigger. 134 * @param { TriggerInfo } triggerInfo - parameters. 135 * @param { Callback<CompleteData> } [callback] - Indicates the callback method to be called after 136 * the {@link WantAgent} is triggered. 137 * @syscap SystemCapability.Ability.AbilityRuntime.Core 138 * @since 7 139 * @deprecated since 9 140 * @useinstead ohos.app.ability.wantAgent/wantAgent#trigger 141 */ 142 function trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>): void; 143 144 /** 145 * Checks whether two WantAgent objects are equal. 146 * 147 * @param { WantAgent } agent - to compare. 148 * @param { WantAgent } otherAgent - WantAgent Object. 149 * @param { AsyncCallback<boolean> } callback - Callback method for determining whether two WantAgent instances are 150 * equal. 151 * @syscap SystemCapability.Ability.AbilityRuntime.Core 152 * @since 7 153 * @deprecated since 9 154 * @useinstead ohos.app.ability.wantAgent/wantAgent#equal 155 */ 156 function equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>): void; 157 158 /** 159 * Checks whether two WantAgent objects are equal. 160 * 161 * @param { WantAgent } agent - to compare. 162 * @param { WantAgent } otherAgent - WantAgent Object. 163 * @returns { Promise<boolean> } Returns {@code true} If the two objects are the same; returns {@code false} otherwise. 164 * @syscap SystemCapability.Ability.AbilityRuntime.Core 165 * @since 7 166 * @deprecated since 9 167 * @useinstead ohos.app.ability.wantAgent/wantAgent#equal 168 */ 169 function equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean>; 170 171 /** 172 * Obtains a WantAgent object. 173 * 174 * @param { WantAgentInfo } info - about the WantAgent object to obtain. 175 * @param { AsyncCallback<WantAgent> } callback - Callback method for obtaining the user ID of WantAgent instance. 176 * @syscap SystemCapability.Ability.AbilityRuntime.Core 177 * @since 7 178 * @deprecated since 9 179 * @useinstead ohos.app.ability.wantAgent/wantAgent#getWantAgent 180 */ 181 function getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void; 182 183 /** 184 * Obtains a WantAgent object. 185 * 186 * @param { WantAgentInfo } info - about the WantAgent object to obtain. 187 * @returns { Promise<WantAgent> } Returns the created {@link WantAgent} object. 188 * @syscap SystemCapability.Ability.AbilityRuntime.Core 189 * @since 7 190 * @deprecated since 9 191 * @useinstead ohos.app.ability.wantAgent/wantAgent#getWantAgent 192 */ 193 function getWantAgent(info: WantAgentInfo): Promise<WantAgent>; 194 195 /** 196 * Enumerates flags for using a WantAgent. 197 * 198 * @enum { number } 199 * @syscap SystemCapability.Ability.AbilityRuntime.Core 200 * @since 7 201 * @deprecated since 9 202 * @useinstead ohos.app.ability.wantAgent/wantAgent#WantAgentFlags 203 */ 204 export enum WantAgentFlags { 205 /** 206 * Indicates that the WantAgent can be used only once. 207 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 208 * 209 * @syscap SystemCapability.Ability.AbilityRuntime.Core 210 * @since 7 211 * @deprecated since 9 212 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#ONE_TIME_FLAG 213 */ 214 ONE_TIME_FLAG = 0, 215 216 /** 217 * Indicates that null is returned if the WantAgent does not exist. 218 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 219 * 220 * @syscap SystemCapability.Ability.AbilityRuntime.Core 221 * @since 7 222 * @deprecated since 9 223 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#NO_BUILD_FLAG 224 */ 225 NO_BUILD_FLAG, 226 227 /** 228 * Indicates that the existing WantAgent should be canceled before a new object is generated. 229 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 230 * 231 * @syscap SystemCapability.Ability.AbilityRuntime.Core 232 * @since 7 233 * @deprecated since 9 234 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#CANCEL_PRESENT_FLAG 235 */ 236 CANCEL_PRESENT_FLAG, 237 238 /** 239 * Indicates that the system only replaces the extra data of the existing WantAgent with that of the new object. 240 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 241 * 242 * @syscap SystemCapability.Ability.AbilityRuntime.Core 243 * @since 7 244 * @deprecated since 9 245 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#UPDATE_PRESENT_FLAG 246 */ 247 UPDATE_PRESENT_FLAG, 248 249 /** 250 * Indicates that the created WantAgent should be immutable. 251 * 252 * @syscap SystemCapability.Ability.AbilityRuntime.Core 253 * @since 7 254 * @deprecated since 9 255 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#CONSTANT_FLAG 256 */ 257 CONSTANT_FLAG, 258 259 /** 260 * Indicates that the current value of element can be replaced when the WantAgent is triggered. 261 * 262 * @syscap SystemCapability.Ability.AbilityRuntime.Core 263 * @since 7 264 * @deprecated since 9 265 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#REPLACE_ELEMENT 266 */ 267 REPLACE_ELEMENT, 268 269 /** 270 * Indicates that the current value of action can be replaced when the WantAgent is triggered. 271 * 272 * @syscap SystemCapability.Ability.AbilityRuntime.Core 273 * @since 7 274 * @deprecated since 9 275 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#REPLACE_ACTION 276 */ 277 REPLACE_ACTION, 278 279 /** 280 * Indicates that the current value of uri can be replaced when the WantAgent is triggered. 281 * 282 * @syscap SystemCapability.Ability.AbilityRuntime.Core 283 * @since 7 284 * @deprecated since 9 285 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#REPLACE_URI 286 */ 287 REPLACE_URI, 288 289 /** 290 * Indicates that the current value of entities can be replaced when the WantAgent is triggered. 291 * 292 * @syscap SystemCapability.Ability.AbilityRuntime.Core 293 * @since 7 294 * @deprecated since 9 295 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#REPLACE_ENTITIES 296 */ 297 REPLACE_ENTITIES, 298 299 /** 300 * Indicates that the current value of packageName can be replaced when the WantAgent is triggered. 301 * 302 * @syscap SystemCapability.Ability.AbilityRuntime.Core 303 * @since 7 304 * @deprecated since 9 305 * @useinstead ohos.app.ability.wantAgent/wantAgent.WantAgentFlags#REPLACE_BUNDLE 306 */ 307 REPLACE_BUNDLE 308 } 309 310 /** 311 * Identifies the operation for using a WantAgent, such as starting an ability or sending a common event. 312 * 313 * @enum { number } 314 * @syscap SystemCapability.Ability.AbilityRuntime.Core 315 * @since 7 316 * @deprecated since 9 317 * @useinstead ohos.app.ability.wantAgent/wantAgent#OperationType 318 */ 319 export enum OperationType { 320 /** 321 * Unknown operation. 322 * 323 * @syscap SystemCapability.Ability.AbilityRuntime.Core 324 * @since 7 325 * @deprecated since 9 326 * @useinstead ohos.app.ability.wantAgent/wantAgent.OperationType#UNKNOWN_TYPE 327 */ 328 UNKNOWN_TYPE = 0, 329 330 /** 331 * Starts an ability with a UI. 332 * 333 * @syscap SystemCapability.Ability.AbilityRuntime.Core 334 * @since 7 335 * @deprecated since 9 336 * @useinstead ohos.app.ability.wantAgent/wantAgent.OperationType#START_ABILITY 337 */ 338 START_ABILITY, 339 340 /** 341 * Starts multiple abilities with a UI. 342 * 343 * @syscap SystemCapability.Ability.AbilityRuntime.Core 344 * @since 7 345 * @deprecated since 9 346 * @useinstead ohos.app.ability.wantAgent/wantAgent.OperationType#START_ABILITIES 347 */ 348 START_ABILITIES, 349 350 /** 351 * Starts an ability without a UI. 352 * 353 * @syscap SystemCapability.Ability.AbilityRuntime.Core 354 * @since 7 355 * @deprecated since 9 356 * @useinstead ohos.app.ability.wantAgent/wantAgent.OperationType#START_SERVICE 357 */ 358 START_SERVICE, 359 360 /** 361 * Sends a common event. 362 * 363 * @syscap SystemCapability.Ability.AbilityRuntime.Core 364 * @since 7 365 * @deprecated since 9 366 * @useinstead ohos.app.ability.wantAgent/wantAgent.OperationType#SEND_COMMON_EVENT 367 */ 368 SEND_COMMON_EVENT 369 } 370 371 /** 372 * Describes the data returned by after wantAgent.trigger is called. 373 * 374 * @typedef CompleteData 375 * @syscap SystemCapability.Ability.AbilityRuntime.Core 376 * @since 7 377 * @deprecated since 9 378 * @useinstead ohos.app.ability.wantAgent/wantAgent#CompleteData 379 */ 380 export interface CompleteData { 381 /** 382 * Triggered WantAgent. 383 * 384 * @type { WantAgent } 385 * @syscap SystemCapability.Ability.AbilityRuntime.Core 386 * @since 7 387 * @deprecated since 9 388 * @useinstead ohos.app.ability.wantAgent/wantAgent.CompleteData#info 389 */ 390 info: WantAgent; 391 392 /** 393 * Existing Want that is triggered. 394 * 395 * @type { Want } 396 * @syscap SystemCapability.Ability.AbilityRuntime.Core 397 * @since 7 398 * @deprecated since 9 399 * @useinstead ohos.app.ability.wantAgent/wantAgent.CompleteData#want 400 */ 401 want: Want; 402 403 /** 404 * Request code used to trigger the WantAgent. 405 * 406 * @type { number } 407 * @syscap SystemCapability.Ability.AbilityRuntime.Core 408 * @since 7 409 * @deprecated since 9 410 * @useinstead ohos.app.ability.wantAgent/wantAgent.CompleteData#finalCode 411 */ 412 finalCode: number; 413 414 /** 415 * Final data collected by the common event. 416 * 417 * @type { string } 418 * @syscap SystemCapability.Ability.AbilityRuntime.Core 419 * @since 7 420 * @deprecated since 9 421 * @useinstead ohos.app.ability.wantAgent/wantAgent.CompleteData#finalData 422 */ 423 finalData: string; 424 425 /** 426 * Extra data collected by the common event. 427 * 428 * @type { ?object } 429 * @syscap SystemCapability.Ability.AbilityRuntime.Core 430 * @since 7 431 * @deprecated since 9 432 * @useinstead ohos.app.ability.wantAgent/wantAgent.CompleteData#extraInfo 433 */ 434 extraInfo?: { [key: string]: any }; 435 } 436} 437 438/** 439 * WantAgent object. 440 * 441 * @syscap SystemCapability.Ability.AbilityRuntime.Core 442 * @since 7 443 */ 444export type WantAgent = object; 445 446export default wantAgent; 447