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