From 9f8bf53817b1ac3d9cfdb9b54512f08b7b2dc3e9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 7 Oct 2019 13:33:50 -0700 Subject: [PATCH 01/23] Plugin side of new embedding --- .../firebase/core/FirebaseCoreHandler.java | 85 +++++++++++++++++ .../firebase/core/FirebaseCorePlugin.java | 93 +++---------------- .../example/android/gradle.properties | 1 + 3 files changed, 98 insertions(+), 81 deletions(-) create mode 100644 packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java diff --git a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java new file mode 100644 index 000000000000..f5b7110cdf6c --- /dev/null +++ b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java @@ -0,0 +1,85 @@ +package io.flutter.plugins.firebase.core; + +import android.content.Context; +import com.google.firebase.FirebaseApp; +import com.google.firebase.FirebaseOptions; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; + +public class FirebaseCoreHandler implements MethodChannel.MethodCallHandler { + private final Context context; + + FirebaseCoreHandler(Context context) { + this.context = context; + } + + private Map asMap(FirebaseApp app) { + Map appMap = new HashMap<>(); + appMap.put("name", app.getName()); + FirebaseOptions options = app.getOptions(); + Map optionsMap = new HashMap<>(); + optionsMap.put("googleAppID", options.getApplicationId()); + optionsMap.put("GCMSenderID", options.getGcmSenderId()); + optionsMap.put("APIKey", options.getApiKey()); + optionsMap.put("databaseURL", options.getDatabaseUrl()); + optionsMap.put("storageBucket", options.getStorageBucket()); + optionsMap.put("projectID", options.getProjectId()); + appMap.put("options", optionsMap); + return appMap; + } + + @Override + public void onMethodCall(MethodCall call, final MethodChannel.Result result) { + switch (call.method) { + case "FirebaseApp#configure": + { + Map arguments = call.arguments(); + String name = (String) arguments.get("name"); + @SuppressWarnings("unchecked") + Map optionsMap = (Map) arguments.get("options"); + FirebaseOptions options = + new FirebaseOptions.Builder() + .setApiKey(optionsMap.get("APIKey")) + .setApplicationId(optionsMap.get("googleAppID")) + .setDatabaseUrl(optionsMap.get("databaseURL")) + .setGcmSenderId(optionsMap.get("GCMSenderID")) + .setProjectId(optionsMap.get("projectID")) + .setStorageBucket(optionsMap.get("storageBucket")) + .build(); + FirebaseApp.initializeApp(context, options, name); + result.success(null); + break; + } + case "FirebaseApp#allApps": + { + List> apps = new ArrayList<>(); + for (FirebaseApp app : FirebaseApp.getApps(context)) { + apps.add(asMap(app)); + } + result.success(apps); + break; + } + case "FirebaseApp#appNamed": + { + String name = call.arguments(); + try { + FirebaseApp app = FirebaseApp.getInstance(name); + result.success(asMap(app)); + } catch (IllegalStateException ex) { + // App doesn't exist, so successfully return null. + result.success(null); + } + break; + } + default: + { + result.notImplemented(); + break; + } + } + } +} diff --git a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java index ef82fbf92573..3a4047f7046b 100644 --- a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java +++ b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java @@ -1,100 +1,31 @@ // Copyright 2017 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.firebase.core; -import android.content.Context; -import com.google.firebase.FirebaseApp; -import com.google.firebase.FirebaseOptions; -import io.flutter.plugin.common.MethodCall; +import androidx.annotation.NonNull; + +import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry; -import java.lang.String; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class FirebaseCorePlugin implements MethodCallHandler { - private final Context context; +public class FirebaseCorePlugin implements FlutterPlugin { + private MethodChannel channel; public static void registerWith(PluginRegistry.Registrar registrar) { final MethodChannel channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_core"); - channel.setMethodCallHandler(new FirebaseCorePlugin(registrar.context())); + channel.setMethodCallHandler(new FirebaseCoreHandler(registrar.context())); } - private FirebaseCorePlugin(Context context) { - this.context = context; - } - - private Map asMap(FirebaseApp app) { - Map appMap = new HashMap<>(); - appMap.put("name", app.getName()); - FirebaseOptions options = app.getOptions(); - Map optionsMap = new HashMap<>(); - optionsMap.put("googleAppID", options.getApplicationId()); - optionsMap.put("GCMSenderID", options.getGcmSenderId()); - optionsMap.put("APIKey", options.getApiKey()); - optionsMap.put("databaseURL", options.getDatabaseUrl()); - optionsMap.put("storageBucket", options.getStorageBucket()); - optionsMap.put("projectID", options.getProjectId()); - appMap.put("options", optionsMap); - return appMap; + @Override + public void onAttachedToEngine(FlutterPluginBinding binding) { + channel = new MethodChannel(binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/firebase_core"); + channel.setMethodCallHandler(new FirebaseCoreHandler(binding.getApplicationContext())); } @Override - public void onMethodCall(MethodCall call, final Result result) { - switch (call.method) { - case "FirebaseApp#configure": - { - Map arguments = call.arguments(); - String name = (String) arguments.get("name"); - @SuppressWarnings("unchecked") - Map optionsMap = (Map) arguments.get("options"); - FirebaseOptions options = - new FirebaseOptions.Builder() - .setApiKey(optionsMap.get("APIKey")) - .setApplicationId(optionsMap.get("googleAppID")) - .setDatabaseUrl(optionsMap.get("databaseURL")) - .setGcmSenderId(optionsMap.get("GCMSenderID")) - .setProjectId(optionsMap.get("projectID")) - .setStorageBucket(optionsMap.get("storageBucket")) - .build(); - FirebaseApp.initializeApp(context, options, name); - result.success(null); - break; - } - case "FirebaseApp#allApps": - { - List> apps = new ArrayList<>(); - for (FirebaseApp app : FirebaseApp.getApps(context)) { - apps.add(asMap(app)); - } - result.success(apps); - break; - } - case "FirebaseApp#appNamed": - { - String name = call.arguments(); - try { - FirebaseApp app = FirebaseApp.getInstance(name); - result.success(asMap(app)); - } catch (IllegalStateException ex) { - // App doesn't exist, so successfully return null. - result.success(null); - } - break; - } - default: - { - result.notImplemented(); - break; - } - } + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + if (channel != null) channel.setMethodCallHandler(null); } } diff --git a/packages/firebase_core/example/android/gradle.properties b/packages/firebase_core/example/android/gradle.properties index 8bd86f680510..7be3d8b46841 100644 --- a/packages/firebase_core/example/android/gradle.properties +++ b/packages/firebase_core/example/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true From 550b2d9c079b2d23d506257c14d3e5d7df114b5e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 7 Oct 2019 14:00:16 -0700 Subject: [PATCH 02/23] Update example app to used embedding api --- .../example/android/app/src/main/AndroidManifest.xml | 11 +++++++++++ .../plugins/firebasecoreexample/MainActivity2.java | 12 ++++++++++++ .../firebase_core/example/android/gradle.properties | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java diff --git a/packages/firebase_core/example/android/app/src/main/AndroidManifest.xml b/packages/firebase_core/example/android/app/src/main/AndroidManifest.xml index 48cbadd2a13b..4469f23de55d 100644 --- a/packages/firebase_core/example/android/app/src/main/AndroidManifest.xml +++ b/packages/firebase_core/example/android/app/src/main/AndroidManifest.xml @@ -17,6 +17,17 @@ + + + + + + diff --git a/packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java b/packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java new file mode 100644 index 000000000000..ba70fda18a71 --- /dev/null +++ b/packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java @@ -0,0 +1,12 @@ +package io.flutter.plugins.firebasecoreexample; + +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugins.firebase.core.FirebaseCorePlugin; + +public class MainActivity2 extends FlutterActivity { + @Override + public void configureFlutterEngine(FlutterEngine flutterEngine) { + flutterEngine.getPlugins().add(new FirebaseCorePlugin()); + } +} diff --git a/packages/firebase_core/example/android/gradle.properties b/packages/firebase_core/example/android/gradle.properties index 7be3d8b46841..38c8d4544ff1 100644 --- a/packages/firebase_core/example/android/gradle.properties +++ b/packages/firebase_core/example/android/gradle.properties @@ -1,2 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true From 3e73439320218a0d7b05774d7a68a1a3370113d4 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 7 Oct 2019 14:07:42 -0700 Subject: [PATCH 03/23] I always forget to format --- .../firebase/core/FirebaseCoreHandler.java | 82 +++++++++---------- .../firebase/core/FirebaseCorePlugin.java | 5 +- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java index f5b7110cdf6c..b8afa518e212 100644 --- a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java +++ b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java @@ -3,12 +3,12 @@ import android.content.Context; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; public class FirebaseCoreHandler implements MethodChannel.MethodCallHandler { private final Context context; @@ -36,50 +36,50 @@ private Map asMap(FirebaseApp app) { public void onMethodCall(MethodCall call, final MethodChannel.Result result) { switch (call.method) { case "FirebaseApp#configure": - { - Map arguments = call.arguments(); - String name = (String) arguments.get("name"); - @SuppressWarnings("unchecked") - Map optionsMap = (Map) arguments.get("options"); - FirebaseOptions options = - new FirebaseOptions.Builder() - .setApiKey(optionsMap.get("APIKey")) - .setApplicationId(optionsMap.get("googleAppID")) - .setDatabaseUrl(optionsMap.get("databaseURL")) - .setGcmSenderId(optionsMap.get("GCMSenderID")) - .setProjectId(optionsMap.get("projectID")) - .setStorageBucket(optionsMap.get("storageBucket")) - .build(); - FirebaseApp.initializeApp(context, options, name); - result.success(null); - break; - } + { + Map arguments = call.arguments(); + String name = (String) arguments.get("name"); + @SuppressWarnings("unchecked") + Map optionsMap = (Map) arguments.get("options"); + FirebaseOptions options = + new FirebaseOptions.Builder() + .setApiKey(optionsMap.get("APIKey")) + .setApplicationId(optionsMap.get("googleAppID")) + .setDatabaseUrl(optionsMap.get("databaseURL")) + .setGcmSenderId(optionsMap.get("GCMSenderID")) + .setProjectId(optionsMap.get("projectID")) + .setStorageBucket(optionsMap.get("storageBucket")) + .build(); + FirebaseApp.initializeApp(context, options, name); + result.success(null); + break; + } case "FirebaseApp#allApps": - { - List> apps = new ArrayList<>(); - for (FirebaseApp app : FirebaseApp.getApps(context)) { - apps.add(asMap(app)); + { + List> apps = new ArrayList<>(); + for (FirebaseApp app : FirebaseApp.getApps(context)) { + apps.add(asMap(app)); + } + result.success(apps); + break; } - result.success(apps); - break; - } case "FirebaseApp#appNamed": - { - String name = call.arguments(); - try { - FirebaseApp app = FirebaseApp.getInstance(name); - result.success(asMap(app)); - } catch (IllegalStateException ex) { - // App doesn't exist, so successfully return null. - result.success(null); + { + String name = call.arguments(); + try { + FirebaseApp app = FirebaseApp.getInstance(name); + result.success(asMap(app)); + } catch (IllegalStateException ex) { + // App doesn't exist, so successfully return null. + result.success(null); + } + break; } - break; - } default: - { - result.notImplemented(); - break; - } + { + result.notImplemented(); + break; + } } } } diff --git a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java index 3a4047f7046b..7198e1026e4e 100644 --- a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java +++ b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java @@ -4,7 +4,6 @@ package io.flutter.plugins.firebase.core; import androidx.annotation.NonNull; - import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.PluginRegistry; @@ -20,7 +19,9 @@ public static void registerWith(PluginRegistry.Registrar registrar) { @Override public void onAttachedToEngine(FlutterPluginBinding binding) { - channel = new MethodChannel(binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/firebase_core"); + channel = + new MethodChannel( + binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/firebase_core"); channel.setMethodCallHandler(new FirebaseCoreHandler(binding.getApplicationContext())); } From 143b53419a93f4cdd6a36935e3691aa6d8ad0c44 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 7 Oct 2019 17:14:27 -0700 Subject: [PATCH 04/23] channel name constant no null check --- .../plugins/firebase/core/FirebaseCorePlugin.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java index 7198e1026e4e..6b1f03713cbc 100644 --- a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java +++ b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java @@ -9,24 +9,23 @@ import io.flutter.plugin.common.PluginRegistry; public class FirebaseCorePlugin implements FlutterPlugin { + private static final String CHANNEL_NAME = "plugins.flutter.io/firebase_core"; + private MethodChannel channel; public static void registerWith(PluginRegistry.Registrar registrar) { - final MethodChannel channel = - new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_core"); + final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME); channel.setMethodCallHandler(new FirebaseCoreHandler(registrar.context())); } @Override public void onAttachedToEngine(FlutterPluginBinding binding) { - channel = - new MethodChannel( - binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/firebase_core"); + channel = new MethodChannel(binding.getFlutterEngine().getDartExecutor(), CHANNEL_NAME); channel.setMethodCallHandler(new FirebaseCoreHandler(binding.getApplicationContext())); } @Override public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - if (channel != null) channel.setMethodCallHandler(null); + channel.setMethodCallHandler(null); } } From d00e5b9ca5552b2fa12b3d452f828d3fb4dff474 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 15:06:21 -0700 Subject: [PATCH 05/23] migrate --- .../FirebaseRemoteConfigPlugin.java | 190 ++---------------- .../MethodCallHandlerImpl.java | 181 +++++++++++++++++ .../android/app/src/main/AndroidManifest.xml | 11 +- .../EmbeddingV1Activity.java | 13 ++ .../MainActivity.java | 13 +- .../example/android/gradle.properties | 3 + .../example/lib/main.dart | 1 + 7 files changed, 234 insertions(+), 178 deletions(-) create mode 100644 packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java create mode 100644 packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java index d07a9ad1d57a..2db9b16bb827 100644 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java @@ -5,192 +5,40 @@ package io.flutter.plugins.firebase.firebaseremoteconfig; import android.content.Context; -import android.content.SharedPreferences; -import androidx.annotation.NonNull; -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.Task; -import com.google.firebase.remoteconfig.FirebaseRemoteConfig; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; -import io.flutter.plugin.common.MethodCall; +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry.Registrar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; /** FirebaseRemoteConfigPlugin */ -public class FirebaseRemoteConfigPlugin implements MethodCallHandler { +public class FirebaseRemoteConfigPlugin implements FlutterPlugin { - public static final String TAG = "FirebaseRemoteConfigPlugin"; - public static final String PREFS_NAME = + static final String TAG = "FirebaseRemoteConfigPlugin"; + static final String PREFS_NAME = "io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin"; - public static final String DEFAULT_PREF_KEY = "default_keys"; + static final String METHOD_CHANNEL = "plugins.flutter.io/firebase_remote_config"; - private static SharedPreferences sharedPreferences; + private MethodChannel channel; public static void registerWith(Registrar registrar) { - final MethodChannel channel = - new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_remote_config"); - channel.setMethodCallHandler(new FirebaseRemoteConfigPlugin()); - sharedPreferences = registrar.context().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + FirebaseRemoteConfigPlugin plugin = new FirebaseRemoteConfigPlugin(); + plugin.setupChannel(registrar.messenger(), registrar.context()); } @Override - public void onMethodCall(MethodCall call, final Result result) { - switch (call.method) { - case "RemoteConfig#instance": - { - FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = - FirebaseRemoteConfig.getInstance().getInfo(); - - Map properties = new HashMap<>(); - properties.put("lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); - properties.put( - "lastFetchStatus", mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); - properties.put( - "inDebugMode", firebaseRemoteConfigInfo.getConfigSettings().isDeveloperModeEnabled()); - properties.put("parameters", getConfigParameters()); - result.success(properties); - break; - } - case "RemoteConfig#setConfigSettings": - { - boolean debugMode = call.argument("debugMode"); - final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - FirebaseRemoteConfigSettings settings = - new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(debugMode).build(); - firebaseRemoteConfig.setConfigSettings(settings); - result.success(null); - break; - } - case "RemoteConfig#fetch": - { - long expiration = ((Number) call.argument("expiration")).longValue(); - final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - firebaseRemoteConfig - .fetch(expiration) - .addOnCompleteListener( - new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = - firebaseRemoteConfig.getInfo(); - Map properties = new HashMap<>(); - properties.put( - "lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); - properties.put( - "lastFetchStatus", - mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); - if (!task.isSuccessful()) { - final Exception exception = task.getException(); - - if (exception instanceof FirebaseRemoteConfigFetchThrottledException) { - properties.put( - "fetchThrottledEnd", - ((FirebaseRemoteConfigFetchThrottledException) exception) - .getThrottleEndTimeMillis()); - String errorMessage = - "Fetch has been throttled. See the error's " - + "FETCH_THROTTLED_END field for throttle end time."; - result.error("fetchFailedThrottled", errorMessage, properties); - } else { - String errorMessage = - "Unable to complete fetch. Reason is unknown " - + "but this could be due to lack of connectivity."; - result.error("fetchFailed", errorMessage, properties); - } - } else { - result.success(properties); - } - } - }); - break; - } - case "RemoteConfig#activate": - { - boolean newConfig = FirebaseRemoteConfig.getInstance().activateFetched(); - Map properties = new HashMap<>(); - properties.put("parameters", getConfigParameters()); - properties.put("newConfig", newConfig); - result.success(properties); - break; - } - case "RemoteConfig#setDefaults": - { - Map defaults = call.argument("defaults"); - FirebaseRemoteConfig.getInstance().setDefaults(defaults); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putStringSet(DEFAULT_PREF_KEY, defaults.keySet()).apply(); - result.success(null); - break; - } - default: - { - result.notImplemented(); - break; - } - } - } - - private Map getConfigParameters() { - FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - Map parameterMap = new HashMap<>(); - Set keys = firebaseRemoteConfig.getKeysByPrefix(""); - for (String key : keys) { - FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(key); - parameterMap.put(key, createRemoteConfigValueMap(remoteConfigValue)); - } - // Add default parameters if missing since `getKeysByPrefix` does not return default keys. - Set defaultKeys = - sharedPreferences.getStringSet(DEFAULT_PREF_KEY, new HashSet()); - for (String defaultKey : defaultKeys) { - if (!parameterMap.containsKey(defaultKey)) { - FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(defaultKey); - parameterMap.put(defaultKey, createRemoteConfigValueMap(remoteConfigValue)); - } - } - return parameterMap; + public void onAttachedToEngine(FlutterPluginBinding binding) { + setupChannel(binding.getFlutterEngine().getDartExecutor(), binding.getApplicationContext()); } - private Map createRemoteConfigValueMap( - FirebaseRemoteConfigValue remoteConfigValue) { - Map valueMap = new HashMap<>(); - valueMap.put("value", remoteConfigValue.asByteArray()); - valueMap.put("source", mapValueSource(remoteConfigValue.getSource())); - return valueMap; - } - - private String mapLastFetchStatus(int status) { - switch (status) { - case FirebaseRemoteConfig.LAST_FETCH_STATUS_SUCCESS: - return "success"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_FAILURE: - return "failure"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED: - return "throttled"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_NO_FETCH_YET: - return "noFetchYet"; - default: - return "failure"; - } + @Override + public void onDetachedFromEngine(FlutterPluginBinding binding) { + channel = null; } - private String mapValueSource(int source) { - switch (source) { - case FirebaseRemoteConfig.VALUE_SOURCE_STATIC: - return "static"; - case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT: - return "default"; - case FirebaseRemoteConfig.VALUE_SOURCE_REMOTE: - return "remote"; - default: - return "static"; - } + private void setupChannel(BinaryMessenger messenger, Context context) { + MethodCallHandlerImpl handler = + new MethodCallHandlerImpl(context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)); + channel = new MethodChannel(messenger, METHOD_CHANNEL); + channel.setMethodCallHandler(handler); } } diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java new file mode 100644 index 000000000000..5c59bad7f116 --- /dev/null +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java @@ -0,0 +1,181 @@ +package io.flutter.plugins.firebase.firebaseremoteconfig; + +import android.content.SharedPreferences; +import androidx.annotation.NonNull; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.remoteconfig.FirebaseRemoteConfig; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler { + + private static final String DEFAULT_PREF_KEY = "default_keys"; + + private static SharedPreferences sharedPreferences; + + MethodCallHandlerImpl(@NonNull SharedPreferences sharedPreferences) { + this.sharedPreferences = sharedPreferences; + } + + @Override + public void onMethodCall(MethodCall call, final MethodChannel.Result result) { + switch (call.method) { + case "RemoteConfig#instance": + { + FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = + FirebaseRemoteConfig.getInstance().getInfo(); + + Map properties = new HashMap<>(); + properties.put("lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); + properties.put( + "lastFetchStatus", mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); + properties.put( + "inDebugMode", firebaseRemoteConfigInfo.getConfigSettings().isDeveloperModeEnabled()); + properties.put("parameters", getConfigParameters()); + result.success(properties); + break; + } + case "RemoteConfig#setConfigSettings": + { + boolean debugMode = call.argument("debugMode"); + final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + FirebaseRemoteConfigSettings settings = + new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(debugMode).build(); + firebaseRemoteConfig.setConfigSettings(settings); + result.success(null); + break; + } + case "RemoteConfig#fetch": + { + long expiration = ((Number) call.argument("expiration")).longValue(); + final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + firebaseRemoteConfig + .fetch(expiration) + .addOnCompleteListener( + new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = + firebaseRemoteConfig.getInfo(); + Map properties = new HashMap<>(); + properties.put( + "lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); + properties.put( + "lastFetchStatus", + mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); + if (!task.isSuccessful()) { + final Exception exception = task.getException(); + + if (exception instanceof FirebaseRemoteConfigFetchThrottledException) { + properties.put( + "fetchThrottledEnd", + ((FirebaseRemoteConfigFetchThrottledException) exception) + .getThrottleEndTimeMillis()); + String errorMessage = + "Fetch has been throttled. See the error's " + + "FETCH_THROTTLED_END field for throttle end time."; + result.error("fetchFailedThrottled", errorMessage, properties); + } else { + String errorMessage = + "Unable to complete fetch. Reason is unknown " + + "but this could be due to lack of connectivity."; + result.error("fetchFailed", errorMessage, properties); + } + } else { + result.success(properties); + } + } + }); + break; + } + case "RemoteConfig#activate": + { + boolean newConfig = FirebaseRemoteConfig.getInstance().activateFetched(); + Map properties = new HashMap<>(); + properties.put("parameters", getConfigParameters()); + properties.put("newConfig", newConfig); + result.success(properties); + break; + } + case "RemoteConfig#setDefaults": + { + Map defaults = call.argument("defaults"); + FirebaseRemoteConfig.getInstance().setDefaults(defaults); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putStringSet(DEFAULT_PREF_KEY, defaults.keySet()).apply(); + result.success(null); + break; + } + default: + { + result.notImplemented(); + break; + } + } + } + + private Map getConfigParameters() { + FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + Map parameterMap = new HashMap<>(); + Set keys = firebaseRemoteConfig.getKeysByPrefix(""); + for (String key : keys) { + FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(key); + parameterMap.put(key, createRemoteConfigValueMap(remoteConfigValue)); + } + // Add default parameters if missing since `getKeysByPrefix` does not return default keys. + Set defaultKeys = + sharedPreferences.getStringSet(DEFAULT_PREF_KEY, new HashSet()); + for (String defaultKey : defaultKeys) { + if (!parameterMap.containsKey(defaultKey)) { + FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(defaultKey); + parameterMap.put(defaultKey, createRemoteConfigValueMap(remoteConfigValue)); + } + } + return parameterMap; + } + + private Map createRemoteConfigValueMap( + FirebaseRemoteConfigValue remoteConfigValue) { + Map valueMap = new HashMap<>(); + valueMap.put("value", remoteConfigValue.asByteArray()); + valueMap.put("source", mapValueSource(remoteConfigValue.getSource())); + return valueMap; + } + + private String mapLastFetchStatus(int status) { + switch (status) { + case FirebaseRemoteConfig.LAST_FETCH_STATUS_SUCCESS: + return "success"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_FAILURE: + return "failure"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED: + return "throttled"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_NO_FETCH_YET: + return "noFetchYet"; + default: + return "failure"; + } + } + + private String mapValueSource(int source) { + switch (source) { + case FirebaseRemoteConfig.VALUE_SOURCE_STATIC: + return "static"; + case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT: + return "default"; + case FirebaseRemoteConfig.VALUE_SOURCE_REMOTE: + return "remote"; + default: + return "static"; + } + } +} diff --git a/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml b/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml index fe4292fe0322..7100b12a4e6e 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml +++ b/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml @@ -17,8 +17,9 @@ android:label="firebase_remote_config_example" android:icon="@mipmap/ic_launcher"> + + diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java new file mode 100644 index 000000000000..2af625cab23d --- /dev/null +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java @@ -0,0 +1,13 @@ +package io.flutter.plugins.firebase.firebaseremoteconfigexample; + +import android.os.Bundle; +import io.flutter.app.FlutterActivity; +import io.flutter.plugins.GeneratedPluginRegistrant; + +public class EmbeddingV1Activity extends FlutterActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } +} diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index ef048c74f4df..a03548b6e845 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -1,13 +1,14 @@ package io.flutter.plugins.firebase.firebaseremoteconfigexample; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin; public class MainActivity extends FlutterActivity { + @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); + public void configureFlutterEngine(FlutterEngine flutterEngine) { + super.configureFlutterEngine(flutterEngine); + flutterEngine.getPlugins().add(new FirebaseRemoteConfigPlugin()); } } diff --git a/packages/firebase_remote_config/example/android/gradle.properties b/packages/firebase_remote_config/example/android/gradle.properties index 8bd86f680510..a5965ab8dced 100644 --- a/packages/firebase_remote_config/example/android/gradle.properties +++ b/packages/firebase_remote_config/example/android/gradle.properties @@ -1 +1,4 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/packages/firebase_remote_config/example/lib/main.dart b/packages/firebase_remote_config/example/lib/main.dart index 8db737372086..89a7d6de387e 100644 --- a/packages/firebase_remote_config/example/lib/main.dart +++ b/packages/firebase_remote_config/example/lib/main.dart @@ -8,6 +8,7 @@ import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:flutter/material.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); runApp(MaterialApp( title: 'Remote Config Example', home: FutureBuilder( From 78c882890126ba6788006cee9b042c7b3daecf67 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 15:07:37 -0700 Subject: [PATCH 06/23] migrate --- .../FirebaseRemoteConfigPlugin.java | 190 ++++++++++++++++-- .../MethodCallHandlerImpl.java | 181 ----------------- .../android/app/src/main/AndroidManifest.xml | 11 +- .../EmbeddingV1Activity.java | 13 -- .../MainActivity.java | 13 +- .../example/android/gradle.properties | 3 - .../example/lib/main.dart | 1 - 7 files changed, 178 insertions(+), 234 deletions(-) delete mode 100644 packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java delete mode 100644 packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java index 2db9b16bb827..d07a9ad1d57a 100644 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java @@ -5,40 +5,192 @@ package io.flutter.plugins.firebase.firebaseremoteconfig; import android.content.Context; -import io.flutter.embedding.engine.plugins.FlutterPlugin; -import io.flutter.plugin.common.BinaryMessenger; +import android.content.SharedPreferences; +import androidx.annotation.NonNull; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.remoteconfig.FirebaseRemoteConfig; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry.Registrar; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** FirebaseRemoteConfigPlugin */ -public class FirebaseRemoteConfigPlugin implements FlutterPlugin { +public class FirebaseRemoteConfigPlugin implements MethodCallHandler { - static final String TAG = "FirebaseRemoteConfigPlugin"; - static final String PREFS_NAME = + public static final String TAG = "FirebaseRemoteConfigPlugin"; + public static final String PREFS_NAME = "io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin"; - static final String METHOD_CHANNEL = "plugins.flutter.io/firebase_remote_config"; + public static final String DEFAULT_PREF_KEY = "default_keys"; - private MethodChannel channel; + private static SharedPreferences sharedPreferences; public static void registerWith(Registrar registrar) { - FirebaseRemoteConfigPlugin plugin = new FirebaseRemoteConfigPlugin(); - plugin.setupChannel(registrar.messenger(), registrar.context()); + final MethodChannel channel = + new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_remote_config"); + channel.setMethodCallHandler(new FirebaseRemoteConfigPlugin()); + sharedPreferences = registrar.context().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); } @Override - public void onAttachedToEngine(FlutterPluginBinding binding) { - setupChannel(binding.getFlutterEngine().getDartExecutor(), binding.getApplicationContext()); + public void onMethodCall(MethodCall call, final Result result) { + switch (call.method) { + case "RemoteConfig#instance": + { + FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = + FirebaseRemoteConfig.getInstance().getInfo(); + + Map properties = new HashMap<>(); + properties.put("lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); + properties.put( + "lastFetchStatus", mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); + properties.put( + "inDebugMode", firebaseRemoteConfigInfo.getConfigSettings().isDeveloperModeEnabled()); + properties.put("parameters", getConfigParameters()); + result.success(properties); + break; + } + case "RemoteConfig#setConfigSettings": + { + boolean debugMode = call.argument("debugMode"); + final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + FirebaseRemoteConfigSettings settings = + new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(debugMode).build(); + firebaseRemoteConfig.setConfigSettings(settings); + result.success(null); + break; + } + case "RemoteConfig#fetch": + { + long expiration = ((Number) call.argument("expiration")).longValue(); + final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + firebaseRemoteConfig + .fetch(expiration) + .addOnCompleteListener( + new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = + firebaseRemoteConfig.getInfo(); + Map properties = new HashMap<>(); + properties.put( + "lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); + properties.put( + "lastFetchStatus", + mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); + if (!task.isSuccessful()) { + final Exception exception = task.getException(); + + if (exception instanceof FirebaseRemoteConfigFetchThrottledException) { + properties.put( + "fetchThrottledEnd", + ((FirebaseRemoteConfigFetchThrottledException) exception) + .getThrottleEndTimeMillis()); + String errorMessage = + "Fetch has been throttled. See the error's " + + "FETCH_THROTTLED_END field for throttle end time."; + result.error("fetchFailedThrottled", errorMessage, properties); + } else { + String errorMessage = + "Unable to complete fetch. Reason is unknown " + + "but this could be due to lack of connectivity."; + result.error("fetchFailed", errorMessage, properties); + } + } else { + result.success(properties); + } + } + }); + break; + } + case "RemoteConfig#activate": + { + boolean newConfig = FirebaseRemoteConfig.getInstance().activateFetched(); + Map properties = new HashMap<>(); + properties.put("parameters", getConfigParameters()); + properties.put("newConfig", newConfig); + result.success(properties); + break; + } + case "RemoteConfig#setDefaults": + { + Map defaults = call.argument("defaults"); + FirebaseRemoteConfig.getInstance().setDefaults(defaults); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putStringSet(DEFAULT_PREF_KEY, defaults.keySet()).apply(); + result.success(null); + break; + } + default: + { + result.notImplemented(); + break; + } + } } - @Override - public void onDetachedFromEngine(FlutterPluginBinding binding) { - channel = null; + private Map getConfigParameters() { + FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + Map parameterMap = new HashMap<>(); + Set keys = firebaseRemoteConfig.getKeysByPrefix(""); + for (String key : keys) { + FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(key); + parameterMap.put(key, createRemoteConfigValueMap(remoteConfigValue)); + } + // Add default parameters if missing since `getKeysByPrefix` does not return default keys. + Set defaultKeys = + sharedPreferences.getStringSet(DEFAULT_PREF_KEY, new HashSet()); + for (String defaultKey : defaultKeys) { + if (!parameterMap.containsKey(defaultKey)) { + FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(defaultKey); + parameterMap.put(defaultKey, createRemoteConfigValueMap(remoteConfigValue)); + } + } + return parameterMap; + } + + private Map createRemoteConfigValueMap( + FirebaseRemoteConfigValue remoteConfigValue) { + Map valueMap = new HashMap<>(); + valueMap.put("value", remoteConfigValue.asByteArray()); + valueMap.put("source", mapValueSource(remoteConfigValue.getSource())); + return valueMap; + } + + private String mapLastFetchStatus(int status) { + switch (status) { + case FirebaseRemoteConfig.LAST_FETCH_STATUS_SUCCESS: + return "success"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_FAILURE: + return "failure"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED: + return "throttled"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_NO_FETCH_YET: + return "noFetchYet"; + default: + return "failure"; + } } - private void setupChannel(BinaryMessenger messenger, Context context) { - MethodCallHandlerImpl handler = - new MethodCallHandlerImpl(context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)); - channel = new MethodChannel(messenger, METHOD_CHANNEL); - channel.setMethodCallHandler(handler); + private String mapValueSource(int source) { + switch (source) { + case FirebaseRemoteConfig.VALUE_SOURCE_STATIC: + return "static"; + case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT: + return "default"; + case FirebaseRemoteConfig.VALUE_SOURCE_REMOTE: + return "remote"; + default: + return "static"; + } } } diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java deleted file mode 100644 index 5c59bad7f116..000000000000 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java +++ /dev/null @@ -1,181 +0,0 @@ -package io.flutter.plugins.firebase.firebaseremoteconfig; - -import android.content.SharedPreferences; -import androidx.annotation.NonNull; -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.Task; -import com.google.firebase.remoteconfig.FirebaseRemoteConfig; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler { - - private static final String DEFAULT_PREF_KEY = "default_keys"; - - private static SharedPreferences sharedPreferences; - - MethodCallHandlerImpl(@NonNull SharedPreferences sharedPreferences) { - this.sharedPreferences = sharedPreferences; - } - - @Override - public void onMethodCall(MethodCall call, final MethodChannel.Result result) { - switch (call.method) { - case "RemoteConfig#instance": - { - FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = - FirebaseRemoteConfig.getInstance().getInfo(); - - Map properties = new HashMap<>(); - properties.put("lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); - properties.put( - "lastFetchStatus", mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); - properties.put( - "inDebugMode", firebaseRemoteConfigInfo.getConfigSettings().isDeveloperModeEnabled()); - properties.put("parameters", getConfigParameters()); - result.success(properties); - break; - } - case "RemoteConfig#setConfigSettings": - { - boolean debugMode = call.argument("debugMode"); - final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - FirebaseRemoteConfigSettings settings = - new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(debugMode).build(); - firebaseRemoteConfig.setConfigSettings(settings); - result.success(null); - break; - } - case "RemoteConfig#fetch": - { - long expiration = ((Number) call.argument("expiration")).longValue(); - final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - firebaseRemoteConfig - .fetch(expiration) - .addOnCompleteListener( - new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = - firebaseRemoteConfig.getInfo(); - Map properties = new HashMap<>(); - properties.put( - "lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); - properties.put( - "lastFetchStatus", - mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); - if (!task.isSuccessful()) { - final Exception exception = task.getException(); - - if (exception instanceof FirebaseRemoteConfigFetchThrottledException) { - properties.put( - "fetchThrottledEnd", - ((FirebaseRemoteConfigFetchThrottledException) exception) - .getThrottleEndTimeMillis()); - String errorMessage = - "Fetch has been throttled. See the error's " - + "FETCH_THROTTLED_END field for throttle end time."; - result.error("fetchFailedThrottled", errorMessage, properties); - } else { - String errorMessage = - "Unable to complete fetch. Reason is unknown " - + "but this could be due to lack of connectivity."; - result.error("fetchFailed", errorMessage, properties); - } - } else { - result.success(properties); - } - } - }); - break; - } - case "RemoteConfig#activate": - { - boolean newConfig = FirebaseRemoteConfig.getInstance().activateFetched(); - Map properties = new HashMap<>(); - properties.put("parameters", getConfigParameters()); - properties.put("newConfig", newConfig); - result.success(properties); - break; - } - case "RemoteConfig#setDefaults": - { - Map defaults = call.argument("defaults"); - FirebaseRemoteConfig.getInstance().setDefaults(defaults); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putStringSet(DEFAULT_PREF_KEY, defaults.keySet()).apply(); - result.success(null); - break; - } - default: - { - result.notImplemented(); - break; - } - } - } - - private Map getConfigParameters() { - FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - Map parameterMap = new HashMap<>(); - Set keys = firebaseRemoteConfig.getKeysByPrefix(""); - for (String key : keys) { - FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(key); - parameterMap.put(key, createRemoteConfigValueMap(remoteConfigValue)); - } - // Add default parameters if missing since `getKeysByPrefix` does not return default keys. - Set defaultKeys = - sharedPreferences.getStringSet(DEFAULT_PREF_KEY, new HashSet()); - for (String defaultKey : defaultKeys) { - if (!parameterMap.containsKey(defaultKey)) { - FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(defaultKey); - parameterMap.put(defaultKey, createRemoteConfigValueMap(remoteConfigValue)); - } - } - return parameterMap; - } - - private Map createRemoteConfigValueMap( - FirebaseRemoteConfigValue remoteConfigValue) { - Map valueMap = new HashMap<>(); - valueMap.put("value", remoteConfigValue.asByteArray()); - valueMap.put("source", mapValueSource(remoteConfigValue.getSource())); - return valueMap; - } - - private String mapLastFetchStatus(int status) { - switch (status) { - case FirebaseRemoteConfig.LAST_FETCH_STATUS_SUCCESS: - return "success"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_FAILURE: - return "failure"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED: - return "throttled"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_NO_FETCH_YET: - return "noFetchYet"; - default: - return "failure"; - } - } - - private String mapValueSource(int source) { - switch (source) { - case FirebaseRemoteConfig.VALUE_SOURCE_STATIC: - return "static"; - case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT: - return "default"; - case FirebaseRemoteConfig.VALUE_SOURCE_REMOTE: - return "remote"; - default: - return "static"; - } - } -} diff --git a/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml b/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml index 7100b12a4e6e..fe4292fe0322 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml +++ b/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml @@ -17,9 +17,8 @@ android:label="firebase_remote_config_example" android:icon="@mipmap/ic_launcher"> - - diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java deleted file mode 100644 index 2af625cab23d..000000000000 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.flutter.plugins.firebase.firebaseremoteconfigexample; - -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; - -public class EmbeddingV1Activity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } -} diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index a03548b6e845..ef048c74f4df 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -1,14 +1,13 @@ package io.flutter.plugins.firebase.firebaseremoteconfigexample; -import io.flutter.embedding.android.FlutterActivity; -import io.flutter.embedding.engine.FlutterEngine; -import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin; +import android.os.Bundle; +import io.flutter.app.FlutterActivity; +import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { - @Override - public void configureFlutterEngine(FlutterEngine flutterEngine) { - super.configureFlutterEngine(flutterEngine); - flutterEngine.getPlugins().add(new FirebaseRemoteConfigPlugin()); + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); } } diff --git a/packages/firebase_remote_config/example/android/gradle.properties b/packages/firebase_remote_config/example/android/gradle.properties index a5965ab8dced..8bd86f680510 100644 --- a/packages/firebase_remote_config/example/android/gradle.properties +++ b/packages/firebase_remote_config/example/android/gradle.properties @@ -1,4 +1 @@ org.gradle.jvmargs=-Xmx1536M -android.enableR8=true -android.useAndroidX=true -android.enableJetifier=true \ No newline at end of file diff --git a/packages/firebase_remote_config/example/lib/main.dart b/packages/firebase_remote_config/example/lib/main.dart index 89a7d6de387e..8db737372086 100644 --- a/packages/firebase_remote_config/example/lib/main.dart +++ b/packages/firebase_remote_config/example/lib/main.dart @@ -8,7 +8,6 @@ import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:flutter/material.dart'; void main() { - WidgetsFlutterBinding.ensureInitialized(); runApp(MaterialApp( title: 'Remote Config Example', home: FutureBuilder( From 839defa34fc13abeee60fb1c7917b404122aa073 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 15:09:31 -0700 Subject: [PATCH 07/23] Revert "migrate" This reverts commit 78c882890126ba6788006cee9b042c7b3daecf67. --- .../FirebaseRemoteConfigPlugin.java | 190 ++---------------- .../MethodCallHandlerImpl.java | 181 +++++++++++++++++ .../android/app/src/main/AndroidManifest.xml | 11 +- .../EmbeddingV1Activity.java | 13 ++ .../MainActivity.java | 13 +- .../example/android/gradle.properties | 3 + .../example/lib/main.dart | 1 + 7 files changed, 234 insertions(+), 178 deletions(-) create mode 100644 packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java create mode 100644 packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java index d07a9ad1d57a..2db9b16bb827 100644 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java @@ -5,192 +5,40 @@ package io.flutter.plugins.firebase.firebaseremoteconfig; import android.content.Context; -import android.content.SharedPreferences; -import androidx.annotation.NonNull; -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.Task; -import com.google.firebase.remoteconfig.FirebaseRemoteConfig; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; -import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; -import io.flutter.plugin.common.MethodCall; +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry.Registrar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; /** FirebaseRemoteConfigPlugin */ -public class FirebaseRemoteConfigPlugin implements MethodCallHandler { +public class FirebaseRemoteConfigPlugin implements FlutterPlugin { - public static final String TAG = "FirebaseRemoteConfigPlugin"; - public static final String PREFS_NAME = + static final String TAG = "FirebaseRemoteConfigPlugin"; + static final String PREFS_NAME = "io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin"; - public static final String DEFAULT_PREF_KEY = "default_keys"; + static final String METHOD_CHANNEL = "plugins.flutter.io/firebase_remote_config"; - private static SharedPreferences sharedPreferences; + private MethodChannel channel; public static void registerWith(Registrar registrar) { - final MethodChannel channel = - new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_remote_config"); - channel.setMethodCallHandler(new FirebaseRemoteConfigPlugin()); - sharedPreferences = registrar.context().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + FirebaseRemoteConfigPlugin plugin = new FirebaseRemoteConfigPlugin(); + plugin.setupChannel(registrar.messenger(), registrar.context()); } @Override - public void onMethodCall(MethodCall call, final Result result) { - switch (call.method) { - case "RemoteConfig#instance": - { - FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = - FirebaseRemoteConfig.getInstance().getInfo(); - - Map properties = new HashMap<>(); - properties.put("lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); - properties.put( - "lastFetchStatus", mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); - properties.put( - "inDebugMode", firebaseRemoteConfigInfo.getConfigSettings().isDeveloperModeEnabled()); - properties.put("parameters", getConfigParameters()); - result.success(properties); - break; - } - case "RemoteConfig#setConfigSettings": - { - boolean debugMode = call.argument("debugMode"); - final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - FirebaseRemoteConfigSettings settings = - new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(debugMode).build(); - firebaseRemoteConfig.setConfigSettings(settings); - result.success(null); - break; - } - case "RemoteConfig#fetch": - { - long expiration = ((Number) call.argument("expiration")).longValue(); - final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - firebaseRemoteConfig - .fetch(expiration) - .addOnCompleteListener( - new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = - firebaseRemoteConfig.getInfo(); - Map properties = new HashMap<>(); - properties.put( - "lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); - properties.put( - "lastFetchStatus", - mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); - if (!task.isSuccessful()) { - final Exception exception = task.getException(); - - if (exception instanceof FirebaseRemoteConfigFetchThrottledException) { - properties.put( - "fetchThrottledEnd", - ((FirebaseRemoteConfigFetchThrottledException) exception) - .getThrottleEndTimeMillis()); - String errorMessage = - "Fetch has been throttled. See the error's " - + "FETCH_THROTTLED_END field for throttle end time."; - result.error("fetchFailedThrottled", errorMessage, properties); - } else { - String errorMessage = - "Unable to complete fetch. Reason is unknown " - + "but this could be due to lack of connectivity."; - result.error("fetchFailed", errorMessage, properties); - } - } else { - result.success(properties); - } - } - }); - break; - } - case "RemoteConfig#activate": - { - boolean newConfig = FirebaseRemoteConfig.getInstance().activateFetched(); - Map properties = new HashMap<>(); - properties.put("parameters", getConfigParameters()); - properties.put("newConfig", newConfig); - result.success(properties); - break; - } - case "RemoteConfig#setDefaults": - { - Map defaults = call.argument("defaults"); - FirebaseRemoteConfig.getInstance().setDefaults(defaults); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putStringSet(DEFAULT_PREF_KEY, defaults.keySet()).apply(); - result.success(null); - break; - } - default: - { - result.notImplemented(); - break; - } - } - } - - private Map getConfigParameters() { - FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); - Map parameterMap = new HashMap<>(); - Set keys = firebaseRemoteConfig.getKeysByPrefix(""); - for (String key : keys) { - FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(key); - parameterMap.put(key, createRemoteConfigValueMap(remoteConfigValue)); - } - // Add default parameters if missing since `getKeysByPrefix` does not return default keys. - Set defaultKeys = - sharedPreferences.getStringSet(DEFAULT_PREF_KEY, new HashSet()); - for (String defaultKey : defaultKeys) { - if (!parameterMap.containsKey(defaultKey)) { - FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(defaultKey); - parameterMap.put(defaultKey, createRemoteConfigValueMap(remoteConfigValue)); - } - } - return parameterMap; + public void onAttachedToEngine(FlutterPluginBinding binding) { + setupChannel(binding.getFlutterEngine().getDartExecutor(), binding.getApplicationContext()); } - private Map createRemoteConfigValueMap( - FirebaseRemoteConfigValue remoteConfigValue) { - Map valueMap = new HashMap<>(); - valueMap.put("value", remoteConfigValue.asByteArray()); - valueMap.put("source", mapValueSource(remoteConfigValue.getSource())); - return valueMap; - } - - private String mapLastFetchStatus(int status) { - switch (status) { - case FirebaseRemoteConfig.LAST_FETCH_STATUS_SUCCESS: - return "success"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_FAILURE: - return "failure"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED: - return "throttled"; - case FirebaseRemoteConfig.LAST_FETCH_STATUS_NO_FETCH_YET: - return "noFetchYet"; - default: - return "failure"; - } + @Override + public void onDetachedFromEngine(FlutterPluginBinding binding) { + channel = null; } - private String mapValueSource(int source) { - switch (source) { - case FirebaseRemoteConfig.VALUE_SOURCE_STATIC: - return "static"; - case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT: - return "default"; - case FirebaseRemoteConfig.VALUE_SOURCE_REMOTE: - return "remote"; - default: - return "static"; - } + private void setupChannel(BinaryMessenger messenger, Context context) { + MethodCallHandlerImpl handler = + new MethodCallHandlerImpl(context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)); + channel = new MethodChannel(messenger, METHOD_CHANNEL); + channel.setMethodCallHandler(handler); } } diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java new file mode 100644 index 000000000000..5c59bad7f116 --- /dev/null +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java @@ -0,0 +1,181 @@ +package io.flutter.plugins.firebase.firebaseremoteconfig; + +import android.content.SharedPreferences; +import androidx.annotation.NonNull; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.remoteconfig.FirebaseRemoteConfig; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler { + + private static final String DEFAULT_PREF_KEY = "default_keys"; + + private static SharedPreferences sharedPreferences; + + MethodCallHandlerImpl(@NonNull SharedPreferences sharedPreferences) { + this.sharedPreferences = sharedPreferences; + } + + @Override + public void onMethodCall(MethodCall call, final MethodChannel.Result result) { + switch (call.method) { + case "RemoteConfig#instance": + { + FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = + FirebaseRemoteConfig.getInstance().getInfo(); + + Map properties = new HashMap<>(); + properties.put("lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); + properties.put( + "lastFetchStatus", mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); + properties.put( + "inDebugMode", firebaseRemoteConfigInfo.getConfigSettings().isDeveloperModeEnabled()); + properties.put("parameters", getConfigParameters()); + result.success(properties); + break; + } + case "RemoteConfig#setConfigSettings": + { + boolean debugMode = call.argument("debugMode"); + final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + FirebaseRemoteConfigSettings settings = + new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(debugMode).build(); + firebaseRemoteConfig.setConfigSettings(settings); + result.success(null); + break; + } + case "RemoteConfig#fetch": + { + long expiration = ((Number) call.argument("expiration")).longValue(); + final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + firebaseRemoteConfig + .fetch(expiration) + .addOnCompleteListener( + new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = + firebaseRemoteConfig.getInfo(); + Map properties = new HashMap<>(); + properties.put( + "lastFetchTime", firebaseRemoteConfigInfo.getFetchTimeMillis()); + properties.put( + "lastFetchStatus", + mapLastFetchStatus(firebaseRemoteConfigInfo.getLastFetchStatus())); + if (!task.isSuccessful()) { + final Exception exception = task.getException(); + + if (exception instanceof FirebaseRemoteConfigFetchThrottledException) { + properties.put( + "fetchThrottledEnd", + ((FirebaseRemoteConfigFetchThrottledException) exception) + .getThrottleEndTimeMillis()); + String errorMessage = + "Fetch has been throttled. See the error's " + + "FETCH_THROTTLED_END field for throttle end time."; + result.error("fetchFailedThrottled", errorMessage, properties); + } else { + String errorMessage = + "Unable to complete fetch. Reason is unknown " + + "but this could be due to lack of connectivity."; + result.error("fetchFailed", errorMessage, properties); + } + } else { + result.success(properties); + } + } + }); + break; + } + case "RemoteConfig#activate": + { + boolean newConfig = FirebaseRemoteConfig.getInstance().activateFetched(); + Map properties = new HashMap<>(); + properties.put("parameters", getConfigParameters()); + properties.put("newConfig", newConfig); + result.success(properties); + break; + } + case "RemoteConfig#setDefaults": + { + Map defaults = call.argument("defaults"); + FirebaseRemoteConfig.getInstance().setDefaults(defaults); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putStringSet(DEFAULT_PREF_KEY, defaults.keySet()).apply(); + result.success(null); + break; + } + default: + { + result.notImplemented(); + break; + } + } + } + + private Map getConfigParameters() { + FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); + Map parameterMap = new HashMap<>(); + Set keys = firebaseRemoteConfig.getKeysByPrefix(""); + for (String key : keys) { + FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(key); + parameterMap.put(key, createRemoteConfigValueMap(remoteConfigValue)); + } + // Add default parameters if missing since `getKeysByPrefix` does not return default keys. + Set defaultKeys = + sharedPreferences.getStringSet(DEFAULT_PREF_KEY, new HashSet()); + for (String defaultKey : defaultKeys) { + if (!parameterMap.containsKey(defaultKey)) { + FirebaseRemoteConfigValue remoteConfigValue = firebaseRemoteConfig.getValue(defaultKey); + parameterMap.put(defaultKey, createRemoteConfigValueMap(remoteConfigValue)); + } + } + return parameterMap; + } + + private Map createRemoteConfigValueMap( + FirebaseRemoteConfigValue remoteConfigValue) { + Map valueMap = new HashMap<>(); + valueMap.put("value", remoteConfigValue.asByteArray()); + valueMap.put("source", mapValueSource(remoteConfigValue.getSource())); + return valueMap; + } + + private String mapLastFetchStatus(int status) { + switch (status) { + case FirebaseRemoteConfig.LAST_FETCH_STATUS_SUCCESS: + return "success"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_FAILURE: + return "failure"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED: + return "throttled"; + case FirebaseRemoteConfig.LAST_FETCH_STATUS_NO_FETCH_YET: + return "noFetchYet"; + default: + return "failure"; + } + } + + private String mapValueSource(int source) { + switch (source) { + case FirebaseRemoteConfig.VALUE_SOURCE_STATIC: + return "static"; + case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT: + return "default"; + case FirebaseRemoteConfig.VALUE_SOURCE_REMOTE: + return "remote"; + default: + return "static"; + } + } +} diff --git a/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml b/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml index fe4292fe0322..7100b12a4e6e 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml +++ b/packages/firebase_remote_config/example/android/app/src/main/AndroidManifest.xml @@ -17,8 +17,9 @@ android:label="firebase_remote_config_example" android:icon="@mipmap/ic_launcher"> + + diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java new file mode 100644 index 000000000000..2af625cab23d --- /dev/null +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java @@ -0,0 +1,13 @@ +package io.flutter.plugins.firebase.firebaseremoteconfigexample; + +import android.os.Bundle; +import io.flutter.app.FlutterActivity; +import io.flutter.plugins.GeneratedPluginRegistrant; + +public class EmbeddingV1Activity extends FlutterActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } +} diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index ef048c74f4df..a03548b6e845 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -1,13 +1,14 @@ package io.flutter.plugins.firebase.firebaseremoteconfigexample; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin; public class MainActivity extends FlutterActivity { + @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); + public void configureFlutterEngine(FlutterEngine flutterEngine) { + super.configureFlutterEngine(flutterEngine); + flutterEngine.getPlugins().add(new FirebaseRemoteConfigPlugin()); } } diff --git a/packages/firebase_remote_config/example/android/gradle.properties b/packages/firebase_remote_config/example/android/gradle.properties index 8bd86f680510..a5965ab8dced 100644 --- a/packages/firebase_remote_config/example/android/gradle.properties +++ b/packages/firebase_remote_config/example/android/gradle.properties @@ -1 +1,4 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/packages/firebase_remote_config/example/lib/main.dart b/packages/firebase_remote_config/example/lib/main.dart index 8db737372086..89a7d6de387e 100644 --- a/packages/firebase_remote_config/example/lib/main.dart +++ b/packages/firebase_remote_config/example/lib/main.dart @@ -8,6 +8,7 @@ import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:flutter/material.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); runApp(MaterialApp( title: 'Remote Config Example', home: FutureBuilder( From 46b97e8c8b1c92189bb607c6e9699eed2db38be4 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 15:13:34 -0700 Subject: [PATCH 08/23] add firebase core dependency in example app --- .../firebase/firebaseremoteconfigexample/MainActivity.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index a03548b6e845..078bb260ecf4 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -2,6 +2,8 @@ import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry; +import io.flutter.plugins.firebase.core.FirebaseCorePlugin; import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin; public class MainActivity extends FlutterActivity { @@ -10,5 +12,9 @@ public class MainActivity extends FlutterActivity { public void configureFlutterEngine(FlutterEngine flutterEngine) { super.configureFlutterEngine(flutterEngine); flutterEngine.getPlugins().add(new FirebaseRemoteConfigPlugin()); + + ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine); + FirebaseCorePlugin.registerWith( + shimPluginRegistry.registrarFor("io.flutter.plugins.firebase.core.FirebaseCorePlugin")); } } From e592f6a5851583bb5baafbee57e3d11efc26bbd9 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 15:59:59 -0700 Subject: [PATCH 09/23] Update gradle.properties --- .../firebase_remote_config/example/android/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_remote_config/example/android/gradle.properties b/packages/firebase_remote_config/example/android/gradle.properties index a5965ab8dced..38c8d4544ff1 100644 --- a/packages/firebase_remote_config/example/android/gradle.properties +++ b/packages/firebase_remote_config/example/android/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.enableR8=true android.useAndroidX=true -android.enableJetifier=true \ No newline at end of file +android.enableJetifier=true From 1dcd55f20886eb9693adabdfd8edb35553ee68eb Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 16:06:56 -0700 Subject: [PATCH 10/23] Update MethodCallHandlerImpl.java --- .../firebase/firebaseremoteconfig/MethodCallHandlerImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java index 5c59bad7f116..d56b5df4f2a7 100644 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java @@ -1,3 +1,7 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. // found in the LICENSE file. + package io.flutter.plugins.firebase.firebaseremoteconfig; import android.content.SharedPreferences; From 4f0c1df7569201e87aea8d35fc78fc34afa853c3 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 16:07:14 -0700 Subject: [PATCH 11/23] Update EmbeddingV1Activity.java --- .../firebaseremoteconfigexample/EmbeddingV1Activity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java index 2af625cab23d..de38f44e080a 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java @@ -1,3 +1,7 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. // found in the LICENSE file. + package io.flutter.plugins.firebase.firebaseremoteconfigexample; import android.os.Bundle; From a27c3cd26006422ab3c4b1bbe85729ff4cb29f6f Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 16:07:34 -0700 Subject: [PATCH 12/23] Update MainActivity.java --- .../firebase/firebaseremoteconfigexample/MainActivity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index 078bb260ecf4..1fb8d046a77e 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -1,3 +1,7 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. // found in the LICENSE file. + package io.flutter.plugins.firebase.firebaseremoteconfigexample; import io.flutter.embedding.android.FlutterActivity; From bc2f587354c642c8bfba2c7ec87826a4e7218766 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 16:09:52 -0700 Subject: [PATCH 13/23] Update MethodCallHandlerImpl.java --- .../firebaseremoteconfig/MethodCallHandlerImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java index d56b5df4f2a7..9de05029ae70 100644 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java @@ -1,6 +1,6 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. // found in the LICENSE file. +// 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.firebase.firebaseremoteconfig; From 593e84f9646372ef779c7fd026d39bf57f8e6a72 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 16:10:08 -0700 Subject: [PATCH 14/23] Update EmbeddingV1Activity.java --- .../firebaseremoteconfigexample/EmbeddingV1Activity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java index de38f44e080a..37b8ecf074fa 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java @@ -1,6 +1,6 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. // found in the LICENSE file. +// 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.firebase.firebaseremoteconfigexample; From ca428a811ecb8a0f8b0e843e24edcf310cbdea79 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 8 Oct 2019 16:10:18 -0700 Subject: [PATCH 15/23] Update MainActivity.java --- .../firebase/firebaseremoteconfigexample/MainActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index 1fb8d046a77e..39e754e41cff 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -1,6 +1,6 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. // found in the LICENSE file. +// 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.firebase.firebaseremoteconfigexample; From 1f1359c1b11b589422d273229d37f1af97628e90 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 11 Oct 2019 14:08:10 -0700 Subject: [PATCH 16/23] fix gradle --- .../android/build.gradle | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/firebase_remote_config/android/build.gradle b/packages/firebase_remote_config/android/build.gradle index b4eb1e6158d7..74a1de7b1135 100644 --- a/packages/firebase_remote_config/android/build.gradle +++ b/packages/firebase_remote_config/android/build.gradle @@ -52,3 +52,27 @@ android { } apply from: file("./user-agent.gradle") + +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 = "2.1.0" + api "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" + api "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" + } + } + } +} From 6721ca41b92b9db4f6d4624a8b7ab8d62769200b Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 15 Oct 2019 16:11:27 -0700 Subject: [PATCH 17/23] Update MainActivity.java --- .../firebase/firebaseremoteconfigexample/MainActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index 39e754e41cff..e62eafc771c7 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -12,6 +12,8 @@ public class MainActivity extends FlutterActivity { + // TODO(cyanglaz): Remove this once v2 of GeneratedPluginRegistrant rolls to stable. + // https://github.com/flutter/flutter/issues/42694 @Override public void configureFlutterEngine(FlutterEngine flutterEngine) { super.configureFlutterEngine(flutterEngine); From 9ed474587760712f17a6d2b8902fcc2aeaaa4748 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 12 Nov 2019 21:17:20 -0800 Subject: [PATCH 18/23] Update MainActivity.java --- .../firebase/firebaseremoteconfigexample/MainActivity.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index e62eafc771c7..a26cd421d6d0 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -4,6 +4,7 @@ package io.flutter.plugins.firebase.firebaseremoteconfigexample; +import dev.flutter.plugins.e2e.E2EPlugin; import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry; @@ -18,9 +19,6 @@ public class MainActivity extends FlutterActivity { public void configureFlutterEngine(FlutterEngine flutterEngine) { super.configureFlutterEngine(flutterEngine); flutterEngine.getPlugins().add(new FirebaseRemoteConfigPlugin()); - - ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine); - FirebaseCorePlugin.registerWith( - shimPluginRegistry.registrarFor("io.flutter.plugins.firebase.core.FirebaseCorePlugin")); + flutterEngine.getPlugins().add(new E2EPlugin()); } } From ab84f7b7eaaafde381d4509d1dbf6ea1620edaa7 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 13 Nov 2019 08:36:30 -0800 Subject: [PATCH 19/23] adding e2d tests --- packages/firebase_remote_config/CHANGELOG.md | 5 +++++ .../firebase_remote_config/android/build.gradle | 7 ++++--- .../FirebaseRemoteConfigPlugin.java | 7 ++++++- .../MethodCallHandlerImpl.java | 7 +++---- .../EmbeddingV1ActivityTest.java | 17 +++++++++++++++++ .../MainActivityTest.java | 15 +++++++++++++++ .../firebase_remote_config/example/pubspec.yaml | 5 +++++ ...fig.dart => firebase_remote_config_e2e.dart} | 9 +++------ .../firebase_remote_config_e2e_test.dart | 11 +++++++++++ .../firebase_remote_config_test.dart | 7 ------- packages/firebase_remote_config/pubspec.yaml | 5 +++-- 11 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java create mode 100644 packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java rename packages/firebase_remote_config/example/test_driver/{firebase_remote_config.dart => firebase_remote_config_e2e.dart} (82%) create mode 100644 packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart delete mode 100644 packages/firebase_remote_config/example/test_driver/firebase_remote_config_test.dart diff --git a/packages/firebase_remote_config/CHANGELOG.md b/packages/firebase_remote_config/CHANGELOG.md index 7bc7823f783f..ea060e93b5c2 100644 --- a/packages/firebase_remote_config/CHANGELOG.md +++ b/packages/firebase_remote_config/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.1 + +* Support Android V2 embedding. +* Migrate to using the new e2e test binding. + ## 0.2.0+7 * Fix `Bad state: Future already completed` error when initially diff --git a/packages/firebase_remote_config/android/build.gradle b/packages/firebase_remote_config/android/build.gradle index 74a1de7b1135..b44ef3401bbf 100644 --- a/packages/firebase_remote_config/android/build.gradle +++ b/packages/firebase_remote_config/android/build.gradle @@ -69,9 +69,10 @@ afterEvaluate { if (!containsEmbeddingDependencies) { android { dependencies { - def lifecycle_version = "2.1.0" - api "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" - api "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" + def lifecycle_version = "1.1.1" + compileOnly "android.arch.lifecycle:runtime:$lifecycle_version" + compileOnly "android.arch.lifecycle:common:$lifecycle_version" + compileOnly "android.arch.lifecycle:common-java8:$lifecycle_version" } } } diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java index 2db9b16bb827..faee7bd4a26a 100644 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java @@ -32,7 +32,7 @@ public void onAttachedToEngine(FlutterPluginBinding binding) { @Override public void onDetachedFromEngine(FlutterPluginBinding binding) { - channel = null; + tearDownChannel(); } private void setupChannel(BinaryMessenger messenger, Context context) { @@ -41,4 +41,9 @@ private void setupChannel(BinaryMessenger messenger, Context context) { channel = new MethodChannel(messenger, METHOD_CHANNEL); channel.setMethodCallHandler(handler); } + + private void tearDownChannel() { + channel.setMethodCallHandler(null); + channel = null; + } } diff --git a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java index 9de05029ae70..c377554a9733 100644 --- a/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java +++ b/packages/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/MethodCallHandlerImpl.java @@ -5,7 +5,6 @@ package io.flutter.plugins.firebase.firebaseremoteconfig; import android.content.SharedPreferences; -import androidx.annotation.NonNull; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.remoteconfig.FirebaseRemoteConfig; @@ -26,8 +25,8 @@ class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler { private static SharedPreferences sharedPreferences; - MethodCallHandlerImpl(@NonNull SharedPreferences sharedPreferences) { - this.sharedPreferences = sharedPreferences; + MethodCallHandlerImpl(SharedPreferences sharedPreferences) { + MethodCallHandlerImpl.sharedPreferences = sharedPreferences; } @Override @@ -67,7 +66,7 @@ public void onMethodCall(MethodCall call, final MethodChannel.Result result) { .addOnCompleteListener( new OnCompleteListener() { @Override - public void onComplete(@NonNull Task task) { + public void onComplete(Task task) { FirebaseRemoteConfigInfo firebaseRemoteConfigInfo = firebaseRemoteConfig.getInfo(); Map properties = new HashMap<>(); diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java new file mode 100644 index 000000000000..09ebef3aa80b --- /dev/null +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java @@ -0,0 +1,17 @@ +// 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.firebase.firebaseremoteconfigexample; + +import androidx.test.rule.ActivityTestRule; +import dev.flutter.plugins.e2e.FlutterRunner; +import org.junit.Rule; +import org.junit.runner.RunWith; + +@RunWith(FlutterRunner.class) +public class EmbeddingV1ActivityTest { + @Rule + public ActivityTestRule rule = + new ActivityTestRule<>(EmbeddingV1Activity.class); +} \ No newline at end of file diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java new file mode 100644 index 000000000000..d5933a3ca6d3 --- /dev/null +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java @@ -0,0 +1,15 @@ +// 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.firebase.firebaseremoteconfigexample; + +import androidx.test.rule.ActivityTestRule; +import dev.flutter.plugins.e2e.FlutterRunner; +import org.junit.Rule; +import org.junit.runner.RunWith; + +@RunWith(FlutterRunner.class) +public class MainActivityTest { + @Rule public ActivityTestRule rule = new ActivityTestRule<>(MainActivity.class); +} \ No newline at end of file diff --git a/packages/firebase_remote_config/example/pubspec.yaml b/packages/firebase_remote_config/example/pubspec.yaml index 06c9b5bea711..e633e0e6dd5c 100644 --- a/packages/firebase_remote_config/example/pubspec.yaml +++ b/packages/firebase_remote_config/example/pubspec.yaml @@ -18,3 +18,8 @@ dev_dependencies: flutter_driver: sdk: flutter test: any + e2e: ^0.2.0 + +environment: + sdk: ">=2.0.0-dev.28.0 <3.0.0" + flutter: ">=1.9.1+hotfix.2 <2.0.0" \ No newline at end of file diff --git a/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart b/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart similarity index 82% rename from packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart rename to packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart index 2514b2a08a1d..5748e2cf1823 100644 --- a/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart +++ b/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart @@ -1,12 +1,9 @@ -import 'dart:async'; -import 'package:flutter_driver/driver_extension.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:e2e/e2e.dart'; import 'package:firebase_remote_config/firebase_remote_config.dart'; void main() { - final Completer completer = Completer(); - enableFlutterDriverExtension(handler: (_) => completer.future); - tearDownAll(() => completer.complete(null)); + E2EWidgetsFlutterBinding.ensureInitialized(); group('$RemoteConfig', () { RemoteConfig remoteConfig; @@ -21,7 +18,7 @@ void main() { }); }); - test('fetch', () async { + testWidgets('fetch', (WidgetTester tester) async { final DateTime lastFetchTime = remoteConfig.lastFetchTime; expect(lastFetchTime.isBefore(DateTime.now()), true); await remoteConfig.fetch(expiration: const Duration(seconds: 0)); diff --git a/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart b/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart new file mode 100644 index 000000000000..4ebcfe11ad4d --- /dev/null +++ b/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart @@ -0,0 +1,11 @@ +import 'dart:async'; +import 'dart:io'; +import 'package:flutter_driver/flutter_driver.dart'; + +Future main() async { + final FlutterDriver driver = await FlutterDriver.connect(); + final String result = + await driver.requestData(null, timeout: const Duration(minutes: 1)); + driver.close(); + exit(result == 'pass' ? 0 : 1); +} \ No newline at end of file diff --git a/packages/firebase_remote_config/example/test_driver/firebase_remote_config_test.dart b/packages/firebase_remote_config/example/test_driver/firebase_remote_config_test.dart deleted file mode 100644 index 38fe6c447e05..000000000000 --- a/packages/firebase_remote_config/example/test_driver/firebase_remote_config_test.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:flutter_driver/flutter_driver.dart'; - -Future main() async { - final FlutterDriver driver = await FlutterDriver.connect(); - await driver.requestData(null, timeout: const Duration(minutes: 1)); - driver.close(); -} diff --git a/packages/firebase_remote_config/pubspec.yaml b/packages/firebase_remote_config/pubspec.yaml index 48de94cafc12..f448aedb32c0 100644 --- a/packages/firebase_remote_config/pubspec.yaml +++ b/packages/firebase_remote_config/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Remote Config. Update your application re-releasing. author: Flutter Team homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_remote_config -version: 0.2.0+7 +version: 0.2.1 dependencies: flutter: @@ -16,6 +16,7 @@ dev_dependencies: flutter_driver: sdk: flutter test: any + e2e: ^0.2.0 flutter: plugin: @@ -24,4 +25,4 @@ flutter: environment: sdk: ">=2.0.0-dev.28.0 <3.0.0" - flutter: ">=1.5.0 <2.0.0" + flutter: ">=1.9.1+hotfix.2 <2.0.0" From 86a66aef41b2da5a46aea5a516dfa955de0a529a Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 13 Nov 2019 08:47:58 -0800 Subject: [PATCH 20/23] formatting --- .../firebaseremoteconfigexample/EmbeddingV1ActivityTest.java | 2 +- .../firebase/firebaseremoteconfigexample/MainActivity.java | 2 -- .../firebase/firebaseremoteconfigexample/MainActivityTest.java | 2 +- .../example/test_driver/firebase_remote_config_e2e_test.dart | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java index 09ebef3aa80b..b7ab6b3f5b55 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java @@ -14,4 +14,4 @@ public class EmbeddingV1ActivityTest { @Rule public ActivityTestRule rule = new ActivityTestRule<>(EmbeddingV1Activity.class); -} \ No newline at end of file +} diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index a26cd421d6d0..f789fe74e535 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -7,8 +7,6 @@ import dev.flutter.plugins.e2e.E2EPlugin; import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine; -import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry; -import io.flutter.plugins.firebase.core.FirebaseCorePlugin; import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin; public class MainActivity extends FlutterActivity { diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java index d5933a3ca6d3..3531b55a3fdc 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivityTest.java @@ -12,4 +12,4 @@ @RunWith(FlutterRunner.class) public class MainActivityTest { @Rule public ActivityTestRule rule = new ActivityTestRule<>(MainActivity.class); -} \ No newline at end of file +} diff --git a/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart b/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart index 4ebcfe11ad4d..bcfa86da4455 100644 --- a/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart +++ b/packages/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart @@ -8,4 +8,4 @@ Future main() async { await driver.requestData(null, timeout: const Duration(minutes: 1)); driver.close(); exit(result == 'pass' ? 0 : 1); -} \ No newline at end of file +} From 4523a3b5df243bb6d3bc26e4f27e463979084485 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 13 Nov 2019 09:01:13 -0800 Subject: [PATCH 21/23] revert local change to firebase core --- .../firebase/core/FirebaseCoreHandler.java | 85 ------------------- .../firebase/core/FirebaseCorePlugin.java | 17 +++- .../firebasecoreexample/MainActivity2.java | 12 --- 3 files changed, 13 insertions(+), 101 deletions(-) delete mode 100644 packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java delete mode 100644 packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java diff --git a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java deleted file mode 100644 index b8afa518e212..000000000000 --- a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCoreHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -package io.flutter.plugins.firebase.core; - -import android.content.Context; -import com.google.firebase.FirebaseApp; -import com.google.firebase.FirebaseOptions; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class FirebaseCoreHandler implements MethodChannel.MethodCallHandler { - private final Context context; - - FirebaseCoreHandler(Context context) { - this.context = context; - } - - private Map asMap(FirebaseApp app) { - Map appMap = new HashMap<>(); - appMap.put("name", app.getName()); - FirebaseOptions options = app.getOptions(); - Map optionsMap = new HashMap<>(); - optionsMap.put("googleAppID", options.getApplicationId()); - optionsMap.put("GCMSenderID", options.getGcmSenderId()); - optionsMap.put("APIKey", options.getApiKey()); - optionsMap.put("databaseURL", options.getDatabaseUrl()); - optionsMap.put("storageBucket", options.getStorageBucket()); - optionsMap.put("projectID", options.getProjectId()); - appMap.put("options", optionsMap); - return appMap; - } - - @Override - public void onMethodCall(MethodCall call, final MethodChannel.Result result) { - switch (call.method) { - case "FirebaseApp#configure": - { - Map arguments = call.arguments(); - String name = (String) arguments.get("name"); - @SuppressWarnings("unchecked") - Map optionsMap = (Map) arguments.get("options"); - FirebaseOptions options = - new FirebaseOptions.Builder() - .setApiKey(optionsMap.get("APIKey")) - .setApplicationId(optionsMap.get("googleAppID")) - .setDatabaseUrl(optionsMap.get("databaseURL")) - .setGcmSenderId(optionsMap.get("GCMSenderID")) - .setProjectId(optionsMap.get("projectID")) - .setStorageBucket(optionsMap.get("storageBucket")) - .build(); - FirebaseApp.initializeApp(context, options, name); - result.success(null); - break; - } - case "FirebaseApp#allApps": - { - List> apps = new ArrayList<>(); - for (FirebaseApp app : FirebaseApp.getApps(context)) { - apps.add(asMap(app)); - } - result.success(apps); - break; - } - case "FirebaseApp#appNamed": - { - String name = call.arguments(); - try { - FirebaseApp app = FirebaseApp.getInstance(name); - result.success(asMap(app)); - } catch (IllegalStateException ex) { - // App doesn't exist, so successfully return null. - result.success(null); - } - break; - } - default: - { - result.notImplemented(); - break; - } - } - } -} diff --git a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java index 228cd221318f..c99ab401535a 100644 --- a/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java +++ b/packages/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java @@ -62,10 +62,19 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) { applicationContext = null; } - @Override - public void onAttachedToEngine(FlutterPluginBinding binding) { - channel = new MethodChannel(binding.getFlutterEngine().getDartExecutor(), CHANNEL_NAME); - channel.setMethodCallHandler(new FirebaseCoreHandler(binding.getApplicationContext())); + private Map asMap(FirebaseApp app) { + Map appMap = new HashMap<>(); + appMap.put("name", app.getName()); + FirebaseOptions options = app.getOptions(); + Map optionsMap = new HashMap<>(); + optionsMap.put("googleAppID", options.getApplicationId()); + optionsMap.put("GCMSenderID", options.getGcmSenderId()); + optionsMap.put("APIKey", options.getApiKey()); + optionsMap.put("databaseURL", options.getDatabaseUrl()); + optionsMap.put("storageBucket", options.getStorageBucket()); + optionsMap.put("projectID", options.getProjectId()); + appMap.put("options", optionsMap); + return appMap; } @Override diff --git a/packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java b/packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java deleted file mode 100644 index ba70fda18a71..000000000000 --- a/packages/firebase_core/example/android/app/src/main/java/io/flutter/plugins/firebasecoreexample/MainActivity2.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.flutter.plugins.firebasecoreexample; - -import io.flutter.embedding.android.FlutterActivity; -import io.flutter.embedding.engine.FlutterEngine; -import io.flutter.plugins.firebase.core.FirebaseCorePlugin; - -public class MainActivity2 extends FlutterActivity { - @Override - public void configureFlutterEngine(FlutterEngine flutterEngine) { - flutterEngine.getPlugins().add(new FirebaseCorePlugin()); - } -} From 9a7e3715dca9f3eefd02773bcd927893084b08f4 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 13 Nov 2019 09:05:26 -0800 Subject: [PATCH 22/23] Update pubspec.yaml --- packages/firebase_remote_config/example/pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/firebase_remote_config/example/pubspec.yaml b/packages/firebase_remote_config/example/pubspec.yaml index e633e0e6dd5c..d20c6ac987fe 100644 --- a/packages/firebase_remote_config/example/pubspec.yaml +++ b/packages/firebase_remote_config/example/pubspec.yaml @@ -22,4 +22,5 @@ dev_dependencies: environment: sdk: ">=2.0.0-dev.28.0 <3.0.0" - flutter: ">=1.9.1+hotfix.2 <2.0.0" \ No newline at end of file + flutter: ">=1.9.1+hotfix.2 <2.0.0" + From a85b301642dd1cbd0dd00bd02ca2277c389eb2c3 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 13 Nov 2019 19:49:08 -0800 Subject: [PATCH 23/23] update firebase core dependency --- .../firebase/firebaseremoteconfigexample/MainActivity.java | 4 ++-- packages/firebase_remote_config/example/pubspec.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java index f789fe74e535..491f04a7b0a6 100644 --- a/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java +++ b/packages/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/MainActivity.java @@ -4,9 +4,9 @@ package io.flutter.plugins.firebase.firebaseremoteconfigexample; -import dev.flutter.plugins.e2e.E2EPlugin; import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugins.firebase.core.FirebaseCorePlugin; import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin; public class MainActivity extends FlutterActivity { @@ -17,6 +17,6 @@ public class MainActivity extends FlutterActivity { public void configureFlutterEngine(FlutterEngine flutterEngine) { super.configureFlutterEngine(flutterEngine); flutterEngine.getPlugins().add(new FirebaseRemoteConfigPlugin()); - flutterEngine.getPlugins().add(new E2EPlugin()); + flutterEngine.getPlugins().add(new FirebaseCorePlugin()); } } diff --git a/packages/firebase_remote_config/example/pubspec.yaml b/packages/firebase_remote_config/example/pubspec.yaml index d20c6ac987fe..77e4a07a48da 100644 --- a/packages/firebase_remote_config/example/pubspec.yaml +++ b/packages/firebase_remote_config/example/pubspec.yaml @@ -10,7 +10,7 @@ dependencies: cupertino_icons: ^0.1.0 firebase_remote_config: path: ../ - firebase_core: ^0.4.0 + firebase_core: ^0.4.1 dev_dependencies: flutter_test: @@ -23,4 +23,4 @@ dev_dependencies: environment: sdk: ">=2.0.0-dev.28.0 <3.0.0" flutter: ">=1.9.1+hotfix.2 <2.0.0" - +