diff options
| author | 2020-06-10 15:36:54 -0400 | |
|---|---|---|
| committer | 2020-06-11 14:51:56 -0400 | |
| commit | 9da55a7a38b5bf4b5731fa8ef6fb61e1398e5322 (patch) | |
| tree | a7453c411e378b71fa60be825d2bec9741c157de | |
| parent | a4614b0f1fa2b1aed944a659355a5a91c2a91c5d (diff) | |
Controls UI - Correctly persist seeding state
It is incorrect to attempt to modify a Set that is returned from
SharedPreferences.getStringSet(). Won't work. Create a new Set.
Also handle the case on device restore, where we need to set the
seeded flag when controls exist.
Also fix the uninstall logic to look at the actual service list and
not the favorites list
Fixes: 158678748
Test: seed, remove all controls, and restart phone
Change-Id: I3dbc1c7cbac999b06b572b8348cf41617a73adde
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt | 4 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java | 46 |
2 files changed, 25 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt index ebdcdccead90..40c8c6bfa9f7 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt @@ -200,9 +200,9 @@ class ControlsControllerImpl @Inject constructor ( GlobalActionsDialog.PREFS_CONTROLS_FILE, Context.MODE_PRIVATE) val completedSeedingPackageSet = prefs.getStringSet( GlobalActionsDialog.PREFS_CONTROLS_SEEDING_COMPLETED, mutableSetOf<String>()) - val favoritePackageSet = favoriteComponentSet.map { it.packageName } + val servicePackageSet = serviceInfoSet.map { it.packageName } prefs.edit().putStringSet(GlobalActionsDialog.PREFS_CONTROLS_SEEDING_COMPLETED, - completedSeedingPackageSet.intersect(favoritePackageSet)).apply() + completedSeedingPackageSet.intersect(servicePackageSet)).apply() var changed = false favoriteComponentSet.subtract(serviceInfoSet).forEach { diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java index bc95a2514c0b..915092134cc5 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java @@ -247,7 +247,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, private final Executor mBackgroundExecutor; private List<ControlsServiceInfo> mControlsServiceInfos = new ArrayList<>(); private Optional<ControlsController> mControlsControllerOptional; - private SharedPreferences mControlsPreferences; private final RingerModeTracker mRingerModeTracker; private int mDialogPressDelay = DIALOG_PRESS_DELAY; // ms private Handler mMainHandler; @@ -405,12 +404,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, }); } - // Need to be user-specific with the context to make sure we read the correct prefs - Context userContext = context.createContextAsUser( - new UserHandle(mUserManager.getUserHandle()), 0); - mControlsPreferences = userContext.getSharedPreferences(PREFS_CONTROLS_FILE, - Context.MODE_PRIVATE); - // Listen for changes to show controls on the power menu while locked onPowerMenuLockScreenSettingsChanged(); mContext.getContentResolver().registerContentObserver( @@ -444,19 +437,22 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, Collections.emptySet()); List<ComponentName> componentsToSeed = new ArrayList<>(); - for (ControlsServiceInfo info : mControlsServiceInfos) { - String pkg = info.componentName.getPackageName(); - if (seededPackages.contains(pkg) - || mControlsControllerOptional.get().countFavoritesForComponent( - info.componentName) > 0) { - continue; - } - - for (int i = 0; i < Math.min(SEEDING_MAX, preferredControlsPackages.length); i++) { - if (pkg.equals(preferredControlsPackages[i])) { - componentsToSeed.add(info.componentName); + for (int i = 0; i < Math.min(SEEDING_MAX, preferredControlsPackages.length); i++) { + String pkg = preferredControlsPackages[i]; + for (ControlsServiceInfo info : mControlsServiceInfos) { + if (!pkg.equals(info.componentName.getPackageName())) continue; + if (seededPackages.contains(pkg)) { + break; + } else if (mControlsControllerOptional.get() + .countFavoritesForComponent(info.componentName) > 0) { + // When there are existing controls but no saved preference, assume it + // is out of sync, perhaps through a device restore, and update the + // preference + addPackageToSeededSet(prefs, pkg); break; } + componentsToSeed.add(info.componentName); + break; } } @@ -466,16 +462,20 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, componentsToSeed, (response) -> { Log.d(TAG, "Controls seeded: " + response); - Set<String> completedPkgs = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, - new HashSet<String>()); if (response.getAccepted()) { - completedPkgs.add(response.getPackageName()); - prefs.edit().putStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, - completedPkgs).apply(); + addPackageToSeededSet(prefs, response.getPackageName()); } }); } + private void addPackageToSeededSet(SharedPreferences prefs, String pkg) { + Set<String> seededPackages = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, + Collections.emptySet()); + Set<String> updatedPkgs = new HashSet<>(seededPackages); + updatedPkgs.add(pkg); + prefs.edit().putStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, updatedPkgs).apply(); + } + /** * Show the global actions dialog (creating if necessary) * |