|
17 | 17 | import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
18 | 18 | import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
19 | 19 | import io.flutter.plugin.common.BinaryMessenger;
|
| 20 | +import io.flutter.plugin.common.BinaryMessenger.TaskQueue; |
20 | 21 | import io.flutter.plugin.common.MethodCall;
|
21 | 22 | import io.flutter.plugin.common.MethodChannel;
|
22 | 23 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
23 | 24 | import io.flutter.plugin.common.MethodChannel.Result;
|
24 |
| -import io.flutter.plugin.common.MethodCodec; |
25 | 25 | import io.flutter.plugin.common.StandardMethodCodec;
|
26 | 26 | import io.flutter.util.PathUtils;
|
27 | 27 | import java.io.File;
|
28 |
| -import java.lang.reflect.Constructor; |
29 |
| -import java.lang.reflect.Method; |
30 | 28 | import java.util.ArrayList;
|
31 | 29 | import java.util.List;
|
32 | 30 | import java.util.concurrent.Callable;
|
@@ -154,25 +152,17 @@ public PathProviderPlugin() {}
|
154 | 152 |
|
155 | 153 | private void setup(BinaryMessenger messenger, Context context) {
|
156 | 154 | String channelName = "plugins.flutter.io/path_provider_android";
|
157 |
| - // TODO(gaaclarke): Remove reflection guard when https://github.com/flutter/engine/pull/29147 |
158 |
| - // becomes available on the stable branch. |
| 155 | + TaskQueue taskQueue = messenger.makeBackgroundTaskQueue(); |
| 156 | + |
159 | 157 | try {
|
160 |
| - Class methodChannelClass = Class.forName("io.flutter.plugin.common.MethodChannel"); |
161 |
| - Class taskQueueClass = Class.forName("io.flutter.plugin.common.BinaryMessenger$TaskQueue"); |
162 |
| - Method makeBackgroundTaskQueue = messenger.getClass().getMethod("makeBackgroundTaskQueue"); |
163 |
| - Object taskQueue = makeBackgroundTaskQueue.invoke(messenger); |
164 |
| - Constructor<MethodChannel> constructor = |
165 |
| - methodChannelClass.getConstructor( |
166 |
| - BinaryMessenger.class, String.class, MethodCodec.class, taskQueueClass); |
167 | 158 | channel =
|
168 |
| - constructor.newInstance(messenger, channelName, StandardMethodCodec.INSTANCE, taskQueue); |
| 159 | + (MethodChannel) |
| 160 | + new MethodChannel(messenger, channelName, StandardMethodCodec.INSTANCE, taskQueue); |
169 | 161 | impl = new PathProviderBackgroundThread();
|
170 |
| - Log.d(TAG, "Use TaskQueues."); |
171 | 162 | } catch (Exception ex) {
|
172 |
| - channel = new MethodChannel(messenger, channelName); |
173 |
| - impl = new PathProviderPlatformThread(); |
174 |
| - Log.d(TAG, "Don't use TaskQueues."); |
| 163 | + Log.e(TAG, "Received exception while setting up PathProviderPlugin", ex); |
175 | 164 | }
|
| 165 | + |
176 | 166 | this.context = context;
|
177 | 167 | channel.setMethodCallHandler(this);
|
178 | 168 | }
|
|
0 commit comments