1 /* 2 * Copyright (c) 2023 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 SECURITY_GUARD_DATA_COLLECT_MANAGER_H 17 #define SECURITY_GUARD_DATA_COLLECT_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 #include "i_collector_subscriber.h" 22 #include "security_event_query_callback.h" 23 #include "security_event_ruler.h" 24 #include "acquire_data_manager_callback_service.h" 25 #include "event_info.h" 26 namespace OHOS::Security::SecurityGuard { 27 class DataCollectManager { 28 public: 29 static DataCollectManager& GetInstance(); 30 class DeathRecipient : public IRemoteObject::DeathRecipient { 31 public: 32 DeathRecipient() = default; 33 ~DeathRecipient() override = default; 34 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 35 }; 36 int32_t ReportSecurityEvent(const std::shared_ptr<EventInfo> &info, bool isSync); 37 int32_t SecurityGuardConfigUpdate(int32_t fd, const std::string &name); 38 int32_t Subscribe(const std::shared_ptr<SecurityCollector::ICollectorSubscriber> &subscriber); 39 int32_t Unsubscribe(const std::shared_ptr<SecurityCollector::ICollectorSubscriber> &subscriber); 40 int32_t QuerySecurityEvent(std::vector<SecurityCollector::SecurityEventRuler> rulers, 41 std::shared_ptr<SecurityEventQueryCallback> callback); 42 int32_t QuerySecurityEvent(std::vector<SecurityCollector::SecurityEventRuler> rulers, 43 std::shared_ptr<SecurityEventQueryCallback> callback, const std::string &eventGroup); 44 int32_t QuerySecurityEventConfig(std::string &result); 45 int32_t StartCollector(const SecurityCollector::Event &event, int64_t duration); 46 int32_t StopCollector(const SecurityCollector::Event &event); 47 int32_t RequestSecurityEventInfo(std::string &devId, std::string &eventList, RequestRiskDataCallback callback); 48 int32_t QuerySecurityEventById(std::vector<SecurityCollector::SecurityEventRuler> rulers, 49 std::shared_ptr<SecurityEventQueryCallback> callback, const std::string &eventGroup); 50 private: 51 DataCollectManager(); 52 ~DataCollectManager() = default; 53 void HandleDecipient(); 54 bool IsCurrentSubscriberEventIdExist(const std::shared_ptr<SecurityCollector::ICollectorSubscriber> &sub); 55 int32_t SetDeathRecipient(const sptr<IRemoteObject> &remote); 56 std::mutex mutex_{}; 57 sptr<AcquireDataManagerCallbackService> callback_{}; 58 std::string sdkFlag_{}; 59 sptr<IRemoteObject::DeathRecipient> deathRecipient_{}; 60 std::set<std::shared_ptr<SecurityCollector::ICollectorSubscriber>> subscribers_{}; 61 uint32_t count_ = 0; 62 }; 63 } // namespace OHOS::Security::SecurityGuard 64 #endif // SECURITY_GUARD_DATA_COLLECT_MANAGER_H