[device_info] started using Background Platform Channels (#4456)
diff --git a/packages/device_info/device_info/CHANGELOG.md b/packages/device_info/device_info/CHANGELOG.md
index 97349d4..cdcb906 100644
--- a/packages/device_info/device_info/CHANGELOG.md
+++ b/packages/device_info/device_info/CHANGELOG.md
@@ -1,7 +1,8 @@
-## NEXT
+## 2.0.3
* Remove references to the Android V1 embedding.
* Updated Android lint settings.
+* Started using Background Platform Channels when available.
## 2.0.2
diff --git a/packages/device_info/device_info/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java b/packages/device_info/device_info/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java
index 9b766d7..756f5e0 100644
--- a/packages/device_info/device_info/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java
+++ b/packages/device_info/device_info/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java
@@ -5,13 +5,18 @@
package io.flutter.plugins.deviceinfo;
import android.content.Context;
+import android.util.Log;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
+import io.flutter.plugin.common.MethodCodec;
+import io.flutter.plugin.common.StandardMethodCodec;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
/** DeviceInfoPlugin */
public class DeviceInfoPlugin implements FlutterPlugin {
-
+ static final String TAG = "DeviceInfoPlugin";
MethodChannel channel;
/** Plugin registration. */
@@ -32,7 +37,24 @@
}
private void setupMethodChannel(BinaryMessenger messenger, Context context) {
- channel = new MethodChannel(messenger, "plugins.flutter.io/device_info");
+ String channelName = "plugins.flutter.io/device_info";
+ // TODO(gaaclarke): Remove reflection guard when https://github.com/flutter/engine/pull/29147
+ // becomes available on the stable branch.
+ try {
+ Class methodChannelClass = Class.forName("io.flutter.plugin.common.MethodChannel");
+ Class taskQueueClass = Class.forName("io.flutter.plugin.common.BinaryMessenger$TaskQueue");
+ Method makeBackgroundTaskQueue = messenger.getClass().getMethod("makeBackgroundTaskQueue");
+ Object taskQueue = makeBackgroundTaskQueue.invoke(messenger);
+ Constructor<MethodChannel> constructor =
+ methodChannelClass.getConstructor(
+ BinaryMessenger.class, String.class, MethodCodec.class, taskQueueClass);
+ channel =
+ constructor.newInstance(messenger, channelName, StandardMethodCodec.INSTANCE, taskQueue);
+ Log.d(TAG, "Use TaskQueues.");
+ } catch (Exception ex) {
+ channel = new MethodChannel(messenger, channelName);
+ Log.d(TAG, "Don't use TaskQueues.");
+ }
final MethodCallHandlerImpl handler =
new MethodCallHandlerImpl(context.getContentResolver(), context.getPackageManager());
channel.setMethodCallHandler(handler);
diff --git a/packages/device_info/device_info/pubspec.yaml b/packages/device_info/device_info/pubspec.yaml
index c5830f4..d557e49 100644
--- a/packages/device_info/device_info/pubspec.yaml
+++ b/packages/device_info/device_info/pubspec.yaml
@@ -3,7 +3,7 @@
(make, model, etc.), and Android or iOS version the app is running on.
repository: https://github.com/flutter/plugins/tree/master/packages/device_info/device_info
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+device_info%22
-version: 2.0.2
+version: 2.0.3
environment:
sdk: ">=2.12.0 <3.0.0"