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