Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
62e74ea
Fix README.md for url_launcher_web (#2136)
hterkelsen Oct 7, 2019
a5a1b36
[video_player] Basic test for VideoPlayerController initialization (#…
amirh Oct 7, 2019
a9153ef
BugFix: `formatHint` was meant for network streams. (#2141)
jtmcdole Oct 7, 2019
bf17b0a
Rename instrumentation_adapter plugin to e2e plugin (#2161)
collinjackson Oct 8, 2019
9f9e5f7
[local_auth] Define clang module for iOS (#2146)
jmagman Oct 8, 2019
2fcff58
[url_launcher] Enable androidx and jetifier in android gradle propert…
bparrishMines Oct 10, 2019
1dae5b7
[url_launcher] Define clang module for iOS (#2177)
jmagman Oct 11, 2019
3900700
[shared_preferences] Define clang module for iOS
jmagman Oct 11, 2019
369a879
[sensors] Define clang module for iOS (#2175)
jmagman Oct 11, 2019
b182da8
[package_info] Define clang module for iOS (#2148)
jmagman Oct 11, 2019
178263d
[quick_actions] Define clang module for iOS (#2149)
jmagman Oct 11, 2019
ff8a4d7
[path_provider] Define clang module for iOS (#2147)
jmagman Oct 11, 2019
decb6b6
[e2e] update README (#2178)
collinjackson Oct 11, 2019
0359295
[android_intent] Migrate to the new embedding (#2143)
Oct 14, 2019
026043e
[video_player] Define clang module for iOS (#2183)
jmagman Oct 14, 2019
878daa9
[google_sign_in] Define clang module for iOS (#2184)
jmagman Oct 14, 2019
3f8502e
[webview_flutter] Define clang module for iOS (#2185)
jmagman Oct 14, 2019
37cb413
[battery] Define clang module for iOS (#2179)
jmagman Oct 14, 2019
f54320b
[share] Define clang module for iOS (#2180)
jmagman Oct 14, 2019
63d0571
[android_intent] Bump the Flutter SDK min version (#2188)
Oct 14, 2019
8697a03
Run clang analyzer on iOS and macOS code in CI test when packages cha…
jmagman Oct 14, 2019
326b21b
[battery] Support the v2 Android embedder (#2152)
amirh Oct 14, 2019
3a77d38
[battery] relax the example app minimal required Flutter version (#2…
amirh Oct 14, 2019
0992077
[image_picker] fix crash when aar from 'flutter build aar' (#2120)
liujingtech Oct 14, 2019
573c9ff
[flutter_webview] Migrate to the new embedding (#2169)
Oct 15, 2019
f7297f5
[e2e] Update to support new embedder (#2190)
collinjackson Oct 15, 2019
fb37cfc
[image_picker] Fix iOS build and analyzer warnings (#2191)
jmagman Oct 15, 2019
ba5c774
[camera] Migrate to the new embedding (#2165)
Oct 15, 2019
67697ab
[Connectivity] migrate to the new android embedding (#2142)
Oct 15, 2019
93fe8f7
[in_app_purchase] Fix iOS build warning (#2192)
jmagman Oct 15, 2019
c794ac1
[in_app_purchase] migrate to the v2 android embedding (#2155)
Oct 15, 2019
8150245
[url_launcher] Migrate to the new embedding (#2157)
Oct 15, 2019
3305e37
[webview_flutter] (Trivial) Add V2 warnings (#2196)
Oct 15, 2019
ac1052e
[battery] add e2e dependency to the example app (#2194)
amirh Oct 15, 2019
c155379
Enable testing on both master and stable (#2197)
collinjackson Oct 16, 2019
575f3e7
Revert "Enable testing on both master and stable (#2197)" (#2199)
collinjackson Oct 16, 2019
3e047f9
[url_launcher] Revert embedding support (#2201)
Oct 16, 2019
2ca7b52
[flutter_webview] Revert v2 embedder support (#2200)
Oct 16, 2019
8251326
Add plugin for Android lifecycle in embedding (#2168)
amirh Oct 16, 2019
ec57790
s/flutter_android_lifecycle/flutter_plugin_android_lifecycle/ (#2205)
amirh Oct 17, 2019
c3a9764
update readme (#2206)
amirh Oct 17, 2019
2c161ec
[flutter_plugin_android_lifecycle] bump e2e depenency to 0.2.1 (#2207)
amirh Oct 17, 2019
8099875
[android_intent] Cleanup the V2 migration (#2195)
Oct 17, 2019
dce7169
[package_info] Support the v2 Android embedder (with e2e tests) (#2160)
collinjackson Oct 17, 2019
3e271bc
Re-land testing of plugins on stable (#2203)
collinjackson Oct 17, 2019
2951f84
[url_launcher] Re-land v2 embedding support (#2204)
Oct 17, 2019
b1488e6
Ensure that when testing on stable Cirrus is upgraded to latest on iO…
collinjackson Oct 17, 2019
37936b5
[google_maps_flutter] Add NonNull macro to reduce warnings in iOS (#2…
ened Oct 18, 2019
4cb29b5
[android_intent] componentName must be provided before resolveActivit…
Oct 18, 2019
7310033
[battery]remove AndroidX constraint (#2216)
Oct 18, 2019
a3b00b0
[in_app_purchase] remove AndroidX constraint (#2215)
Oct 18, 2019
53e2151
remove android x in magic script (#2218)
Oct 18, 2019
e4b0cc4
remove android x constraint (#2219)
Oct 18, 2019
a79b89c
[connectivity]remove AndroidX constraint (#2212)
Oct 18, 2019
84dec1a
[url_launcher]remove AndroidX constraint (#2220)
Oct 19, 2019
dadb913
remove android x constraint (#2221)
Oct 19, 2019
017a57e
[path_provider] Android: Support multiple external storage options (#…
ened Oct 21, 2019
08fd95c
[Share] Support v2 android embedder. (#2156)
Oct 21, 2019
3ad2d83
[sensor] Support v2 android embedder. (#2164)
Oct 21, 2019
e61ba6e
[device_info] Support v2 android embedding. (#2163)
Oct 21, 2019
655dd19
[flutter_plugin_android_lifecycle] register the e2e plugin in the exa…
amirh Oct 21, 2019
28107c1
delete all example/android/app/gradle.properties files (#2208)
amirh Oct 21, 2019
fe9b559
[shared_preferences] Support v2 android embedding. (#2162)
Oct 22, 2019
f04b3c8
[url_launcher] Add `url_launcher_platform_interface` package (#2217)
hterkelsen Oct 22, 2019
a68932e
Forbid `... implements UrlLauncherPlatform` (#2230)
amirh Oct 23, 2019
63b4e6b
[url_launcher] Use `url_launcher_platform_interface` to handle calls …
hterkelsen Oct 23, 2019
a1fffa6
[multiple] V2 embedding plugins use compileOnly (#2232)
Oct 25, 2019
a5b7ba8
Use package import to import files inside lib/ directory. (#2236)
chingjun Oct 25, 2019
8160f31
[cleanup] Remove AndroidX warning (#2231)
Oct 28, 2019
bdd41e9
[Shared_preferences]suppress warnings (#2241)
Oct 28, 2019
fe49a79
[e2e] update README (#2233)
collinjackson Oct 28, 2019
7a6c105
[image_picker] swap width and height when source image when orientati…
owops Oct 29, 2019
421b241
[google_maps_flutter] Cast error.code to unsigned long to avoid using…
tommyzed Oct 29, 2019
dff23ca
[url_launcher] Migrate url_launcher_web to the platform interface (#2…
hterkelsen Oct 29, 2019
5b179e3
Adapt the FlutterLifecycleAdapter to the new embedding API (#2243)
amirh Oct 29, 2019
89c4816
[camera] Android: Improve image streaming by creating a request suita…
PerLycke Oct 29, 2019
4c793a3
[google_sign_in] Fix deprecated API usage issue by upgrading CocoaPod…
collinjackson Oct 29, 2019
ffb7903
[local_auth] Api to stop authentication (#2111)
karan-rawal Oct 30, 2019
451a689
run the publish with the pub version from flutter stable (#2250)
amirh Nov 1, 2019
f31d16a
[webview_flutter] Re-land support v2 embedding support (#2209)
Nov 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[shared_preferences] Support v2 android embedding. (flutter#2162)
  • Loading branch information
Chris Yang authored Oct 22, 2019
commit fe9b5594f92fceafe2031c20aba586eb350e00ea
6 changes: 6 additions & 0 deletions packages/shared_preferences/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.4

* Support the v2 Android embedding.
* Update to AndroidX.
* Migrate to using the new e2e test binding.

## 0.5.3+5

* Define clang module for iOS.
Expand Down
26 changes: 26 additions & 0 deletions packages/shared_preferences/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,29 @@ android {
disable 'InvalidPackage'
}
}

// TODO(cyanglaz): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "1.1.1"
api "android.arch.lifecycle:runtime:$lifecycle_version"
api "android.arch.lifecycle:common:$lifecycle_version"
api "android.arch.lifecycle:common-java8:$lifecycle_version"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.sharedpreferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Base64;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Implementation of the {@link MethodChannel.MethodCallHandler} for the plugin. It is also
* responsible of managing the {@link android.content.SharedPreferences}.
*/
class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {

private static final String SHARED_PREFERENCES_NAME = "FlutterSharedPreferences";

// Fun fact: The following is a base64 encoding of the string "This is the prefix for a list."
private static final String LIST_IDENTIFIER = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu";
private static final String BIG_INTEGER_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy";
private static final String DOUBLE_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu";

private final android.content.SharedPreferences preferences;

/**
* Constructs a {@link MethodCallHandlerImpl} instance. Creates a {@link
* android.content.SharedPreferences} based on the {@code context}.
*/
MethodCallHandlerImpl(Context context) {
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
String key = call.argument("key");
try {
switch (call.method) {
case "setBool":
commitAsync(preferences.edit().putBoolean(key, (boolean) call.argument("value")), result);
break;
case "setDouble":
double doubleValue = ((Number) call.argument("value")).doubleValue();
String doubleValueStr = Double.toString(doubleValue);
commitAsync(preferences.edit().putString(key, DOUBLE_PREFIX + doubleValueStr), result);
break;
case "setInt":
Number number = call.argument("value");
if (number instanceof BigInteger) {
BigInteger integerValue = (BigInteger) number;
commitAsync(
preferences
.edit()
.putString(
key, BIG_INTEGER_PREFIX + integerValue.toString(Character.MAX_RADIX)),
result);
} else {
commitAsync(preferences.edit().putLong(key, number.longValue()), result);
}
break;
case "setString":
String value = (String) call.argument("value");
if (value.startsWith(LIST_IDENTIFIER) || value.startsWith(BIG_INTEGER_PREFIX)) {
result.error(
"StorageError",
"This string cannot be stored as it clashes with special identifier prefixes.",
null);
return;
}
commitAsync(preferences.edit().putString(key, value), result);
break;
case "setStringList":
List<String> list = call.argument("value");
commitAsync(
preferences.edit().putString(key, LIST_IDENTIFIER + encodeList(list)), result);
break;
case "commit":
// We've been committing the whole time.
result.success(true);
break;
case "getAll":
result.success(getAllPrefs());
return;
case "remove":
commitAsync(preferences.edit().remove(key), result);
break;
case "clear":
Set<String> keySet = getAllPrefs().keySet();
SharedPreferences.Editor clearEditor = preferences.edit();
for (String keyToDelete : keySet) {
clearEditor.remove(keyToDelete);
}
commitAsync(clearEditor, result);
break;
default:
result.notImplemented();
break;
}
} catch (IOException e) {
result.error("IOException encountered", call.method, e);
}
}

private void commitAsync(
final SharedPreferences.Editor editor, final MethodChannel.Result result) {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... voids) {
return editor.commit();
}

@Override
protected void onPostExecute(Boolean value) {
result.success(value);
}
}.execute();
}

private List<String> decodeList(String encodedList) throws IOException {
ObjectInputStream stream = null;
try {
stream = new ObjectInputStream(new ByteArrayInputStream(Base64.decode(encodedList, 0)));
return (List<String>) stream.readObject();
} catch (ClassNotFoundException e) {
throw new IOException(e);
} finally {
if (stream != null) {
stream.close();
}
}
}

private String encodeList(List<String> list) throws IOException {
ObjectOutputStream stream = null;
try {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
stream = new ObjectOutputStream(byteStream);
stream.writeObject(list);
stream.flush();
return Base64.encodeToString(byteStream.toByteArray(), 0);
} finally {
if (stream != null) {
stream.close();
}
}
}

// Filter preferences to only those set by the flutter app.
private Map<String, Object> getAllPrefs() throws IOException {
Map<String, ?> allPrefs = preferences.getAll();
Map<String, Object> filteredPrefs = new HashMap<>();
for (String key : allPrefs.keySet()) {
if (key.startsWith("flutter.")) {
Object value = allPrefs.get(key);
if (value instanceof String) {
String stringValue = (String) value;
if (stringValue.startsWith(LIST_IDENTIFIER)) {
value = decodeList(stringValue.substring(LIST_IDENTIFIER.length()));
} else if (stringValue.startsWith(BIG_INTEGER_PREFIX)) {
String encoded = stringValue.substring(BIG_INTEGER_PREFIX.length());
value = new BigInteger(encoded, Character.MAX_RADIX);
} else if (stringValue.startsWith(DOUBLE_PREFIX)) {
String doubleStr = stringValue.substring(DOUBLE_PREFIX.length());
value = Double.valueOf(doubleStr);
}
} else if (value instanceof Set) {
// This only happens for previous usage of setStringSet. The app expects a list.
List<String> listValue = new ArrayList<>((Set) value);
// Let's migrate the value too while we are at it.
boolean success =
preferences
.edit()
.remove(key)
.putString(key, LIST_IDENTIFIER + encodeList(listValue))
.commit();
if (!success) {
// If we are unable to migrate the existing preferences, it means we potentially lost them.
// In this case, an error from getAllPrefs() is appropriate since it will alert the app during plugin initialization.
throw new IOException("Could not migrate set to list");
}
value = listValue;
}
filteredPrefs.put(key, value);
}
}
return filteredPrefs;
}
}
Loading