SharedPreferencesPlugin -- Look for all shared pref files
Summary: Searches for all shared pref files instead of only the package name by default Reviewed By: xiphirx Differential Revision: D14763787 fbshipit-source-id: a3b7dfe8db078ac4f55e236b1516ed2de668f8d2
This commit is contained in:
committed by
Facebook Github Bot
parent
8e9643e8a1
commit
825ecb8e23
@@ -17,6 +17,9 @@ import com.facebook.flipper.core.FlipperObject;
|
|||||||
import com.facebook.flipper.core.FlipperPlugin;
|
import com.facebook.flipper.core.FlipperPlugin;
|
||||||
import com.facebook.flipper.core.FlipperReceiver;
|
import com.facebook.flipper.core.FlipperReceiver;
|
||||||
import com.facebook.flipper.core.FlipperResponder;
|
import com.facebook.flipper.core.FlipperResponder;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,6 +27,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
|
public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
|
||||||
|
|
||||||
|
private static final String SHARED_PREFS_DIR = "shared_prefs";
|
||||||
|
private static final String XML_SUFFIX = ".xml";
|
||||||
private FlipperConnection mConnection;
|
private FlipperConnection mConnection;
|
||||||
private final Map<SharedPreferences, SharedPreferencesDescriptor> mSharedPreferences;
|
private final Map<SharedPreferences, SharedPreferencesDescriptor> mSharedPreferences;
|
||||||
private final SharedPreferences.OnSharedPreferenceChangeListener
|
private final SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
@@ -57,7 +62,7 @@ public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
|
|||||||
* name with {@link Context#MODE_PRIVATE}.
|
* name with {@link Context#MODE_PRIVATE}.
|
||||||
*/
|
*/
|
||||||
public SharedPreferencesFlipperPlugin(Context context) {
|
public SharedPreferencesFlipperPlugin(Context context) {
|
||||||
this(context, context.getPackageName());
|
this(context, buildDescriptorForAllPrefsFiles(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,6 +113,27 @@ public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
|
|||||||
return "Preferences";
|
return "Preferences";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<SharedPreferencesDescriptor> buildDescriptorForAllPrefsFiles(
|
||||||
|
Context context) {
|
||||||
|
File dir = new File(context.getApplicationInfo().dataDir, SHARED_PREFS_DIR);
|
||||||
|
String[] list =
|
||||||
|
dir.list(
|
||||||
|
new FilenameFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.endsWith(XML_SUFFIX);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
List<SharedPreferencesDescriptor> descriptors = new ArrayList<>();
|
||||||
|
if (list != null) {
|
||||||
|
for (String each : list) {
|
||||||
|
String prefName = each.substring(0, each.indexOf(XML_SUFFIX));
|
||||||
|
descriptors.add(new SharedPreferencesDescriptor(prefName, MODE_PRIVATE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return descriptors;
|
||||||
|
}
|
||||||
|
|
||||||
private SharedPreferences getSharedPreferencesFor(String name) {
|
private SharedPreferences getSharedPreferencesFor(String name) {
|
||||||
for (Map.Entry<SharedPreferences, SharedPreferencesDescriptor> entry :
|
for (Map.Entry<SharedPreferences, SharedPreferencesDescriptor> entry :
|
||||||
mSharedPreferences.entrySet()) {
|
mSharedPreferences.entrySet()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user