• 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 
16 #ifndef FOUNDATION_APPEXECFWK_OHOS_ABILITY_H
17 #define FOUNDATION_APPEXECFWK_OHOS_ABILITY_H
18 
19 #include "iremote_object.h"
20 #include "ability_context.h"
21 #include "ability_event_interface.h"
22 #include <functional>
23 #include <string>
24 #include <unistd.h>
25 #include "context.h"
26 #include "want.h"
27 #include "dummy_component_container.h"
28 #include "pac_map.h"
29 #include "dummy_notification_request.h"
30 #include "continuation_state.h"
31 #include "dummy_ability_package.h"
32 #include "dummy_configuration.h"
33 #include "aafwk_dummy_configuration.h"
34 #include "continuation_handler.h"
35 #include "ability_window.h"
36 #include "ability_lifecycle_interface.h"
37 #include "ability_lifecycle_executor.h"
38 #include "ability_continuation_interface.h"
39 
40 #include "form_callback_interface.h"
41 #include "form_constants.h"
42 #include "form_death_callback.h"
43 #include "form_provider_info.h"
44 #include "form_info.h"
45 
46 #ifndef MMI_COMPILE
47 #include "key_event.h"
48 #include "touch_event.h"
49 #endif
50 
51 using Uri = OHOS::Uri;
52 
53 namespace OHOS {
54 namespace NativeRdb {
55 class AbsSharedResultSet;
56 class DataAbilityPredicates;
57 class ValuesBucket;
58 }  // namespace NativeRdb
59 #ifdef MMI_COMPILE
60 class KeyEvent;
61 class TouchEvent;
62 #endif
63 namespace AppExecFwk {
64 class DataAbilityResult;
65 class DataAbilityOperation;
66 class AbilityPostEventTimeout;
67 class OHOSApplication;
68 class AbilityHandler;
69 class AbilityWindow;
70 class ILifeCycle;
71 class ContinuationManager;
72 class ContinuationRegisterManager;
73 class IContinuationRegisterManager;
74 class Ability : public IAbilityEvent,
75                 public ILifeCycle,
76                 public AbilityContext,
77                 public FormCallbackInterface,
78                 public IAbilityContinuation,
79                 public std::enable_shared_from_this<Ability> {
80 public:
81     friend class PageAbilityImpl;
82 
83     Ability() = default;
84     virtual ~Ability() = default;
85 
86     /**
87      * @brief Destroys ability.
88      *
89      * @param want Indicates the want containing information about TerminateAbility
90      *
91      * @return Returns the result of TerminateAbility
92      */
93     using AbilityContext::TerminateAbility;
94     int TerminateAbility(Want &want);
95 
96     /**
97      * @brief By binding an action, you can set different action parameters in Intent to present different initial
98      * pages. You must register actions in the profile file.
99      *
100      * @param action Indicates the action to bind.
101      *
102      * @param entry Indicates the entry, which is the fully qualified name of your AbilitySlice class.
103      *
104      * @return Returns the result of AddActionRoute
105      */
106     virtual void AddActionRoute(const std::string &action, const std::string &entry) final;
107 
108     /**
109      * @brief Sets the background color of the window in RGB color mode.
110      *
111      * @param red The value ranges from 0 to 255.
112      *
113      * @param green The value ranges from 0 to 255.
114      *
115      * @param blue The value ranges from 0 to 255.
116      *
117      * @return Returns the result of SetWindowBackgroundColor
118      */
119     virtual int SetWindowBackgroundColor(int red, int green, int blue) final;
120 
121     /**
122      * @brief Destroys this Page or Service ability.
123      * After a Page or Service ability performs all operations, it can use this method to destroy itself
124      * to free up memory. This method can be called only after the ability is initialized.
125      */
126     virtual void TerminateAbility() final;
127 
128     /**
129      * @brief Obtains the Lifecycle object of the current ability.
130      *
131      * @return Returns the Lifecycle object.
132      */
133     virtual std::shared_ptr<LifeCycle> GetLifecycle() override final;
134 
135     /**
136      * @brief Obtains a resource manager.
137      *
138      * @return Returns a ResourceManager object.
139      */
140     std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const override;
141 
142     /**
143      * @brief Inflates UI controls by using ComponentContainer.
144      * You can create a ComponentContainer instance that contains multiple components.
145      *
146      * @param componentContainer Indicates a set of customized components.
147      */
148     virtual void SetUIContent(const ComponentContainer &componentContainer);
149 
150     /**
151      * @brief Inflates layout resources by using the layout resource ID.
152      *
153      * @param layoutRes Indicates the layout resource ID, which cannot be a negative number.
154      */
155     virtual void SetUIContent(int layoutRes) final;
156 
157     /**
158      * Start other ability for result.
159      *
160      * @param want information of other ability
161      * @param requestCode request code for abilityMS to return result
162      */
163     virtual void StartAbilityForResult(const Want &want, int requestCode) final;
164 
165     /**
166      * Starts an ability with specific start settings and returns the execution result when the ability is destroyed.
167      * When the ability is destroyed, onAbilityResult(int,int,ohos.aafwk.content.Want) is called and the returned
168      * requestCode is transferred to the current method. The given requestCode is customized and cannot be a negative
169      * number.
170      *
171      * @param want Indicates the ability to start.
172      * @param requestCode Indicates the request code returned after the ability is started. You can define the request
173      * code to identify the results returned by abilities. The value ranges from 0 to 65535.
174      * @param abilityStartSetting Indicates the setting ability used to start.
175      */
176     virtual void StartAbilityForResult(
177         const Want &want, int requestCode, AbilityStartSetting abilityStartSetting) final;
178 
179     /**
180      * Starts a new ability with specific start settings.
181      * A Page or Service ability uses this method to start a specific ability.
182      * The system locates the target ability from installed abilities based on
183      * the value of the intent parameter and then starts it. You can specify the
184      * ability to start using the intent parameter.
185      *
186      * @param want Indicates the ability to start.
187      * @param abilityStartSetting Indicates the setting ability used to start.
188      */
189     void StartAbility(const Want &want, AbilityStartSetting abilityStartSetting);
190 
191     // lifecycle callback
192     virtual void Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
193         const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
194         const sptr<IRemoteObject> &token);
195 
196     /**
197      * @brief Called when this ability is started. You must override this function if you want to perform some
198      *        initialization operations during ability startup.
199      *
200      * This function can be called only once in the entire lifecycle of an ability.
201      * @param Want Indicates the {@link Want} structure containing startup information about the ability.
202      */
203     virtual void OnStart(const Want &want);
204 
205     /**
206      * @brief Called when this ability enters the <b>STATE_STOP</b> state.
207      *
208      * The ability in the <b>STATE_STOP</b> is being destroyed.
209      * You can override this function to implement your own processing logic.
210      */
211     virtual void OnStop();
212 
213     /**
214      * @brief Called when this ability enters the <b>STATE_ACTIVE</b> state.
215      *
216      * The ability in the <b>STATE_ACTIVE</b> state is visible and has focus.
217      * You can override this function to implement your own processing logic.
218      *
219      * @param Want Indicates the {@link Want} structure containing activation information about the ability.
220      */
221     virtual void OnActive();
222 
223     /**
224      * @brief Called when this ability enters the <b>STATE_INACTIVE</b> state.
225      *
226      * <b>STATE_INACTIVE</b> is an instantaneous state. The ability in this state may be visible but does not have
227      * focus.You can override this function to implement your own processing logic.
228      */
229     virtual void OnInactive();
230 
231     /**
232      * @brief Called when this ability enters the <b>STATE_FOREGROUND</b> state.
233      *
234      *
235      * The ability in the <b>STATE_FOREGROUND</b> state is visible.
236      * You can override this function to implement your own processing logic.
237      */
238     virtual void OnForeground(const Want &want);
239 
240     /**
241      * @brief Called when this ability enters the <b>STATE_BACKGROUND</b> state.
242      *
243      *
244      * The ability in the <b>STATE_BACKGROUND</b> state is invisible.
245      * You can override this function to implement your own processing logic.
246      */
247     virtual void OnBackground();
248 
249     /**
250      * @brief Called when a key is pressed. When any component in the Ability gains focus, the key-down event for
251      * the component will be handled first. This callback will not be invoked if the callback triggered for the
252      * key-down event of the component returns true. The default implementation of this callback does nothing
253      * and returns false.
254      *
255      * @param keyCode Indicates the code of the key pressed.
256      * @param keyEvent Indicates the key-down event.
257      *
258      * @return Returns true if this event is handled and will not be passed further; returns false if this event
259      * is not handled and should be passed to other handlers.
260      */
261     virtual bool OnKeyDown(int keyCode, const KeyEvent &keyEvent);
262 
263     /**
264      * @brief Called when a key is released. When any component in the Ability gains focus, the key-up event for
265      * the component will be handled first. This callback will not be invoked if the callback triggered for the
266      * key-up event of the component returns true. The default implementation of this callback does nothing and
267      * returns false.
268      *
269      * @param keyCode Indicates the code of the key released.
270      * @param keyEvent Indicates the key-up event.
271      *
272      * @return Returns true if this event is handled and will not be passed further; returns false if this event
273      * is not handled and should be passed to other handlers.
274      */
275     virtual bool OnKeyUp(int keyCode, const KeyEvent &keyEvent);
276 
277     /**
278      * @brief Called when a touch event is dispatched to this ability. The default implementation of this callback
279      * does nothing and returns false.
280      *
281      * @param event  Indicates information about the touch event.
282      *
283      * @return Returns true if the event is handled; returns false otherwise.
284      */
285     virtual bool OnTouchEvent(const TouchEvent &touchEvent);
286 
287     /**
288      * @brief Called when this Service ability is connected for the first time.
289      *
290      * You can override this function to implement your own processing logic.
291      *
292      * @param want Indicates the {@link Want} structure containing connection information about the Service ability.
293      * @return Returns a pointer to the <b>sid</b> of the connected Service ability.
294      */
295     virtual sptr<IRemoteObject> OnConnect(const Want &want);
296 
297     /**
298      * @brief Called when all abilities connected to this Service ability are disconnected.
299      *
300      * You can override this function to implement your own processing logic.
301      *
302      */
303     virtual void OnDisconnect(const Want &want);
304 
305     /**
306      * @brief Inflates UI controls by using ComponentContainer.
307      * You can create a ComponentContainer instance that contains multiple components.
308      *
309      * @param componentContainer Indicates the component layout defined by the user.
310      * @param context Indicates the context to use.
311      * @param typeFlag Indicates the window type.
312      */
313     virtual void SetUIContent(
314         const ComponentContainer &componentContainer, std::shared_ptr<Context> &context, int typeFlag);
315 
316     /**
317      * @brief Inflates layout resources by using the layout resource ID.
318      *
319      * @param layoutRes Indicates the layout resource ID, which cannot be a negative number.
320      * @param context Indicates the context to use.
321      * @param typeFlag Indicates the window type.
322      */
323     virtual void SetUIContent(int layoutRes, std::shared_ptr<Context> &context, int typeFlag);
324 
325     /**
326      * @brief Called when this ability gains or loses window focus.
327      *
328      * @param hasFocus Specifies whether this ability has focus.
329      */
330     virtual void OnWindowFocusChanged(bool hasFocus);
331 
332     /**
333      * @brief Called when this ability is moved to or removed from the top of the stack.
334      *
335      * @param topActive Specifies whether this ability is moved to or removed from the top of the stack. The value true
336      * indicates that it is moved to the top, and false indicates that it is removed from the top of the stack.
337      */
338     virtual void OnTopActiveAbilityChanged(bool topActive);
339 
340     /**
341      * @brief Inflates UI controls by using WindowConfig.
342      *
343      * @param config Indicates the window config defined by the user.
344      */
345     virtual void SetUIContent(const sptr<WindowOption> &config);
346 
347     /**
348      * @brief Get the window belong to the ability.
349      *
350      * @return Returns a Window object pointer.
351      */
352     virtual const sptr<Window> GetWindow();
353 
354     /**
355      * @brief Checks whether the main window of this ability has window focus.
356      *
357      * @return Returns true if this ability currently has window focus; returns false otherwise.
358      */
359     bool HasWindowFocus();
360 
361     /**
362      * @brief Called when a key is lone pressed.
363      *
364      * @param keyCode Indicates the code of the key long pressed.
365      * @param keyEvent Indicates the key-long-press event.
366      *
367      * @return Returns true if this event is handled and will not be passed further; returns false if this event
368      * is not handled and should be passed to other handlers.
369      */
370     virtual bool OnKeyPressAndHold(int keyCode, const std::shared_ptr<KeyEvent> &keyEvent);
371 
372     /**
373      * @brief Called back after permissions are requested by using
374      * AbilityContext.requestPermissionsFromUser(java.lang.String[],int).
375      *
376      * @param requestCode Indicates the request code passed to this method from
377      * AbilityContext.requestPermissionsFromUser(java.lang.String[],int).
378      * @param permissions Indicates the list of permissions requested by using
379      * AbilityContext.requestPermissionsFromUser(java.lang.String[],int). This parameter cannot be null.
380      * @param grantResults Indicates the granting results of the corresponding permissions requested using
381      * AbilityContext.requestPermissionsFromUser(java.lang.String[],int). The value 0 indicates that a
382      * permission is granted, and the value -1 indicates not.
383      *
384      */
385     virtual void OnRequestPermissionsFromUserResult(
386         int requestCode, const std::vector<std::string> &permissions, const std::vector<int> &grantResults);
387 
388     /**
389      * @brief Called when this ability is about to leave the foreground and enter the background due to a user
390      * operation, for example, when the user touches the Home key.
391      *
392      */
393     virtual void OnLeaveForeground();
394 
395     /**
396      * @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
397      * implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
398      *
399      * @param uri Indicates the URI of the data.
400      *
401      * @return Returns the MIME type that matches the data specified by uri.
402      */
403     virtual std::string GetType(const Uri &uri);
404 
405     /**
406      * @brief Inserts a data record into the database. This method should be implemented by a Data ability.
407      *
408      * @param uri Indicates the position where the data is to insert.
409      * @param value Indicates the data to insert.
410      *
411      * @return Returns the index of the newly inserted data record.
412      */
413     virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value);
414 
415     /**
416      * @brief Called when the system configuration is updated.
417      *
418      * @param configuration Indicates the updated configuration information.
419      */
420     virtual void OnConfigurationUpdated(const Configuration &configuration);
421 
422     /**
423      * @brief Called when the system configuration is updated.
424      *
425      * @param level Indicates the memory trim level, which shows the current memory usage status.
426      *
427      */
428     virtual void OnMemoryLevel(int level);
429 
430     /**
431      * @brief This is like openFile, open a file that need to be able to return sub-sections of files,often assets
432      * inside of their .hap.
433      *
434      * @param uri Indicates the path of the file to open.
435      * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
436      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
437      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing
438      * data, or "rwt" for read and write access that truncates any existing file.
439      *
440      * @return Returns the RawFileDescriptor object containing file descriptor.
441      */
442     virtual int OpenRawFile(const Uri &uri, const std::string &mode);
443 
444     /**
445      * @brief Updates one or more data records in the database. This method should be implemented by a Data ability.
446      *
447      * @param uri Indicates the database table storing the data to update.
448      * @param value Indicates the data to update. This parameter can be null.
449      * @param predicates Indicates filter criteria. If this parameter is null, all data records will be updated by
450      * default.
451      *
452      * @return Returns the number of data records updated.
453      */
454     virtual int Update(
455         const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates);
456 
457     /**
458      * @brief get application witch the ability belong
459      *
460      * @return Returns the application ptr
461      */
462     std::shared_ptr<OHOSApplication> GetApplication();
463 
464     /**
465      * @brief Obtains the class name in this ability name, without the prefixed bundle name.
466      *
467      * @return Returns the class name of this ability.
468      */
469     std::string GetAbilityName();
470 
471     /**
472      * @brief OChecks whether the current ability is being destroyed.
473      * An ability is being destroyed if you called terminateAbility() on it or someone else requested to destroy it.
474      *
475      * @return Returns true if the current ability is being destroyed; returns false otherwise.
476      */
477     bool IsTerminating();
478 
479     /**
480      * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int) is called to start an ability and the
481      * result is returned. This method is called only on Page abilities. You can start a new ability to perform some
482      * calculations and use setResult (int,ohos.aafwk.content.Want) to return the calculation result. Then the system
483      * calls back the current method to use the returned data to execute its own logic.
484      *
485      * @param requestCode Indicates the request code returned after the ability is started. You can define the request
486      * code to identify the results returned by abilities. The value ranges from 0 to 65535.
487      * @param resultCode Indicates the result code returned after the ability is started. You can define the result code
488      * to identify an error.
489      * @param resultData Indicates the data returned after the ability is started. You can define the data returned. The
490      * value can be null.
491      *
492      */
493     virtual void OnAbilityResult(int requestCode, int resultCode, const Want &resultData);
494 
495     /**
496      * @brief Called back when the Back key is pressed.
497      * The default implementation destroys the ability. You can override this method.
498      *
499      */
500     virtual void OnBackPressed() override;
501 
502     /**
503      * @brief Called when the launch mode of an ability is set to singleInstance. This happens when you re-launch an
504      * ability that has been at the top of the ability stack.
505      *
506      * @param want Indicates the new Want containing information about the ability.
507      */
508     virtual void OnNewWant(const Want &want);
509 
510     /**
511      * @brief Restores data and states of an ability when it is restored by the system. This method should be
512      * implemented by a Page ability. This method is called if an ability was destroyed at a certain time due to
513      * resource reclaim or was unexpectedly destroyed and the onSaveAbilityState(ohos.utils.PacMap) method was called to
514      * save its user data and states. Generally, this method is called after the onStart(ohos.aafwk.content.Want)
515      * method.
516      *
517      *  @param inState Indicates the PacMap object used for storing data and states. This parameter can not be null.
518      *
519      */
520     virtual void OnRestoreAbilityState(const PacMap &inState);
521 
522     /**
523      * @brief Saves temporary data and states of this ability. This method should be implemented by a Page ability.
524      * This method is called when the system determines that the ability may be destroyed in an unexpected situation,
525      * for example, when the screen orientation changes or the user touches the Home key. Generally, this method is used
526      * only to save temporary states.
527      *
528      *  @param outState Indicates the PacMap object used for storing user data and states. This parameter cannot be
529      * null.
530      *
531      */
532     virtual void OnSaveAbilityState(PacMap &outState);
533 
534     /**
535      * @brief Called every time a key, touch, or trackball event is dispatched to this ability.
536      * You can override this callback method if you want to know that the user has interacted with
537      * the device in a certain way while this ability is running. This method, together with onLeaveForeground(),
538      * is designed to help abilities intelligently manage status bar notifications. Specifically, they help
539      * abilities determine when to cancel a notification.
540      *
541      */
542     virtual void OnEventDispatch();
543 
544     /**
545      * @brief Sets the want object that can be obtained by calling getWant().
546      *
547      * @param Want information of other ability
548      */
549     void SetWant(const AAFwk::Want &want);
550 
551     /**
552      * @brief Obtains the Want object that starts this ability.
553      *
554      * @return Returns the Want object that starts this ability.
555      */
556     std::shared_ptr<AAFwk::Want> GetWant();
557 
558     /**
559      * @brief Sets the result code and data to be returned by this Page ability to the caller.
560      * When a Page ability is destroyed, the caller overrides the AbilitySlice#onAbilityResult(int, int, Want) method to
561      * receive the result set in the current method. This method can be called only after the ability has been
562      * initialized.
563      *
564      * @param resultCode Indicates the result code returned after the ability is destroyed. You can define the result
565      * code to identify an error.
566      * @param resultData Indicates the data returned after the ability is destroyed. You can define the data returned.
567      * This parameter can be null.
568      */
569     virtual void SetResult(int resultCode, const Want &resultData) final;
570 
571     /**
572      * @brief Sets the type of audio whose volume will be adjusted by the volume button.
573      *
574      * @param volumeType Indicates the AudioManager.AudioVolumeType to set.
575      */
576     virtual void SetVolumeTypeAdjustedByKey(int volumeType);
577 
578     /**
579      * @brief Called back when Service is started.
580      * This method can be called only by Service. You can use the StartAbility(ohos.aafwk.content.Want) method to start
581      * Service. Then the system calls back the current method to use the transferred want parameter to execute its own
582      * logic.
583      *
584      * @param want Indicates the want of Service to start.
585      * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
586      * destroyed, and the value false indicates a normal startup.
587      * @param startId Indicates the number of times the Service ability has been started. The startId is incremented by
588      * 1 every time the ability is started. For example, if the ability has been started for six times, the value of
589      * startId is 6.
590      */
591     virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId);
592 
593     /**
594      * @brief dump ability info
595      *
596      * @param extra dump ability info
597      */
598     virtual void Dump(const std::string &extra);
599 
600     /**
601      * @brief Keeps this Service ability in the background and displays a notification bar.
602      * To use this method, you need to request the ohos.permission.KEEP_BACKGROUND_RUNNING permission from the system.
603      * The ohos.permission.KEEP_BACKGROUND_RUNNING permission is of the normal level.
604      * This method can be called only by Service abilities after the onStart(ohos.aafwk.content.Want) method is called.
605      *
606      * @param id Identifies the notification bar information.
607      * @param notificationRequest Indicates the NotificationRequest instance containing information for displaying a
608      * notification bar.
609      */
610     virtual void KeepBackgroundRunning(int id, const NotificationRequest &notificationRequest) final;
611 
612     /**
613      * @brief Cancels background running of this ability to free up system memory.
614      * This method can be called only by Service abilities when the onStop() method is called.
615      *
616      */
617     virtual void CancelBackgroundRunning() final;
618 
619     /**
620      * @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used
621      * across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the
622      * context has changed. If you implement URI normalization for a Data ability, you must also implement
623      * denormalizeUri(ohos.utils.net.Uri) to enable URI denormalization. After this feature is enabled, URIs passed to
624      * any method that is called on the Data ability must require normalization verification and denormalization. The
625      * default implementation of this method returns null, indicating that this Data ability does not support URI
626      * normalization.
627      *
628      * @param uri Indicates the Uri object to normalize.
629      *
630      * @return Returns the normalized Uri object if the Data ability supports URI normalization; returns null otherwise.
631      */
632     virtual Uri NormalizeUri(const Uri &uri);
633 
634     /**
635      * @brief Deletes one or more data records. This method should be implemented by a Data ability.
636      *
637      * @param uri Indicates the database table storing the data to delete.
638      * @param predicates Indicates filter criteria. If this parameter is null, all data records will be deleted by
639      * default.
640      *
641      * @return Returns the number of data records deleted.
642      */
643     virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates);
644 
645     /**
646      * @brief Obtains the MIME type of files. This method should be implemented by a Data ability.
647      *
648      * @param uri Indicates the path of the files to obtain.
649      * @param mimeTypeFilter Indicates the MIME type of the files to obtain. This parameter cannot be set to null.
650      * 1. * / *: Obtains all types supported by a Data ability.
651      * 2. image/ *: Obtains files whose main type is image of any subtype.
652      * 3. * /jpg: Obtains files whose subtype is JPG of any main type.
653      *
654      * @return Returns the MIME type of the matched files; returns null if there is no type that matches the Data
655      * ability.
656      */
657     virtual std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter);
658 
659     /**
660      * @brief Opens a file. This method should be implemented by a Data ability.
661      *
662      * @param uri Indicates the path of the file to open.
663      * @param mode Indicates the open mode, which can be "r" for read-only access, "w" for write-only access
664      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
665      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data,
666      * or "rwt" for read and write access that truncates any existing file.
667      *
668      * @return Returns the FileDescriptor object of the file descriptor.
669      */
670     virtual int OpenFile(const Uri &uri, const std::string &mode);
671 
672     /**
673      * @brief Queries one or more data records in the database. This method should be implemented by a Data ability.
674      *
675      * @param uri Indicates the database table storing the data to query.
676      * @param columns Indicates the columns to be queried, in array, for example, {"name","age"}. You should define the
677      * processing logic when this parameter is null.
678      * @param predicates Indicates filter criteria. If this parameter is null, all data records will be queried by
679      * default.
680      *
681      * @return Returns the queried data.
682      */
683     virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(
684         const Uri &uri, const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates);
685 
686     /**
687      * @brief Sets the main route for this ability.
688      *
689      * The main route, also called main entry, refers to the default <b>AbilitySlice</b> to present for this ability.
690      * This function should be called only on Feature Abilities. If this function is not called in the
691      * {@link OnStart(const Want &want)} function for a Feature Ability, the Feature Ability will fail to start.
692      *
693      * @param entry Indicates the main entry, which is the class name of the <b>AbilitySlice</b> instance to start.
694      *
695      * @return Returns the result of SetMainRoute
696      */
697     virtual void SetMainRoute(const std::string &entry) final;
698 
699     /**
700      * @brief Migrates this ability to the given device on the same distributed network in a reversible way that allows
701      * this ability to be migrated back to the local device through reverseContinueAbility(). The ability to migrate and
702      * its ability slices must implement the IAbilityContinuation interface. Otherwise, an exception is thrown,
703      * indicating that the ability does not support migration.
704      *
705      * @param deviceId Indicates the ID of the target device where this ability will be migrated to. If this parameter
706      * is null, this method has the same effect as ContinueAbilityReversibly().
707      *
708      */
709     virtual void ContinueAbilityReversibly(const std::string &deviceId) final;
710 
711     /**
712      * @brief  Obtains the ID of the source device from which this ability is migrated.
713      *
714      * @return Returns the source device ID.
715      */
716     virtual std::string GetOriginalDeviceId() final;
717 
718     /**
719      * @brief Obtains the migration state of this ability.
720      * @return Returns the migration state.
721      */
722     virtual ContinuationState GetContinuationState() final;
723 
724     /**
725      * @brief Obtains the singleton AbilityPackage object to which this ability belongs.
726      *
727      * @return Returns the singleton AbilityPackage object to which this ability belongs.
728      */
729     virtual std::shared_ptr<AbilityPackage> GetAbilityPackage();
730 
731     /**
732      * @brief Converts the given normalized uri generated by normalizeUri(ohos.utils.net.Uri) into a denormalized one.
733      * The default implementation of this method returns the original URI passed to it.
734      *
735      * @param uri uri Indicates the Uri object to denormalize.
736      *
737      * @return Returns the denormalized Uri object if the denormalization is successful; returns the original Uri passed
738      * to this method if there is nothing to do; returns null if the data identified by the original Uri cannot be found
739      * in the current environment.
740      */
741     virtual Uri DenormalizeUri(const Uri &uri);
742 
743     /**
744      * @brief Reloads data in the database.
745      *
746      * @param uri Indicates the position where the data is to reload. This parameter is mandatory.
747      * @param extras Indicates the PacMap object containing the additional parameters to be passed in this call. This
748      * parameter can be null. If a custom Sequenceable object is put in the PacMap object and will be transferred across
749      * processes, you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
750      *
751      * @return Returns true if the data is successfully reloaded; returns false otherwise.
752      */
753     virtual bool Reload(const Uri &uri, const PacMap &extras);
754 
755     /**
756      * @brief Inserts multiple data records into the database.
757      *
758      * @param uri Indicates the path of the data to operate.
759      * @param values Indicates the data records to insert.
760      *
761      * @return Returns the number of data records inserted.
762      */
763     virtual int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values);
764 
765     /**
766      * @brief Obtains the type of audio whose volume is adjusted by the volume button.
767      *
768      * @return Returns the AudioManager.AudioVolumeType.
769      */
770     int GetVolumeTypeAdjustedByKey();
771 
772     /**
773      * @brief Obtains the lifecycle state of this ability.
774      *
775      * @return Returns the lifecycle state of this ability.
776      */
777     virtual AbilityLifecycleExecutor::LifecycleState GetState() final;
778 
779     /**
780      * @brief A Page or Service ability uses this method to start a specific ability. The system locates the target
781      * ability from installed abilities based on the value of the intent parameter and then starts it. You can specify
782      * the ability to start using the intent parameter.
783      *
784      * @param intent Indicates the ability to start.
785      */
786     using AbilityContext::StartAbility;
787     virtual void StartAbility(const Want &want) final;
788 
789     /**
790      * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template.
791      *
792      * @param want Indicates the want containing information about the ability to connect
793      *
794      * @param conn Indicates the callback object when the target ability is connected.
795      *
796      * @return True means success and false means failure
797      */
798     bool ConnectAbility(const Want &want, const sptr<AAFwk::IAbilityConnection> &conn) override;
799 
800     /**
801      * @brief Disconnects the current ability from an ability
802      *
803      * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection
804      *              is set up. The IAbilityConnection object uniquely identifies a connection between two abilities.
805      */
806     void DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &conn) override;
807 
808     /**
809      * @brief Destroys another ability that uses the AbilityInfo.AbilityType.SERVICE template.
810      * The current ability using either the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE
811      * template can call this method to destroy another ability that uses the AbilityInfo.AbilityType.SERVICE
812      * template. The current ability itself can be destroyed by calling the terminateAbility() method.
813      *
814      * @param want Indicates the Want containing information about the ability to destroy.
815      *
816      * @return Returns true if the ability is destroyed successfully; returns false otherwise.
817      */
818     bool StopAbility(const AAFwk::Want &want) override;
819 
820     /**
821      * @brief Posts a scheduled Runnable task to a new non-UI thread.
822      * The task posted via this method will be executed in a new thread, which allows you to perform certain
823      * time-consuming operations. To use this method, you must also override the supportHighPerformanceUI() method.
824      * Additionally, the usage of this method must comply with the following constraints: 1、This method can only be
825      * used to initialize the component tree in parallel mode. 2、The task can only be processed during system cold
826      * start. 3、If the parallel loading mechanism is used, the component tree-related operations to be performed in
827      * onActive() and onStop() of the ability slice must also be added to the parallel thread. 4、You must run
828      * setUIContent(ohos.agp.components.ComponentContainer) to unlock the UI thread and wait until the component tree is
829      * ready. 5、Other time-consuming operations, such as I/O and network processing, cannot be added to the parallel
830      * task queue.
831      *
832      * @param task Indicates the Runnable task to post.
833      *
834      * @param delayTime Indicates the number of milliseconds after which the task will be executed.
835      *
836      * @return -
837      */
838     void PostTask(std::function<void()> task, long delayTime);
839 
840     /**
841      * @brief Called to set caller information for the application. The default implementation returns null.
842      *
843      * @return Returns the caller information.
844      */
845     virtual Uri OnSetCaller();
846 
847     /**
848      * @brief Call this when your ability should be closed and the mission should be completely removed as a part of
849      * finishing the root ability of the mission.
850      */
851     void TerminateAndRemoveMission() override;
852 
853     /**
854      * @brief Create a PostEvent timeout task. The default delay is 5000ms
855      *
856      * @return Return a smart pointer to a timeout object
857      */
858     std::shared_ptr<AbilityPostEventTimeout> CreatePostEventTimeouter(std::string taskstr);
859 
860     /**
861      * Releases an obtained form by its ID.
862      *
863      * <p>After this method is called, the form won't be available for use by the application, but the Form Manager
864      * Service still keeps the cache information about the form, so that the application can quickly obtain it based on
865      * the {@code formId}.</p>
866      * <p><b>Permission: </b>{@link ohos.security.SystemPermission#REQUIRE_FORM}</p>
867      *
868      * @param formId Indicates the form ID.
869      * @return Returns {@code true} if the form is successfully released; returns {@code false} otherwise.
870      *
871      * <ul>
872      * <li>The passed {@code formId} is invalid. Its value must be larger than 0.</li>
873      * <li>The specified form has not been added by the application.</li>
874      * <li>An error occurred when connecting to the Form Manager Service.</li>
875      * <li>The application is not granted with the {@link ohos.security.SystemPermission#REQUIRE_FORM} permission.</li>
876      * <li>The form has been obtained by another application and cannot be released by the current application.</li>
877      * <li>The form is being restored.</li>
878      * </ul>
879      */
880     bool ReleaseForm(const int64_t formId);
881 
882     /**
883      * @brief Releases an obtained form by its ID.
884      *
885      * <p>After this method is called, the form won't be available for use by the application, if isReleaseCache is
886      * false, this method is same as {@link #releaseForm(int)}, otherwise the Form Manager Service still store this
887      * form in the cache.</p>
888      * <p><b>Permission: </b>{@link ohos.security.SystemPermission#REQUIRE_FORM}</p>
889      *
890      * @param formId Indicates the form ID.
891      * @param isReleaseCache Indicates whether to clear cache in service.
892      * @return Returns {@code true} if the form is successfully released; returns {@code false} otherwise.
893      *
894      * <ul>
895      * <li>The passed {@code formId} is invalid. Its value must be larger than 0.</li>
896      * <li>The specified form has not been added by the application.</li>
897      * <li>An error occurred when connecting to the Form Manager Service.</li>
898      * <li>The application is not granted with the {@link ohos.security.SystemPermission#REQUIRE_FORM} permission.</li>
899      * <li>The form has been obtained by another application and cannot be released by the current application.</li>
900      * <li>The form is being restored.</li>
901      * </ul>
902      */
903     bool ReleaseForm(const int64_t formId, const bool isReleaseCache);
904 
905     /**
906      * @brief Deletes an obtained form by its ID.
907      *
908      * <p>After this method is called, the form won't be available for use by the application and the Form Manager
909      * Service no longer keeps the cache information about the form.</p>
910      * <p><b>Permission: </b>{@link ohos.security.SystemPermission#REQUIRE_FORM}</p>
911      *
912      * @param formId Indicates the form ID.
913      * @return Returns {@code true} if the form is successfully deleted; returns {@code false} otherwise.
914      *
915      * <ul>
916      * <li>The passed {@code formId} is invalid. Its value must be larger than 0.</li>
917      * <li>The specified form has not been added by the application.</li>
918      * <li>An error occurred when connecting to the Form Manager Service.</li>
919      * <li>The application is not granted with the {@link ohos.security.SystemPermission#REQUIRE_FORM} permission.</li>
920      * <li>The form has been obtained by another application and cannot be deleted by the current application.</li>
921      * <li>The form is being restored.</li>
922      * </ul>
923      */
924     bool DeleteForm(const int64_t formId);
925 
926     /**
927      * @brief The form callback.
928      */
929     class FormCallback {
930     public:
931         static const int32_t OHOS_FORM_ACQUIRE_SUCCESS = 0;
932         static const int32_t OHOS_FORM_UPDATE_SUCCESS = 0;
933         static const int32_t OHOS_FORM_PREVIEW_FAILURE = 1;
934         static const int32_t OHOS_FORM_RESTORE_FAILURE = 2;
935 
936         /**
937          * @brief Called to notify the application that the {@code FormJsInfo} instance has been obtained after
938          * the application called the asynchronous method {@link Ability#acquireForm(Want, FormCallback)}.
939          * The application must present the form information on a specific page in this callback.
940          *
941          * @param result Specifies whether the asynchronous form acquisition process is successful.
942          *               {@link FormCallback#OHOS_FORM_ACQUIRE_SUCCESS} indicates that the form
943          *               is successfully obtained, and other values indicate that the process fails.
944          * @param formJsInfo Indicates the obtained {@code FormJsInfo} instance.
945          */
946         virtual void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const = 0;
947 
948         /**
949          * @brief Called to notify the application that the {@code FormJsInfo} instance has been obtained after
950          * the application called the asynchronous method {@link Ability#acquireForm(Want, FormCallback)}.
951          * The application must present the form information on a specific page in this callback.
952          *
953          * @param result Specifies whether the asynchronous form acquisition process is successful.
954          *               {@link FormCallback#OHOS_FORM_UPDATE_SUCCESS} indicates that the form is
955          *               successfully obtained, and other values indicate that the process fails.
956          * @param formJsInfo Indicates the obtained {@code FormJsInfo} instance.
957          */
958         virtual void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const = 0;
959 
960         /**
961          * @brief Called to notify the application that the {@code Form} provider has been uninstalled and the
962          * corresponding
963          * {@code Form} instance is no longer available.
964          *
965          * @param formId Indicates the ID of the {@code Form} instance provided by the uninstalled form provider.
966          */
967         virtual void OnFormUninstall(const int64_t formId) const = 0;
968     };
969 
970     /**
971      * @brief Obtains a specified form that matches the application bundle name, module name, form name, and
972      * other related information specified in the passed {@code Want}.
973      *
974      * <p>This method is asynchronous. After the {@link FormJsInfo} instance is obtained.
975      *
976      * @param formId Indicates the form ID.
977      * @param want Indicates the detailed information about the form to be obtained, including the bundle name,
978      *        module name, ability name, form name, form id, tempForm flag, form dimension, and form customize data.
979      * @param callback Indicates the callback to be invoked whenever the {@link FormJsInfo} instance is obtained.
980      * @return Returns {@code true} if the request is successfully initiated; returns {@code false} otherwise.
981      */
982     bool AcquireForm(const int64_t formId, const Want &want, const std::shared_ptr<FormCallback> callback);
983 
984     /**
985      * @brief Updates the content of a specified JS form.
986      *
987      * <p>This method is called by a form provider to update JS form data as needed.
988      *
989      * @param formId Indicates the form ID.
990      * @param formProviderData The data used to update the JS form displayed on the client.
991      * @return Returns {@code true} if the request is successfully initiated; returns {@code false} otherwise.
992      */
993     bool UpdateForm(const int64_t formId, const FormProviderData &formProviderData);
994 
995     /**
996      * @brief Cast temp form with formId.
997      *
998      * @param formId Indicates the form's ID.
999      *
1000      * @return Returns {@code true} if the form is successfully casted; returns {@code false} otherwise.
1001      */
1002     bool CastTempForm(const int64_t formId);
1003 
1004     /**
1005      * @brief Sends a notification to the form framework to make the specified forms visible.
1006      *
1007      * <p>After this method is successfully called, {@link Ability#OnVisibilityChanged(std::map<int64_t, int>)}
1008      * will be called to notify the form provider of the form visibility change event.</p>
1009      *
1010      * @param formIds Indicates the IDs of the forms to be made visible.
1011      * @return Returns {@code true} if the request is successfully initiated; returns {@code false} otherwise.
1012      */
1013     bool NotifyVisibleForms(const std::vector<int64_t> &formIds);
1014 
1015     /**
1016      * @brief Sends a notification to the form framework to make the specified forms invisible.
1017      *
1018      * <p>After this method is successfully called, {@link Ability#OnVisibilityChanged(std::map<int64_t, int>)}
1019      * will be called to notify the form provider of the form visibility change event.</p>
1020      *
1021      * @param formIds Indicates the IDs of the forms to be made invisible.
1022      * @return Returns {@code true} if the request is successfully initiated; returns {@code false} otherwise.
1023      */
1024     bool NotifyInvisibleForms(const std::vector<int64_t> &formIds);
1025 
1026     /**
1027      * @brief Set form next refresh time.
1028      *
1029      * <p>This method is called by a form provider to set refresh time.
1030      *
1031      * @param formId Indicates the ID of the form to set refresh time.
1032      * @param nextTime Indicates the next time gap now in seconds, can not be litter than 300 seconds.
1033      * @return Returns {@code true} if seting succeed; returns {@code false} otherwise.
1034      */
1035 
1036     bool SetFormNextRefreshTime(const int64_t formId, const int64_t nextTime);
1037 
1038     /**
1039      * @brief Update form.
1040      *
1041      * @param formJsInfo Indicates the obtained {@code FormJsInfo} instance.
1042      */
1043     void ProcessFormUpdate(const FormJsInfo &formJsInfo) override;
1044 
1045     /**
1046      * @brief Uninstall form.
1047      *
1048      * @param formId Indicates the ID of the form to uninstall.
1049      */
1050     void ProcessFormUninstall(const int64_t formId) override;
1051 
1052     /**
1053      * @brief Called to reacquire form and update the form host after the death callback is received.
1054      *
1055      */
1056     void OnDeathReceived() override;
1057 
1058     /**
1059      * @brief Called to return a FormProviderInfo object.
1060      *
1061      * <p>You must override this method if your ability will serve as a form provider to provide a form for clients.
1062      * The default implementation returns nullptr. </p>
1063      *
1064      * @param want   Indicates the detailed information for creating a FormProviderInfo.
1065      *               The Want object must include the form ID, form name of the form,
1066      *               which can be obtained from Ability#PARAM_FORM_IDENTITY_KEY,
1067      *               Ability#PARAM_FORM_NAME_KEY, and Ability#PARAM_FORM_DIMENSION_KEY,
1068      *               respectively. Such form information must be managed as persistent data for further form
1069      *               acquisition, update, and deletion.
1070      *
1071      * @return Returns the created FormProviderInfo object.
1072      */
1073     virtual FormProviderInfo OnCreate(const Want &want);
1074 
1075     /**
1076      * @brief Called to notify the form provider that a specified form has been deleted. Override this method if
1077      * you want your application, as the form provider, to be notified of form deletion.
1078      *
1079      * @param formId Indicates the ID of the deleted form.
1080      * @return None.
1081      */
1082     virtual void OnDelete(const int64_t formId);
1083 
1084     /**
1085      * @brief Called when the form provider is notified that a temporary form is successfully converted to
1086      * a normal form.
1087      *
1088      * @param formId Indicates the ID of the form.
1089      * @return None.
1090      */
1091     virtual void OnCastTemptoNormal(const int64_t formId);
1092 
1093     /**
1094      * @brief Called to notify the form provider to update a specified form.
1095      *
1096      * @param formId Indicates the ID of the form to update.
1097      * @return none.
1098      */
1099     virtual void OnUpdate(const int64_t formId);
1100 
1101     /**
1102      * @brief Called when the form provider receives form events from the fms.
1103      *
1104      * @param formEventsMap Indicates the form events occurred. The key in the Map object indicates the form ID,
1105      *                      and the value indicates the event type, which can be either FORM_VISIBLE
1106      *                      or FORM_INVISIBLE. FORM_VISIBLE means that the form becomes visible,
1107      *                      and FORM_INVISIBLE means that the form becomes invisible.
1108      * @return none.
1109      */
1110     virtual void OnVisibilityChanged(const std::map<int64_t, int32_t> &formEventsMap);
1111     /**
1112      * @brief Called to notify the form provider to update a specified form.
1113      *
1114      * @param formId Indicates the ID of the form to update.
1115      * @param message Form event message.
1116      */
1117     virtual void OnTriggerEvent(const int64_t formId, const std::string &message);
1118     /**
1119      * @brief Requests for form data update.
1120      *
1121      * This method must be called when the application has detected that a system setting item (such as the language,
1122      * resolution, or screen orientation) being listened for has changed. Upon receiving the update request, the form
1123      * provider automatically updates the form data (if there is any update) through the form framework, with the update
1124      * process being unperceivable by the application.
1125      *
1126      * @param formId Indicates the ID of the form to update.
1127      * @return Returns true if the update request is successfully initiated, returns false otherwise.
1128      */
1129     bool RequestForm(const int64_t formId);
1130 
1131     /**
1132      * @brief Requests for form data update, by passing a set of parameters (using Want) to the form provider.
1133      *
1134      * This method must be called when the application has detected that a system setting item (such as the language,
1135      * resolution, or screen orientation) being listened for has changed. Upon receiving the update request, the form
1136      * provider automatically updates the form data (if there is any update) through the form framework, with the update
1137      * process being unperceivable by the application.
1138      *
1139      * @param formId Indicates the ID of the form to update.
1140      * @param want Indicates a set of parameters to be transparently passed to the form provider.
1141      * @return Returns true if the update request is successfully initiated, returns false otherwise.
1142      */
1143     bool RequestForm(const int64_t formId, const Want &want);
1144     /**
1145      * @brief Enable form update.
1146      *
1147      * @param formIds formIds of hostclient.
1148      */
1149     bool EnableUpdateForm(const std::vector<int64_t> &formIds);
1150 
1151     /**
1152      * @brief Disable form update.
1153      *
1154      * @param formIds formIds of hostclient.
1155      */
1156     bool DisableUpdateForm(const std::vector<int64_t> &formIds);
1157 
1158     /**
1159      * @brief Check form manager service ready.
1160      *
1161      * @return Returns true if form manager service ready; returns false otherwise.
1162      */
1163     bool CheckFMSReady();
1164 
1165     /**
1166      * @brief Get All FormsInfo.
1167      *
1168      * @param formInfos Returns the forms' information of all forms provided.
1169      * @return Returns true if the request is successfully initiated; returns false otherwise.
1170      */
1171     bool GetAllFormsInfo(std::vector<FormInfo> &formInfos);
1172 
1173     /**
1174      * @brief Get forms info by application name.
1175      *
1176      * @param bundleName Application name.
1177      * @param formInfos Returns the forms' information of the specify application name.
1178      * @return Returns true if the request is successfully initiated; returns false otherwise.
1179      */
1180     bool GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos);
1181 
1182     /**
1183      * @brief Get forms info by application name and module name.
1184      *
1185      * @param bundleName Application name.
1186      * @param moduleName Module name of hap.
1187      * @param formInfos Returns the forms' information of the specify application name and module name.
1188      * @return Returns true if the request is successfully initiated; returns false otherwise.
1189      */
1190     bool GetFormsInfoByModule(std::string &bundleName, std::string &moduleName, std::vector<FormInfo> &formInfos);
1191 
1192     /**
1193      * @brief Acquire a bundle manager, if it not existed,
1194      * @return returns the bundle manager ipc object, or nullptr for failed.
1195      */
1196     sptr<IBundleMgr> GetBundleMgr();
1197 
1198     /**
1199      * @brief check permission of bundle, if it not existed.
1200      * @return returns the permission is vaild, or false for failed.
1201      */
1202     bool CheckPermission();
1203 
1204     /**
1205      * @brief Permission check.
1206      * @param bundleName bundleName.
1207      * @return Returns true on success, false on failure.
1208      */
1209     bool CheckFormPermission(const std::string &bundleName) const;
1210 
1211     /**
1212      * @brief Add the bundle manager instance for debug.
1213      * @param bundleManager the bundle manager ipc object.
1214      */
1215     void SetBundleManager(const sptr<IBundleMgr> &bundleManager);
1216 
1217     /**
1218      * @brief You can use the IContinuationRegisterManager object to interact with the Device+ control center,
1219      * including registering and unregistering the ability to migrate, updating the device connection state, and
1220      * showing the list of devices that can be selected for ability migration.
1221      *
1222      * @return Returns true if the migration request is successful; returns false otherwise.
1223      */
1224     std::weak_ptr<IContinuationRegisterManager> GetContinuationRegisterManager();
1225 
1226     /**
1227      * @brief Migrates this ability to the given device on the same distributed network. The ability to migrate and its
1228      * ability slices must implement the IAbilityContinuation interface.
1229      *
1230      * @param deviceId Indicates the ID of the target device where this ability will be migrated to. If this parameter
1231      * is null, this method has the same effect as continueAbility().
1232      *
1233      */
1234     virtual void ContinueAbility(const std::string &deviceId) final;
1235 
1236     /**
1237      * @brief Callback function to ask the user whether to start the migration .
1238      *
1239      * @return If the user allows migration, it returns true; otherwise, it returns false.
1240      */
1241     virtual bool OnStartContinuation() override;
1242 
1243     /**
1244      * @brief Performs batch operations on the database.
1245      *
1246      * @param operations Indicates a list of database operations on the database.
1247      * @return Returns the result of each operation, in array.
1248      */
1249     virtual std::vector<std::shared_ptr<DataAbilityResult>> ExecuteBatch(
1250         const std::vector<std::shared_ptr<DataAbilityOperation>> &operations);
1251 
1252     /**
1253      * @brief Executes an operation among the batch operations to be executed.
1254      *
1255      * @param operation Indicates the operation to execute.
1256      * @param results Indicates a set of results of the batch operations.
1257      * @param index Indicates the index of the current operation result in the batch operation results.
1258      */
1259     void ExecuteOperation(std::shared_ptr<DataAbilityOperation> &operation,
1260         std::vector<std::shared_ptr<DataAbilityResult>> &results, int index);
1261 
1262     /**
1263      * @brief Save user data of local Ability generated at runtime.
1264      *
1265      * @param saveData Indicates the user data to be saved.
1266      * @return If the data is saved successfully, it returns true; otherwise, it returns false.
1267      */
1268     virtual bool OnSaveData(WantParams &saveData) override;
1269 
1270     /**
1271      * @brief After creating the Ability on the remote device,
1272      *      immediately restore the user data saved during the migration of the Ability on the remote device.
1273      * @param restoreData Indicates the user data to be restored.
1274      * @return If the data is restored successfully, it returns true; otherwise, it returns false .
1275      */
1276     virtual bool OnRestoreData(WantParams &restoreData) override;
1277 
1278     /**
1279      * @brief This function can be used to implement the processing logic after the migration is completed.
1280      *
1281      * @param result Migration result code. 0 means the migration was successful, -1 means the migration failed.
1282      * @return None.
1283      */
1284     virtual void OnCompleteContinuation(int result) override;
1285 
1286     /**
1287      * @brief Used to notify the local Ability that the remote Ability has been destroyed.
1288      *
1289      * @return None.
1290      */
1291     virtual void OnRemoteTerminated() override;
1292 
1293 protected:
1294     /**
1295      * @brief Acquire a form provider remote object.
1296      * @return Returns form provider remote object.
1297      */
1298     sptr<IRemoteObject> GetFormRemoteObject();
1299 
1300 private:
1301     std::shared_ptr<NativeRdb::DataAbilityPredicates> ParsePredictionArgsReference(
1302         std::vector<std::shared_ptr<DataAbilityResult>> &results, std::shared_ptr<DataAbilityOperation> &operation,
1303         int numRefs);
1304 
1305     std::shared_ptr<NativeRdb::ValuesBucket> ParseValuesBucketReference(
1306         std::vector<std::shared_ptr<DataAbilityResult>> &results, std::shared_ptr<DataAbilityOperation> &operation,
1307         int numRefs);
1308 
1309     int ChangeRef2Value(std::vector<std::shared_ptr<DataAbilityResult>> &results, int numRefs, int index);
1310 
1311     bool CheckAssertQueryResult(std::shared_ptr<NativeRdb::AbsSharedResultSet> &queryResult,
1312         std::shared_ptr<NativeRdb::ValuesBucket> &&valuesBucket);
1313 
1314     friend class AbilityImpl;
1315     bool VerifySupportForContinuation();
1316     void HandleCreateAsContinuation(const Want &want);
1317     bool IsFlagExists(unsigned int flag, unsigned int flagSet);
1318     /**
1319      * @brief Set the start ability setting.
1320      * @param setting the start ability setting.
1321      */
1322     void SetStartAbilitySetting(std::shared_ptr<AbilityStartSetting> setting);
1323 
1324 private:
1325     std::shared_ptr<ContinuationHandler> continuationHandler_ = nullptr;
1326     std::shared_ptr<ContinuationManager> continuationManager_ = nullptr;
1327     std::shared_ptr<ContinuationRegisterManager> continuationRegisterManager_ = nullptr;
1328     std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
1329     std::shared_ptr<Context> context_ = nullptr;
1330     std::shared_ptr<AbilityHandler> handler_ = nullptr;
1331     std::shared_ptr<LifeCycle> lifecycle_ = nullptr;
1332     std::shared_ptr<AbilityLifecycleExecutor> abilityLifecycleExecutor_ = nullptr;
1333     std::shared_ptr<OHOSApplication> application_ = nullptr;
1334     std::vector<std::string> types_;
1335     std::shared_ptr<AbilityWindow> abilityWindow_ = nullptr;
1336     std::shared_ptr<AAFwk::Want> setWant_ = nullptr;
1337     sptr<IRemoteObject> reverseContinuationSchedulerReplica_ = nullptr;
1338     std::shared_ptr<AbilityStartSetting> setting_ = nullptr;
1339     bool bWindowFocus_ = false;
1340 
1341     static const std::string SYSTEM_UI;
1342     static const std::string STATUS_BAR;
1343     static const std::string NAVIGATION_BAR;
1344     sptr<IRemoteObject> providerRemoteObject_ = nullptr;
1345     // Keep consistent with DMS defines. Used to callback to DMS.
1346     static const std::string DMS_SESSION_ID;
1347 
1348     // The originating deviceId passed by DMS using intent param.
1349     static const std::string DMS_ORIGIN_DEVICE_ID;
1350 
1351     // If session id cannot get from intent, assign it as default.
1352     static const int DEFAULT_DMS_SESSION_ID;
1353 
1354     std::vector<int64_t> lostedByReconnectTempForms_;
1355     std::map<int64_t, std::shared_ptr<FormCallback>> appCallbacks_;
1356     std::map<int64_t, Want> userReqParams_;
1357     sptr<IBundleMgr> iBundleMgr_;
1358 
1359     static const int32_t OHOS_FORM_ACQUIRE_FORM = 0;
1360     static const int32_t OHOS_FORM_UPDATE_FORM = 1;
1361 
1362     static const int32_t DELETE_FORM = 3;
1363     static const int32_t ENABLE_FORM_UPDATE = 5;
1364     static const int32_t DISABLE_FORM_UPDATE = 6;
1365     static const int32_t RELEASE_FORM = 8;
1366     static const int32_t RELEASE_CACHED_FORM = 9;
1367     static const int64_t MIN_NEXT_TIME = 5;
1368 
1369 private:
1370     /**
1371      * @brief Delete or release form with formId.
1372      *
1373      * @param formId Indicates the form's ID.
1374      * @param deleteType Indicates the type of delete or release.
1375      * @return Returns {@code true} if the form is successfully deleted; returns {@code false} otherwise.
1376      */
1377     bool DeleteForm(const int64_t formId, const int32_t deleteType);
1378 
1379     /**
1380      * @brief Clean form resource with formId.
1381      *
1382      * @param formId Indicates the form's ID.
1383      */
1384     void CleanFormResource(const int64_t formId);
1385 
1386     /**
1387      * @brief Handle acquire result of the obtained form instance.
1388      *
1389      * @param want Indicates the detailed information about the form to be obtained, including the bundle name,
1390      *        module name, ability name, form name, form id, tempForm flag, form dimension, and form customize data.
1391      * @param formJsInfo Indicates the obtained {@code FormJsInfo} instance.
1392      * @param callback Indicates the callback to be invoked whenever the {@link FormJsInfo} instance is obtained.
1393      */
1394     void HandleAcquireResult(
1395         const Want &want,
1396         const FormJsInfo &formJsInfo,
1397         const std::shared_ptr<FormCallback> callback
1398         );
1399 
1400     /**
1401      * @brief Handle acquire message of the obtained form instance.
1402      *
1403      * @param msgCode Indicates the code of message type.
1404      * @param formJsInfo Indicates the obtained {@code FormJsInfo} instance.
1405      */
1406     void HandleFormMessage(const int32_t msgCode, const FormJsInfo &formJsInfo);
1407 
1408     /**
1409      * @brief Notify the forms visibility change event.
1410      *
1411      * @param formIds Indicates the IDs of the forms to be made visible or invisible.
1412      * @param eventType Indicates the form events occurred. FORM_VISIBLE means that the form becomes visible,
1413      *                  and FORM_INVISIBLE means that the form becomes invisible.
1414      * @return none.
1415      */
1416     bool NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, int32_t eventType);
1417 
1418     /**
1419      * @brief Check the param of want.
1420      *
1421      * @param formId Indicates the form's ID.
1422      * @param want Indicates the detailed information about the form to be obtained, including the bundle name,
1423      *        module name, ability name, form name, form id, tempForm flag, form dimension, and form customize data.
1424      * @return Returns {@code true} if the check result is ok; returns {@code false} ng.
1425      */
1426     bool CheckWantValid(const int64_t formId, const Want &want);
1427 
1428     /**
1429      * @brief Handle enable/disable form update.
1430      *
1431      * @param formIds Indicates the IDs of the forms to be made visible.
1432      * @param updateType Update type.
1433      * @return Returns true if the result is ok; returns false otherwise.
1434      */
1435     bool LifecycleUpdate(std::vector<int64_t> formIds, int32_t updateType);
1436 
1437     /**
1438      * @brief Reacquire a specified form when the death callback is received.
1439      *
1440      * @param formId Indicates the form ID.
1441      * @param want Indicates the detailed information about the form to be obtained.
1442      * @return Returns true if the request is successfully initiated; returns false otherwise.
1443      */
1444     bool ReAcquireForm(const int64_t formId, const Want &want);
1445 };
1446 
1447 }  // namespace AppExecFwk
1448 }  // namespace OHOS
1449 #endif  // FOUNDATION_APPEXECFWK_OHOS_ABILITY_H
1450