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_RECORD_MGR_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_RECORD_MGR_H 18 19 #include <map> 20 #include "iremote_object.h" 21 #include "ability_local_record.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 class AbilityLocalRecord; 26 class AbilityRecordMgr { 27 public: 28 AbilityRecordMgr() = default; 29 ~AbilityRecordMgr() = default; 30 31 /** 32 * @brief Set the eventRunner of abilitythread to the AbilityRecordMgr. 33 * 34 * @param eventRunner The runner of the abilitythread. 35 * 36 */ 37 void SetEventRunner(const std::shared_ptr<EventRunner> &eventRunner); 38 39 /** 40 * @brief Get the token witch is set to the AbilityRecordMgr. 41 * 42 * @return Returns the token which is set to the AbilityRecordMgr. 43 */ 44 sptr<IRemoteObject> GetToken() const; 45 46 /** 47 * @brief Set the token witch the app launched. 48 * 49 * @param token The token which the is launched by app. 50 */ 51 void SetToken(const sptr<IRemoteObject> &token); 52 53 /** 54 * @brief Save the token and abilityRecord to the AbilityRecordMgr. 55 * 56 * @param token The token which the abilityRecord belongs to. 57 * @param abilityRecord the abilityRecord witch contains the context info belong the the ability. 58 * 59 */ 60 void AddAbilityRecord(const sptr<IRemoteObject> &token, const std::shared_ptr<AbilityLocalRecord> &abilityRecord); 61 62 /** 63 * @brief Remove the abilityRecord by token. 64 * 65 * @param token The token which the abilityRecord belongs to. 66 * 67 */ 68 void RemoveAbilityRecord(const sptr<IRemoteObject> &token); 69 70 /** 71 * @brief Get the number of abilityRecords which the AbilityRecordMgr saved. 72 * 73 * @return Return the number of abilityRecords which the AbilityRecordMgr saved. 74 * 75 */ 76 int GetRecordCount() const; 77 78 /** 79 * @brief Get the abilityRecord by token. 80 * 81 * @param token The token which the abilityRecord belongs to. 82 * 83 */ 84 std::shared_ptr<AbilityLocalRecord> GetAbilityItem(const sptr<IRemoteObject> &token) const; 85 86 /** 87 * @brief Get the all tokens in the abilityRecordMgr. 88 * 89 * @return all tokens in the abilityRecordMgr. 90 * 91 */ 92 std::vector<sptr<IRemoteObject>> GetAllTokens(); 93 94 private: 95 std::map<sptr<IRemoteObject>, std::shared_ptr<AbilityLocalRecord>> abilityRecords_; 96 sptr<IRemoteObject> tokens_; // we use ThreadLocal 97 }; 98 } // namespace AppExecFwk 99 } // namespace OHOS 100 #endif // OHOS_ABILITY_RUNTIME_ABILITY_RECORD_MGR_H 101