1 /*
2  * Copyright (c) 2021-2023 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_LOCAL_RECORD_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_LOCAL_RECORD_H
18 
19 #include <string>
20 
21 #include "iremote_object.h"
22 #include "event_runner.h"
23 #include "ability_info.h"
24 #include "application_info.h"
25 #include "refbase.h"
26 #include "want.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 class AbilityThread;
31 class AbilityImpl;
32 class AbilityLocalRecord {
33 public:
34     /**
35      *
36      * default constructor
37      *
38      */
39     AbilityLocalRecord(const std::shared_ptr<AbilityInfo> &info, const sptr<IRemoteObject> &token);
40 
41     /**
42      *
43      * @default Destructor
44      *
45      */
46     virtual ~AbilityLocalRecord();
47 
48     /**
49      * @description: Get an AbilityInfo in an ability.
50      *
51      * @return Returns a pointer to abilityinfo.
52      */
53     const std::shared_ptr<AbilityInfo> &GetAbilityInfo();
54 
55     /**
56      * @description: Get an EventHandler in an ability.
57      *
58      * @return Returns a pointer to EventHandler
59      */
60     const std::shared_ptr<EventHandler> &GetEventHandler();
61 
62     /**
63      * @description: Set an EventHandler in an ability.
64      * @param handler EventHandler object
65      * @return None.
66      */
67     void SetEventHandler(const std::shared_ptr<EventHandler> &handler);
68 
69     /**
70      * @description: Get an EventRunner in an ability.
71      *
72      * @return Returns a pointer to EventRunner
73      */
74     const std::shared_ptr<EventRunner> &GetEventRunner();
75 
76     /**
77      * @description: Set an EventRunner in an ability.
78      * @param runner EventHandler object
79      * @return None.
80      */
81     void SetEventRunner(const std::shared_ptr<EventRunner> &runner);
82 
83     /**
84      * @description: Gets the identity of the ability
85      * @return return the identity of the ability.
86      */
87     const sptr<IRemoteObject> &GetToken();
88 
GetAbilityRecordId()89     int32_t GetAbilityRecordId() const
90     {
91         return abilityRecordId_;
92     }
SetAbilityRecordId(int32_t abilityRecordId)93     void SetAbilityRecordId(int32_t abilityRecordId)
94     {
95         abilityRecordId_ = abilityRecordId;
96     }
97 
98     /**
99      * @description: Obtains the information based on ability thread.
100      * @return return AbilityThread Pointer
101      */
102     const sptr<AbilityThread> &GetAbilityThread();
103 
104     /**
105      * @description: Set an AbilityThread in an ability.
106      * @param abilityThread AbilityThread object
107      * @return None.
108      */
109     void SetAbilityThread(const sptr<AbilityThread> &abilityThread);
110 
111     void SetWant(const std::shared_ptr<AAFwk::Want> &want);
112 
113     const std::shared_ptr<AAFwk::Want> &GetWant();
114 private:
115     std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
116     sptr<IRemoteObject> token_;
117     int32_t abilityRecordId_ = 0;
118     std::shared_ptr<EventRunner> runner_ = nullptr;
119     std::shared_ptr<EventHandler> handler_ = nullptr;
120     std::shared_ptr<AbilityImpl> abilityImpl_ = nullptr;  // store abilityImpl
121     sptr<AbilityThread> abilityThread_;
122     std::shared_ptr<AAFwk::Want> want_ = nullptr;
123 };
124 }  // namespace AppExecFwk
125 }  // namespace OHOS
126 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_LOCAL_RECORD_H
127