Add support for deleting a shared preference (#1018)

Summary:
This change makes it possible to remove preferences. I also added a `Delete` context menu option to `DataInspector` because I needed it to implement this feature. passy confirmed that it makes sense to add this because delete is a common action.

Fixes https://github.com/facebook/flipper/issues/451
Pull Request resolved: https://github.com/facebook/flipper/pull/1018

Reviewed By: jknoxville

Differential Revision: D21086308

Pulled By: passy

fbshipit-source-id: 551ff0908d5e6c93f58d6012b42e1ee3531de997
This commit is contained in:
Michal Zielinski
2020-04-17 08:58:14 -07:00
committed by Facebook GitHub Bot
parent 9b8974eeb3
commit 2d1870cf7d
5 changed files with 71 additions and 0 deletions

View File

@@ -229,6 +229,22 @@ public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
responder.success(getFlipperObjectFor(sharedPreferencesName));
}
});
connection.receive(
"deleteSharedPreference",
new FlipperReceiver() {
@Override
public void onReceive(FlipperObject params, FlipperResponder responder)
throws IllegalArgumentException {
String sharedPreferencesName = params.getString("sharedPreferencesName");
String preferenceName = params.getString("preferenceName");
SharedPreferences sharedPrefs = getSharedPreferencesFor(sharedPreferencesName);
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.remove(preferenceName);
editor.apply();
responder.success(getFlipperObjectFor(sharedPreferencesName));
}
});
}
@Override