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_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 89 /** 90 * @description: Get an AbilityImpl in an ability. 91 * 92 * @return Returns AbilityImpl pointer 93 */ 94 const std::shared_ptr<AbilityImpl> &GetAbilityImpl(); 95 96 /** 97 * @description: Set an AbilityImpl in an ability. 98 * @param abilityImpl AbilityImpl object 99 * @return None. 100 */ 101 void SetAbilityImpl(const std::shared_ptr<AbilityImpl> &abilityImpl); 102 103 /** 104 * @description: Obtains the information based on ability thread. 105 * @return return AbilityThread Pointer 106 */ 107 const sptr<AbilityThread> &GetAbilityThread(); 108 109 /** 110 * @description: Set an AbilityThread in an ability. 111 * @param abilityThread AbilityThread object 112 * @return None. 113 */ 114 void SetAbilityThread(const sptr<AbilityThread> &abilityThread); 115 116 void SetWant(const std::shared_ptr<AAFwk::Want> &want); 117 118 const std::shared_ptr<AAFwk::Want> &GetWant(); 119 private: 120 std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr; 121 sptr<IRemoteObject> token_; 122 std::shared_ptr<EventRunner> runner_ = nullptr; 123 std::shared_ptr<EventHandler> handler_ = nullptr; 124 std::shared_ptr<AbilityImpl> abilityImpl_ = nullptr; // store abilityImpl 125 sptr<AbilityThread> abilityThread_; 126 std::shared_ptr<AAFwk::Want> want_ = nullptr; 127 }; 128 } // namespace AppExecFwk 129 } // namespace OHOS 130 #endif // OHOS_ABILITY_RUNTIME_ABILITY_LOCAL_RECORD_H 131