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 Get the token witch is set to the AbilityRecordMgr. 33 * 34 * @return Returns the token which is set to the AbilityRecordMgr. 35 */ 36 sptr<IRemoteObject> GetToken() const; 37 38 /** 39 * @brief Set the token witch the app launched. 40 * 41 * @param token The token which the is launched by app. 42 */ 43 void SetToken(const sptr<IRemoteObject> &token); 44 45 /** 46 * @brief Save the token and abilityRecord to the AbilityRecordMgr. 47 * 48 * @param token The token which the abilityRecord belongs to. 49 * @param abilityRecord the abilityRecord witch contains the context info belong the the ability. 50 * 51 */ 52 void AddAbilityRecord(const sptr<IRemoteObject> &token, const std::shared_ptr<AbilityLocalRecord> &abilityRecord); 53 54 /** 55 * @brief Remove the abilityRecord by token. 56 * 57 * @param token The token which the abilityRecord belongs to. 58 * 59 */ 60 void RemoveAbilityRecord(const sptr<IRemoteObject> &token); 61 62 /** 63 * @brief Get the number of abilityRecords which the AbilityRecordMgr saved. 64 * 65 * @return Return the number of abilityRecords which the AbilityRecordMgr saved. 66 * 67 */ 68 int GetRecordCount() const; 69 70 /** 71 * @brief Get the abilityRecord by token. 72 * 73 * @param token The token which the abilityRecord belongs to. 74 * 75 */ 76 std::shared_ptr<AbilityLocalRecord> GetAbilityItem(const sptr<IRemoteObject> &token) const; 77 78 /** 79 * @brief Get the all tokens in the abilityRecordMgr. 80 * 81 * @return all tokens in the abilityRecordMgr. 82 * 83 */ 84 std::vector<sptr<IRemoteObject>> GetAllTokens(); 85 86 private: 87 std::map<sptr<IRemoteObject>, std::shared_ptr<AbilityLocalRecord>> abilityRecords_; 88 sptr<IRemoteObject> tokens_; // we use ThreadLocal 89 }; 90 } // namespace AppExecFwk 91 } // namespace OHOS 92 #endif // OHOS_ABILITY_RUNTIME_ABILITY_RECORD_MGR_H 93