• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.systemui;
18 
19 import android.annotation.StringDef;
20 import android.content.Context;
21 import android.content.SharedPreferences;
22 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 import java.util.Map;
27 import java.util.Set;
28 
29 public final class Prefs {
Prefs()30     private Prefs() {} // no instantation
31 
32     @Retention(RetentionPolicy.SOURCE)
33     @StringDef({
34             Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME,
35             Key.DEBUG_MODE_ENABLED,
36             Key.HOTSPOT_TILE_LAST_USED,
37             Key.COLOR_INVERSION_TILE_LAST_USED,
38             Key.DND_TILE_VISIBLE,
39             Key.DND_TILE_COMBINED_ICON,
40             Key.DND_CONFIRMED_PRIORITY_INTRODUCTION,
41             Key.DND_CONFIRMED_SILENCE_INTRODUCTION,
42             Key.DND_FAVORITE_BUCKET_INDEX,
43             Key.DND_NONE_SELECTED,
44             Key.DND_FAVORITE_ZEN,
45             Key.QS_HOTSPOT_ADDED,
46             Key.QS_DATA_SAVER_ADDED,
47             Key.QS_DATA_SAVER_DIALOG_SHOWN,
48             Key.QS_INVERT_COLORS_ADDED,
49             Key.QS_WORK_ADDED,
50             Key.QS_NIGHTDISPLAY_ADDED,
51             Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT,
52             Key.SEEN_MULTI_USER,
53             Key.HAS_SEEN_RECENTS_SWIPE_UP_ONBOARDING,
54             Key.HAS_SEEN_RECENTS_QUICK_SCRUB_ONBOARDING,
55             Key.OVERVIEW_OPENED_COUNT,
56             Key.OVERVIEW_OPENED_FROM_HOME_COUNT,
57             Key.SEEN_RINGER_GUIDANCE_COUNT,
58             Key.QS_HAS_TURNED_OFF_MOBILE_DATA,
59             Key.TOUCHED_RINGER_TOGGLE,
60             Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP
61     })
62     public @interface Key {
63         @Deprecated
64         String OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME = "OverviewLastStackTaskActiveTime";
65         String DEBUG_MODE_ENABLED = "debugModeEnabled";
66         String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed";
67         String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed";
68         String DND_TILE_VISIBLE = "DndTileVisible";
69         String DND_TILE_COMBINED_ICON = "DndTileCombinedIcon";
70         String DND_CONFIRMED_PRIORITY_INTRODUCTION = "DndConfirmedPriorityIntroduction";
71         String DND_CONFIRMED_SILENCE_INTRODUCTION = "DndConfirmedSilenceIntroduction";
72         String DND_CONFIRMED_ALARM_INTRODUCTION = "DndConfirmedAlarmIntroduction";
73         String DND_FAVORITE_BUCKET_INDEX = "DndCountdownMinuteIndex";
74         String DND_NONE_SELECTED = "DndNoneSelected";
75         String DND_FAVORITE_ZEN = "DndFavoriteZen";
76         String QS_DATA_SAVER_DIALOG_SHOWN = "QsDataSaverDialogShown";
77         @Deprecated
78         String QS_HOTSPOT_ADDED = "QsHotspotAdded";
79         @Deprecated
80         String QS_DATA_SAVER_ADDED = "QsDataSaverAdded";
81         @Deprecated
82         String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded";
83         @Deprecated
84         String QS_WORK_ADDED = "QsWorkAdded";
85         @Deprecated
86         String QS_NIGHTDISPLAY_ADDED = "QsNightDisplayAdded";
87         /**
88          * Used for tracking how many times the user has seen the long press tooltip in the Quick
89          * Settings panel.
90          */
91         String QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT = "QsLongPressTooltipShownCount";
92         String SEEN_MULTI_USER = "HasSeenMultiUser";
93         String OVERVIEW_OPENED_COUNT = "OverviewOpenedCount";
94         String OVERVIEW_OPENED_FROM_HOME_COUNT = "OverviewOpenedFromHomeCount";
95         String HAS_SEEN_RECENTS_SWIPE_UP_ONBOARDING = "HasSeenRecentsSwipeUpOnboarding";
96         String HAS_SEEN_RECENTS_QUICK_SCRUB_ONBOARDING = "HasSeenRecentsQuickScrubOnboarding";
97         String DISMISSED_RECENTS_SWIPE_UP_ONBOARDING_COUNT =
98                 "DismissedRecentsSwipeUpOnboardingCount";
99         String HAS_DISMISSED_RECENTS_QUICK_SCRUB_ONBOARDING_ONCE =
100                 "HasDismissedRecentsQuickScrubOnboardingOnce";
101         String SEEN_RINGER_GUIDANCE_COUNT = "RingerGuidanceCount";
102         String QS_TILE_SPECS_REVEALED = "QsTileSpecsRevealed";
103         String QS_HAS_TURNED_OFF_MOBILE_DATA = "QsHasTurnedOffMobileData";
104         String TOUCHED_RINGER_TOGGLE = "TouchedRingerToggle";
105         String HAS_SEEN_ODI_CAPTIONS_TOOLTIP = "HasSeenODICaptionsTooltip";
106     }
107 
getBoolean(Context context, @Key String key, boolean defaultValue)108     public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) {
109         return get(context).getBoolean(key, defaultValue);
110     }
111 
putBoolean(Context context, @Key String key, boolean value)112     public static void putBoolean(Context context, @Key String key, boolean value) {
113         get(context).edit().putBoolean(key, value).apply();
114     }
115 
getInt(Context context, @Key String key, int defaultValue)116     public static int getInt(Context context, @Key String key, int defaultValue) {
117         return get(context).getInt(key, defaultValue);
118     }
119 
putInt(Context context, @Key String key, int value)120     public static void putInt(Context context, @Key String key, int value) {
121         get(context).edit().putInt(key, value).apply();
122     }
123 
getLong(Context context, @Key String key, long defaultValue)124     public static long getLong(Context context, @Key String key, long defaultValue) {
125         return get(context).getLong(key, defaultValue);
126     }
127 
putLong(Context context, @Key String key, long value)128     public static void putLong(Context context, @Key String key, long value) {
129         get(context).edit().putLong(key, value).apply();
130     }
131 
getString(Context context, @Key String key, String defaultValue)132     public static String getString(Context context, @Key String key, String defaultValue) {
133         return get(context).getString(key, defaultValue);
134     }
135 
putString(Context context, @Key String key, String value)136     public static void putString(Context context, @Key String key, String value) {
137         get(context).edit().putString(key, value).apply();
138     }
139 
putStringSet(Context context, @Key String key, Set<String> value)140     public static void putStringSet(Context context, @Key String key, Set<String> value) {
141         get(context).edit().putStringSet(key, value).apply();
142     }
143 
getStringSet( Context context, @Key String key, Set<String> defaultValue)144     public static Set<String> getStringSet(
145             Context context, @Key String key, Set<String> defaultValue) {
146         return get(context).getStringSet(key, defaultValue);
147     }
148 
getAll(Context context)149     public static Map<String, ?> getAll(Context context) {
150         return get(context).getAll();
151     }
152 
remove(Context context, @Key String key)153     public static void remove(Context context, @Key String key) {
154         get(context).edit().remove(key).apply();
155     }
156 
registerListener(Context context, OnSharedPreferenceChangeListener listener)157     public static void registerListener(Context context,
158             OnSharedPreferenceChangeListener listener) {
159         get(context).registerOnSharedPreferenceChangeListener(listener);
160     }
161 
unregisterListener(Context context, OnSharedPreferenceChangeListener listener)162     public static void unregisterListener(Context context,
163             OnSharedPreferenceChangeListener listener) {
164         get(context).unregisterOnSharedPreferenceChangeListener(listener);
165     }
166 
get(Context context)167     private static SharedPreferences get(Context context) {
168         return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
169     }
170 }
171