• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PostTask(std::function<void()> callback) override;
40     void PostDelayTask(std::function<void()> callback, int32_t delayTime) override;
41     int32_t GetOnDemandReasonExtraData(int64_t extraDataId, OnDemandReasonExtraData& extraData);
42     int32_t GetOnDemandEvents(int32_t systemAbilityId, OnDemandPolicyType type,
43         std::vector<OnDemandEvent>& events);
44     int32_t UpdateOnDemandEvents(int32_t systemAbilityId, OnDemandPolicyType type,
45         const std::vector<OnDemandEvent>& events);
46     void SaveSaExtraDataId(int32_t saId, int64_t extraDataId);
47     void RemoveSaExtraDataId(int64_t extraDataId);
48     void ClearSaExtraDataId(int32_t saId);
49     void SaveCacheCommonEventSaExtraId(const OnDemandEvent& event,
50         const std::list<SaControlInfo>& saControlList);
51     int32_t GetSaExtraDataIdList(int32_t saId, std::vector<int64_t>& extraDataIdList,
52         const std::string& eventName = "");
53     int32_t IsExistInPluginMap(int32_t eventId);
54     void RemoveWhiteCommonEvent();
55 private:
56     bool NeedPersistOnDemandEvent(const OnDemandEvent& event);
57     void PersistOnDemandEvent(int32_t systemAbilityId, OnDemandPolicyType type,
58         const std::vector<OnDemandEvent>& events);
59     void StringToTypeAndSaid(const std::string& str, OnDemandPolicyType& type, int32_t& systemAbilityId);
60     std::string TypeAndSaidToString(OnDemandPolicyType type, int32_t systemAbilityId);
61     void FilterOnDemandSaProfiles(const std::list<SaProfile>& saProfiles);
62     void GetSaControlListByPersistEvent(const OnDemandEvent& event,
63         std::list<SaControlInfo>& saControlList);
64     void GetSaControlListByEvent(const OnDemandEvent& event, std::list<SaControlInfo>& saControlList);
65     void SortSaControlListByLoadPriority(std::list<SaControlInfo>& saControlList);
66     bool CheckEventUsedLocked(const OnDemandEvent& events);
67     static bool IsSameEvent(const OnDemandEvent& ev1, const OnDemandEvent& ev2);
68     bool IsSameEventName(const OnDemandEvent& ev1, const OnDemandEvent& ev2);
69     bool CheckConditions(const OnDemandEvent& onDemandEvent);
70     bool CheckExtraMessages(const OnDemandEvent& ev1, const OnDemandEvent& ev2);
71     int32_t AddCollectEvents(const std::vector<OnDemandEvent>& events);
72     int32_t RemoveUnusedEventsLocked(const std::vector<OnDemandEvent>& events);
73     std::map<int32_t, sptr<ICollectPlugin>> collectPluginMap_;
74     std::shared_ptr<FFRTHandler> collectHandler_;
75     std::shared_mutex saProfilesLock_;
76     std::list<CollMgrSaProfile> onDemandSaProfiles_;
77 };
78 } // namespace OHOS
79 #endif // OHOS_SYSTEM_ABILITY_MANAGER_DEVICE_STATUS_COLLECT_MANAGER_H