• 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 */
15
16import Want from "../../@ohos.app.ability.Want";
17import { ResultSet } from "../../data/rdb/resultSet";
18import { AbilityInfo } from "../../bundle/abilityInfo";
19import { DataAbilityResult } from "../../ability/dataAbilityResult";
20import { DataAbilityOperation } from "../../ability/dataAbilityOperation";
21import dataAbility from "../../@ohos.data.dataAbility";
22import formBindingData from "../../@ohos.application.formBindingData";
23import formInfo from "../../@ohos.app.form.formInfo";
24import rdb from "../../@ohos.data.rdb";
25import rpc from "../../@ohos.rpc";
26import resourceManager from "../../@ohos.resourceManager";
27import { PacMap } from "../../ability/dataAbilityHelper";
28import { AsyncCallback } from "../../basic";
29
30/**
31 * interface of form lifecycle.
32 *
33 * @name LifecycleForm
34 * @since 7
35 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
36 * @FAModelOnly
37 */
38export declare interface LifecycleForm {
39  /**
40   * Called to return a {@link formBindingData.FormBindingData} object.
41   *
42   * @since 8
43   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
44   * @param want Indicates the detailed information for creating a {@link formBindingData#FormBindingData}.
45   *               The {@code Want} object must include the form ID, form name, and grid style of the form,
46   *               which can be obtained from {@link formInfo#FormParam#IDENTITY_KEY},
47   *               {@link formInfo#FormParam#NAME_KEY}, and {@link formInfo#FormParam#DIMENSION_KEY},
48   *               respectively. Such form information must be managed as persistent data for further form
49   *               acquisition, update, and deletion.
50   * @returns Returns the created {@link formBindingData#FormBindingData} object.
51   * @FAModelOnly
52   */
53  onCreate?(want: Want): formBindingData.FormBindingData;
54
55  /**
56   * Called when the form provider is notified that a temporary form is successfully converted to a normal form.
57   *
58   * @since 8
59   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
60   * @param formId Indicates the ID of the form.
61   * @returns -
62   * @FAModelOnly
63   */
64  onCastToNormal?(formId: string): void;
65
66  /**
67   * Called to notify the form provider to update a specified form.
68   *
69   * @since 8
70   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
71   * @param formId Indicates the ID of the form to update.
72   * @returns -
73   * @FAModelOnly
74   */
75  onUpdate?(formId: string): void;
76
77  /**
78   * Called when the form provider receives form events from the system.
79   *
80   * @since 8
81   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
82   * @param newStatus Indicates the form events occurred. The key in the {@code Map} object indicates the form ID,
83   *    and the value indicates the event type, which can be either {@link formInfo#VisibilityType#FORM_VISIBLE}
84   *    or {@link formInfo#VisibilityType#FORM_INVISIBLE}. {@link formInfo#VisibilityType#FORM_VISIBLE}
85   *    means that the form becomes visible, and {@link formInfo#VisibilityType#FORM_INVISIBLE}
86   *    means that the form becomes invisible.
87   * @returns -
88   * @FAModelOnly
89   */
90  onVisibilityChange?(newStatus: { [key: string]: number }): void;
91
92  /**
93   * Called when a specified message event defined by the form provider is triggered. This method is valid only for
94   * JS forms.
95   *
96   * @since 8
97   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
98   * @param formId Indicates the ID of the form on which the message event is triggered, which is provided by
99   *               the client to the form provider.
100   * @param message Indicates the value of the {@code params} field of the message event. This parameter is
101   *                used to identify the specific component on which the event is triggered.
102   * @returns -
103   * @FAModelOnly
104   */
105  onEvent?(formId: string, message: string): void;
106
107  /**
108   * Called to notify the form provider that a specified form has been deleted. Override this method if
109   * you want your application, as the form provider, to be notified of form deletion.
110   *
111   * @since 8
112   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
113   * @param formId Indicates the ID of the deleted form.
114   * @returns -
115   * @FAModelOnly
116   */
117  onDestroy?(formId: string): void;
118
119  /**
120   * Called to return a {@link FormState} object.
121   *
122   * <p>You must override this callback if you want this ability to return the actual form state. Otherwise,
123   * this method returns {@link FormState#DEFAULT} by default.</p>
124   *
125   * @since 8
126   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
127   * @param want Indicates the description of the form for which the {@link formInfo#FormState} is obtained.
128   *    The description covers the bundle name, ability name, module name, form name, and form dimensions.
129   * @returns Returns the {@link formInfo#FormState} object.
130   * @FAModelOnly
131   */
132  onAcquireFormState?(want: Want): formInfo.FormState;
133
134  /**
135   * Called when the system shares the form.
136   *
137   * @since 9
138   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
139   * @param formId Indicates the ID of the deleted form.
140   * @systemapi hide for inner use.
141   * @returns Returns the wantParams object.
142   * @FAModelOnly
143   */
144  onShare?(formId: string): {[key: string]: any};
145}
146
147/**
148 * interface of app lifecycle.
149 *
150 * @name LifecycleApp
151 * @since 7
152 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
153 * @FAModelOnly
154 */
155export declare interface LifecycleApp {
156  /**
157   * Called back when the state of an ability changes from <b>BACKGROUND</b> to <b>INACTIVE</b>.
158   *
159   * @since 7
160   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
161   * @returns -
162   * @FAModelOnly
163   */
164  onShow?(): void;
165
166  /**
167   * Called back when an ability enters the <b>BACKGROUND</b> state.
168   *
169   * @since 7
170   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
171   * @returns -
172   * @FAModelOnly
173   */
174  onHide?(): void;
175
176  /**
177   * Called back before an ability is destroyed.
178   *
179   * @since 7
180   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
181   * @returns -
182   * @FAModelOnly
183   */
184  onDestroy?(): void;
185
186  /**
187   * Called back when an ability is started for initialization.
188   *
189   * @since 7
190   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
191   * @returns -
192   * @FAModelOnly
193   */
194  onCreate?(): void;
195
196  /**
197   * Called when the window display mode of this ability changes, for example, from fullscreen mode
198   *     to multi-window mode or from multi-window mode to fullscreen mode.
199   *
200   * @since 7
201   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
202   * @param isShownInMultiWindow Specifies whether this ability is currently in multi-window mode.
203   *     The value {@code true} indicates the multi-window mode, and {@code false} indicates another mode.
204   * @param newConfig Indicates the new configuration information about this Page ability.
205   * @returns -
206   * @systemapi hide for inner use.
207   * @FAModelOnly
208   */
209  onWindowDisplayModeChanged?(isShownInMultiWindow: boolean, newConfig: resourceManager.Configuration): void;
210
211  /**
212   * Asks a user whether to start the migration.
213   *
214   * @since 7
215   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
216   * @returns Returns {@code true} if the user allows the migration; returns {@code false} otherwise.
217   * @FAModelOnly
218   */
219  onStartContinuation?(): boolean;
220
221  /**
222   * Saves the user data of a local ability generated during runtime.
223   * After the migration is triggered and the local ability is ready, this method is called when the Distributed
224   * Scheduler Service requests data from the local ability.
225   *
226   * @since 7
227   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
228   * @param data Indicates the user data to save.
229   * @returns Returns {@code true} if the data is successfully saved; returns {@code false} otherwise.
230   * @FAModelOnly
231   */
232  onSaveData?(data: Object): boolean;
233
234  /**
235   * Called back when a local ability migration is complete.
236   *
237   * <p>You can define the processing logic after the migration is complete. For example, you can display a prompt to
238   * notify the user of the successful migration and then exit the local ability.</p>
239   *
240   * @since 7
241   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
242   * @param result Indicates the migration result code. The value {@code 0} indicates that the migration is
243   *               successful, and {@code -1} indicates that the migration fails.
244   * @returns -
245   * @FAModelOnly
246   */
247  onCompleteContinuation?(result: number): void;
248
249  /**
250   * Restores the user data saved during the migration for an ability on the remote device immediately after the
251   * ability is created on the remote device. Lifecycle scheduling for the ability starts only after the user data
252   * is restored.
253   *
254   * @since 7
255   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
256   * @param data Indicates the user data to restore.
257   * @returns -
258   * @FAModelOnly
259   */
260  onRestoreData?(data: Object): void;
261
262  /**
263   * Called to notify the local device when a running ability on the remote device is destroyed after a reversible
264   * migration is performed for the ability from the local device to the remote device.
265   *
266   * @since 7
267   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
268   * @returns -
269   * @FAModelOnly
270   */
271  onRemoteTerminated?(): void;
272
273  /**
274   * This method is called when the system determines that the ability may be destroyed in an unexpected
275   * situation, for example, when the screen orientation changes or the user touches the Home key. Generally,
276   * this method is used only to save temporary states.
277   *
278   * @since 7
279   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
280   * @param outState Indicates the {@code PacMap} object used for storing user data and states. This
281   * parameter cannot be null.
282   * @returns -
283   * @FAModelOnly
284   */
285  onSaveAbilityState?(outState: PacMap): void;
286
287  /**
288   * This method is called if an ability was destroyed at a certain time due to resource reclaim or was
289   * unexpectedly destroyed and the {@link #onSaveAbilityState(PacMap)} method was called to save its user data and
290   * states. Generally, this method is called after the {@link #onStart(Want)} method.
291   *
292   * @since 7
293   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
294   * @param inState Indicates the {@code PacMap} object used for storing data and states. This
295   * parameter can not be null.
296   * @returns -
297   * @FAModelOnly
298   */
299  onRestoreAbilityState?(inState: PacMap): void;
300
301  /**
302   * Called back when an ability enters the <b>INACTIVE</b> state (an ability in this state is not interactive and may
303   * change to the <b>BACKGROUND</b> or <b>ACTIVE</b> state).
304   *
305   * @since 7
306   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
307   * @returns -
308   * @FAModelOnly
309   */
310  onInactive?(): void;
311
312  /**
313   * Called back when an ability enters the <b>ACTIVE</b> state.
314   *
315   * @since 7
316   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
317   * @returns -
318   * @FAModelOnly
319   */
320  onActive?(): void;
321
322  /**
323   * Called when the launch mode of an ability is set to singleton.
324   *
325   * @since 7
326   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
327   * @param want Indicates the new {@code want} containing information about the ability.
328   * @returns -
329   * @FAModelOnly
330   */
331  onNewWant?(want: Want): void;
332
333  /**
334   * Called when the system has determined to trim the memory, for example, when the ability is running in the
335   * background and there is no enough memory for running as many background processes as possible.
336   *
337   * @since 7
338   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
339   * @param level Indicates the memory trim level, which shows the current memory usage status.
340   * @returns -
341   * @FAModelOnly
342   */
343  onMemoryLevel?(level: number): void;
344}
345
346/**
347 * interface of service lifecycle.
348 *
349 * @name LifecycleService
350 * @since 7
351 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
352 * @FAModelOnly
353 */
354export declare interface LifecycleService {
355  /**
356   * Called back when an ability is started for initialization (it can be called only once in the entire lifecycle of
357   * an ability).
358   *
359   * @since 7
360   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
361   * @returns -
362   * @FAModelOnly
363   */
364  onStart?(): void;
365
366  /**
367   * Called back when Service is started.
368   *
369   * @since 7
370   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
371   * @param want Indicates the want of Service to start.
372   * @param startId Indicates the number of times the Service ability has been started. The {@code startId} is
373   *     incremented by 1 every time the ability is started. For example, if the ability has been started
374   *     for six times.
375   * @returns -
376   * @FAModelOnly
377   */
378  onCommand?(want: Want, startId: number): void;
379
380  /**
381   * Called back before an ability is destroyed.
382   *
383   * @since 7
384   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
385   * @returns -
386   * @FAModelOnly
387   */
388  onStop?(): void;
389
390  /**
391   * Called back when a Service ability is first connected to an ability.
392   *
393   * @since 7
394   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
395   * @param want Indicates connection information about the Service ability.
396   * @returns Returns the proxy of the Service ability.
397   * @FAModelOnly
398   */
399  onConnect?(want: Want): rpc.RemoteObject;
400
401  /**
402   * Called back when all abilities connected to a Service ability are disconnected.
403   *
404   * @since 7
405   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
406   * @param want Indicates disconnection information about the Service ability.
407   * @returns -
408   * @FAModelOnly
409   */
410  onDisconnect?(want: Want): void;
411
412  /**
413   * Called when a new client attempts to connect to a Service ability after all previous client connections to it
414   * are disconnected.
415   *
416   * <p>The Service ability must have been started but not been destroyed, that is, {@link #startAbility} has been
417   * called but {@link #terminateSelf} has not.</p>
418   *
419   * @since 7
420   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
421   * @param want Indicates the want of the Service ability being connected.
422   * @returns -
423   * @FAModelOnly
424   */
425  onReconnect?(want: Want): void;
426}
427
428/**
429 * interface of data lifecycle.
430 *
431 * @name LifecycleData
432 * @since 7
433 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
434 * @FAModelOnly
435 */
436export declare interface LifecycleData {
437  /**
438   * Updates one or more data records in the database. This method should be implemented by a Data ability.
439   *
440   * @since 7
441   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
442   * @param uri Indicates the database table storing the data to update.
443   * @param valueBucket Indicates the data to update. This parameter can be null.
444   * @param predicates Indicates filter criteria. If this parameter is null, all data records will be updated by
445   *                   default.
446   * @param callback function specified by framework to receive the result, developer should call this function to
447   *                 return the result to framework.
448   * @returns -
449   * @FAModelOnly
450   */
451   update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;
452
453  /**
454   * Queries one or more data records in the database. This method should be implemented by a Data ability.
455   *
456   * @since 7
457   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
458   * @param uri Indicates the database table storing the data to query.
459   * @param columns Indicates the columns to be queried, in array, for example, {"name","age"}. You should define
460   *                the processing logic when this parameter is null.
461   * @param predicates Indicates filter criteria. If this parameter is null, all data records will be queried by
462   *                   default.
463   * @param callback function specified by framework to receive the result, developer should call this function to
464   *                 return the result to framework.
465   * @returns -
466   * @FAModelOnly
467   */
468   query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;
469
470  /**
471   * Deletes one or more data records. This method should be implemented by a Data ability.
472   *
473   * @since 7
474   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
475   * @param uri Indicates the database table storing the data to delete.
476   * @param predicates Indicates filter criteria. If this parameter is null, all data records will be deleted by
477   *     default.
478   * @param callback function specified by framework to receive the result, developer should call this function to
479   *                 return the result to framework.
480   * @returns -
481   * @FAModelOnly
482   */
483   delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;
484
485  /**
486   * Converts the given {@code uri} that refer to the Data ability into a normalized URI. A normalized URI can be
487   * used across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability
488   * even if the context has changed.
489   *
490   * @since 7
491   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
492   * @param uri Indicates the uri to normalize.
493   * @param callback function specified by framework to receive the result, developer should call this function to
494   *                 return the result to framework.
495   * @returns -
496   * @FAModelOnly
497   */
498   normalizeUri?(uri: string, callback: AsyncCallback<string>): void;
499
500  /**
501   * Inserts multiple data records into the database. This method should be implemented by a Data ability.
502   *
503   * @since 7
504   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
505   * @param uri Indicates the position where the data is to insert.
506   * @param valueBuckets Indicates the data to insert.
507   * @param callback function specified by framework to receive the result, developer should call this function to
508   *                 return the result to framework.
509   * @returns -
510   * @FAModelOnly
511   */
512   batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void;
513
514  /**
515   * Converts the given normalized {@code uri} generated by {@link #normalizeUri(uri)} into a denormalized one.
516   * The default implementation of this method returns the original uri passed to it.
517   *
518   * @since 7
519   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
520   * @param uri Indicates the uri to denormalize.
521   * @param callback function specified by framework to receive the result, developer should call this function to
522   *                 return the result to framework.
523   * @returns -
524   * @FAModelOnly
525   */
526   denormalizeUri?(uri: string, callback: AsyncCallback<string>): void;
527
528  /**
529   * Inserts a data record into the database. This method should be implemented by a Data ability.
530   *
531   * @since 7
532   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
533   * @param uri Indicates the position where the data is to insert.
534   * @param valueBucket Indicates the data to insert.
535   * @param callback function specified by framework to receive the result, developer should call this function to
536   *                 return the result to framework.
537   * @returns -
538   * @FAModelOnly
539   */
540   insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;
541
542  /**
543   * Opens a file. This method should be implemented by a Data ability.
544   *
545   * @since 7
546   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
547   * @param uri Indicates the path of the file to open.
548   * @param mode Indicates the open mode, which can be "r" for read-only access, "w" for write-only access (erasing
549   *     whatever data is currently in the file), "wt" for write access that truncates any existing file,
550   *     "wa" for write-only access to append to any existing data, "rw" for read and write access on any
551   *     existing data, or "rwt" for read and write access that truncates any existing file.
552   * @param callback function specified by framework to receive the result, developer should call this function to
553   *                 return the result to framework.
554   * @returns -
555   * @FAModelOnly
556   */
557   openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void;
558
559  /**
560   * Obtains the MIME type of files. This method should be implemented by a Data ability.
561   *
562   * @since 7
563   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
564   * @param uri Indicates the path of the files to obtain.
565   * @param mimeTypeFilter Indicates the MIME type of the files to obtain. This parameter cannot be set to {@code
566   *     null}.
567   *     <p>1. "&ast;/*": Obtains all types supported by a Data ability.
568   *     <p>2. "image/*": Obtains files whose main type is image of any subtype.
569   *     <p>3. "&ast;/jpg": Obtains files whose subtype is JPG of any main type.
570   * @param callback function specified by framework to receive the result, developer should call this function to
571   *                 return the result to framework.
572   * @returns -
573   * @FAModelOnly
574   */
575   getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void;
576
577  /**
578   * Called to carry {@code AbilityInfo} to this ability after the ability is initialized.
579   *
580   * @since 7
581   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
582   * @param info Indicates the {@code AbilityInfo} object containing information about this ability.
583   * @returns -
584   * @FAModelOnly
585   */
586  onInitialized?(info: AbilityInfo): void;
587
588  /**
589   * Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
590   * implemented by a Data ability.
591   *
592   * <p>Data abilities supports general data types, including text, HTML, and JPEG.</p>
593   *
594   * @since 7
595   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
596   * @param uri Indicates the uri of the data.
597   * @param callback function specified by framework to receive the result, developer should call this function to
598   *                 return the result to framework.
599   * @returns -
600   * @FAModelOnly
601   */
602  getType?(uri: string, callback: AsyncCallback<string>): void;
603
604  /**
605   * Performs batch operations on the database. This method should be implemented by a Data ability.
606   *
607   * @since 7
608   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
609   * @param ops Indicates the data operation list, which can contain multiple operations on the database.
610   * @param callback function specified by framework to receive the result, developer should call this function to
611   *                 return the result to framework.
612   * @returns -
613   * @FAModelOnly
614   */
615  executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void;
616
617  /**
618   * Defines a method in this Data ability (implementation depending on child classes).
619   *
620   * @since 7
621   * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
622   * @param method Indicates the method name.
623   * @param arg Indicates the parameter transferred by the method.
624   * @param extras Indicates the parameter transferred by the method.
625   * @param callback function specified by framework to receive the result, developer should call this function to
626   *                 return the result to framework.
627   * @returns -
628   * @FAModelOnly
629   */
630   call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void;
631}
632