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