1 /* 2 * Copyright (c) 2023-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_UI_ABILITY_H 17 #define OHOS_ABILITY_RUNTIME_UI_ABILITY_H 18 19 #include "ability_context.h" 20 #include "ability_continuation_interface.h" 21 #include "ability_lifecycle_executor.h" 22 #include "ability_lifecycle_interface.h" 23 #include "ability_local_record.h" 24 #include "ability_transaction_callback_info.h" 25 #include "configuration.h" 26 #include "context.h" 27 #include "continuation_handler_stage.h" 28 #include "fa_ability_context.h" 29 #include "iability_callback.h" 30 #include "resource_config_helper.h" 31 #include "want.h" 32 33 #ifdef SUPPORT_SCREEN 34 #include "display_manager.h" 35 #include "session_info.h" 36 #include "window_scene.h" 37 #include "window_manager.h" 38 #endif 39 40 namespace OHOS { 41 namespace AppExecFwk { 42 class AbilityHandler; 43 class AbilityRecovery; 44 class OHOSApplication; 45 class LifeCycle; 46 class ContinuationHandlerStage; 47 class ContinuationManagerStage; 48 class InsightIntentExecuteParam; 49 struct InsightIntentExecuteResult; 50 using InsightIntentExecutorAsyncCallback = AbilityTransactionCallbackInfo<InsightIntentExecuteResult>; 51 } // namespace AppExecFwk 52 namespace AbilityRuntime { 53 class Runtime; 54 using InsightIntentExecuteResult = AppExecFwk::InsightIntentExecuteResult; 55 using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam; 56 using InsightIntentExecutorAsyncCallback = AppExecFwk::InsightIntentExecutorAsyncCallback; 57 class UIAbility : public AppExecFwk::AbilityContext, 58 public AppExecFwk::ILifeCycle, 59 public AppExecFwk::IAbilityCallback, 60 public AppExecFwk::IAbilityContinuation, 61 public std::enable_shared_from_this<UIAbility> { 62 public: 63 UIAbility() = default; 64 virtual ~UIAbility() = default; 65 66 /** 67 * @brief Create a UIAbility instance through the singleton pattern 68 * @param runtime the runtime pointer 69 * @return Returns the UIAbility object of the ability 70 */ 71 static UIAbility *Create(const std::unique_ptr<Runtime> &runtime); 72 73 /** 74 * @brief Obtains the Lifecycle object of the current ability 75 * @return Returns the Lifecycle object. 76 */ 77 std::shared_ptr<AppExecFwk::LifeCycle> GetLifecycle() override final; 78 79 /** 80 * Register lifecycle observer on UIAbility. 81 * 82 * @param observer the lifecycle observer to be registered on UIAbility. 83 */ 84 void RegisterAbilityLifecycleObserver( 85 const std::shared_ptr<AppExecFwk::ILifecycleObserver> &observer) override final; 86 87 /** 88 * Unregister lifecycle observer on UIAbility. 89 * 90 * @param observer the lifecycle observer to be unregistered on UIAbility. 91 */ 92 void UnregisterAbilityLifecycleObserver( 93 const std::shared_ptr<AppExecFwk::ILifecycleObserver> &observer) override final; 94 95 /** 96 * @brief Obtains the AbilityContext object of the ability. 97 * @return Returns the AbilityContext object of the ability. 98 */ 99 std::shared_ptr<AbilityRuntime::AbilityContext> GetAbilityContext(); 100 101 /** 102 * @brief Obtains the Want object that starts this ability. 103 * @return Returns the Want object that starts this ability. 104 */ 105 std::shared_ptr<AAFwk::Want> GetWant() override; 106 107 /** 108 * @brief Init the UIability 109 * @param abilityInfo Indicate the Ability information 110 * @param application Indicates the main process 111 * @param handler the UIability EventHandler object 112 * @param token the remote token 113 */ 114 virtual void Init(std::shared_ptr<AppExecFwk::AbilityLocalRecord> record, 115 const std::shared_ptr<AppExecFwk::OHOSApplication> application, 116 std::shared_ptr<AppExecFwk::AbilityHandler> &handler, const sptr<IRemoteObject> &token); 117 118 /** 119 * @brief Attach Ability Context 120 * @param abilityContext Indicate the AbilityContext 121 */ 122 void AttachAbilityContext(const std::shared_ptr<AbilityRuntime::AbilityContext> &abilityContext); 123 124 /** 125 * @brief Called when this ability is started. You must override this function if you want to perform some 126 * initialization operations during ability startup. 127 * This function can be called only once in the entire lifecycle of an ability. 128 * @param Want Indicates the {@link Want} structure containing startup information about the ability. 129 * @param sessionInfo Indicates the sessionInfo. 130 */ 131 virtual void OnStart(const AAFwk::Want &want, sptr<AAFwk::SessionInfo> sessionInfo = nullptr); 132 133 /** 134 * @brief Called when this ability enters the <b>STATE_STOP</b> state. 135 * The ability in the <b>STATE_STOP</b> is being destroyed. 136 * You can override this function to implement your own processing logic. 137 */ 138 virtual void OnStop(); 139 140 /** 141 * @brief Called when this ability enters the <b>STATE_STOP</b> state. 142 * The ability in the <b>STATE_STOP</b> is being destroyed. 143 * You can override this function to implement your own processing logic. 144 * @param callbackInfo Indicates the lifecycle transaction callback information 145 * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback 146 */ 147 virtual void OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback); 148 149 /** 150 * @brief The callback of OnStop. 151 */ 152 virtual void OnStopCallback(); 153 154 /** 155 * @brief request a remote object of callee from this ability. 156 * @return Returns the remote object of callee. 157 */ 158 virtual sptr<IRemoteObject> CallRequest(); 159 160 /** 161 * @brief Called when the system configuration is updated. 162 * @param configuration Indicates the updated configuration information. 163 */ 164 void OnConfigurationUpdatedNotify(const AppExecFwk::Configuration &configuration); 165 166 /** 167 * @brief Update context.config when configuration is updated. 168 */ UpdateContextConfiguration()169 virtual void UpdateContextConfiguration() {} 170 171 /** 172 * @brief Called when the system configuration is updated. 173 * @param level Indicates the memory trim level, which shows the current memory usage status. 174 */ 175 virtual void OnMemoryLevel(int level); 176 177 /** 178 * @brief Obtains the class name in this ability name, without the prefixed bundle name. 179 * @return Returns the class name of this ability. 180 */ 181 std::string GetAbilityName(); 182 183 /** 184 * @brief Obtains the module name in this ability name, without the prefixed bundle name. 185 * @return Returns the module name of this ability. 186 */ 187 std::string GetModuleName(); 188 189 /** 190 * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int) is called to start an ability and the 191 * result is returned. This method is called only on Page abilities. You can start a new ability to perform some 192 * calculations and use setResult (int,ohos.aafwk.content.Want) to return the calculation result. Then the system 193 * calls back the current method to use the returned data to execute its own logic. 194 * @param requestCode Indicates the request code returned after the ability is started. You can define the request 195 * code to identify the results returned by abilities. The value ranges from 0 to 65535. 196 * @param resultCode Indicates the result code returned after the ability is started. You can define the result code 197 * to identify an error. 198 * @param want Indicates the data returned after the ability is started. You can define the data returned. The 199 * value can be null. 200 */ 201 virtual void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &want); 202 203 /** 204 * @brief Called when the launch mode of an ability is set to singleInstance. This happens when you re-launch an 205 * ability that has been at the top of the ability stack. 206 * @param want Indicates the new Want containing information about the ability. 207 */ 208 virtual void OnNewWant(const AAFwk::Want &want); 209 210 /** 211 * @brief Restores data and states of an ability when it is restored by the system. This method should be 212 * implemented by a Page ability. This method is called if an ability was destroyed at a certain time due to 213 * resource reclaim or was unexpectedly destroyed and the onSaveAbilityState(ohos.utils.PacMap) method was called to 214 * save its user data and states. Generally, this method is called after the onStart(ohos.aafwk.content.Want) 215 * method. 216 * @param inState Indicates the PacMap object used for storing data and states. This parameter can not be null. 217 */ 218 virtual void OnRestoreAbilityState(const AppExecFwk::PacMap &inState); 219 220 /** 221 * @brief Sets the want object that can be obtained by calling getWant(). 222 * @param Want information of other ability 223 */ 224 void SetWant(const AAFwk::Want &want); 225 226 /** 227 * @brief dump ability info 228 * @param params dump params that indicate different dump targets 229 * @param info dump ability info 230 */ 231 virtual void Dump(const std::vector<std::string> ¶ms, std::vector<std::string> &info); 232 233 /** 234 * @brief Save user data of local Ability generated at runtime. 235 * @param saveData Indicates the user data to be saved. 236 * @return If the data is saved successfully, it returns true; otherwise, it returns false. 237 */ 238 bool OnSaveData(AAFwk::WantParams &saveData) override; 239 240 /** 241 * @brief After creating the Ability on the remote device, 242 * immediately restore the user data saved during the migration of the Ability on the remote device. 243 * @param restoreData Indicates the user data to be restored. 244 * @return If the data is restored successfully, it returns true; otherwise, it returns false . 245 */ 246 bool OnRestoreData(AAFwk::WantParams &restoreData) override; 247 248 /** 249 * @brief Obtains the lifecycle state of this ability. 250 * @return Returns the lifecycle state of this ability. 251 */ 252 virtual AppExecFwk::AbilityLifecycleExecutor::LifecycleState GetState() final; 253 254 /** 255 * @brief Release the ability instance. 256 */ 257 void DestroyInstance(); 258 259 /** 260 * @brief Update configuration 261 * @param configuration Indicates the updated configuration information. 262 */ 263 virtual void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration); 264 265 /** 266 * @brief The async callback of OnContinue. 267 */ 268 virtual int32_t OnContinueAsyncCB(napi_ref jsWantParams, int32_t status, 269 const AppExecFwk::AbilityInfo &abilityInfo); 270 271 /** 272 * @brief Prepare user data of local Ability. 273 * @param wantParams Indicates the user data to be saved. 274 * @return If the ability is willing to continue and data saved successfully, it returns 0; 275 * otherwise, it returns errcode. 276 */ 277 virtual int32_t OnContinue(AAFwk::WantParams &wantParams, bool &isAsyncOnContinue, 278 const AppExecFwk::AbilityInfo &abilityInfo); 279 280 /** 281 * @brief Migrates this ability to the given device on the same distributed network. The ability to migrate and its 282 * ability slices must implement the IAbilityContinuation interface. 283 * @param deviceId Indicates the ID of the target device where this ability will be migrated to. 284 * @param versionCode Target bundle version. 285 */ 286 virtual void ContinueAbilityWithStack(const std::string &deviceId, uint32_t versionCode) final; 287 288 /** 289 * @brief Callback function to ask the user whether to start the migration . 290 * @return If the user allows migration, it returns true; otherwise, it returns false. 291 */ 292 bool OnStartContinuation() override; 293 294 /** 295 * @brief This function can be used to implement the processing logic after the migration is completed. 296 * @param result Migration result code. 0 means the migration was successful, -1 means the migration failed. 297 * @return None. 298 */ 299 void OnCompleteContinuation(int result) override; 300 301 /** 302 * @brief Used to notify the local Ability that the remote Ability has been destroyed. 303 * @return None. 304 */ 305 void OnRemoteTerminated() override; 306 307 /** 308 * @brief Prepare user data of local Ability. 309 * @param reason the reason why framework invoke this function 310 * @param wantParams Indicates the user data to be saved. 311 * @return result code defined in abilityConstants 312 */ 313 virtual int32_t OnSaveState(int32_t reason, AAFwk::WantParams &wantParams); 314 315 /** 316 * @brief enable ability recovery. 317 * @param abilityRecovery shared_ptr of abilityRecovery 318 * @param useAppSettedRecoveryValue Indicates use default recovery or not. 319 */ 320 void EnableAbilityRecovery(const std::shared_ptr<AppExecFwk::AbilityRecovery> &abilityRecovery, 321 bool useAppSettedRecoveryValue); 322 323 /** 324 * @brief Callback when the ability is shared.You can override this function to implement your own sharing logic. 325 * @param wantParams Indicates the user data to be saved. 326 * @return the result of OnShare 327 */ 328 virtual int32_t OnShare(AAFwk::WantParams &wantParams); 329 330 bool CheckIsSilentForeground() const; 331 332 void SetIsSilentForeground(bool isSilentForeground); 333 334 protected: 335 const AAFwk::LaunchParam &GetLaunchParam() const; 336 bool IsRestoredInContinuation() const; 337 void NotifyContinuationResult(const AAFwk::Want &want, bool success); 338 bool ShouldRecoverState(const AAFwk::Want &want); 339 bool ShouldDefaultRecoverState(const AAFwk::Want &want); 340 bool IsUseNewStartUpRule(); 341 342 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_ = nullptr; 343 std::shared_ptr<AppExecFwk::AbilityStartSetting> setting_ = nullptr; 344 std::shared_ptr<AppExecFwk::AbilityRecovery> abilityRecovery_ = nullptr; 345 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo_ = nullptr; 346 AAFwk::LaunchParam launchParam_; 347 bool securityFlag_ = false; 348 349 private: 350 friend class UIAbilityImpl; 351 void DispatchLifecycleOnForeground(const AAFwk::Want &want); 352 void HandleCreateAsRecovery(const AAFwk::Want &want); 353 void SetStartAbilitySetting(std::shared_ptr<AppExecFwk::AbilityStartSetting> setting); 354 void SetLaunchParam(const AAFwk::LaunchParam &launchParam); 355 void InitConfigurationProperties(const AppExecFwk::Configuration &changeConfiguration, 356 ResourceConfigHelper &resourceConfig); 357 358 std::shared_ptr<AppExecFwk::ContinuationHandlerStage> continuationHandler_ = nullptr; 359 std::shared_ptr<AppExecFwk::ContinuationManagerStage> continuationManager_ = nullptr; 360 std::shared_ptr<AppExecFwk::AbilityHandler> handler_ = nullptr; 361 std::shared_ptr<AppExecFwk::LifeCycle> lifecycle_ = nullptr; 362 std::shared_ptr<AppExecFwk::AbilityLifecycleExecutor> abilityLifecycleExecutor_ = nullptr; 363 std::shared_ptr<AppExecFwk::OHOSApplication> application_ = nullptr; 364 std::shared_ptr<AAFwk::Want> setWant_ = nullptr; 365 sptr<IRemoteObject> reverseContinuationSchedulerReplica_ = nullptr; 366 bool isNewRuleFlagSetted_ = false; 367 bool startUpNewRule_ = false; 368 bool isSilentForeground_ = false; 369 std::atomic<bool> useAppSettedRecoveryValue_ = false; 370 371 #ifdef SUPPORT_SCREEN 372 public: 373 uint32_t sceneFlag_ = 0; 374 375 /** 376 * @brief Called after instantiating WindowScene. 377 * You can override this function to implement your own processing logic. 378 */ 379 virtual void OnSceneCreated(); 380 381 /** 382 * @brief Called after ability stoped. 383 * You can override this function to implement your own processing logic. 384 */ 385 virtual void OnSceneWillDestroy(); 386 387 /** 388 * @brief Called after ability stoped. 389 * You can override this function to implement your own processing logic. 390 */ 391 virtual void onSceneDestroyed(); 392 393 /** 394 * @brief Called after ability restored. 395 * You can override this function to implement your own processing logic. 396 */ 397 virtual void OnSceneRestored(); 398 399 /** 400 * @brief Called when this ability enters the <b>STATE_FOREGROUND</b> state. 401 * The ability in the <b>STATE_FOREGROUND</b> state is visible. 402 * You can override this function to implement your own processing logic. 403 */ 404 virtual void OnForeground(const AAFwk::Want &want); 405 406 /** 407 * @brief Called when this ability enters the <b>STATE_BACKGROUND</b> state. 408 * The ability in the <b>STATE_BACKGROUND</b> state is invisible. 409 * You can override this function to implement your own processing logic. 410 */ 411 virtual void OnBackground(); 412 413 /** 414 * @brief Called before this ability enters the <b>STATE_FOREGROUND</b> state. 415 * The ability in the <b>STATE_FOREGROUND</b> state is invisible. 416 * You can override this function to implement your own processing logic. 417 */ 418 virtual void OnWillForeground(); 419 420 /** 421 * @brief Called after wms show event. 422 * The ability in the <b>STATE_FOREGROUND</b> state is invisible. 423 * You can override this function to implement your own processing logic. 424 */ 425 virtual void OnDidForeground(); 426 427 /** 428 * @brief Called before OnBackground. 429 * The ability in the <b>STATE_BACKGROUND</b> state is invisible. 430 * You can override this function to implement your own processing logic. 431 */ 432 virtual void OnWillBackground(); 433 434 /** 435 * @brief Called after wms hiden event. 436 * The ability in the <b>STATE_BACKGROUND</b> state is invisible. 437 * You can override this function to implement your own processing logic. 438 */ 439 virtual void OnDidBackground(); 440 441 /** 442 * @brief Called after window stage focused or unfocused 443 * You can override this function to implement your own processing logic. 444 */ 445 virtual void OnAfterFocusedCommon(bool isFocused); 446 447 /** 448 * @brief Called when ability prepare terminate. 449 * @return Return true if ability need to stop terminating; return false if ability need to terminate. 450 */ 451 virtual bool OnPrepareTerminate(); 452 453 /** 454 * @brief Called when ability prepare terminate. 455 * @param callbackInfo The callbackInfo is used when onPrepareToTerminateAsync is implemented. 456 * @param isAsync The returned flag indicates if onPrepareToTerminateAsync is implemented. 457 */ 458 virtual void OnPrepareTerminate(AppExecFwk::AbilityTransactionCallbackInfo<bool> *callbackInfo, bool &isAsync); 459 460 /** 461 * @brief Inflates UI controls by using windowOption. 462 * @param windowOption Indicates the window option defined by the user. 463 */ 464 virtual void InitWindow(int32_t displayId, sptr<Rosen::WindowOption> option); 465 466 /** 467 * @brief Get the window belong to the ability. 468 * @return Returns a Window object pointer. 469 */ 470 virtual const sptr<Rosen::Window> GetWindow(); 471 472 /** 473 * @brief get the scene belong to the ability. 474 * @return Returns a WindowScene object pointer. 475 */ 476 std::shared_ptr<Rosen::WindowScene> GetScene(); 477 478 /** 479 * @brief Called when this ability is about to leave the foreground and enter the background due to a user 480 * operation, for example, when the user touches the Home key. 481 */ 482 virtual void OnLeaveForeground(); 483 484 /** 485 * @brief Get page ability stack info. 486 * @return A string represents page ability stack info, empty if failed; 487 */ 488 virtual std::string GetContentInfo(); 489 virtual std::string GetContentInfoForRecovery(); 490 virtual std::string GetContentInfoForDefaultRecovery(); 491 492 /** 493 * @brief Set WindowScene listener 494 * @param listener WindowScene listener 495 * @return None. 496 */ 497 void SetSceneListener(const sptr<Rosen::IWindowLifeCycle> &listener); 498 499 /** 500 * @brief Called back at ability context. 501 * @return current window mode of the ability. 502 */ 503 int GetCurrentWindowMode() override; 504 505 /** 506 * @brief Set mission label of this ability. 507 * @param label the label of this ability. 508 * @return Returns ERR_OK if success. 509 */ 510 ErrCode SetMissionLabel(const std::string &label) override; 511 512 /** 513 * @brief Set mission icon of this ability. 514 * @param icon the icon of this ability. 515 * @return Returns ERR_OK if success. 516 */ 517 ErrCode SetMissionIcon(const std::shared_ptr<OHOS::Media::PixelMap> &icon) override; 518 519 /** 520 * @brief Get window rectangle of this ability. 521 * @param left the left position of window rectangle. 522 * @param top the top position of window rectangle. 523 * @param width the width position of window rectangle. 524 * @param height the height position of window rectangle. 525 */ 526 void GetWindowRect(int32_t &left, int32_t &top, int32_t &width, int32_t &height) override; 527 528 /** 529 * @brief Get ui content object. 530 * @return UIContent object of ACE. 531 */ 532 Ace::UIContent *GetUIContent() override; 533 534 /** 535 * @brief Call "onForeground" js function barely. 536 * 537 * @param want Want 538 */ 539 virtual void CallOnForegroundFunc(const AAFwk::Want &want); 540 541 /** 542 * @brief Request focus for current window, can be override. 543 * 544 * @param want Want 545 */ 546 virtual void RequestFocus(const AAFwk::Want &want); 547 548 /** 549 * @brief Execute insight intent when an ability is in foreground, schedule it to foreground repeatly. 550 * 551 * @param want Want. 552 * @param executeParam insight intent execute param. 553 * @param callback insight intent async callback. 554 */ 555 virtual void ExecuteInsightIntentRepeateForeground(const AAFwk::Want &want, 556 const std::shared_ptr<InsightIntentExecuteParam> &executeParam, 557 std::unique_ptr<InsightIntentExecutorAsyncCallback> callback); 558 559 /** 560 * @brief Execute insight intent when an ability didn't started or in background, schedule it to foreground. 561 * 562 * @param want Want. 563 * @param executeParam insight intent execute param. 564 * @param callback insight intent async callback. 565 */ 566 virtual void ExecuteInsightIntentMoveToForeground(const AAFwk::Want &want, 567 const std::shared_ptr<InsightIntentExecuteParam> &executeParam, 568 std::unique_ptr<InsightIntentExecutorAsyncCallback> callback); 569 570 /** 571 * @brief Execute insight intent when an ability didn't started, schedule it to background. 572 * 573 * @param want Want. 574 * @param executeParam insight intent execute param. 575 * @param callback insight intent async callback. 576 */ 577 virtual void ExecuteInsightIntentBackground(const AAFwk::Want &want, 578 const std::shared_ptr<InsightIntentExecuteParam> &executeParam, 579 std::unique_ptr<InsightIntentExecutorAsyncCallback> callback); 580 581 /** 582 * @brief create modal UIExtension. 583 * @param want Create modal UIExtension with want object. 584 */ 585 int CreateModalUIExtension(const AAFwk::Want &want); 586 587 /** 588 * @brief Update sessionToken. 589 * @param sessionToken The token of session. 590 */ 591 void UpdateSessionToken(sptr<IRemoteObject> sessionToken); 592 593 void EraseUIExtension(int32_t sessionId) override; 594 595 void SetIdentityToken(const std::string &identityToken); 596 std::string GetIdentityToken() const; 597 598 /** 599 * @brief Called when distributed system trying to collaborate remote ability. 600 * @param want want with collaborative info. 601 */ 602 virtual void HandleCollaboration(const AAFwk::Want &want); 603 604 protected: 605 class UIAbilityDisplayListener : public OHOS::Rosen::IDisplayInfoChangedListener { 606 public: UIAbilityDisplayListener(const std::weak_ptr<UIAbility> & ability)607 explicit UIAbilityDisplayListener(const std::weak_ptr<UIAbility> &ability) 608 { 609 ability_ = ability; 610 } 611 OnDisplayInfoChange(const sptr<IRemoteObject> & token,Rosen::DisplayId displayId,float density,Rosen::DisplayOrientation orientation)612 void OnDisplayInfoChange(const sptr<IRemoteObject>& token, Rosen::DisplayId displayId, float density, 613 Rosen::DisplayOrientation orientation) override 614 { 615 auto sptr = ability_.lock(); 616 if (sptr != nullptr) { 617 sptr->OnDisplayInfoChange(token, displayId, density, orientation); 618 } 619 } 620 621 private: 622 std::weak_ptr<UIAbility> ability_; 623 }; 624 625 void OnCreate(Rosen::DisplayId displayId); 626 void OnDestroy(Rosen::DisplayId displayId); 627 void OnChange(Rosen::DisplayId displayId); 628 void OnDisplayInfoChange(const sptr<IRemoteObject>& token, Rosen::DisplayId displayId, float density, 629 Rosen::DisplayOrientation orientation); 630 631 class AbilityDisplayMoveListener : public OHOS::Rosen::IDisplayMoveListener { 632 public: AbilityDisplayMoveListener(std::weak_ptr<UIAbility> && ability)633 explicit AbilityDisplayMoveListener(std::weak_ptr<UIAbility> &&ability) : ability_(ability) {} 634 OnDisplayMove(Rosen::DisplayId from,Rosen::DisplayId to)635 void OnDisplayMove(Rosen::DisplayId from, Rosen::DisplayId to) override 636 { 637 auto sptr = ability_.lock(); 638 if (sptr != nullptr) { 639 sptr->OnDisplayMove(from, to); 640 } 641 } 642 643 private: 644 std::weak_ptr<UIAbility> ability_; 645 }; 646 647 void OnDisplayMove(Rosen::DisplayId from, Rosen::DisplayId to); 648 void UpdateConfiguration(Rosen::DisplayId to, float density, int32_t width, int32_t height); 649 virtual void DoOnForeground(const AAFwk::Want &want); 650 sptr<Rosen::WindowOption> GetWindowOption(const AAFwk::Want &want); 651 virtual void ContinuationRestore(const AAFwk::Want &want); 652 bool CheckRecoveryEnabled(); 653 bool CheckDefaultRecoveryEnabled(); 654 bool IsStartByScb(); 655 656 std::shared_ptr<Rosen::WindowScene> scene_ = nullptr; 657 sptr<Rosen::IWindowLifeCycle> sceneListener_ = nullptr; 658 sptr<UIAbilityDisplayListener> abilityDisplayListener_ = nullptr; 659 sptr<Rosen::IDisplayMoveListener> abilityDisplayMoveListener_ = nullptr; 660 private: 661 void OnStartForSupportGraphics(const AAFwk::Want &want); 662 void OnChangeForUpdateConfiguration(const AppExecFwk::Configuration &newConfig); 663 void SetSessionToken(sptr<IRemoteObject> sessionToken); 664 665 std::string identityToken_; 666 bool showOnLockScreen_ = false; 667 std::mutex wantMutexlock_; 668 #endif 669 }; 670 } // namespace AbilityRuntime 671 } // namespace OHOS 672 #endif // OHOS_ABILITY_RUNTIME_UI_ABILITY_H 673