Clear preferences when package is removed.
BUG: 30900628
Change-Id: I989b8b49e32ae9b729963ac1921cd1e921555ebe
(cherry picked from commit 2154caf2f80fa87df84813b8e344f85094a454fd)
diff --git a/src/com/android/documentsui/LocalPreferences.java b/src/com/android/documentsui/LocalPreferences.java
index d2e9885..32d0082 100644
--- a/src/com/android/documentsui/LocalPreferences.java
+++ b/src/com/android/documentsui/LocalPreferences.java
@@ -84,6 +84,10 @@
@Retention(RetentionPolicy.SOURCE)
public @interface PermissionStatus {}
+ static void clearPackagePreferences(Context context, String packageName) {
+ clearScopedAccessPreferences(context, packageName);
+ }
+
/**
* Methods below are used to keep track of denied user requests on scoped directory access so
* the dialog is not offered when user checked the 'Do not ask again' box
@@ -108,6 +112,16 @@
getPrefs(context).edit().putInt(key, status).apply();
}
+ private static void clearScopedAccessPreferences(Context context, String packageName) {
+ final String keySubstring = "|" + packageName + "|";
+ final SharedPreferences prefs = getPrefs(context);
+ for (final String key : prefs.getAll().keySet()) {
+ if (key.contains(keySubstring)) {
+ prefs.edit().remove(key).apply();
+ }
+ }
+ }
+
private static String getScopedAccessDenialsKey(String packageName, String uuid,
String directory) {
final int userId = UserHandle.myUserId();
diff --git a/src/com/android/documentsui/PackageReceiver.java b/src/com/android/documentsui/PackageReceiver.java
index aef63af..b5c7c87 100644
--- a/src/com/android/documentsui/PackageReceiver.java
+++ b/src/com/android/documentsui/PackageReceiver.java
@@ -23,7 +23,7 @@
import android.net.Uri;
/**
- * Clean up {@link RecentsProvider} when packages are removed.
+ * Clean up {@link RecentsProvider} and {@link LocalPreferences} when packages are removed.
*/
public class PackageReceiver extends BroadcastReceiver {
@Override
@@ -31,15 +31,19 @@
final ContentResolver resolver = context.getContentResolver();
final String action = intent.getAction();
+ final Uri data = intent.getData();
+ final String packageName = data == null ? null : data.getSchemeSpecificPart();
+
if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE, null, null);
-
+ if (packageName != null) {
+ LocalPreferences.clearPackagePreferences(context, packageName);
+ }
} else if (Intent.ACTION_PACKAGE_DATA_CLEARED.equals(action)) {
- final Uri data = intent.getData();
- if (data != null) {
- final String packageName = data.getSchemeSpecificPart();
+ if (packageName != null) {
resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE_PACKAGE,
packageName, null);
+ LocalPreferences.clearPackagePreferences(context, packageName);
}
}
}