• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15import { AsyncCallback } from './.basic';
16import { Want } from './ability/want';
17import { FormInfo } from './ability/forminfo';
18
19/**
20 * Provides utilities for system application components to access ability form
21 * on the OHOS OS.
22 * @name formManager
23 * @since 7
24 * @sysCap AAFwk
25 * @devices phone, tablet
26 * @permission N/A
27 */
28declare namespace formManager {
29  /**
30   * user need to force refresh form.
31   *
32   * <p>You can use this method to ask for newly form from service.</p>
33   *
34   * @param formId the specify form id.
35   * @since 7
36   */
37  function requestForm(formId: number, callback: AsyncCallback<void>): void;
38  function requestForm(formId: number): Promise<void>;
39
40  /**
41   * delete forms.
42   *
43   * <p>You can use this method to delete ability form.</p>
44   *
45   * @param formId Indicates the form to be deleted.
46   * @since 7
47   */
48  function deleteForm(formId: number, callback: AsyncCallback<void>): void;
49  function deleteForm(formId: number): Promise<void>;
50
51  /**
52   * release form.
53   *
54   * <p>You can use this method to release ability form, it does not delete form cache in
55   * form manager.</p>
56   *
57   * @param formId Indicates the form to be released.
58   * @param isReleaseCache Indicates whether to delete cache in service.
59   * @since 7
60   */
61  function releaseForm(formId: number, isReleaseCache: boolean, callback: AsyncCallback<void>): void;
62  function releaseForm(formId: number, isReleaseCache: boolean): Promise<void>;
63
64  /**
65   * Sends a notification to the form framework to make the specified forms visible.
66   *
67   * @param formIds Indicates the IDs of the forms to be made visible.
68   * @since 7
69   */
70  function notifyVisibleForms(formIds: Array<number>, callback: AsyncCallback<void>): void;
71  function notifyVisibleForms(formIds: Array<number>): Promise<void>;
72
73  /**
74   * Sends a notification to the form framework to make the specified forms invisible.
75   *
76   * @param formIds Indicates the IDs of the forms to be made invisible.
77   * @since 7
78   */
79  function notifyInvisibleForms(formIds: Array<number>, callback: AsyncCallback<void>): void;
80  function notifyInvisibleForms(formIds: Array<number>): Promise<void>;
81
82  /**
83   * set form refresh state to true.
84   *
85   * <p>You can use this method to set form refresh state to true, the form can receive new
86   * update from service.</p>
87   *
88   * @param formIds the specify form id.
89   * @since 7
90   */
91  function enableFormsUpdate(formIds: Array<number>, callback: AsyncCallback<void>): void;
92  function enableFormsUpdate(formIds: Array<number>): Promise<void>;
93
94  /**
95   * set form refresh state to false.
96   *
97   * <p>You can use this method to set form refresh state to false, the form do not receive
98     * new update from service.</p>
99   *
100   * @param formIds the specify form id.
101   * @since 7
102   */
103  function disableFormsUpdate(formIds: Array<number>, callback: AsyncCallback<void>): void;
104  function disableFormsUpdate(formIds: Array<number>): Promise<void>;
105
106  /**
107   * Check form manager service ready.
108   *
109   * <p>You can use this method to check if form manager service is ready.</p>
110   *
111   * @return Returns {@code true} form manager service ready; returns {@code false} otherwise.
112   * @since 7
113   */
114  function checkFMSReady(callback: AsyncCallback<boolean>): void;
115  function checkFMSReady(): Promise<boolean>;
116
117  /**
118   * Cast temp form to narmal form.
119   *
120   * <p>You can use this method to cast a temp form to normal form.</p>
121   *
122   * @param formId the specify form id to be casted.
123   * @since 7
124   */
125  function castTempForm(formId: number, callback: AsyncCallback<void>): void;
126  function castTempForm(formId: number): Promise<void>;
127
128  /**
129   * Checks for and deletes invalid forms of the application in the Form Manager Service based on the list of valid
130   * form IDs passed.
131   *
132   * <p>If an empty list is passed to this method, the Form Manager Service will delete all forms of the
133   * application.</p>
134   *
135   * @param persistedIds Indicates the list of valid forms with persisted IDs.
136   * @since 7
137   */
138  function checkAndDeleteInvalidForms(persistedIds: Array<number>, callback: AsyncCallback<void>): void;
139  function checkAndDeleteInvalidForms(persistedIds: Array<number>): Promise<void>;
140
141   /**
142   * Updates the content of a specified JS form.
143   *
144   * <p>This method is called by a form provider to update JS form data as needed.
145   *
146   * @param formId Indicates the ID of the JS form to update.
147   * @param formBindingData Indicates the object used to update the JS form displayed
148   *                        on the client.
149   * @return Returns {@code true} if the update is successful; returns {@code false} otherwise.
150   * @throws FormException Throws this exception if the form fails to be obtained due to any of the following reasons:
151   * <ul>
152   * <li>The passed {@code formID} or {@code component} is invalid. The value of {@code formID} must be larger than 0,
153   * and {@code component} must not be null.</li>
154   * <li>An error occurred when connecting to the Form Manager Service.</li>
155   * <li>The specified form ID does not exist. </li>
156   * <li>The form has been obtained by another application and cannot be updated by the current application.</li>
157   * <li>The form is being restored.</li>
158   * </ul>
159   * @since 7
160   */
161  function updateForm(formid: number, data: FormBindingData, callback: AsyncCallback<boolean>): void;
162  function updateForm(formid: number, data: FormBindingData): Promise<boolean>;
163
164  /**
165     * Set next refresh time since now.
166     *
167     * <p>This method is called by a form provider to set refresh time.
168     *
169     * @param formId Indicates the ID of the form to set refreshTime.
170     * @param bundleName Indicates the bundleName of current form.
171     * @param nextTime Indicates the next time gap now in seconds, can not be litter than 5 mins.
172     * @return Returns {@code true} if seting succeed; returns {@code false} otherwise.
173     * @throws FormException Throws this exception if the form fails to be obtained due to any of the following reasons:
174     * <ul>
175     * <li>The passed {@code formId} or {@code nextTime} is invalid. The value of {@code formId} must be larger
176     * than 0, and {@code nextTime} must at least be 120 (5min).</li>
177     * <li>An error occurred when connecting to the Form Manager Service.</li>
178     * <li>The specified form ID does not exist. </li>
179     * <li>The form has been obtained by another application and cannot be updated by the current application.</li>
180     * <li>The form is being restored.</li>
181     * </ul>
182     * @since 7
183     */
184  function setFormNextRefreshTime(formid: number, nextTime: number, callback: AsyncCallback<boolean>): boolean;
185  function setFormNextRefreshTime(formid: number, nextTime: number): Promise<boolean>;
186
187  /**
188   * get all forms info.
189   *
190   * <p>You can use this method to get all forms info.</p>
191   *
192   * @return Returns the forms' information of all forms provided
193   * @since 7
194   */
195  function getAllFormsInfo(callback: AsyncCallback<Array<FormInfo>>): void;
196  function getAllFormsInfo(): Promise<Array<FormInfo>>;
197
198  /**
199   * get forms info by application name.
200   *
201   * <p>You can use this method to get all forms info of the specify application name.</p>
202   *
203   * @param bundleName application name.
204   * @return Returns the forms' information of the specify application name.
205   * @since 7
206   */
207  function getFormsInfoByApp(bundleName: string, callback: AsyncCallback<FormInfo>): void;
208  function getFormsInfoByApp(bundleName: string): Promise<FormInfo>;
209
210  /**
211   * get forms info by application name and module name.
212   *
213   * <p>You can use this method to get all forms info of the specify application name and module name.</p>
214   *
215   * @param bundleName application name.
216   * @param moduleName module name of hap
217   * @return Returns the forms' information of the specify application name and module name
218   * @since 7
219   */
220  function getFormsInfoByModule(bundleName: string, moduleName: string, callback: AsyncCallback<FormInfo>): void;
221  function getFormsInfoByModule(bundleName: string, moduleName: string): Promise<FormInfo>;
222
223  on(type: "formUninstalled", formID: number, callback: AsyncCallback<void>): void;
224  off(type: "formUninstalled", formID: number, callback?: AsyncCallback<void>): void;
225
226  on(type: "getAnimation", callback: AsyncCallback<AnimatorOption>): void;
227  off(type: "getAnimation", callback?: AsyncCallback<AnimatorOption>): void;
228
229  export enum FromParam {
230    /**
231     * Indicates the key specifying the ID of the form to be obtained, which is represented as
232     * {@code intent.setParam(PARAM_FORM_IDENTITY_KEY, 1L)}.
233     */
234    IDENTITY_KEY = "ohos.extra.param.key.form_identity",
235    /**
236     * Indicates the form dimension, now value support 1,2,3,4.
237     */
238    DIMENSION_KEY = "ohos.extra.param.key.form_dimension",
239    /**
240     * Indicates the form name.
241     */
242    NAME_KEY = "ohos.extra.param.key.form_name",
243    /**
244     * Indicates the module name of the form.
245     */
246    NAME_KEY = "ohos.extra.param.key.module_name",
247    /**
248     * Indicates the form view width.
249     */
250    WIDTH_KEY = "ohos.extra.param.key.form_width",
251    /**
252     * Indicates the form view height.
253     */
254    HEIGHT_KEY = "ohos.extra.param.key.form_height",
255    /**
256     * Indicates the temporary flag of form to be obtained
257     */
258    TEMPORARY_KEY = "ohos.extra.param.key.form_temporary"
259  }
260
261  export enum FormError {
262    ERR_CODE_COMMON = 1,
263    ERR_PERMISSION_DENY = 2,
264    ERR_GET_INFO_FAILED = 4,
265    ERR_GET_BUNDLE_FAILED = 5,
266    ERR_GET_LAYOUT_FAILED = 6,
267    ERR_ADD_INVALID_PARAM = 7,
268    ERR_CFG_NOT_MATCH_ID = 8,
269    ERR_NOT_EXIST_ID = 9,
270    ERR_BIND_PROVIDER_FAILED = 10,
271    ERR_MAX_SYSTEM_FORMS = 11,
272    ERR_MAX_INSTANCES_PER_FORM = 12,
273    ERR_OPERATION_FORM_NOT_SELF = 13,
274    ERR_PROVIDER_DEL_FAIL = 14,
275    ERR_MAX_FORMS_PER_CLIENT = 15,
276    ERR_MAX_SYSTEM_TEMP_FORMS = 16,
277    ERR_FORM_NO_SUCH_MODULE = 17,
278    ERR_FORM_NO_SUCH_ABILITY = 18,
279    ERR_FORM_NO_SUCH_DIMENSION = 19,
280    ERR_FORM_FA_NOT_INSTALLED = 20,
281
282    // error code in sdk
283    ERR_GET_FMS_RPC = 30,
284    ERR_FORM_DUPLICATE_ADDED = 31,
285    ERR_SEND_FMS_MSG = 32,
286    ERR_GET_BMS_RPC = 33,
287    ERR_SEND_BMS_MSG = 34,
288    ERR_START_ABILITY = 35,
289    ERR_IN_RECOVER = 36
290  }
291}
292export default formManager;