Skip to content

Commit 9ac6da7

Browse files
authored
[device_info] started using Background Platform Channels (flutter#4456)
1 parent 34caa5f commit 9ac6da7

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

packages/device_info/device_info/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## NEXT
1+
## 2.0.3
22

33
* Remove references to the Android V1 embedding.
44
* Updated Android lint settings.
5+
* Started using Background Platform Channels when available.
56

67
## 2.0.2
78

packages/device_info/device_info/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
package io.flutter.plugins.deviceinfo;
66

77
import android.content.Context;
8+
import android.util.Log;
89
import io.flutter.embedding.engine.plugins.FlutterPlugin;
910
import io.flutter.plugin.common.BinaryMessenger;
1011
import io.flutter.plugin.common.MethodChannel;
12+
import io.flutter.plugin.common.MethodCodec;
13+
import io.flutter.plugin.common.StandardMethodCodec;
14+
import java.lang.reflect.Constructor;
15+
import java.lang.reflect.Method;
1116

1217
/** DeviceInfoPlugin */
1318
public class DeviceInfoPlugin implements FlutterPlugin {
14-
19+
static final String TAG = "DeviceInfoPlugin";
1520
MethodChannel channel;
1621

1722
/** Plugin registration. */
@@ -32,7 +37,24 @@ public void onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding binding) {
3237
}
3338

3439
private void setupMethodChannel(BinaryMessenger messenger, Context context) {
35-
channel = new MethodChannel(messenger, "plugins.flutter.io/device_info");
40+
String channelName = "plugins.flutter.io/device_info";
41+
// TODO(gaaclarke): Remove reflection guard when https://github.com/flutter/engine/pull/29147
42+
// becomes available on the stable branch.
43+
try {
44+
Class methodChannelClass = Class.forName("io.flutter.plugin.common.MethodChannel");
45+
Class taskQueueClass = Class.forName("io.flutter.plugin.common.BinaryMessenger$TaskQueue");
46+
Method makeBackgroundTaskQueue = messenger.getClass().getMethod("makeBackgroundTaskQueue");
47+
Object taskQueue = makeBackgroundTaskQueue.invoke(messenger);
48+
Constructor<MethodChannel> constructor =
49+
methodChannelClass.getConstructor(
50+
BinaryMessenger.class, String.class, MethodCodec.class, taskQueueClass);
51+
channel =
52+
constructor.newInstance(messenger, channelName, StandardMethodCodec.INSTANCE, taskQueue);
53+
Log.d(TAG, "Use TaskQueues.");
54+
} catch (Exception ex) {
55+
channel = new MethodChannel(messenger, channelName);
56+
Log.d(TAG, "Don't use TaskQueues.");
57+
}
3658
final MethodCallHandlerImpl handler =
3759
new MethodCallHandlerImpl(context.getContentResolver(), context.getPackageManager());
3860
channel.setMethodCallHandler(handler);

packages/device_info/device_info/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin providing detailed information about the device
33
(make, model, etc.), and Android or iOS version the app is running on.
44
repository: https://github.com/flutter/plugins/tree/master/packages/device_info/device_info
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+device_info%22
6-
version: 2.0.2
6+
version: 2.0.3
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)