1 /* 2 * Copyright (c) 2022 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_SYSTEM_ABILITY_MANAGER_DEVICE_STATUS_COLLECT_MANAGER_H 17 #define OHOS_SYSTEM_ABILITY_MANAGER_DEVICE_STATUS_COLLECT_MANAGER_H 18 19 #include <list> 20 #include <memory> 21 #include <shared_mutex> 22 23 #include "ffrt_handler.h" 24 #include "icollect_plugin.h" 25 #include "system_ability_ondemand_reason.h" 26 #include "system_ability_on_demand_event.h" 27 28 namespace OHOS { 29 class DeviceStatusCollectManager : public IReport { 30 public: 31 DeviceStatusCollectManager() = default; 32 ~DeviceStatusCollectManager() = default; 33 void Init(const std::list<SaProfile>& saProfiles); 34 void UnInit(); 35 void CleanFfrt(); 36 void SetFfrt(); 37 void ReportEvent(const OnDemandEvent& event) override; 38 void StartCollect(); 39 void PostDelayTask(std::function<void()> callback, int32_t delayTime) override; 40 int32_t GetOnDemandReasonExtraData(int64_t extraDataId, OnDemandReasonExtraData& extraData); 41 int32_t GetOnDemandEvents(int32_t systemAbilityId, OnDemandPolicyType type, 42 std::vector<OnDemandEvent>& events); 43 int32_t UpdateOnDemandEvents(int32_t systemAbilityId, OnDemandPolicyType type, 44 const std::vector<OnDemandEvent>& events); 45 private: 46 bool NeedPersistOnDemandEvent(const OnDemandEvent& event); 47 void PersistOnDemandEvent(int32_t systemAbilityId, OnDemandPolicyType type, 48 const std::vector<OnDemandEvent>& events); 49 void StringToTypeAndSaid(const std::string& str, OnDemandPolicyType& type, int32_t& systemAbilityId); 50 std::string TypeAndSaidToString(OnDemandPolicyType type, int32_t systemAbilityId); 51 void FilterOnDemandSaProfiles(const std::list<SaProfile>& saProfiles); 52 void GetSaControlListByPersistEvent(const OnDemandEvent& event, 53 std::list<SaControlInfo>& saControlList); 54 void GetSaControlListByEvent(const OnDemandEvent& event, std::list<SaControlInfo>& saControlList); 55 void SortSaControlListByLoadPriority(std::list<SaControlInfo>& saControlList); 56 bool CheckEventUsedLocked(const OnDemandEvent& events); 57 static bool IsSameEvent(const OnDemandEvent& ev1, const OnDemandEvent& ev2); 58 bool IsSameEventName(const OnDemandEvent& ev1, const OnDemandEvent& ev2); 59 bool CheckConditions(const OnDemandEvent& onDemandEvent); 60 bool CheckExtraMessages(const OnDemandEvent& ev1, const OnDemandEvent& ev2); 61 int32_t AddCollectEvents(const std::vector<OnDemandEvent>& events); 62 int32_t RemoveUnusedEventsLocked(const std::vector<OnDemandEvent>& events); 63 std::map<int32_t, sptr<ICollectPlugin>> collectPluginMap_; 64 std::shared_ptr<FFRTHandler> collectHandler_; 65 std::shared_mutex saProfilesLock_; 66 std::list<SaProfile> onDemandSaProfiles_; 67 }; 68 } // namespace OHOS 69 #endif // OHOS_SYSTEM_ABILITY_MANAGER_DEVICE_STATUS_COLLECT_MANAGER_H