Skip to content

Commit

Permalink
[path_provider] Update Android Pigeon for non-nullable generics (#7783)
Browse files Browse the repository at this point in the history
Removes workarounds for previous lack of non-nullable generics support. There are no native code changes because in practice we already didn't want nullable values in the collection, we just couldn't express it formally.

Part of flutter/flutter#155891
  • Loading branch information
stuartmorgan authored Oct 7, 2024
1 parent 3890cee commit e784c3e
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 222 deletions.
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.2.12

* Updates Pigeon for non-nullable collection type support.

## 2.2.11

* Updates Java compatibility version to 11.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (v9.2.5), do not edit directly.
// Autogenerated from Pigeon (v22.4.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.pathprovider;
Expand All @@ -13,6 +13,8 @@
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MessageCodec;
import io.flutter.plugin.common.StandardMessageCodec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -38,7 +40,7 @@ public FlutterError(@NonNull String code, @Nullable String message, @Nullable Ob

@NonNull
protected static ArrayList<Object> wrapError(@NonNull Throwable exception) {
ArrayList<Object> errorList = new ArrayList<Object>(3);
ArrayList<Object> errorList = new ArrayList<>(3);
if (exception instanceof FlutterError) {
FlutterError error = (FlutterError) exception;
errorList.add(error.code);
Expand Down Expand Up @@ -68,10 +70,40 @@ public enum StorageDirectory {

final int index;

private StorageDirectory(final int index) {
StorageDirectory(final int index) {
this.index = index;
}
}

private static class PigeonCodec extends StandardMessageCodec {
public static final PigeonCodec INSTANCE = new PigeonCodec();

private PigeonCodec() {}

@Override
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 129:
{
Object value = readValue(buffer);
return value == null ? null : StorageDirectory.values()[((Long) value).intValue()];
}
default:
return super.readValueOfType(type, buffer);
}
}

@Override
protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
if (value instanceof StorageDirectory) {
stream.write(129);
writeValue(stream, value == null ? null : ((StorageDirectory) value).index);
} else {
super.writeValue(stream, value);
}
}
}

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface PathProviderApi {

Expand All @@ -98,30 +130,38 @@ public interface PathProviderApi {

/** The codec used by PathProviderApi. */
static @NonNull MessageCodec<Object> getCodec() {
return new StandardMessageCodec();
return PigeonCodec.INSTANCE;
}
/**
* Sets up an instance of `PathProviderApi` to handle messages through the `binaryMessenger`.
*/
static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProviderApi api) {
static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProviderApi api) {
setUp(binaryMessenger, "", api);
}

static void setUp(
@NonNull BinaryMessenger binaryMessenger,
@NonNull String messageChannelSuffix,
@Nullable PathProviderApi api) {
messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix;
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getTemporaryPath",
"dev.flutter.pigeon.path_provider_android.PathProviderApi.getTemporaryPath"
+ messageChannelSuffix,
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> wrapped = new ArrayList<>();
try {
String output = api.getTemporaryPath();
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
Expand All @@ -134,19 +174,19 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath",
"dev.flutter.pigeon.path_provider_android.PathProviderApi.getApplicationSupportPath"
+ messageChannelSuffix,
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> wrapped = new ArrayList<>();
try {
String output = api.getApplicationSupportPath();
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
Expand All @@ -159,19 +199,19 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath",
"dev.flutter.pigeon.path_provider_android.PathProviderApi.getApplicationDocumentsPath"
+ messageChannelSuffix,
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> wrapped = new ArrayList<>();
try {
String output = api.getApplicationDocumentsPath();
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
Expand All @@ -184,19 +224,19 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getApplicationCachePath",
"dev.flutter.pigeon.path_provider_android.PathProviderApi.getApplicationCachePath"
+ messageChannelSuffix,
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> wrapped = new ArrayList<>();
try {
String output = api.getApplicationCachePath();
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
Expand All @@ -209,19 +249,19 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePath",
"dev.flutter.pigeon.path_provider_android.PathProviderApi.getExternalStoragePath"
+ messageChannelSuffix,
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> wrapped = new ArrayList<>();
try {
String output = api.getExternalStoragePath();
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
Expand All @@ -234,19 +274,19 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalCachePaths",
"dev.flutter.pigeon.path_provider_android.PathProviderApi.getExternalCachePaths"
+ messageChannelSuffix,
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> wrapped = new ArrayList<>();
try {
List<String> output = api.getExternalCachePaths();
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
Expand All @@ -259,22 +299,21 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths",
"dev.flutter.pigeon.path_provider_android.PathProviderApi.getExternalStoragePaths"
+ messageChannelSuffix,
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> wrapped = new ArrayList<>();
ArrayList<Object> args = (ArrayList<Object>) message;
StorageDirectory directoryArg =
args.get(0) == null ? null : StorageDirectory.values()[(int) args.get(0)];
StorageDirectory directoryArg = (StorageDirectory) args.get(0);
try {
List<String> output = api.getExternalStoragePaths(directoryArg);
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class PathProviderPlugin implements FlutterPlugin, PathProviderApi {

public PathProviderPlugin() {}

private void setup(BinaryMessenger messenger, Context context) {
private void setUp(BinaryMessenger messenger, Context context) {
try {
PathProviderApi.setup(messenger, this);
PathProviderApi.setUp(messenger, this);
} catch (Exception ex) {
Log.e(TAG, "Received exception while setting up PathProviderPlugin", ex);
}
Expand All @@ -34,12 +34,12 @@ private void setup(BinaryMessenger messenger, Context context) {

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
setup(binding.getBinaryMessenger(), binding.getApplicationContext());
setUp(binding.getBinaryMessenger(), binding.getApplicationContext());
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
PathProviderApi.setup(binding.getBinaryMessenger(), null);
PathProviderApi.setUp(binding.getBinaryMessenger(), null);
}

@Override
Expand Down
Loading

0 comments on commit e784c3e

Please sign in to comment.