• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.stats.pull;
18 
19 import static android.provider.Settings.System.PEAK_REFRESH_RATE;
20 
21 import android.annotation.Nullable;
22 import android.content.Context;
23 import android.util.Log;
24 
25 import com.android.internal.display.RefreshRateSettingsUtils;
26 
27 /**
28  * Utility methods for processing raw settings values to the format that
29  * is acceptable for telemetry system.
30  * For instance, raw setting values could be hard to visualize on dashboards, etc.
31  */
32 public final class RawSettingsTelemetryUtils {
33 
34     private static final String TAG = "SettingsTelemetryUtils";
35 
36     /**
37      * Get string that should be written as a value of settingKey and should be sent to telemetry
38      * system.
39      *
40      * @param context The context
41      * @param key The setting key
42      * @param value The setting raw value that was parsed from Settings.
43      * @return The setting string value that should be sent to telemetry system.
44      */
45     @Nullable
getTelemetrySettingFromRawVal(Context context, String key, String value)46     public static String getTelemetrySettingFromRawVal(Context context, String key, String value) {
47         if (key == null) {
48             return null;
49         }
50 
51         if (key.equals(PEAK_REFRESH_RATE)) {
52             return getPeakRefreshRateSetting(context, value);
53         }
54 
55         return value;
56     }
57 
58     /**
59      * Get string that should be written as a value of "peak_refresh_setting" setting
60      * and should be sent to telemetry.
61      * system.
62      *
63      * @param context The context
64      * @param settingRawValue The setting raw value that was parsed from Settings.
65      * @return The "peak_refresh_setting" string value that should be sent to telemetry system.
66      */
67     @Nullable
getPeakRefreshRateSetting(Context context, String settingRawValue)68     private static String getPeakRefreshRateSetting(Context context, String settingRawValue) {
69         if (settingRawValue == null) {
70             Log.e(TAG, "PEAK_REFRESH_RATE value is null");
71             return null;
72         }
73 
74         String floatInfinityStr = Float.toString(Float.POSITIVE_INFINITY);
75         if (settingRawValue.equals(floatInfinityStr)) {
76             float max_refresh_rate =
77                     RefreshRateSettingsUtils.findHighestRefreshRateAmongAllBuiltInDisplays(context);
78             return Float.toString(max_refresh_rate);
79         }
80 
81         return settingRawValue;
82     }
83 }
84