Skip to content

Commit aeb7ab6

Browse files
authored
Revert "[shared_preferences] update List<String> encode/decode (#8335)"
This reverts commit f7efc2b.
1 parent 258f6dc commit aeb7ab6

File tree

18 files changed

+303
-894
lines changed

18 files changed

+303
-894
lines changed

packages/shared_preferences/shared_preferences_android/CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
## 2.4.3
2-
3-
* Migrates `List<String>` value encoding to JSON.
4-
51
## 2.4.2
62

73
* Bumps gradle-plugin to 2.1.0.

packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesPlugin.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,18 @@
2525
import java.util.HashSet;
2626
import java.util.List;
2727
import java.util.Map;
28-
import java.util.Objects;
2928
import java.util.Set;
3029

3130
/** LegacySharedPreferencesPlugin */
3231
public class LegacySharedPreferencesPlugin implements FlutterPlugin, SharedPreferencesApi {
3332
private static final String TAG = "SharedPreferencesPlugin";
3433
private static final String SHARED_PREFERENCES_NAME = "FlutterSharedPreferences";
35-
// All identifiers must match the SharedPreferencesPlugin.kt file, as well as the strings.dart file.
3634
private static final String LIST_IDENTIFIER = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu";
37-
// The symbol `!` was chosen as it cannot be created by the base 64 encoding used with LIST_IDENTIFIER.
38-
private static final String JSON_LIST_IDENTIFIER = LIST_IDENTIFIER + "!";
3935
private static final String BIG_INTEGER_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy";
4036
private static final String DOUBLE_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu";
4137

4238
private SharedPreferences preferences;
43-
private final SharedPreferencesListEncoder listEncoder;
39+
private SharedPreferencesListEncoder listEncoder;
4440

4541
public LegacySharedPreferencesPlugin() {
4642
this(new ListEncoder());
@@ -104,15 +100,7 @@ public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding bin
104100
}
105101

106102
@Override
107-
public @NonNull Boolean setEncodedStringList(@NonNull String key, @NonNull String value)
108-
throws RuntimeException {
109-
return preferences.edit().putString(key, value).commit();
110-
}
111-
112-
// Deprecated, for testing purposes only.
113-
@Deprecated
114-
@Override
115-
public @NonNull Boolean setDeprecatedStringList(@NonNull String key, @NonNull List<String> value)
103+
public @NonNull Boolean setStringList(@NonNull String key, @NonNull List<String> value)
116104
throws RuntimeException {
117105
return preferences.edit().putString(key, LIST_IDENTIFIER + listEncoder.encode(value)).commit();
118106
}
@@ -143,13 +131,14 @@ public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding bin
143131

144132
// Gets all shared preferences, filtered to only those set with the given prefix.
145133
// Optionally filtered also to only those items in the optional [allowList].
134+
@SuppressWarnings("unchecked")
146135
private @NonNull Map<String, Object> getAllPrefs(
147136
@NonNull String prefix, @Nullable Set<String> allowList) throws RuntimeException {
148137
Map<String, ?> allPrefs = preferences.getAll();
149138
Map<String, Object> filteredPrefs = new HashMap<>();
150139
for (String key : allPrefs.keySet()) {
151140
if (key.startsWith(prefix) && (allowList == null || allowList.contains(key))) {
152-
filteredPrefs.put(key, transformPref(key, Objects.requireNonNull(allPrefs.get(key))));
141+
filteredPrefs.put(key, transformPref(key, allPrefs.get(key)));
153142
}
154143
}
155144

@@ -160,13 +149,7 @@ private Object transformPref(@NonNull String key, @NonNull Object value) {
160149
if (value instanceof String) {
161150
String stringValue = (String) value;
162151
if (stringValue.startsWith(LIST_IDENTIFIER)) {
163-
// The JSON-encoded lists use an extended prefix to distinguish them from
164-
// lists that are encoded on the platform.
165-
if (stringValue.startsWith(JSON_LIST_IDENTIFIER)) {
166-
return value;
167-
} else {
168-
return listEncoder.decode(stringValue.substring(LIST_IDENTIFIER.length()));
169-
}
152+
return listEncoder.decode(stringValue.substring(LIST_IDENTIFIER.length()));
170153
} else if (stringValue.startsWith(BIG_INTEGER_PREFIX)) {
171154
// TODO (tarrinneal): Remove all BigInt code.
172155
// https://github.com/flutter/flutter/issues/124420

0 commit comments

Comments
 (0)