blob: 6aa2326c388a6fb1930774a4192ddf39b9f64f20 [file] [log] [blame]
Andrew Flynn82862572015-04-01 14:22:37 -04001/*
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
17package com.android.systemui;
18
19import android.annotation.StringDef;
20import android.content.Context;
21import android.content.SharedPreferences;
22import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
23
24import java.lang.annotation.Retention;
25import java.lang.annotation.RetentionPolicy;
26import java.util.Map;
Amin Shaikha07a17b2018-02-23 16:02:52 -050027import java.util.Set;
Andrew Flynn82862572015-04-01 14:22:37 -040028
29public final class Prefs {
30 private Prefs() {} // no instantation
31
32 @Retention(RetentionPolicy.SOURCE)
33 @StringDef({
Julia Reynoldsee571932018-02-21 11:41:33 -050034 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,
Tracy Zhou27599052018-04-16 15:47:29 -070053 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,
Amin Shaikh329c8282018-03-09 14:50:59 -050057 Key.SEEN_RINGER_GUIDANCE_COUNT,
Julia Reynoldsac55e012018-03-27 11:17:30 -040058 Key.QS_HAS_TURNED_OFF_MOBILE_DATA,
Winson Chungd95a2252018-04-04 17:02:29 +000059 Key.TOUCHED_RINGER_TOGGLE,
Mady Mellor5a3e94b2020-02-07 12:16:21 -080060 Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP,
61 Key.HAS_SEEN_BUBBLES_EDUCATION,
Fabian Kozynski75ad41e2020-03-06 09:52:46 -050062 Key.HAS_SEEN_BUBBLES_MANAGE_EDUCATION,
63 Key.CONTROLS_STRUCTURE_SWIPE_TOOLTIP_COUNT
Andrew Flynn82862572015-04-01 14:22:37 -040064 })
65 public @interface Key {
Winson Chung28217a42017-02-15 13:46:52 -080066 @Deprecated
Winson250608a2015-11-24 15:00:31 -080067 String OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME = "OverviewLastStackTaskActiveTime";
Andrew Flynn82862572015-04-01 14:22:37 -040068 String DEBUG_MODE_ENABLED = "debugModeEnabled";
69 String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed";
70 String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed";
71 String DND_TILE_VISIBLE = "DndTileVisible";
72 String DND_TILE_COMBINED_ICON = "DndTileCombinedIcon";
John Spurlockf55b7f22015-04-13 19:21:26 -040073 String DND_CONFIRMED_PRIORITY_INTRODUCTION = "DndConfirmedPriorityIntroduction";
John Spurlockd9c75db2015-04-28 11:19:13 -040074 String DND_CONFIRMED_SILENCE_INTRODUCTION = "DndConfirmedSilenceIntroduction";
Julia Reynoldsd7a00aa2017-02-16 15:01:36 -050075 String DND_CONFIRMED_ALARM_INTRODUCTION = "DndConfirmedAlarmIntroduction";
John Spurlockf55b7f22015-04-13 19:21:26 -040076 String DND_FAVORITE_BUCKET_INDEX = "DndCountdownMinuteIndex";
77 String DND_NONE_SELECTED = "DndNoneSelected";
John Spurlockd9c75db2015-04-28 11:19:13 -040078 String DND_FAVORITE_ZEN = "DndFavoriteZen";
Felipe Leme0281a992016-04-27 10:22:32 -070079 String QS_DATA_SAVER_DIALOG_SHOWN = "QsDataSaverDialogShown";
Jason Monkcb5296a2017-06-30 10:28:18 -040080 @Deprecated
81 String QS_HOTSPOT_ADDED = "QsHotspotAdded";
82 @Deprecated
83 String QS_DATA_SAVER_ADDED = "QsDataSaverAdded";
84 @Deprecated
Jason Monkc3f42c12016-02-05 12:33:13 -050085 String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded";
Jason Monkcb5296a2017-06-30 10:28:18 -040086 @Deprecated
Jason Monkc3f42c12016-02-05 12:33:13 -050087 String QS_WORK_ADDED = "QsWorkAdded";
Jason Monkcb5296a2017-06-30 10:28:18 -040088 @Deprecated
Christine Franks69c2d1d2017-01-23 14:45:29 -080089 String QS_NIGHTDISPLAY_ADDED = "QsNightDisplayAdded";
Rohan Shahdb2cfa32018-02-20 11:27:22 -080090 /**
91 * Used for tracking how many times the user has seen the long press tooltip in the Quick
92 * Settings panel.
93 */
94 String QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT = "QsLongPressTooltipShownCount";
Jason Monk24f8a752017-06-30 11:31:03 -040095 String SEEN_MULTI_USER = "HasSeenMultiUser";
Tracy Zhou27599052018-04-16 15:47:29 -070096 String OVERVIEW_OPENED_COUNT = "OverviewOpenedCount";
97 String OVERVIEW_OPENED_FROM_HOME_COUNT = "OverviewOpenedFromHomeCount";
98 String HAS_SEEN_RECENTS_SWIPE_UP_ONBOARDING = "HasSeenRecentsSwipeUpOnboarding";
99 String HAS_SEEN_RECENTS_QUICK_SCRUB_ONBOARDING = "HasSeenRecentsQuickScrubOnboarding";
Tracy Zhou9198f772018-05-21 15:30:31 -0700100 String DISMISSED_RECENTS_SWIPE_UP_ONBOARDING_COUNT =
101 "DismissedRecentsSwipeUpOnboardingCount";
Tracy Zhou75418cc2018-05-01 16:28:51 -0700102 String HAS_DISMISSED_RECENTS_QUICK_SCRUB_ONBOARDING_ONCE =
103 "HasDismissedRecentsQuickScrubOnboardingOnce";
Julia Reynoldsee571932018-02-21 11:41:33 -0500104 String SEEN_RINGER_GUIDANCE_COUNT = "RingerGuidanceCount";
Amin Shaikha07a17b2018-02-23 16:02:52 -0500105 String QS_TILE_SPECS_REVEALED = "QsTileSpecsRevealed";
Amin Shaikh329c8282018-03-09 14:50:59 -0500106 String QS_HAS_TURNED_OFF_MOBILE_DATA = "QsHasTurnedOffMobileData";
Julia Reynoldsac55e012018-03-27 11:17:30 -0400107 String TOUCHED_RINGER_TOGGLE = "TouchedRingerToggle";
Anthony Tripaldiea0236d2019-03-18 11:47:52 -0400108 String HAS_SEEN_ODI_CAPTIONS_TOOLTIP = "HasSeenODICaptionsTooltip";
Mady Mellor5a3e94b2020-02-07 12:16:21 -0800109 String HAS_SEEN_BUBBLES_EDUCATION = "HasSeenBubblesOnboarding";
110 String HAS_SEEN_BUBBLES_MANAGE_EDUCATION = "HasSeenBubblesManageOnboarding";
Fabian Kozynski75ad41e2020-03-06 09:52:46 -0500111 String CONTROLS_STRUCTURE_SWIPE_TOOLTIP_COUNT = "ControlsStructureSwipeTooltipCount";
Andrew Flynn82862572015-04-01 14:22:37 -0400112 }
113
114 public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) {
115 return get(context).getBoolean(key, defaultValue);
116 }
117
118 public static void putBoolean(Context context, @Key String key, boolean value) {
119 get(context).edit().putBoolean(key, value).apply();
120 }
121
122 public static int getInt(Context context, @Key String key, int defaultValue) {
123 return get(context).getInt(key, defaultValue);
124 }
125
126 public static void putInt(Context context, @Key String key, int value) {
127 get(context).edit().putInt(key, value).apply();
128 }
129
130 public static long getLong(Context context, @Key String key, long defaultValue) {
131 return get(context).getLong(key, defaultValue);
132 }
133
134 public static void putLong(Context context, @Key String key, long value) {
135 get(context).edit().putLong(key, value).apply();
136 }
137
Winson Chungaf3bb692015-06-03 17:31:39 -0700138 public static String getString(Context context, @Key String key, String defaultValue) {
139 return get(context).getString(key, defaultValue);
140 }
141
142 public static void putString(Context context, @Key String key, String value) {
143 get(context).edit().putString(key, value).apply();
144 }
145
Amin Shaikha07a17b2018-02-23 16:02:52 -0500146 public static void putStringSet(Context context, @Key String key, Set<String> value) {
147 get(context).edit().putStringSet(key, value).apply();
148 }
149
150 public static Set<String> getStringSet(
151 Context context, @Key String key, Set<String> defaultValue) {
152 return get(context).getStringSet(key, defaultValue);
153 }
154
Andrew Flynn82862572015-04-01 14:22:37 -0400155 public static Map<String, ?> getAll(Context context) {
156 return get(context).getAll();
157 }
158
159 public static void remove(Context context, @Key String key) {
160 get(context).edit().remove(key).apply();
161 }
162
163 public static void registerListener(Context context,
164 OnSharedPreferenceChangeListener listener) {
165 get(context).registerOnSharedPreferenceChangeListener(listener);
166 }
167
168 public static void unregisterListener(Context context,
169 OnSharedPreferenceChangeListener listener) {
170 get(context).unregisterOnSharedPreferenceChangeListener(listener);
171 }
172
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500173 public static SharedPreferences get(Context context) {
Andrew Flynn82862572015-04-01 14:22:37 -0400174 return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
175 }
176}