Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 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 | |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 24 | import com.android.systemui.settings.CurrentUserContextTracker; |
| 25 | |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 26 | import java.lang.annotation.Retention; |
| 27 | import java.lang.annotation.RetentionPolicy; |
| 28 | import java.util.Map; |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 29 | import java.util.Set; |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 30 | |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 31 | /** |
| 32 | * A helper class to store simple preferences for SystemUI. Its main use case is things such as |
| 33 | * feature education, e.g. "has the user seen this tooltip". |
| 34 | * |
| 35 | * As of this writing, feature education settings are *intentionally exempted* from backup and |
| 36 | * restore because there is not a great way to know which subset of features the user _should_ see |
| 37 | * again if, for instance, they are coming from multiple OSes back or switching OEMs. |
| 38 | * |
| 39 | * NOTE: Clients of this class should take care to pass in the correct user context when querying |
| 40 | * settings, otherwise you will always read/write for user 0 which is almost never what you want. |
| 41 | * See {@link CurrentUserContextTracker} for a simple way to get the current context |
| 42 | */ |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 43 | public final class Prefs { |
| 44 | private Prefs() {} // no instantation |
| 45 | |
| 46 | @Retention(RetentionPolicy.SOURCE) |
| 47 | @StringDef({ |
Julia Reynolds | ee57193 | 2018-02-21 11:41:33 -0500 | [diff] [blame] | 48 | Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, |
| 49 | Key.DEBUG_MODE_ENABLED, |
| 50 | Key.HOTSPOT_TILE_LAST_USED, |
| 51 | Key.COLOR_INVERSION_TILE_LAST_USED, |
| 52 | Key.DND_TILE_VISIBLE, |
| 53 | Key.DND_TILE_COMBINED_ICON, |
| 54 | Key.DND_CONFIRMED_PRIORITY_INTRODUCTION, |
| 55 | Key.DND_CONFIRMED_SILENCE_INTRODUCTION, |
| 56 | Key.DND_FAVORITE_BUCKET_INDEX, |
| 57 | Key.DND_NONE_SELECTED, |
| 58 | Key.DND_FAVORITE_ZEN, |
| 59 | Key.QS_HOTSPOT_ADDED, |
| 60 | Key.QS_DATA_SAVER_ADDED, |
| 61 | Key.QS_DATA_SAVER_DIALOG_SHOWN, |
| 62 | Key.QS_INVERT_COLORS_ADDED, |
| 63 | Key.QS_WORK_ADDED, |
| 64 | Key.QS_NIGHTDISPLAY_ADDED, |
| 65 | Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, |
| 66 | Key.SEEN_MULTI_USER, |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 67 | Key.HAS_SEEN_RECENTS_SWIPE_UP_ONBOARDING, |
| 68 | Key.HAS_SEEN_RECENTS_QUICK_SCRUB_ONBOARDING, |
| 69 | Key.OVERVIEW_OPENED_COUNT, |
| 70 | Key.OVERVIEW_OPENED_FROM_HOME_COUNT, |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 71 | Key.SEEN_RINGER_GUIDANCE_COUNT, |
Julia Reynolds | ac55e01 | 2018-03-27 11:17:30 -0400 | [diff] [blame] | 72 | Key.QS_HAS_TURNED_OFF_MOBILE_DATA, |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 73 | Key.TOUCHED_RINGER_TOGGLE, |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 74 | Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, |
| 75 | Key.HAS_SEEN_BUBBLES_EDUCATION, |
Fabian Kozynski | 75ad41e | 2020-03-06 09:52:46 -0500 | [diff] [blame] | 76 | Key.HAS_SEEN_BUBBLES_MANAGE_EDUCATION, |
| 77 | Key.CONTROLS_STRUCTURE_SWIPE_TOOLTIP_COUNT |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 78 | }) |
| 79 | public @interface Key { |
Winson Chung | 28217a4 | 2017-02-15 13:46:52 -0800 | [diff] [blame] | 80 | @Deprecated |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 81 | String OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME = "OverviewLastStackTaskActiveTime"; |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 82 | String DEBUG_MODE_ENABLED = "debugModeEnabled"; |
| 83 | String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed"; |
| 84 | String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed"; |
| 85 | String DND_TILE_VISIBLE = "DndTileVisible"; |
| 86 | String DND_TILE_COMBINED_ICON = "DndTileCombinedIcon"; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 87 | String DND_CONFIRMED_PRIORITY_INTRODUCTION = "DndConfirmedPriorityIntroduction"; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 88 | String DND_CONFIRMED_SILENCE_INTRODUCTION = "DndConfirmedSilenceIntroduction"; |
Julia Reynolds | d7a00aa | 2017-02-16 15:01:36 -0500 | [diff] [blame] | 89 | String DND_CONFIRMED_ALARM_INTRODUCTION = "DndConfirmedAlarmIntroduction"; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 90 | String DND_FAVORITE_BUCKET_INDEX = "DndCountdownMinuteIndex"; |
| 91 | String DND_NONE_SELECTED = "DndNoneSelected"; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 92 | String DND_FAVORITE_ZEN = "DndFavoriteZen"; |
Felipe Leme | 0281a99 | 2016-04-27 10:22:32 -0700 | [diff] [blame] | 93 | String QS_DATA_SAVER_DIALOG_SHOWN = "QsDataSaverDialogShown"; |
Jason Monk | cb5296a | 2017-06-30 10:28:18 -0400 | [diff] [blame] | 94 | @Deprecated |
| 95 | String QS_HOTSPOT_ADDED = "QsHotspotAdded"; |
| 96 | @Deprecated |
| 97 | String QS_DATA_SAVER_ADDED = "QsDataSaverAdded"; |
| 98 | @Deprecated |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 99 | String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded"; |
Jason Monk | cb5296a | 2017-06-30 10:28:18 -0400 | [diff] [blame] | 100 | @Deprecated |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 101 | String QS_WORK_ADDED = "QsWorkAdded"; |
Jason Monk | cb5296a | 2017-06-30 10:28:18 -0400 | [diff] [blame] | 102 | @Deprecated |
Christine Franks | 69c2d1d | 2017-01-23 14:45:29 -0800 | [diff] [blame] | 103 | String QS_NIGHTDISPLAY_ADDED = "QsNightDisplayAdded"; |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 104 | /** |
| 105 | * Used for tracking how many times the user has seen the long press tooltip in the Quick |
| 106 | * Settings panel. |
| 107 | */ |
| 108 | String QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT = "QsLongPressTooltipShownCount"; |
Jason Monk | 24f8a75 | 2017-06-30 11:31:03 -0400 | [diff] [blame] | 109 | String SEEN_MULTI_USER = "HasSeenMultiUser"; |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 110 | String OVERVIEW_OPENED_COUNT = "OverviewOpenedCount"; |
| 111 | String OVERVIEW_OPENED_FROM_HOME_COUNT = "OverviewOpenedFromHomeCount"; |
| 112 | String HAS_SEEN_RECENTS_SWIPE_UP_ONBOARDING = "HasSeenRecentsSwipeUpOnboarding"; |
| 113 | String HAS_SEEN_RECENTS_QUICK_SCRUB_ONBOARDING = "HasSeenRecentsQuickScrubOnboarding"; |
Tracy Zhou | 9198f77 | 2018-05-21 15:30:31 -0700 | [diff] [blame] | 114 | String DISMISSED_RECENTS_SWIPE_UP_ONBOARDING_COUNT = |
| 115 | "DismissedRecentsSwipeUpOnboardingCount"; |
Tracy Zhou | 75418cc | 2018-05-01 16:28:51 -0700 | [diff] [blame] | 116 | String HAS_DISMISSED_RECENTS_QUICK_SCRUB_ONBOARDING_ONCE = |
| 117 | "HasDismissedRecentsQuickScrubOnboardingOnce"; |
Julia Reynolds | ee57193 | 2018-02-21 11:41:33 -0500 | [diff] [blame] | 118 | String SEEN_RINGER_GUIDANCE_COUNT = "RingerGuidanceCount"; |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 119 | String QS_TILE_SPECS_REVEALED = "QsTileSpecsRevealed"; |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 120 | String QS_HAS_TURNED_OFF_MOBILE_DATA = "QsHasTurnedOffMobileData"; |
Julia Reynolds | ac55e01 | 2018-03-27 11:17:30 -0400 | [diff] [blame] | 121 | String TOUCHED_RINGER_TOGGLE = "TouchedRingerToggle"; |
Anthony Tripaldi | ea0236d | 2019-03-18 11:47:52 -0400 | [diff] [blame] | 122 | String HAS_SEEN_ODI_CAPTIONS_TOOLTIP = "HasSeenODICaptionsTooltip"; |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 123 | String HAS_SEEN_BUBBLES_EDUCATION = "HasSeenBubblesOnboarding"; |
| 124 | String HAS_SEEN_BUBBLES_MANAGE_EDUCATION = "HasSeenBubblesManageOnboarding"; |
Fabian Kozynski | 75ad41e | 2020-03-06 09:52:46 -0500 | [diff] [blame] | 125 | String CONTROLS_STRUCTURE_SWIPE_TOOLTIP_COUNT = "ControlsStructureSwipeTooltipCount"; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 126 | /** Tracks whether the user has seen the onboarding screen for priority conversations */ |
Julia Reynolds | c535650 | 2020-06-08 16:14:58 -0400 | [diff] [blame] | 127 | String HAS_SEEN_PRIORITY_ONBOARDING = "HasUserSeenPriorityOnboarding"; |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) { |
| 131 | return get(context).getBoolean(key, defaultValue); |
| 132 | } |
| 133 | |
| 134 | public static void putBoolean(Context context, @Key String key, boolean value) { |
| 135 | get(context).edit().putBoolean(key, value).apply(); |
| 136 | } |
| 137 | |
| 138 | public static int getInt(Context context, @Key String key, int defaultValue) { |
| 139 | return get(context).getInt(key, defaultValue); |
| 140 | } |
| 141 | |
| 142 | public static void putInt(Context context, @Key String key, int value) { |
| 143 | get(context).edit().putInt(key, value).apply(); |
| 144 | } |
| 145 | |
| 146 | public static long getLong(Context context, @Key String key, long defaultValue) { |
| 147 | return get(context).getLong(key, defaultValue); |
| 148 | } |
| 149 | |
| 150 | public static void putLong(Context context, @Key String key, long value) { |
| 151 | get(context).edit().putLong(key, value).apply(); |
| 152 | } |
| 153 | |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 154 | public static String getString(Context context, @Key String key, String defaultValue) { |
| 155 | return get(context).getString(key, defaultValue); |
| 156 | } |
| 157 | |
| 158 | public static void putString(Context context, @Key String key, String value) { |
| 159 | get(context).edit().putString(key, value).apply(); |
| 160 | } |
| 161 | |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 162 | public static void putStringSet(Context context, @Key String key, Set<String> value) { |
| 163 | get(context).edit().putStringSet(key, value).apply(); |
| 164 | } |
| 165 | |
| 166 | public static Set<String> getStringSet( |
| 167 | Context context, @Key String key, Set<String> defaultValue) { |
| 168 | return get(context).getStringSet(key, defaultValue); |
| 169 | } |
| 170 | |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 171 | public static Map<String, ?> getAll(Context context) { |
| 172 | return get(context).getAll(); |
| 173 | } |
| 174 | |
| 175 | public static void remove(Context context, @Key String key) { |
| 176 | get(context).edit().remove(key).apply(); |
| 177 | } |
| 178 | |
| 179 | public static void registerListener(Context context, |
| 180 | OnSharedPreferenceChangeListener listener) { |
| 181 | get(context).registerOnSharedPreferenceChangeListener(listener); |
| 182 | } |
| 183 | |
| 184 | public static void unregisterListener(Context context, |
| 185 | OnSharedPreferenceChangeListener listener) { |
| 186 | get(context).unregisterOnSharedPreferenceChangeListener(listener); |
| 187 | } |
| 188 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 189 | public static SharedPreferences get(Context context) { |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 190 | return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE); |
| 191 | } |
| 192 | } |