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 #include "event_report.h"
17
18 #include <unordered_map>
19
20 #include "app_log_wrapper.h"
21 #ifdef HISYSEVENT_ENABLE
22 #include "hisysevent.h"
23 #endif
24
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace {
28 const std::string GET_REMOTE_ABILITY_INFO = "GET_REMOTE_ABILITY_INFO";
29 const std::string GET_REMOTE_ABILITY_INFOS = "GET_REMOTE_ABILITY_INFOS";
30
31 const std::string DEVICE_ID = "DEVICE_ID";
32 const std::string BUNDLE_NAME = "BUNDLE_NAME";
33 const std::string LOCALE_INFO = "LOCALE_INFO";
34 const std::string ABILITY_NAME = "ABILITY_NAME";
35 const std::string RESULT_CODE = "RESULT_CODE";
36
37 const std::unordered_map<DBMSEventType, std::string> DBMS_EVENT_STR_MAP = {
38 { DBMSEventType::GET_REMOTE_ABILITY_INFO, GET_REMOTE_ABILITY_INFO },
39 { DBMSEventType::GET_REMOTE_ABILITY_INFOS, GET_REMOTE_ABILITY_INFOS },
40 };
41 }
42
SendSystemEvent(DBMSEventType dbmsEventType,const DBMSEventInfo & eventInfo)43 void EventReport::SendSystemEvent(
44 DBMSEventType dbmsEventType, const DBMSEventInfo& eventInfo)
45 {
46 #ifndef HISYSEVENT_ENABLE
47 APP_LOGD("Hisysevent is disabled");
48 #else
49 auto iter = DBMS_EVENT_STR_MAP.find(dbmsEventType);
50 if (iter == DBMS_EVENT_STR_MAP.end()) {
51 return;
52 }
53
54 auto eventName = iter->second;
55 HiSysEventWrite(
56 OHOS::HiviewDFX::HiSysEvent::Domain::BUNDLEMANAGER_UE,
57 eventName,
58 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
59 DEVICE_ID, eventInfo.deviceID,
60 BUNDLE_NAME, eventInfo.bundleName,
61 LOCALE_INFO, eventInfo.localeInfo,
62 ABILITY_NAME, eventInfo.abilityName,
63 RESULT_CODE, eventInfo.resultCode);
64 #endif
65 }
66 } // namespace AppExecFwk
67 } // namespace OHOS