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