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 5 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 @@ -157,15 +157,17 @@ private void setup(BinaryMessenger messenger, Context context) {
// 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");
Class<?> methodChannelClass = Class.forName("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.

@gaaclarke are these APIs available on the stable branch, right? If yes, let's remove TODO and workaround.

Copy link
Contributor

Choose a reason for hiding this comment

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

Be sure to set the right minimum Flutter version for the package if you do this; the legacy tests on CI are Dart analysis only so won't catch it.

Copy link
Contributor Author

@camsim99 camsim99 Apr 15, 2022

Choose a reason for hiding this comment

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

Based on the release notes, the fix should have made it to Flutter 2.8.0 which is the current minimum Flutter version. The guard is still there, though, to catch exceptions.

Copy link

Choose a reason for hiding this comment

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

it looks like we can remove the dynamic lookups, and import io.flutter.plugin.common.MethodChannel statically, etc... This only requires changing flutter: ">=2.8.0" to flutter: ">=2.8.1" in pubspec.yaml

Class<?> taskQueueClass = Class.forName("io.flutter.plugin.common.BinaryMessenger$TaskQueue");
Method makeBackgroundTaskQueue = messenger.getClass().getMethod("makeBackgroundTaskQueue");
Object taskQueue = makeBackgroundTaskQueue.invoke(messenger);
Constructor<MethodChannel> constructor =
Constructor<?> constructor =
methodChannelClass.getConstructor(
BinaryMessenger.class, String.class, MethodCodec.class, taskQueueClass);
channel =
constructor.newInstance(messenger, channelName, StandardMethodCodec.INSTANCE, taskQueue);
(MethodChannel)
constructor.newInstance(
messenger, channelName, StandardMethodCodec.INSTANCE, taskQueue);
impl = new PathProviderBackgroundThread();
Log.d(TAG, "Use TaskQueues.");
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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"
Expand Down