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_report.h"
17 #include "edm_log.h"
18 #include "nlohmann/json.hpp"
19 #ifdef SECURITY_GUARDE_ENABLE
20 #include "event_info.h"
21 #include "sg_collect_client.h"
22 #endif
23
24 namespace OHOS {
25 namespace EDM {
26
ReportSecurityInfo(const std::string & bundleName,const std::string & abilityName,const std::string & policyName)27 void SecurityReport::ReportSecurityInfo(const std::string &bundleName, const std::string &abilityName,
28 const std::string &policyName)
29 {
30 #ifdef SECURITY_GUARDE_ENABLE
31 const int64_t EVENT_ID = 1011015013; // 1011015013: report event id
32 using namespace Security::SecurityGuard;
33 nlohmann::json callPkgJson = nlohmann::json {
34 {"bundleName", bundleName},
35 {"abilityName", abilityName},
36 };
37 nlohmann::json jsonResult;
38 jsonResult["type"] = 0; // default
39 jsonResult["subType"] = 0; // default
40 jsonResult["caller"] = callPkgJson;
41 jsonResult["objectInfo"] = policyName;
42 std::shared_ptr<EventInfo> eventInfo = std::make_shared<EventInfo>(EVENT_ID, "1.0", jsonResult.dump());
43 int32_t ret = OHOS::Security::SecurityGuard::NativeDataCollectKit::ReportSecurityInfo(eventInfo);
44 if (ret != ERR_OK) {
45 EDMLOGE("SecurityReport::ReportSecurityInfo ret: %{public}d", ret);
46 }
47 #endif
48 }
49 } // namespace EDM
50 } // namespace OHOS