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_LIFECYCLE_DEAL_H 17 #define OHOS_ABILITY_RUNTIME_LIFECYCLE_DEAL_H 18 19 #include <memory> 20 #include <shared_mutex> 21 22 #include "ability_scheduler_interface.h" 23 #include "want.h" 24 #include "nocopyable.h" 25 26 namespace OHOS { 27 namespace AAFwk { 28 /** 29 * @class LifecycleDeal 30 * LifecycleDeal schedule ability life. 31 */ 32 class LifecycleDeal { 33 public: 34 LifecycleDeal(); 35 virtual ~LifecycleDeal(); 36 37 /** 38 * set scheduler for accessing ability 39 * 40 * @param scheduler, ability thread ipc proxy. 41 */ 42 void SetScheduler(const sptr<IAbilityScheduler> &scheduler); 43 44 /** 45 * schedule ability life 46 * 47 */ 48 void Activate(const Want &want, LifeCycleStateInfo &stateInfo); 49 void Inactivate(const Want &want, LifeCycleStateInfo &stateInfo, sptr<SessionInfo> sessionInfo = nullptr); 50 /** 51 * schedule ability life cycle to background 52 */ 53 void MoveToBackground(const Want &want, LifeCycleStateInfo &stateInfo); 54 /** 55 * schedule ability onConnect 56 */ 57 void ConnectAbility(const Want &want); 58 /** 59 * schedule ability onDisconnect 60 */ 61 void DisconnectAbility(const Want &want); 62 /** 63 * schedule ability onDestroy 64 */ 65 void Terminate(const Want &want, LifeCycleStateInfo &stateInfo, sptr<SessionInfo> sessionInfo = nullptr); 66 /** 67 * schedule ability onRequest 68 */ 69 void CommandAbility(const Want &want, bool reStart, int startId); 70 void CommandAbilityWindow(const Want &want, const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd); 71 void SaveAbilityState(); 72 void RestoreAbilityState(const PacMap &inState); 73 /** 74 * schedule ability life cycle to foreground 75 */ 76 bool ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo, 77 sptr<SessionInfo> sessionInfo = nullptr); 78 /** 79 * schedule ability life cycle to background 80 */ 81 void BackgroundNew(const Want &want, LifeCycleStateInfo &stateInfo, 82 sptr<SessionInfo> sessionInfo = nullptr); 83 void ContinueAbility(const std::string& deviceId, uint32_t versionCode); 84 void NotifyContinuationResult(int32_t result); 85 void ShareData(const int32_t &uniqueId); 86 bool PrepareTerminateAbility(); 87 void UpdateSessionToken(sptr<IRemoteObject> sessionToken); 88 void ScheduleCollaborate(const Want &want); 89 void NotifyAbilityRequestFailure(const std::string &requestId, const AppExecFwk::ElementName &element, 90 const std::string &message, int32_t resultCode = 0); 91 void NotifyAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element); 92 void NotifyAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode); 93 94 private: 95 sptr<IAbilityScheduler> GetScheduler(); 96 sptr<IAbilityScheduler> abilityScheduler_; // kit interface used to schedule ability life 97 std::shared_mutex schedulerMutex_; 98 99 DISALLOW_COPY_AND_MOVE(LifecycleDeal); 100 }; 101 } // namespace AAFwk 102 } // namespace OHOS 103 #endif // OHOS_ABILITY_RUNTIME_LIFECYCLE_DEAL_H 104