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