Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[device_info] started using Background Platform Channels (#4456)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored Oct 28, 2021
1 parent 34caa5f commit 9ac6da7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/device_info/device_info/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -32,7 +37,24 @@ public void onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding binding) {
}

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);
Expand Down
2 changes: 1 addition & 1 deletion packages/device_info/device_info/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin providing detailed information about the device
(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"
Expand Down

0 comments on commit 9ac6da7

Please sign in to comment.