1 /*
2 * Copyright (c) 2021-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 "stats_utils.h"
17
18 #include "stats_log.h"
19
20 namespace OHOS {
21 namespace PowerMgr {
ConvertTypeForConn(StatsType statsType)22 std::string StatsUtils::ConvertTypeForConn(StatsType statsType)
23 {
24 std::string result = "";
25 switch (statsType) {
26 case STATS_TYPE_BLUETOOTH_BR_ON:
27 result = GET_VARIABLE_NAME(STATS_TYPE_BLUETOOTH_BR_ON);
28 break;
29 case STATS_TYPE_BLUETOOTH_BR_SCAN:
30 result = GET_VARIABLE_NAME(STATS_TYPE_BLUETOOTH_BR_SCAN);
31 break;
32 case STATS_TYPE_BLUETOOTH_BLE_ON:
33 result = GET_VARIABLE_NAME(STATS_TYPE_BLUETOOTH_BLE_ON);
34 break;
35 case STATS_TYPE_BLUETOOTH_BLE_SCAN:
36 result = GET_VARIABLE_NAME(STATS_TYPE_BLUETOOTH_BLE_SCAN);
37 break;
38 case STATS_TYPE_WIFI_ON:
39 result = GET_VARIABLE_NAME(STATS_TYPE_WIFI_ON);
40 break;
41 case STATS_TYPE_WIFI_SCAN:
42 result = GET_VARIABLE_NAME(STATS_TYPE_WIFI_SCAN);
43 break;
44 case STATS_TYPE_PHONE_ACTIVE:
45 result = GET_VARIABLE_NAME(STATS_TYPE_PHONE_ACTIVE);
46 break;
47 case STATS_TYPE_PHONE_DATA:
48 result = GET_VARIABLE_NAME(STATS_TYPE_PHONE_DATA);
49 break;
50 default:
51 break;
52 }
53 STATS_HILOGD(COMP_UTILS, "Convert to %{public}s", result.c_str());
54 return result;
55 }
56
ConvertTypeForCpu(StatsType statsType)57 std::string StatsUtils::ConvertTypeForCpu(StatsType statsType)
58 {
59 std::string result = "";
60 switch (statsType) {
61 case STATS_TYPE_WAKELOCK_HOLD:
62 result = GET_VARIABLE_NAME(STATS_TYPE_WAKELOCK_HOLD);
63 break;
64 case STATS_TYPE_PHONE_IDLE:
65 result = GET_VARIABLE_NAME(STATS_TYPE_PHONE_IDLE);
66 break;
67 case STATS_TYPE_CPU_CLUSTER:
68 result = GET_VARIABLE_NAME(STATS_TYPE_CPU_CLUSTER);
69 break;
70 case STATS_TYPE_CPU_SPEED:
71 result = GET_VARIABLE_NAME(STATS_TYPE_CPU_SPEED);
72 break;
73 case STATS_TYPE_CPU_ACTIVE:
74 result = GET_VARIABLE_NAME(STATS_TYPE_CPU_ACTIVE);
75 break;
76 case STATS_TYPE_CPU_SUSPEND:
77 result = GET_VARIABLE_NAME(STATS_TYPE_CPU_SUSPEND);
78 break;
79 default:
80 break;
81 }
82 STATS_HILOGD(COMP_UTILS, "Convert to %{public}s", result.c_str());
83 return result;
84 }
85
ConvertTypeForCommon(StatsType statsType)86 std::string StatsUtils::ConvertTypeForCommon(StatsType statsType)
87 {
88 std::string result = "";
89 switch (statsType) {
90 case STATS_TYPE_CAMERA_ON:
91 result = GET_VARIABLE_NAME(STATS_TYPE_CAMERA_ON);
92 break;
93 case STATS_TYPE_CAMERA_FLASHLIGHT_ON:
94 result = GET_VARIABLE_NAME(STATS_TYPE_CAMERA_FLASHLIGHT_ON);
95 break;
96 case STATS_TYPE_FLASHLIGHT_ON:
97 result = GET_VARIABLE_NAME(STATS_TYPE_FLASHLIGHT_ON);
98 break;
99 case STATS_TYPE_GNSS_ON:
100 result = GET_VARIABLE_NAME(STATS_TYPE_GNSS_ON);
101 break;
102 case STATS_TYPE_SENSOR_GRAVITY_ON:
103 result = GET_VARIABLE_NAME(STATS_TYPE_SENSOR_GRAVITY_ON);
104 break;
105 case STATS_TYPE_SENSOR_PROXIMITY_ON:
106 result = GET_VARIABLE_NAME(STATS_TYPE_SENSOR_PROXIMITY_ON);
107 break;
108 case STATS_TYPE_AUDIO_ON:
109 result = GET_VARIABLE_NAME(STATS_TYPE_AUDIO_ON);
110 break;
111 case STATS_TYPE_SCREEN_ON:
112 result = GET_VARIABLE_NAME(STATS_TYPE_SCREEN_ON);
113 break;
114 case STATS_TYPE_SCREEN_BRIGHTNESS:
115 result = GET_VARIABLE_NAME(STATS_TYPE_SCREEN_BRIGHTNESS);
116 break;
117 case STATS_TYPE_ALARM:
118 result = GET_VARIABLE_NAME(STATS_TYPE_ALARM);
119 break;
120 default:
121 break;
122 }
123 STATS_HILOGD(COMP_UTILS, "Convert to %{public}s", result.c_str());
124 return result;
125 }
126
ConvertTypeForDebug(StatsType statsType)127 std::string StatsUtils::ConvertTypeForDebug(StatsType statsType)
128 {
129 std::string result = "";
130 switch (statsType) {
131 case STATS_TYPE_BATTERY:
132 result = GET_VARIABLE_NAME(STATS_TYPE_BATTERY);
133 break;
134 case STATS_TYPE_WORKSCHEDULER:
135 result = GET_VARIABLE_NAME(STATS_TYPE_WORKSCHEDULER);
136 break;
137 case STATS_TYPE_THERMAL:
138 result = GET_VARIABLE_NAME(STATS_TYPE_THERMAL);
139 break;
140 case STATS_TYPE_DISTRIBUTEDSCHEDULER:
141 result = GET_VARIABLE_NAME(STATS_TYPE_DISTRIBUTEDSCHEDULER);
142 break;
143 default:
144 break;
145 }
146 STATS_HILOGD(COMP_UTILS, "Convert to %{public}s", result.c_str());
147 return result;
148 }
149
ConvertStatsType(StatsType statsType)150 std::string StatsUtils::ConvertStatsType(StatsType statsType)
151 {
152 std::string result = "";
153 switch (statsType) {
154 case STATS_TYPE_BLUETOOTH_BR_ON:
155 case STATS_TYPE_BLUETOOTH_BR_SCAN:
156 case STATS_TYPE_BLUETOOTH_BLE_ON:
157 case STATS_TYPE_BLUETOOTH_BLE_SCAN:
158 case STATS_TYPE_WIFI_ON:
159 case STATS_TYPE_WIFI_SCAN:
160 case STATS_TYPE_PHONE_ACTIVE:
161 case STATS_TYPE_PHONE_DATA:
162 result = ConvertTypeForConn(statsType);
163 break;
164 case STATS_TYPE_CAMERA_ON:
165 case STATS_TYPE_CAMERA_FLASHLIGHT_ON:
166 case STATS_TYPE_FLASHLIGHT_ON:
167 case STATS_TYPE_GNSS_ON:
168 case STATS_TYPE_SENSOR_GRAVITY_ON:
169 case STATS_TYPE_SENSOR_PROXIMITY_ON:
170 case STATS_TYPE_AUDIO_ON:
171 case STATS_TYPE_SCREEN_ON:
172 case STATS_TYPE_SCREEN_BRIGHTNESS:
173 case STATS_TYPE_ALARM:
174 result = ConvertTypeForCommon(statsType);
175 break;
176 case STATS_TYPE_WAKELOCK_HOLD:
177 case STATS_TYPE_PHONE_IDLE:
178 case STATS_TYPE_CPU_CLUSTER:
179 case STATS_TYPE_CPU_SPEED:
180 case STATS_TYPE_CPU_ACTIVE:
181 case STATS_TYPE_CPU_SUSPEND:
182 result = ConvertTypeForCpu(statsType);
183 break;
184 case STATS_TYPE_BATTERY:
185 case STATS_TYPE_WORKSCHEDULER:
186 case STATS_TYPE_THERMAL:
187 case STATS_TYPE_DISTRIBUTEDSCHEDULER:
188 result = ConvertTypeForDebug(statsType);
189 break;
190 default:
191 STATS_HILOGW(COMP_UTILS, "Convert failed due to illegal type=%{public}d", static_cast<int32_t>(statsType));
192 break;
193 }
194 return result;
195 }
196 } // namespace PowerMgr
197 } // namespace OHOS