1 /*
2  * Copyright (c) 2021 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     void MoveToBackground(const Want &want, LifeCycleStateInfo &stateInfo);
51     void ConnectAbility(const Want &want);
52     void DisconnectAbility(const Want &want);
53     void Terminate(const Want &want, LifeCycleStateInfo &stateInfo, sptr<SessionInfo> sessionInfo = nullptr);
54     void CommandAbility(const Want &want, bool reStart, int startId);
55     void CommandAbilityWindow(const Want &want, const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd);
56     void SaveAbilityState();
57     void RestoreAbilityState(const PacMap &inState);
58     bool ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
59         sptr<SessionInfo> sessionInfo = nullptr);
60     void BackgroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
61         sptr<SessionInfo> sessionInfo = nullptr);
62     void ContinueAbility(const std::string& deviceId, uint32_t versionCode);
63     void NotifyContinuationResult(int32_t result);
64     void ShareData(const int32_t &uniqueId);
65     bool PrepareTerminateAbility();
66     void UpdateSessionToken(sptr<IRemoteObject> sessionToken);
67 
68 private:
69     sptr<IAbilityScheduler> GetScheduler();
70     sptr<IAbilityScheduler> abilityScheduler_;  // kit interface used to schedule ability life
71     std::shared_mutex schedulerMutex_;
72 
73     DISALLOW_COPY_AND_MOVE(LifecycleDeal);
74 };
75 }  // namespace AAFwk
76 }  // namespace OHOS
77 #endif  // OHOS_ABILITY_RUNTIME_LIFECYCLE_DEAL_H
78