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

[path_provider] Fix Unchecked/Unsafe Operation Warning #5267

Merged
merged 12 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.13

* Fixes typing build warning.

## 2.0.12

* Returns to using a different platform channel name, undoing the revert in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package io.flutter.plugins.pathprovider;

import static io.flutter.plugin.common.BinaryMessenger.*;
import static io.flutter.plugin.common.MethodChannel.*;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: here and below, avoid wildcard imports: https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports

I tend to think it's ok to use wildcards in test code, in particular for very repetitive imports like org.junit.Assert or Mockito imports, other than that wildcards makes it harder to reason about when reading some code.


import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
Expand All @@ -16,17 +19,9 @@
import com.google.common.util.concurrent.SettableFuture;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
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.MethodCodec;
import io.flutter.plugin.common.StandardMethodCodec;
import io.flutter.plugin.common.*;
import io.flutter.util.PathUtils;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -154,25 +149,17 @@ public PathProviderPlugin() {}

private void setup(BinaryMessenger messenger, Context context) {
String channelName = "plugins.flutter.io/path_provider_android";
// TODO(gaaclarke): Remove reflection guard when https://github.com/flutter/engine/pull/29147
// becomes available on the stable branch.
TaskQueue taskQueue = messenger.makeBackgroundTaskQueue();

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);
(MethodChannel)
new MethodChannel(messenger, channelName, StandardMethodCodec.INSTANCE, taskQueue);
impl = new PathProviderBackgroundThread();
Log.d(TAG, "Use TaskQueues.");
} catch (Exception ex) {
channel = new MethodChannel(messenger, channelName);
impl = new PathProviderPlatformThread();
Log.d(TAG, "Don't use TaskQueues.");
Log.e(TAG, "Received exception while setting up PathProviderPlugin", ex);
}

this.context = context;
channel.setMethodCallHandler(this);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/path_provider/path_provider_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: path_provider_android
description: Android implementation of the path_provider plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/path_provider/path_provider_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
version: 2.0.12
version: 2.0.13

environment:
sdk: ">=2.14.0 <3.0.0"
flutter: ">=2.8.0"
flutter: ">=2.8.1"

flutter:
plugin:
Expand Down