From 32e72ddb9c30729e337edfec5607be4ba503e273 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Tue, 29 Aug 2023 13:52:24 +0100 Subject: [PATCH] Properly clear the label cache when changing isMultiUser setting --- app/src/main/java/dev/ukanth/ufirewall/Api.java | 4 ++-- .../ukanth/ufirewall/preferences/ExpPreferenceFragment.java | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/dev/ukanth/ufirewall/Api.java b/app/src/main/java/dev/ukanth/ufirewall/Api.java index 74f9d5bb..772e4d3b 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/Api.java +++ b/app/src/main/java/dev/ukanth/ufirewall/Api.java @@ -169,6 +169,7 @@ public final class Api { public static final int NOTIFICATION_ID = 1; public static final String PREF_FIREWALL_STATUS = "AFWallStaus"; public static final String DEFAULT_PREFS_NAME = "AFWallPrefs"; + public static final String CACHE_PREFS_NAME = "AFWallCache"; //for import/export rules //revertback to old approach for performance public static final String PREF_3G_PKG_UIDS = "AllowedPKG3G_UIDS"; @@ -1396,8 +1397,7 @@ public static List getApps(Context ctx, GetAppList appList) { } //revert back to old approach - //always use the defaul preferences to store cache value - reduces the application usage size - SharedPreferences cachePrefs = ctx.getSharedPreferences(DEFAULT_PREFS_NAME, Context.MODE_PRIVATE); + SharedPreferences cachePrefs = ctx.getSharedPreferences(CACHE_PREFS_NAME, Context.MODE_PRIVATE); int count = 0; try { diff --git a/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java b/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java index f7e7e170..84ef288f 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java +++ b/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java @@ -7,6 +7,7 @@ import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -149,6 +150,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, } else { Api.setUserOwner(this.getActivity().getApplicationContext()); } + final Context ctx = getActivity().getApplicationContext(); + SharedPreferences cachePrefs = ctx.getSharedPreferences(Api.CACHE_PREFS_NAME, Context.MODE_PRIVATE); + Editor edit = cachePrefs.edit(); + edit.clear(); + edit.apply(); } }