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 #include "security_guard_sdk_adaptor.h"
17 #include "data_collect_manager.h"
18 #include "sg_collect_client.h"
19 #include "sg_classify_client.h"
20 #include "security_guard_log.h"
21
22 namespace OHOS::Security::SecurityGuard {
23 // LCOV_EXCL_START
RequestSecurityEventInfo(std::string & devId,std::string & eventList,RequestRiskDataCallback callback)24 int32_t SecurityGuardSdkAdaptor::RequestSecurityEventInfo(std::string &devId, std::string &eventList,
25 RequestRiskDataCallback callback)
26 {
27 SGLOGI("enter SecurityGuardSdkAdaptor RequestSecurityEventInfo");
28 return DataCollectManager::GetInstance().RequestSecurityEventInfo(devId, eventList, callback);
29 }
30
InnerRequestSecurityModelResult(const std::string & devId,uint32_t modelId,const std::string & param,SecurityGuardRiskCallback callback)31 int32_t SecurityGuardSdkAdaptor::InnerRequestSecurityModelResult(const std::string &devId, uint32_t modelId,
32 const std::string ¶m, SecurityGuardRiskCallback callback)
33 {
34 SGLOGI("enter SecurityGuardSdkAdaptor InnerRequestSecurityModelResult");
35 return RequestSecurityModelResultAsync(devId, modelId, param, callback);
36 }
37
InnerReportSecurityInfo(const std::shared_ptr<EventInfo> & info)38 int32_t SecurityGuardSdkAdaptor::InnerReportSecurityInfo(const std::shared_ptr<EventInfo> &info)
39 {
40 SGLOGD("enter SecurityGuardSdkAdaptor InnerReportSecurityInfo");
41 return DataCollectManager::GetInstance().ReportSecurityEvent(info, true);
42 }
43
StartCollector(const SecurityCollector::Event & event,int64_t duration)44 int32_t SecurityGuardSdkAdaptor::StartCollector(const SecurityCollector::Event &event,
45 int64_t duration)
46 {
47 SGLOGI("enter SecurityGuardSdkAdaptor StartCollector");
48 return DataCollectManager::GetInstance().StartCollector(event, duration);
49 }
50
StopCollector(const SecurityCollector::Event & event)51 int32_t SecurityGuardSdkAdaptor::StopCollector(const SecurityCollector::Event &event)
52 {
53 SGLOGI("in SecurityGuardSdkAdaptor StopCollector");
54 return DataCollectManager::GetInstance().StopCollector(event);
55 }
56
QuerySecurityEvent(std::vector<SecurityCollector::SecurityEventRuler> rulers,std::shared_ptr<SecurityEventQueryCallback> callback)57 int32_t SecurityGuardSdkAdaptor::QuerySecurityEvent(std::vector<SecurityCollector::SecurityEventRuler> rulers,
58 std::shared_ptr<SecurityEventQueryCallback> callback)
59 {
60 SGLOGI("enter SecurityGuardSdkAdaptor QuerySecurityEvent");
61 return DataCollectManager::GetInstance().QuerySecurityEvent(rulers, callback);
62 }
63
Subscribe(const std::shared_ptr<SecurityCollector::ICollectorSubscriber> & subscriber)64 int32_t SecurityGuardSdkAdaptor::Subscribe(const std::shared_ptr<SecurityCollector::ICollectorSubscriber> &subscriber)
65 {
66 SGLOGI("enter SecurityGuardSdkAdaptor Subscribe");
67 return DataCollectManager::GetInstance().Subscribe(subscriber);
68 }
69
Unsubscribe(const std::shared_ptr<SecurityCollector::ICollectorSubscriber> & subscriber)70 int32_t SecurityGuardSdkAdaptor::Unsubscribe(const std::shared_ptr<SecurityCollector::ICollectorSubscriber> &subscriber)
71 {
72 SGLOGI("enter SecurityGuardSdkAdaptor Unsubscribe");
73 return DataCollectManager::GetInstance().Unsubscribe(subscriber);
74 }
75
ConfigUpdate(const SecurityGuard::SecurityConfigUpdateInfo & updateInfo)76 int32_t SecurityGuardSdkAdaptor::ConfigUpdate(const SecurityGuard::SecurityConfigUpdateInfo &updateInfo)
77 {
78 SGLOGI("enter SecurityGuardSdkAdaptor ConfigUpdate");
79 return DataCollectManager::GetInstance().SecurityGuardConfigUpdate(updateInfo.GetFd(), updateInfo.GetFileName());
80 }
81 // LCOV_EXCL_STOP
82 } // OHOS::Security::SecurityGuard