From 146701ca3eefa854df4e95b5af8cc140b5433613 Mon Sep 17 00:00:00 2001 From: Stefan Andonian Date: Thu, 10 Nov 2022 23:07:40 +0000 Subject: [PATCH] Move SharedPreferences code to its own class. Bug: 251502424 Test: Code compiled correctly. Change-Id: Iea0d6ab2999504117546ee0f7adc0c7b8b45c065 --- .../quickstep/TaskOverlayFactoryGo.java | 6 +++--- .../launcher3/model/PredictionUpdateTask.java | 4 ++-- .../model/QuickstepModelDelegate.java | 2 +- .../taskbar/StashedHandleViewController.java | 4 ++-- .../taskbar/TaskbarStashController.java | 3 ++- .../overlay/TaskbarOverlayContext.java | 4 ++-- .../plugins/PluginEnablerImpl.java | 8 ++++---- .../quickstep/TouchInteractionService.java | 3 ++- .../interaction/GestureSandboxActivity.java | 4 ++-- .../logging/SettingsChangeLogger.java | 4 ++-- .../quickstep/util/RecentsOrientedState.java | 4 ++-- .../launcher3/InvariantDeviceProfile.java | 7 ++++--- src/com/android/launcher3/Launcher.java | 4 ++-- .../android/launcher3/LauncherAppState.java | 4 ++-- src/com/android/launcher3/LauncherPrefs.kt | 20 +++++++++++++++++++ .../android/launcher3/LauncherProvider.java | 8 ++++---- .../launcher3/SessionCommitReceiver.java | 2 +- src/com/android/launcher3/Utilities.java | 13 ------------ .../allapps/BaseAllAppsContainerView.java | 3 ++- .../launcher3/allapps/WorkEduCard.java | 4 ++-- .../graphics/GridCustomizationsProvider.java | 2 +- .../launcher3/model/DeviceGridState.java | 6 +++--- .../launcher3/pm/InstallSessionHelper.java | 2 +- .../launcher3/provider/RestoreDbTask.java | 13 ++++++------ .../launcher3/qsb/QsbContainerView.java | 6 +++--- .../SecondaryDisplayLauncher.java | 4 ++-- .../settings/DeveloperOptionsFragment.java | 5 +++-- .../launcher3/settings/SettingsActivity.java | 4 +++- .../launcher3/states/RotationHelper.java | 4 ++-- src/com/android/launcher3/util/Themes.java | 3 ++- 30 files changed, 88 insertions(+), 72 deletions(-) create mode 100644 src/com/android/launcher3/LauncherPrefs.kt diff --git a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java index c997e52dbd..253147d96b 100644 --- a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java +++ b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java @@ -50,8 +50,8 @@ import androidx.annotation.IntDef; import androidx.annotation.VisibleForTesting; import com.android.launcher3.BaseActivity; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; -import com.android.launcher3.Utilities; import com.android.launcher3.views.ArrowTipView; import com.android.quickstep.util.AssistContentRequester; import com.android.quickstep.util.RecentsOrientedState; @@ -124,7 +124,7 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { AssistContentRequester assistContentRequester) { super(taskThumbnailView); mFactoryContentRequester = assistContentRequester; - mSharedPreferences = Utilities.getPrefs(mApplicationContext); + mSharedPreferences = LauncherPrefs.getPrefs(mApplicationContext); } /** @@ -151,7 +151,7 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { boolean isAllowedByPolicy = mThumbnailView.isRealSnapshot() && !isManagedProfileTask; getActionsView().setCallbacks(new OverlayUICallbacksGoImpl(isAllowedByPolicy, task)); mTaskPackageName = task.key.getPackageName(); - mSharedPreferences = Utilities.getPrefs(mApplicationContext); + mSharedPreferences = LauncherPrefs.getPrefs(mApplicationContext); checkSettings(); if (!mAssistStructurePermitted || !mAssistScreenshotPermitted diff --git a/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java b/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java index bc3253fcfb..e6edeb4dbb 100644 --- a/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java +++ b/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java @@ -30,7 +30,7 @@ import android.os.UserHandle; import androidx.annotation.NonNull; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.Utilities; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.model.BgDataModel.FixedContainerItems; import com.android.launcher3.model.QuickstepModelDelegate.PredictorState; import com.android.launcher3.model.data.AppInfo; @@ -59,7 +59,7 @@ public class PredictionUpdateTask extends BaseModelUpdateTask { Context context = app.getContext(); // TODO: remove this - Utilities.getDevicePrefs(context).edit() + LauncherPrefs.getDevicePrefs(context).edit() .putBoolean(LAST_PREDICTION_ENABLED_STATE, !mTargets.isEmpty()).apply(); Set usersForChangedShortcuts = diff --git a/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java b/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java index de0b14d4fa..3615c52a7a 100644 --- a/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java +++ b/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java @@ -18,12 +18,12 @@ package com.android.launcher3.model; import static android.text.format.DateUtils.DAY_IN_MILLIS; import static android.text.format.DateUtils.formatElapsedTime; +import static com.android.launcher3.LauncherPrefs.getDevicePrefs; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PREDICTION; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; -import static com.android.launcher3.Utilities.getDevicePrefs; import static com.android.launcher3.hybridhotseat.HotseatPredictionModel.convertDataModelToAppTargetBundle; import static com.android.launcher3.model.PredictionHelper.getAppTargetFromItemInfo; import static com.android.launcher3.model.PredictionHelper.wrapAppTargetWithItemLocation; diff --git a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java index 45d573994d..af46df4225 100644 --- a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java @@ -26,8 +26,8 @@ import android.view.View; import android.view.ViewOutlineProvider; import com.android.launcher3.DeviceProfile; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; -import com.android.launcher3.Utilities; import com.android.launcher3.anim.RevealOutlineAnimation; import com.android.launcher3.anim.RoundedRectRevealOutlineProvider; import com.android.launcher3.util.DisplayController; @@ -81,7 +81,7 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT public StashedHandleViewController(TaskbarActivityContext activity, StashedHandleView stashedHandleView) { mActivity = activity; - mPrefs = Utilities.getPrefs(mActivity); + mPrefs = LauncherPrefs.getPrefs(mActivity); mStashedHandleView = stashedHandleView; mTaskbarStashedHandleAlpha = new MultiValueAlpha(mStashedHandleView, NUM_ALPHA_CHANNELS); mTaskbarStashedHandleAlpha.setUpdateVisibility(true); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index 06348e2119..6274ec0f0f 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java @@ -42,6 +42,7 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.jank.InteractionJankMonitor; import com.android.launcher3.Alarm; import com.android.launcher3.DeviceProfile; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.anim.AnimatorListeners; @@ -187,7 +188,7 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba public TaskbarStashController(TaskbarActivityContext activity) { mActivity = activity; - mPrefs = Utilities.getPrefs(mActivity); + mPrefs = LauncherPrefs.getPrefs(mActivity); mSystemUiProxy = SystemUiProxy.INSTANCE.get(activity); if (isPhoneMode()) { // DeviceProfile's taskbar vars aren't initialized w/ the flag off diff --git a/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayContext.java b/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayContext.java index 7e3163ddc5..ebaf60a10f 100644 --- a/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayContext.java @@ -19,8 +19,8 @@ import android.content.Context; import android.view.View; import com.android.launcher3.DeviceProfile; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; -import com.android.launcher3.Utilities; import com.android.launcher3.allapps.ActivityAllAppsContainerView; import com.android.launcher3.allapps.search.DefaultSearchAdapterProvider; import com.android.launcher3.allapps.search.SearchAdapterProvider; @@ -62,7 +62,7 @@ public class TaskbarOverlayContext extends BaseTaskbarContext { mOverlayController = controllers.taskbarOverlayController; mDragController = new TaskbarDragController(this); mDragController.init(controllers); - mOnboardingPrefs = new OnboardingPrefs<>(this, Utilities.getPrefs(this)); + mOnboardingPrefs = new OnboardingPrefs<>(this, LauncherPrefs.getPrefs(this)); mDragLayer = new TaskbarOverlayDragLayer(this); TaskbarStashController taskbarStashController = controllers.taskbarStashController; diff --git a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java index 5afeca7e3b..faa900b714 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java +++ b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java @@ -18,11 +18,11 @@ import android.content.ComponentName; import android.content.Context; import android.content.SharedPreferences; -import com.android.launcher3.Utilities; -import com.android.systemui.shared.plugins.PluginEnabler; - import androidx.preference.PreferenceDataStore; +import com.android.launcher3.LauncherPrefs; +import com.android.systemui.shared.plugins.PluginEnabler; + public class PluginEnablerImpl extends PreferenceDataStore implements PluginEnabler { private static final String PREFIX_PLUGIN_ENABLED = "PLUGIN_ENABLED_"; @@ -30,7 +30,7 @@ public class PluginEnablerImpl extends PreferenceDataStore implements PluginEnab final private SharedPreferences mSharedPrefs; public PluginEnablerImpl(Context context) { - mSharedPrefs = Utilities.getDevicePrefs(context); + mSharedPrefs = LauncherPrefs.getDevicePrefs(context); } @Override diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 450774bee7..f51c9fb119 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -69,6 +69,7 @@ import androidx.annotation.UiThread; import com.android.app.viewcapture.ViewCapture; import com.android.launcher3.BaseDraggingActivity; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; @@ -479,7 +480,7 @@ public class TouchInteractionService extends Service } // Reset home bounce seen on quick step enabled for first time - SharedPreferences sharedPrefs = Utilities.getPrefs(this); + SharedPreferences sharedPrefs = LauncherPrefs.getPrefs(this); if (!sharedPrefs.getBoolean(HAS_ENABLED_QUICKSTEP_ONCE, true)) { sharedPrefs.edit() .putBoolean(HAS_ENABLED_QUICKSTEP_ONCE, true) diff --git a/quickstep/src/com/android/quickstep/interaction/GestureSandboxActivity.java b/quickstep/src/com/android/quickstep/interaction/GestureSandboxActivity.java index bf7023c217..4a701202db 100644 --- a/quickstep/src/com/android/quickstep/interaction/GestureSandboxActivity.java +++ b/quickstep/src/com/android/quickstep/interaction/GestureSandboxActivity.java @@ -28,8 +28,8 @@ import android.view.Window; import androidx.annotation.NonNull; import androidx.fragment.app.FragmentActivity; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; -import com.android.launcher3.Utilities; import com.android.launcher3.logging.StatsLogManager; import com.android.quickstep.TouchInteractionService.TISBinder; import com.android.quickstep.interaction.TutorialController.TutorialType; @@ -63,7 +63,7 @@ public class GestureSandboxActivity extends FragmentActivity { requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.gesture_tutorial_activity); - mSharedPrefs = Utilities.getPrefs(this); + mSharedPrefs = LauncherPrefs.getPrefs(this); mStatsLogManager = StatsLogManager.newInstance(getApplicationContext()); Bundle args = savedInstanceState == null ? getIntent().getExtras() : savedInstanceState; diff --git a/quickstep/src/com/android/quickstep/logging/SettingsChangeLogger.java b/quickstep/src/com/android/quickstep/logging/SettingsChangeLogger.java index 2ccdfa3b36..5efc45e385 100644 --- a/quickstep/src/com/android/quickstep/logging/SettingsChangeLogger.java +++ b/quickstep/src/com/android/quickstep/logging/SettingsChangeLogger.java @@ -16,8 +16,8 @@ package com.android.quickstep.logging; -import static com.android.launcher3.Utilities.getDevicePrefs; -import static com.android.launcher3.Utilities.getPrefs; +import static com.android.launcher3.LauncherPrefs.getDevicePrefs; +import static com.android.launcher3.LauncherPrefs.getPrefs; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_SCREEN_SUGGESTIONS_DISABLED; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NOTIFICATION_DOT_DISABLED; diff --git a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java index c459f303d1..db8c7f23b9 100644 --- a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java +++ b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java @@ -45,7 +45,7 @@ import androidx.annotation.NonNull; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; -import com.android.launcher3.Utilities; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.testing.shared.TestProtocol; import com.android.launcher3.touch.PagedOrientationHandler; import com.android.launcher3.util.DisplayController; @@ -139,7 +139,7 @@ public class RecentsOrientedState implements public RecentsOrientedState(Context context, BaseActivityInterface sizeStrategy, IntConsumer rotationChangeListener) { mContext = context; - mSharedPrefs = Utilities.getPrefs(context); + mSharedPrefs = LauncherPrefs.getPrefs(context); mOrientationListener = new OrientationEventListener(context) { @Override public void onOrientationChanged(int degrees) { diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 9c5ec38866..87f52106e0 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -200,7 +200,8 @@ public class InvariantDeviceProfile { String gridName = getCurrentGridName(context); String newGridName = initGrid(context, gridName); if (!newGridName.equals(gridName)) { - Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply(); + LauncherPrefs.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName) + .apply(); } new DeviceGridState(this).writeToPrefs(context); @@ -308,7 +309,7 @@ public class InvariantDeviceProfile { } public static String getCurrentGridName(Context context) { - return Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null); + return LauncherPrefs.getPrefs(context).getString(KEY_IDP_GRID_NAME, null); } private String initGrid(Context context, String gridName) { @@ -436,7 +437,7 @@ public class InvariantDeviceProfile { public void setCurrentGrid(Context context, String gridName) { Context appContext = context.getApplicationContext(); - Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); + LauncherPrefs.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 578efdf5db..5cce407d0b 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -473,7 +473,7 @@ public class Launcher extends StatefulActivity InvariantDeviceProfile idp = app.getInvariantDeviceProfile(); initDeviceProfile(idp); idp.addOnChangeListener(this); - mSharedPrefs = Utilities.getPrefs(this); + mSharedPrefs = LauncherPrefs.getPrefs(this); mIconCache = app.getIconCache(); mAccessibilityDelegate = createAccessibilityDelegate(); @@ -1563,7 +1563,7 @@ public class Launcher extends StatefulActivity @Override public SharedPreferences getDevicePrefs() { - return Utilities.getDevicePrefs(this); + return LauncherPrefs.getDevicePrefs(this); } public int getOrientation() { diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index ea3f723e29..49659364b9 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -18,7 +18,7 @@ package com.android.launcher3; import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_RESOURCE_UPDATED; -import static com.android.launcher3.Utilities.getDevicePrefs; +import static com.android.launcher3.LauncherPrefs.getDevicePrefs; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI; @@ -117,7 +117,7 @@ public class LauncherAppState implements SafeCloseable { observer, MODEL_EXECUTOR.getHandler()); mOnTerminateCallback.add(iconChangeTracker::close); MODEL_EXECUTOR.execute(observer::verifyIconChanged); - SharedPreferences prefs = Utilities.getPrefs(mContext); + SharedPreferences prefs = LauncherPrefs.getPrefs(mContext); prefs.registerOnSharedPreferenceChangeListener(observer); mOnTerminateCallback.add( () -> prefs.unregisterOnSharedPreferenceChangeListener(observer)); diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt new file mode 100644 index 0000000000..23ff10ad41 --- /dev/null +++ b/src/com/android/launcher3/LauncherPrefs.kt @@ -0,0 +1,20 @@ +package com.android.launcher3 + +import android.content.Context +import android.content.SharedPreferences + +object LauncherPrefs { + + @JvmStatic + fun getPrefs(context: Context): SharedPreferences { + // Use application context for shared preferences, so that we use a single cached instance + return context.applicationContext.getSharedPreferences( + LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) + } + + @JvmStatic + fun getDevicePrefs(context: Context): SharedPreferences { + // Use application context for shared preferences, so that we use a single cached instance + return context.applicationContext.getSharedPreferences( + LauncherFiles.DEVICE_PREFERENCES_KEY, Context.MODE_PRIVATE) + }} \ No newline at end of file diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 457e12673b..d002c2b901 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -374,7 +374,7 @@ public class LauncherProvider extends ContentProvider { case LauncherSettings.Settings.METHOD_WAS_EMPTY_DB_CREATED : { Bundle result = new Bundle(); result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, - Utilities.getPrefs(getContext()).getBoolean( + LauncherPrefs.getPrefs(getContext()).getBoolean( mOpenHelper.getKey(EMPTY_DATABASE_CREATED), false)); return result; } @@ -520,7 +520,7 @@ public class LauncherProvider extends ContentProvider { } private void clearFlagEmptyDbCreated() { - Utilities.getPrefs(getContext()).edit() + LauncherPrefs.getPrefs(getContext()).edit() .remove(mOpenHelper.getKey(EMPTY_DATABASE_CREATED)).commit(); } @@ -532,7 +532,7 @@ public class LauncherProvider extends ContentProvider { * 4) The default configuration for the particular device */ synchronized private void loadDefaultFavoritesIfNecessary() { - SharedPreferences sp = Utilities.getPrefs(getContext()); + SharedPreferences sp = LauncherPrefs.getPrefs(getContext()); if (sp.getBoolean(mOpenHelper.getKey(EMPTY_DATABASE_CREATED), false)) { Log.d(TAG, "loading default workspace"); @@ -738,7 +738,7 @@ public class LauncherProvider extends ContentProvider { */ protected void onEmptyDbCreated() { // Set the flag for empty DB - Utilities.getPrefs(mContext).edit().putBoolean(getKey(EMPTY_DATABASE_CREATED), true) + LauncherPrefs.getPrefs(mContext).edit().putBoolean(getKey(EMPTY_DATABASE_CREATED), true) .commit(); } diff --git a/src/com/android/launcher3/SessionCommitReceiver.java b/src/com/android/launcher3/SessionCommitReceiver.java index bcd4c3f361..50ad2be505 100644 --- a/src/com/android/launcher3/SessionCommitReceiver.java +++ b/src/com/android/launcher3/SessionCommitReceiver.java @@ -98,6 +98,6 @@ public class SessionCommitReceiver extends BroadcastReceiver { } public static boolean isEnabled(Context context) { - return Utilities.getPrefs(context).getBoolean(ADD_ICON_PREFERENCE_KEY, true); + return LauncherPrefs.getPrefs(context).getBoolean(ADD_ICON_PREFERENCE_KEY, true); } } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 743e3aed52..ce009a1375 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -27,7 +27,6 @@ import android.app.ActivityManager; import android.app.Person; import android.app.WallpaperManager; import android.content.Context; -import android.content.SharedPreferences; import android.content.pm.LauncherActivityInfo; import android.content.pm.LauncherApps; import android.content.pm.ShortcutInfo; @@ -509,18 +508,6 @@ public final class Utilities { return spanned; } - public static SharedPreferences getPrefs(Context context) { - // Use application context for shared preferences, so that we use a single cached instance - return context.getApplicationContext().getSharedPreferences( - LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE); - } - - public static SharedPreferences getDevicePrefs(Context context) { - // Use application context for shared preferences, so that we use a single cached instance - return context.getApplicationContext().getSharedPreferences( - LauncherFiles.DEVICE_PREFERENCES_KEY, Context.MODE_PRIVATE); - } - public static boolean isWallpaperSupported(Context context) { return context.getSystemService(WallpaperManager.class).isWallpaperSupported(); } diff --git a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java index da86d98b5e..8e519c1241 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java @@ -54,6 +54,7 @@ import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.Insettable; import com.android.launcher3.InsettableFrameLayout; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.search.SearchAdapterProvider; @@ -148,7 +149,7 @@ public abstract class BaseAllAppsContainerView { } public DeviceGridState(Context context) { - SharedPreferences prefs = Utilities.getPrefs(context); + SharedPreferences prefs = LauncherPrefs.getPrefs(context); mGridSizeString = prefs.getString(KEY_WORKSPACE_SIZE, ""); mNumHotseat = prefs.getInt(KEY_HOTSEAT_COUNT, -1); mDeviceType = prefs.getInt(KEY_DEVICE_TYPE, TYPE_PHONE); @@ -90,7 +90,7 @@ public class DeviceGridState implements Comparable { * Stores the device state to shared preferences */ public void writeToPrefs(Context context) { - Utilities.getPrefs(context).edit() + LauncherPrefs.getPrefs(context).edit() .putString(KEY_WORKSPACE_SIZE, mGridSizeString) .putInt(KEY_HOTSEAT_COUNT, mNumHotseat) .putInt(KEY_DEVICE_TYPE, mDeviceType) diff --git a/src/com/android/launcher3/pm/InstallSessionHelper.java b/src/com/android/launcher3/pm/InstallSessionHelper.java index 16bb868f65..150bca4058 100644 --- a/src/com/android/launcher3/pm/InstallSessionHelper.java +++ b/src/com/android/launcher3/pm/InstallSessionHelper.java @@ -16,7 +16,7 @@ package com.android.launcher3.pm; -import static com.android.launcher3.Utilities.getPrefs; +import static com.android.launcher3.LauncherPrefs.getPrefs; import android.content.Context; import android.content.pm.ApplicationInfo; diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java index 95ac7b0ca9..a45e8354b5 100644 --- a/src/com/android/launcher3/provider/RestoreDbTask.java +++ b/src/com/android/launcher3/provider/RestoreDbTask.java @@ -36,6 +36,7 @@ import androidx.annotation.NonNull; import com.android.launcher3.AppWidgetsRestoredReceiver; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.LauncherProvider.DatabaseHelper; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.Utilities; @@ -86,7 +87,7 @@ public class RestoreDbTask { // Set is pending to false irrespective of the result, so that it doesn't get // executed again. - Utilities.getPrefs(context).edit().remove(RESTORED_DEVICE_TYPE).commit(); + LauncherPrefs.getPrefs(context).edit().remove(RESTORED_DEVICE_TYPE).commit(); idp.reinitializeAfterRestore(context); } @@ -239,7 +240,7 @@ public class RestoreDbTask { } // If restored from a single display backup, remove gaps between screenIds - if (Utilities.getPrefs(context).getInt(RESTORED_DEVICE_TYPE, TYPE_PHONE) + if (LauncherPrefs.getPrefs(context).getInt(RESTORED_DEVICE_TYPE, TYPE_PHONE) != TYPE_MULTI_DISPLAY) { removeScreenIdGaps(db); } @@ -338,7 +339,7 @@ public class RestoreDbTask { } public static boolean isPending(Context context) { - return Utilities.getPrefs(context).contains(RESTORED_DEVICE_TYPE); + return LauncherPrefs.getPrefs(context).contains(RESTORED_DEVICE_TYPE); } /** @@ -346,13 +347,13 @@ public class RestoreDbTask { */ public static void setPending(Context context) { FileLog.d(TAG, "Restore data received through full backup "); - Utilities.getPrefs(context).edit() + LauncherPrefs.getPrefs(context).edit() .putInt(RESTORED_DEVICE_TYPE, new DeviceGridState(context).getDeviceType()) .commit(); } private void restoreAppWidgetIdsIfExists(Context context) { - SharedPreferences prefs = Utilities.getPrefs(context); + SharedPreferences prefs = LauncherPrefs.getPrefs(context); if (prefs.contains(APPWIDGET_OLD_IDS) && prefs.contains(APPWIDGET_IDS)) { LauncherWidgetHolder holder = new LauncherWidgetHolder(context); AppWidgetsRestoredReceiver.restoreAppWidgetIds(context, @@ -370,7 +371,7 @@ public class RestoreDbTask { public static void setRestoredAppWidgetIds(Context context, @NonNull int[] oldIds, @NonNull int[] newIds) { - Utilities.getPrefs(context).edit() + LauncherPrefs.getPrefs(context).edit() .putString(APPWIDGET_OLD_IDS, IntArray.wrap(oldIds).toConcatString()) .putString(APPWIDGET_IDS, IntArray.wrap(newIds).toConcatString()) .commit(); diff --git a/src/com/android/launcher3/qsb/QsbContainerView.java b/src/com/android/launcher3/qsb/QsbContainerView.java index 23ee251772..f2952041f7 100644 --- a/src/com/android/launcher3/qsb/QsbContainerView.java +++ b/src/com/android/launcher3/qsb/QsbContainerView.java @@ -43,8 +43,8 @@ import androidx.annotation.Nullable; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; -import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.FragmentWithPreview; import com.android.launcher3.widget.util.WidgetSizes; @@ -200,7 +200,7 @@ public class QsbContainerView extends FrameLayout { Context context = getContext(); AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); - int widgetId = Utilities.getPrefs(context).getInt(mKeyWidgetId, -1); + int widgetId = LauncherPrefs.getPrefs(context).getInt(mKeyWidgetId, -1); AppWidgetProviderInfo widgetInfo = widgetManager.getAppWidgetInfo(widgetId); boolean isWidgetBound = (widgetInfo != null) && widgetInfo.provider.equals(mWidgetInfo.provider); @@ -244,7 +244,7 @@ public class QsbContainerView extends FrameLayout { } private void saveWidgetId(int widgetId) { - Utilities.getPrefs(getContext()).edit().putInt(mKeyWidgetId, widgetId).apply(); + LauncherPrefs.getPrefs(getContext()).edit().putInt(mKeyWidgetId, widgetId).apply(); } @Override diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java index 7b32d8b749..dbab700a87 100644 --- a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java +++ b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java @@ -35,9 +35,9 @@ import com.android.launcher3.DropTarget; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherModel; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.LauncherSettings; import com.android.launcher3.R; -import com.android.launcher3.Utilities; import com.android.launcher3.allapps.ActivityAllAppsContainerView; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragOptions; @@ -87,7 +87,7 @@ public class SecondaryDisplayLauncher extends BaseDraggingActivity super.onCreate(savedInstanceState); mModel = LauncherAppState.getInstance(this).getModel(); mDragController = new SecondaryDragController(this); - mOnboardingPrefs = new OnboardingPrefs<>(this, Utilities.getPrefs(this)); + mOnboardingPrefs = new OnboardingPrefs<>(this, LauncherPrefs.getPrefs(this)); mSecondaryDisplayPredictions = SecondaryDisplayPredictions.newInstance(this); if (getWindow().getDecorView().isAttachedToWindow()) { initUi(); diff --git a/src/com/android/launcher3/settings/DeveloperOptionsFragment.java b/src/com/android/launcher3/settings/DeveloperOptionsFragment.java index 6057586fca..c81214e67b 100644 --- a/src/com/android/launcher3/settings/DeveloperOptionsFragment.java +++ b/src/com/android/launcher3/settings/DeveloperOptionsFragment.java @@ -59,8 +59,8 @@ import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreference; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; -import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.config.FlagTogglerPrefUi; import com.android.launcher3.secondarydisplay.SecondaryDisplayLauncher; @@ -392,7 +392,8 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat { onboardingPref.setTitle(title); onboardingPref.setSummary("Tap to reset"); onboardingPref.setOnPreferenceClickListener(preference -> { - SharedPreferences.Editor sharedPrefsEdit = Utilities.getPrefs(getContext()).edit(); + SharedPreferences.Editor sharedPrefsEdit = LauncherPrefs.getPrefs(getContext()) + .edit(); for (String key : keys) { sharedPrefsEdit.remove(key); } diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 70956a35ac..4cb4348a5e 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -46,6 +46,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherFiles; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; @@ -113,7 +114,8 @@ public class SettingsActivity extends FragmentActivity // Display the fragment as the main content. fm.beginTransaction().replace(R.id.content_frame, f).commit(); } - Utilities.getPrefs(getApplicationContext()).registerOnSharedPreferenceChangeListener(this); + LauncherPrefs.getPrefs(getApplicationContext()) + .registerOnSharedPreferenceChangeListener(this); } /** diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java index b94ea0707b..642bdcdbb8 100644 --- a/src/com/android/launcher3/states/RotationHelper.java +++ b/src/com/android/launcher3/states/RotationHelper.java @@ -36,7 +36,7 @@ import androidx.annotation.WorkerThread; import com.android.launcher3.BaseActivity; import com.android.launcher3.DeviceProfile; -import com.android.launcher3.Utilities; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.util.DisplayController; /** @@ -104,7 +104,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, mIgnoreAutoRotateSettings = ignoreAutoRotateSettings; if (!mIgnoreAutoRotateSettings) { if (mSharedPrefs == null) { - mSharedPrefs = Utilities.getPrefs(mActivity); + mSharedPrefs = LauncherPrefs.getPrefs(mActivity); mSharedPrefs.registerOnSharedPreferenceChangeListener(this); } mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, diff --git a/src/com/android/launcher3/util/Themes.java b/src/com/android/launcher3/util/Themes.java index 1728f4d0d2..585bea93ad 100644 --- a/src/com/android/launcher3/util/Themes.java +++ b/src/com/android/launcher3/util/Themes.java @@ -30,6 +30,7 @@ import android.util.AttributeSet; import android.util.SparseArray; import android.util.TypedValue; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.icons.GraphicsUtils; @@ -73,7 +74,7 @@ public class Themes { * Returns true if workspace icon theming is enabled */ public static boolean isThemedIconEnabled(Context context) { - return Utilities.getPrefs(context).getBoolean(KEY_THEMED_ICONS, false); + return LauncherPrefs.getPrefs(context).getBoolean(KEY_THEMED_ICONS, false); } public static String getDefaultBodyFont(Context context) {