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 "devicestatus_hisysevent.h"
17 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
18 #include "hisysevent.h"
19 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
20 #include "fi_log.h"
21
22 #undef LOG_TAG
23 #define LOG_TAG "DeviceStatusHiSysEvent"
24
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28
29 template<typename... Types>
WriteEvent(const std::string &packageName, Types ... args)30 static void WriteEvent(const std::string &packageName, Types ... args)
31 {
32 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
33 int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::MSDP, packageName,
34 HiviewDFX::HiSysEvent::EventType::STATISTIC, args...);
35 if (ret != 0) {
36 FI_HILOGE("Write event failed:%{public}s", packageName.c_str());
37 }
38 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
39 }
40
WriteSubscribeHiSysEvent(int32_t uid, const std::string &packageName, int32_t type)41 void WriteSubscribeHiSysEvent(int32_t uid, const std::string &packageName, int32_t type)
42 {
43 WriteEvent("SUBSCRIBE", "UID", uid, "PACKAGE_NAME", packageName, "TYPE", type);
44 }
45
WriteUnSubscribeHiSysEvent(int32_t uid, const std::string &packageName, int32_t type)46 void WriteUnSubscribeHiSysEvent(int32_t uid, const std::string &packageName, int32_t type)
47 {
48 WriteEvent("UNSUBSCRIBE", "UID", uid, "PACKAGE_NAME", packageName, "TYPE", type);
49 }
50 } // namespace DeviceStatus
51 } // namespace Msdp
52 } // namespace OHOS
53
54