Skip to content

Commit

Permalink
[path_provider]: Migrated path_provider for android to pigeon. (flutt…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Jun 16, 2022
1 parent 5847653 commit 8bee94c
Show file tree
Hide file tree
Showing 10 changed files with 760 additions and 260 deletions.
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_android/CHANGELOG.md
@@ -1,3 +1,7 @@
## 2.0.15

* Switches the medium from MethodChannels to Pigeon.

## 2.0.14

* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors
Expand Down
@@ -0,0 +1,241 @@
// 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.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.pathprovider;

import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BinaryMessenger;
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"})
public class Messages {

public enum StorageDirectory {
music(0),
podcasts(1),
ringtones(2),
alarms(3),
notifications(4),
pictures(5),
movies(6),
downloads(7),
dcim(8),
documents(9);

private int index;

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

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

private PathProviderApiCodec() {}
}

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface PathProviderApi {
@Nullable
String getTemporaryPath();

@Nullable
String getApplicationSupportPath();

@Nullable
String getApplicationDocumentsPath();

@Nullable
String getExternalStoragePath();

@NonNull
List<String> getExternalCachePaths();

@NonNull
List<String> getExternalStoragePaths(@NonNull StorageDirectory directory);

/** The codec used by PathProviderApi. */
static MessageCodec<Object> getCodec() {
return PathProviderApiCodec.INSTANCE;
}

/**
* Sets up an instance of `PathProviderApi` to handle messages through the `binaryMessenger`.
*/
static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) {
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getTemporaryPath",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
String output = api.getTemporaryPath();
wrapped.put("result", output);
} catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
String output = api.getApplicationSupportPath();
wrapped.put("result", output);
} catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
String output = api.getApplicationDocumentsPath();
wrapped.put("result", output);
} catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePath",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
String output = api.getExternalStoragePath();
wrapped.put("result", output);
} catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalCachePaths",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
List<String> output = api.getExternalCachePaths();
wrapped.put("result", output);
} catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
ArrayList<Object> args = (ArrayList<Object>) message;
StorageDirectory directoryArg =
args.get(0) == null ? null : StorageDirectory.values()[(int) args.get(0)];
if (directoryArg == null) {
throw new NullPointerException("directoryArg unexpectedly null.");
}
List<String> output = api.getExternalStoragePaths(directoryArg);
wrapped.put("result", output);
} catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
}
}

private static Map<String, Object> wrapError(Throwable exception) {
Map<String, Object> 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;
}
}

0 comments on commit 8bee94c

Please sign in to comment.