1/* 2 * Copyright (c) 2021 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 './basic'; 17import { Want } from './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 * @name wantAgent 26 * @since 7 27 * @syscap SystemCapability.Ability.AbilityRuntime.Core 28 * @import import wantAgent from '@ohos.wantAgent'; 29 * @permission N/A 30 */ 31declare namespace wantAgent { 32 /** 33 * Obtains the bundle name of a WantAgent. 34 * 35 * @param WantAgent whose bundle name to obtain. 36 * @return Returns the bundle name of the {@link WantAgent} if any. 37 */ 38 function getBundleName(agent: WantAgent, callback: AsyncCallback<string>): void; 39 function getBundleName(agent: WantAgent): Promise<string>; 40 41 /** 42 * Obtains the UID of a WantAgent. 43 * 44 * @param WantAgent whose UID to obtain. 45 * @return Returns the UID of the {@link WantAgent} if any; returns {@code -1} otherwise. 46 */ 47 function getUid(agent: WantAgent, callback: AsyncCallback<number>): void; 48 function getUid(agent: WantAgent): Promise<number>; 49 50 /** 51 * Obtains the {@link Want} of an {@link WantAgent}. 52 * 53 * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. 54 * @return Returns the {@link Want} of the {@link WantAgent}. 55 * @systemapi Hide this for inner system use. 56 */ 57 function getWant(agent: WantAgent, callback: AsyncCallback<Want>): void; 58 59 /** 60 * Obtains the {@link Want} of an {@link WantAgent}. 61 * 62 * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. 63 * @return Returns the {@link Want} of the {@link WantAgent}. 64 * @systemapi Hide this for inner system use. 65 */ 66 function getWant(agent: WantAgent): Promise<Want>; 67 68 /** 69 * Cancels a WantAgent. Only the application that creates the WantAgent can cancel it. 70 * 71 * @param WantAgent to cancel. 72 */ 73 function cancel(agent: WantAgent, callback: AsyncCallback<void>): void; 74 function cancel(agent: WantAgent): Promise<void>; 75 76 /** 77 * Triggers a WantAgent. 78 * 79 * @param WantAgent to trigger. 80 * @param Trigger parameters. 81 * @param callback Indicates the callback method to be called after the {@link WantAgent} is triggered. 82 */ 83 function trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>): void; 84 85 /** 86 * Checks whether two WantAgent objects are equal. 87 * 88 * @param WantAgent to compare. 89 * @param WantAgent to compare. 90 * @return Returns {@code true} If the two objects are the same; returns {@code false} otherwise. 91 */ 92 function equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>): void; 93 function equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean>; 94 95 /** 96 * Obtains a WantAgent object. 97 * 98 * @param Information about the WantAgent object to obtain. 99 * @return Returns the created {@link WantAgent} object. 100 */ 101 function getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void; 102 function getWantAgent(info: WantAgentInfo): Promise<WantAgent>; 103 104 /** 105 * Enumerates flags for using a WantAgent. 106 */ 107 export enum WantAgentFlags { 108 /** 109 * Indicates that the WantAgent can be used only once. 110 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 111 */ 112 ONE_TIME_FLAG = 0, 113 114 /** 115 * Indicates that null is returned if the WantAgent does not exist. 116 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 117 */ 118 NO_BUILD_FLAG, 119 120 /** 121 * Indicates that the existing WantAgent should be canceled before a new object is generated. 122 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 123 */ 124 CANCEL_PRESENT_FLAG, 125 126 /** 127 * Indicates that the system only replaces the extra data of the existing WantAgent with that of the new object. 128 * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. 129 */ 130 UPDATE_PRESENT_FLAG, 131 132 /** 133 * Indicates that the created WantAgent should be immutable. 134 */ 135 CONSTANT_FLAG, 136 137 /** 138 * Indicates that the current value of element can be replaced when the WantAgent is triggered. 139 */ 140 REPLACE_ELEMENT, 141 142 /** 143 * Indicates that the current value of action can be replaced when the WantAgent is triggered. 144 */ 145 REPLACE_ACTION, 146 147 /** 148 * Indicates that the current value of uri can be replaced when the WantAgent is triggered. 149 */ 150 REPLACE_URI, 151 152 /** 153 * Indicates that the current value of entities can be replaced when the WantAgent is triggered. 154 */ 155 REPLACE_ENTITIES, 156 157 /** 158 * Indicates that the current value of packageName can be replaced when the WantAgent is triggered. 159 */ 160 REPLACE_BUNDLE 161 } 162 163 /** 164 * Identifies the operation for using a WantAgent, such as starting an ability or sending a common event. 165 */ 166 export enum OperationType { 167 /** 168 * Unknown operation. 169 */ 170 UNKNOWN_TYPE = 0, 171 172 /** 173 * Starts an ability with a UI. 174 */ 175 START_ABILITY, 176 177 /** 178 * Starts multiple abilities with a UI. 179 */ 180 START_ABILITIES, 181 182 /** 183 * Starts an ability without a UI. 184 */ 185 START_SERVICE, 186 187 /** 188 * Sends a common event. 189 */ 190 SEND_COMMON_EVENT 191 } 192 193 /** 194 * Describes the data returned by after wantAgent.trigger is called. 195 */ 196 export interface CompleteData { 197 /** 198 * Triggered WantAgent. 199 */ 200 info: WantAgent; 201 202 /** 203 * Existing Want that is triggered. 204 */ 205 want: Want; 206 207 /** 208 * Request code used to trigger the WantAgent. 209 */ 210 finalCode: number; 211 212 /** 213 * Final data collected by the common event. 214 */ 215 finalData: string; 216 217 /** 218 * Extra data collected by the common event. 219 */ 220 extraInfo?: {[key: string]: any}; 221 } 222} 223 224/** 225 * WantAgent object. 226 */ 227export type WantAgent = object; 228 229export default wantAgent;