• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef DRM_DFX_H
17 #define DRM_DFX_H
18 
19 #include <list>
20 #include <string>
21 #include <queue>
22 #include <refbase.h>
23 #include "drm_dfx_utils.h"
24 #include "nocopyable.h"
25 #include "hisysevent.h"
26 #include "hitrace/tracechain.h"
27 #include <chrono>
28 
29 namespace OHOS {
30 namespace DrmStandard {
31 using namespace OHOS::HiviewDFX;
32 
33 struct DrmServiveInfo {
34     std::string module;
35     uint32_t currentTime;
36     std::string serviceName;
37     std::string action;
38     uint32_t memoryUsage;
39 };
40 
41 struct DrmLicenseInfo {
42     std::string module;
43     uint32_t currentTime;
44     std::string appName;
45     std::string instanceId;
46     std::string drmName;
47     std::string drmUuid;
48     std::string clientVersion;
49     std::string licenseType;
50     uint32_t generationDuration;
51     std::string generationResult;
52     uint32_t processDuration;
53     std::string processResult;
54 };
55 
56 struct DrmCertificateInfo {
57     std::string module;
58     uint32_t currentTime;
59     std::string appName;
60     std::string instanceId;
61     std::string drmName;
62     std::string drmUuid;
63     std::string clientVersion;
64     uint32_t generationDuration;
65     std::string generationResult;
66     uint32_t processDuration;
67     std::string processResult;
68     uint32_t callServerTime;
69     uint32_t serverCostDuration;
70     std::string serverResult;
71 };
72 
73 struct DrmFaultInfo {
74     std::string module;
75     std::string appName;
76     std::string instanceId;
77     int32_t errorCode;
78     std::string errorMesg;
79     std::string extraMesg;
80 };
81 
82 struct DrmDecryptionInfo {
83     std::string module;
84     std::string appName;
85     std::string instanceId;
86     int32_t errorCode;
87     std::string errorMesg;
88     std::string decryptAlgo;
89     std::string decryptKeyid;
90     std::string decryptIv;
91 };
92 
93 struct DownLoadInfo {
94     uint32_t generationDuration;
95     std::string generationResult;
96     uint32_t processDuration;
97     std::string processResult;
98 };
99 
100 struct DecryptionStatistics {
101     uint32_t decryptTimes = 0;
102     uint64_t decryptSumSize = 0;
103     uint64_t decryptSumDuration = 0;
104     uint32_t decryptMaxSize = 0;
105     uint32_t decryptMaxDuration = 0;
106     uint64_t errorDecryptTimes = 0;
107     int32_t errCode = 0;
108     std::string errMessage = "no error";
109     std::priority_queue<int, std::vector<int>, std::greater<int>> topThree;
110 };
111 
112 class DrmEvent {
113 public:
114     static DrmEvent& GetInstance();
115     int32_t WriteServiceEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmServiveInfo &info);
116     int32_t WriteLicenseEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmLicenseInfo &info);
117     int32_t WriteCertificateEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
118         DrmCertificateInfo &info);
119     int32_t WriteFaultEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmFaultInfo &info);
120     int32_t WriteDecryptionEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
121         DrmDecryptionInfo &info);
122 };
123 
124 __attribute__((visibility("default"))) int32_t ReportServiceBehaviorEvent(std::string serviceName, std::string action);
125 __attribute__((visibility("default"))) int32_t ReportLicenseBehaviorEvent(StatisticsInfo statisticsInfo,
126     std::string licenseType, DownLoadInfo downLoadInfo);
127 __attribute__((visibility("default"))) int32_t ReportCertificateBehaviorEvent(StatisticsInfo statisticsInfo,
128     DownLoadInfo downLoadInfo, uint32_t callServerTime, uint32_t serverCostDuration, std::string serverResult);
129 __attribute__((visibility("default"))) int32_t ReportFaultEvent(uint32_t errorCode, std::string errorMesg,
130     std::string extraMesg);
131 __attribute__((visibility("default"))) int32_t ReportDecryptionFaultEvent(int32_t errorCode, std::string errorMesg,
132     std::string decryptAlgo, std::string decryptKeyid, std::string decryptIv);
133 __attribute__((visibility("default"))) DownLoadInfo InitDownLoadInfo(uint32_t generationDuration,
134     std::string generationResult, uint32_t processDuration, std::string processResult);
135 __attribute__((visibility("default"))) void ReportDecryptionStatisticsEvent(uint64_t instanceId, std::string appName,
136     DecryptionStatistics &statistics);
137 } // namespace DrmStandard
138 } // namespace OHOS
139 #endif // DRM_DFX_H