OSDN Git Service

Disable lowBatteryTip and ReducedBatteryTip
[android-x86/packages-apps-Settings.git] / src / com / android / settings / fuelgauge / batterytip / BatteryTipPolicy.java
1 /*
2  * Copyright (C) 2017 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.settings.fuelgauge.batterytip;
18
19 import android.content.Context;
20 import android.provider.Settings;
21 import android.support.annotation.VisibleForTesting;
22 import android.util.KeyValueListParser;
23 import android.util.Log;
24
25 /**
26  * Class to store the policy for battery tips, which comes from
27  * {@link Settings.Global}
28  */
29 public class BatteryTipPolicy {
30     public static final String TAG = "BatteryTipPolicy";
31
32     private static final String KEY_BATTERY_TIP_ENABLED = "battery_tip_enabled";
33     private static final String KEY_SUMMARY_ENABLED = "summary_enabled";
34     private static final String KEY_BATTERY_SAVER_TIP_ENABLED = "battery_saver_tip_enabled";
35     private static final String KEY_HIGH_USAGE_ENABLED = "high_usage_enabled";
36     private static final String KEY_HIGH_USAGE_APP_COUNT = "high_usage_app_count";
37     private static final String KEY_APP_RESTRICTION_ENABLED = "app_restriction_enabled";
38     private static final String KEY_REDUCED_BATTERY_ENABLED = "reduced_battery_enabled";
39     private static final String KEY_REDUCED_BATTERY_PERCENT = "reduced_battery_percent";
40     private static final String KEY_LOW_BATTERY_ENABLED = "low_battery_enabled";
41     private static final String KEY_LOW_BATTERY_HOUR = "low_battery_hour";
42
43     /**
44      * {@code true} if general battery tip is enabled
45      *
46      * @see Settings.Global#BATTERY_TIP_CONSTANTS
47      * @see #KEY_BATTERY_TIP_ENABLED
48      */
49     public final boolean batteryTipEnabled;
50
51     /**
52      * {@code true} if summary tip is enabled
53      *
54      * @see Settings.Global#BATTERY_TIP_CONSTANTS
55      * @see #KEY_SUMMARY_ENABLED
56      */
57     public final boolean summaryEnabled;
58
59     /**
60      * {@code true} if battery saver tip is enabled
61      *
62      * @see Settings.Global#BATTERY_TIP_CONSTANTS
63      * @see #KEY_BATTERY_SAVER_TIP_ENABLED
64      */
65     public final boolean batterySaverTipEnabled;
66
67     /**
68      * {@code true} if high usage tip is enabled
69      *
70      * @see Settings.Global#BATTERY_TIP_CONSTANTS
71      * @see #KEY_HIGH_USAGE_ENABLED
72      */
73     public final boolean highUsageEnabled;
74
75     /**
76      * The maximum number of apps shown in high usage
77      *
78      * @see Settings.Global#BATTERY_TIP_CONSTANTS
79      * @see #KEY_HIGH_USAGE_APP_COUNT
80      */
81     public final int highUsageAppCount;
82
83     /**
84      * {@code true} if app restriction tip is enabled
85      *
86      * @see Settings.Global#BATTERY_TIP_CONSTANTS
87      * @see #KEY_APP_RESTRICTION_ENABLED
88      */
89     public final boolean appRestrictionEnabled;
90
91     /**
92      * {@code true} if reduced battery tip is enabled
93      *
94      * @see Settings.Global#BATTERY_TIP_CONSTANTS
95      * @see #KEY_REDUCED_BATTERY_ENABLED
96      */
97     public final boolean reducedBatteryEnabled;
98
99     /**
100      * The percentage of reduced battery to trigger the tip(e.g. 50%)
101      *
102      * @see Settings.Global#BATTERY_TIP_CONSTANTS
103      * @see #KEY_REDUCED_BATTERY_PERCENT
104      */
105     public final int reducedBatteryPercent;
106
107     /**
108      * {@code true} if low battery tip is enabled
109      *
110      * @see Settings.Global#BATTERY_TIP_CONSTANTS
111      * @see #KEY_LOW_BATTERY_ENABLED
112      */
113     public final boolean lowBatteryEnabled;
114
115     /**
116      * Remaining battery hour to trigger the tip(e.g. 16 hours)
117      *
118      * @see Settings.Global#BATTERY_TIP_CONSTANTS
119      * @see #KEY_LOW_BATTERY_HOUR
120      */
121     public final int lowBatteryHour;
122
123     private final KeyValueListParser mParser;
124
125     public BatteryTipPolicy(Context context) {
126         this(context, new KeyValueListParser(','));
127     }
128
129     @VisibleForTesting
130     BatteryTipPolicy(Context context, KeyValueListParser parser) {
131         mParser = parser;
132         final String value = Settings.Global.getString(context.getContentResolver(),
133                 Settings.Global.BATTERY_TIP_CONSTANTS);
134
135         try {
136             mParser.setString(value);
137         } catch (IllegalArgumentException e) {
138             Log.e(TAG, "Bad battery tip constants");
139         }
140
141         batteryTipEnabled = mParser.getBoolean(KEY_BATTERY_TIP_ENABLED, true);
142         summaryEnabled = mParser.getBoolean(KEY_SUMMARY_ENABLED, true);
143         batterySaverTipEnabled = mParser.getBoolean(KEY_BATTERY_SAVER_TIP_ENABLED, true);
144         highUsageEnabled = mParser.getBoolean(KEY_HIGH_USAGE_ENABLED, true);
145         highUsageAppCount = mParser.getInt(KEY_HIGH_USAGE_APP_COUNT, 3);
146         appRestrictionEnabled = mParser.getBoolean(KEY_APP_RESTRICTION_ENABLED, true);
147         reducedBatteryEnabled = mParser.getBoolean(KEY_REDUCED_BATTERY_ENABLED, false);
148         reducedBatteryPercent = mParser.getInt(KEY_REDUCED_BATTERY_PERCENT, 50);
149         lowBatteryEnabled = mParser.getBoolean(KEY_LOW_BATTERY_ENABLED, false);
150         lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 16);
151     }
152
153 }