diff --git a/packages/path_provider/path_provider_android/CHANGELOG.md b/packages/path_provider/path_provider_android/CHANGELOG.md index d4f1da3af76f..379fd5c4a760 100644 --- a/packages/path_provider/path_provider_android/CHANGELOG.md +++ b/packages/path_provider/path_provider_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.25 + +* Fixes Java warnings. + ## 2.0.24 * Clarifies explanation of endorsement in README. diff --git a/packages/path_provider/path_provider_android/android/build.gradle b/packages/path_provider/path_provider_android/android/build.gradle index 7e348233d342..1fbfa8b76f6c 100644 --- a/packages/path_provider/path_provider_android/android/build.gradle +++ b/packages/path_provider/path_provider_android/android/build.gradle @@ -32,7 +32,6 @@ android { checkAllWarnings true warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' - baseline file("lint-baseline.xml") } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/packages/path_provider/path_provider_android/android/lint-baseline.xml b/packages/path_provider/path_provider_android/android/lint-baseline.xml deleted file mode 100644 index 4ae0352f93c6..000000000000 --- a/packages/path_provider/path_provider_android/android/lint-baseline.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java index 47144d4a8fcd..11cda6b42806 100644 --- a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java +++ b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.2.0), do not edit directly. +// Autogenerated from Pigeon (v9.2.4), do not edit directly. // See also: https://pub.dev/packages/pigeon package io.flutter.plugins.pathprovider; @@ -14,42 +14,67 @@ import io.flutter.plugin.common.MessageCodec; import io.flutter.plugin.common.StandardMessageCodec; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** Generated class from Pigeon. */ -@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) +@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) public class Messages { - public enum StorageDirectory { - root(0), - music(1), - podcasts(2), - ringtones(3), - alarms(4), - notifications(5), - pictures(6), - movies(7), - downloads(8), - dcim(9), - documents(10); - - private int index; + /** Error class for passing custom error details to Flutter via a thrown PlatformException. */ + public static class FlutterError extends RuntimeException { - private StorageDirectory(final int index) { - this.index = index; + /** The error code. */ + public final String code; + + /** The error details. Must be a datatype supported by the api codec. */ + public final Object details; + + public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) { + super(message); + this.code = code; + this.details = details; } } - private static class PathProviderApiCodec extends StandardMessageCodec { - public static final PathProviderApiCodec INSTANCE = new PathProviderApiCodec(); - - private PathProviderApiCodec() {} + @NonNull + protected static ArrayList wrapError(@NonNull Throwable exception) { + ArrayList errorList = new ArrayList(3); + if (exception instanceof FlutterError) { + FlutterError error = (FlutterError) exception; + errorList.add(error.code); + errorList.add(error.getMessage()); + errorList.add(error.details); + } else { + errorList.add(exception.toString()); + errorList.add(exception.getClass().getSimpleName()); + errorList.add( + "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); + } + return errorList; } + public enum StorageDirectory { + ROOT(0), + MUSIC(1), + PODCASTS(2), + RINGTONES(3), + ALARMS(4), + NOTIFICATIONS(5), + PICTURES(6), + MOVIES(7), + DOWNLOADS(8), + DCIM(9), + DOCUMENTS(10); + + final int index; + + private StorageDirectory(final int index) { + this.index = index; + } + } /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface PathProviderApi { + @Nullable String getTemporaryPath(); @@ -69,14 +94,13 @@ public interface PathProviderApi { List getExternalStoragePaths(@NonNull StorageDirectory directory); /** The codec used by PathProviderApi. */ - static MessageCodec getCodec() { - return PathProviderApiCodec.INSTANCE; + static @NonNull MessageCodec getCodec() { + return new StandardMessageCodec(); } - /** * Sets up an instance of `PathProviderApi` to handle messages through the `binaryMessenger`. */ - static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { + static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProviderApi api) { { BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); BasicMessageChannel channel = @@ -88,12 +112,13 @@ static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); try { String output = api.getTemporaryPath(); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -112,12 +137,13 @@ static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); try { String output = api.getApplicationSupportPath(); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -136,12 +162,13 @@ static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); try { String output = api.getApplicationDocumentsPath(); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -160,12 +187,13 @@ static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); try { String output = api.getExternalStoragePath(); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -184,12 +212,13 @@ static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); try { List output = api.getExternalCachePaths(); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -208,18 +237,16 @@ static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + StorageDirectory directoryArg = + args.get(0) == null ? null : StorageDirectory.values()[(int) args.get(0)]; try { - ArrayList args = (ArrayList) message; - StorageDirectory directoryArg = - args.get(0) == null ? null : StorageDirectory.values()[(int) args.get(0)]; - if (directoryArg == null) { - throw new NullPointerException("directoryArg unexpectedly null."); - } List output = api.getExternalStoragePaths(directoryArg); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -229,14 +256,4 @@ static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { } } } - - private static Map wrapError(Throwable exception) { - Map errorMap = new HashMap<>(); - errorMap.put("message", exception.toString()); - errorMap.put("code", exception.getClass().getSimpleName()); - errorMap.put( - "details", - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); - return errorMap; - } } diff --git a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java index 285d62ec68fd..6e259cf5128f 100644 --- a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java +++ b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java @@ -12,7 +12,6 @@ import androidx.annotation.Nullable; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.common.BinaryMessenger.TaskQueue; import io.flutter.plugins.pathprovider.Messages.PathProviderApi; import io.flutter.util.PathUtils; import java.io.File; @@ -26,8 +25,6 @@ public class PathProviderPlugin implements FlutterPlugin, PathProviderApi { public PathProviderPlugin() {} private void setup(BinaryMessenger messenger, Context context) { - TaskQueue taskQueue = messenger.makeBackgroundTaskQueue(); - try { PathProviderApi.setup(messenger, this); } catch (Exception ex) { @@ -38,7 +35,8 @@ private void setup(BinaryMessenger messenger, Context context) { } @SuppressWarnings("deprecation") - public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) { + public static void registerWith( + @NonNull io.flutter.plugin.common.PluginRegistry.Registrar registrar) { PathProviderPlugin instance = new PathProviderPlugin(); instance.setup(registrar.messenger(), registrar.context()); } @@ -105,7 +103,7 @@ private String getPathProviderStorageDirectory() { } private List getPathProviderExternalCacheDirectories() { - final List paths = new ArrayList(); + final List paths = new ArrayList<>(); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { for (File dir : context.getExternalCacheDirs()) { @@ -125,27 +123,27 @@ private List getPathProviderExternalCacheDirectories() { private String getStorageDirectoryString(@NonNull Messages.StorageDirectory directory) { switch (directory) { - case root: + case ROOT: return null; - case music: + case MUSIC: return "music"; - case podcasts: + case PODCASTS: return "podcasts"; - case ringtones: + case RINGTONES: return "ringtones"; - case alarms: + case ALARMS: return "alarms"; - case notifications: + case NOTIFICATIONS: return "notifications"; - case pictures: + case PICTURES: return "pictures"; - case movies: + case MOVIES: return "movies"; - case downloads: + case DOWNLOADS: return "downloads"; - case dcim: + case DCIM: return "dcim"; - case documents: + case DOCUMENTS: return "documents"; default: throw new RuntimeException("Unrecognized directory: " + directory); @@ -154,7 +152,7 @@ private String getStorageDirectoryString(@NonNull Messages.StorageDirectory dire private List getPathProviderExternalStorageDirectories( @NonNull Messages.StorageDirectory directory) { - final List paths = new ArrayList(); + final List paths = new ArrayList<>(); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { for (File dir : context.getExternalFilesDirs(getStorageDirectoryString(directory))) { diff --git a/packages/path_provider/path_provider_android/lib/messages.g.dart b/packages/path_provider/path_provider_android/lib/messages.g.dart index cf095c244b8d..ec5c1f9506fa 100644 --- a/packages/path_provider/path_provider_android/lib/messages.g.dart +++ b/packages/path_provider/path_provider_android/lib/messages.g.dart @@ -1,14 +1,14 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.2.0), do not edit directly. +// Autogenerated from Pigeon (v9.2.4), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name -// @dart = 2.12 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import + import 'dart:async'; -import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; enum StorageDirectory { @@ -25,42 +25,34 @@ enum StorageDirectory { documents, } -class _PathProviderApiCodec extends StandardMessageCodec { - const _PathProviderApiCodec(); -} - class PathProviderApi { /// Constructor for [PathProviderApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. PathProviderApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - static const MessageCodec codec = _PathProviderApiCodec(); + static const MessageCodec codec = StandardMessageCodec(); Future getTemporaryPath() async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PathProviderApi.getTemporaryPath', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -68,23 +60,20 @@ class PathProviderApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -92,23 +81,20 @@ class PathProviderApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -116,23 +102,20 @@ class PathProviderApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePath', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -140,28 +123,25 @@ class PathProviderApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PathProviderApi.getExternalCachePaths', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as List?)!.cast(); + return (replyList[0] as List?)!.cast(); } } @@ -170,28 +150,26 @@ class PathProviderApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_directory.index]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_directory.index]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as List?)!.cast(); + return (replyList[0] as List?)!.cast(); } } } diff --git a/packages/path_provider/path_provider_android/pubspec.yaml b/packages/path_provider/path_provider_android/pubspec.yaml index 4c347d48bb03..781b80899fa3 100644 --- a/packages/path_provider/path_provider_android/pubspec.yaml +++ b/packages/path_provider/path_provider_android/pubspec.yaml @@ -2,7 +2,7 @@ name: path_provider_android description: Android implementation of the path_provider plugin. repository: https://github.com/flutter/packages/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.24 +version: 2.0.25 environment: sdk: ">=2.17.0 <4.0.0" @@ -29,5 +29,5 @@ dev_dependencies: sdk: flutter integration_test: sdk: flutter - pigeon: ^3.1.5 + pigeon: ^9.2.4 test: ^1.16.0 diff --git a/packages/path_provider/path_provider_android/test/messages_test.g.dart b/packages/path_provider/path_provider_android/test/messages_test.g.dart index dc8ee55acc3b..515f6b549fe1 100644 --- a/packages/path_provider/path_provider_android/test/messages_test.g.dart +++ b/packages/path_provider/path_provider_android/test/messages_test.g.dart @@ -1,33 +1,35 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.1.5), do not edit directly. +// Autogenerated from Pigeon (v9.2.4), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports -// @dart = 2.12 import 'dart:async'; -import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; -import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -// The following line is edited by hand to avoid confusing dart with overloaded types. import 'package:path_provider_android/messages.g.dart'; -class _TestPathProviderApiCodec extends StandardMessageCodec { - const _TestPathProviderApiCodec(); -} - abstract class TestPathProviderApi { - static const MessageCodec codec = _TestPathProviderApiCodec(); + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec codec = StandardMessageCodec(); String? getTemporaryPath(); + String? getApplicationSupportPath(); + String? getApplicationDocumentsPath(); + String? getExternalStoragePath(); + List getExternalCachePaths(); + List getExternalStoragePaths(StorageDirectory directory); + static void setup(TestPathProviderApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -35,12 +37,15 @@ abstract class TestPathProviderApi { 'dev.flutter.pigeon.PathProviderApi.getTemporaryPath', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { // ignore message final String? output = api.getTemporaryPath(); - return {'result': output}; + return [output]; }); } } @@ -49,12 +54,15 @@ abstract class TestPathProviderApi { 'dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { // ignore message final String? output = api.getApplicationSupportPath(); - return {'result': output}; + return [output]; }); } } @@ -64,12 +72,15 @@ abstract class TestPathProviderApi { codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { // ignore message final String? output = api.getApplicationDocumentsPath(); - return {'result': output}; + return [output]; }); } } @@ -78,12 +89,15 @@ abstract class TestPathProviderApi { 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePath', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { // ignore message final String? output = api.getExternalStoragePath(); - return {'result': output}; + return [output]; }); } } @@ -92,12 +106,15 @@ abstract class TestPathProviderApi { 'dev.flutter.pigeon.PathProviderApi.getExternalCachePaths', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { // ignore message final List output = api.getExternalCachePaths(); - return {'result': output}; + return [output]; }); } } @@ -106,24 +123,22 @@ abstract class TestPathProviderApi { 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths was null.'); final List args = (message as List?)!; - - /// TODO(gaaclarke): The following line was tweaked by hand to address - /// https://github.com/flutter/flutter/issues/105742. Alternatively - /// the tests could be written with a mock BinaryMessenger but this is - /// how we want to address it eventually. final StorageDirectory? arg_directory = - StorageDirectory.values[args[0] as int]; + args[0] == null ? null : StorageDirectory.values[args[0] as int]; assert(arg_directory != null, 'Argument for dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths was null, expected non-null StorageDirectory.'); final List output = api.getExternalStoragePaths(arg_directory!); - return {'result': output}; + return [output]; }); } }