-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[shared_preferences] Ports SharedPreferencesAndroid to Pigeon #3321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 22 commits into
flutter:main
from
AmanNegi:port-sharedprefs-android-to-pigeon
Apr 13, 2023
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f8260d7
Recreating PR from flutter/plugins
AmanNegi 312dce7
Merge branch 'main' of github.com:flutter/packages into port-sharedpr…
tarrinneal 211b2cf
update to latest api
tarrinneal 11a0ae8
update to latest api, add integration tests
tarrinneal f6a7cdd
Merge branch 'main' of github.com:flutter/packages into port-sharedpr…
tarrinneal 48c9cd9
fix tests?
tarrinneal 366a405
some mocking, but no testing
tarrinneal 7b825a7
tests work, but some fail (commented out) WIP
tarrinneal a37f155
fix tests, no string lists
tarrinneal f2fffa9
listEncoder
tarrinneal c3ac1b9
Merge branch 'main' of github.com:flutter/packages into port-sharedpr…
tarrinneal 03dedc3
format
tarrinneal 1dfb1e7
formatting
tarrinneal b7dfefa
import nonnull
tarrinneal f11df81
Every thing in the world is now nonnull
tarrinneal 50e4b8c
format
tarrinneal 56518bf
most nits (still need to merge files)
tarrinneal 279ec4a
merge files
tarrinneal 4872c06
comments and tests
tarrinneal 5b34294
format pigeons (it's good for their health)
tarrinneal deb7e49
nits
tarrinneal 403826c
final nits
tarrinneal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/shared_preferences/shared_preferences_android/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
316 changes: 316 additions & 0 deletions
316
...ferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/Messages.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,316 @@ | ||
| // 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.3), do not edit directly. | ||
| // See also: https://pub.dev/packages/pigeon | ||
|
|
||
| package io.flutter.plugins.sharedpreferences; | ||
|
|
||
| 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.List; | ||
| import java.util.Map; | ||
|
|
||
| /** Generated class from Pigeon. */ | ||
| @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) | ||
| public class Messages { | ||
|
|
||
| /** Error class for passing custom error details to Flutter via a thrown PlatformException. */ | ||
| public static class FlutterError extends RuntimeException { | ||
|
|
||
| /** 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; | ||
| } | ||
| } | ||
|
|
||
| @NonNull | ||
| protected static ArrayList<Object> wrapError(@NonNull Throwable exception) { | ||
| ArrayList<Object> errorList = new ArrayList<Object>(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; | ||
| } | ||
| /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ | ||
| public interface SharedPreferencesApi { | ||
|
|
||
| @NonNull | ||
| Boolean remove(@NonNull String key); | ||
|
|
||
| @NonNull | ||
| Boolean setBool(@NonNull String key, @NonNull Boolean value); | ||
|
|
||
| @NonNull | ||
| Boolean setString(@NonNull String key, @NonNull String value); | ||
|
|
||
| @NonNull | ||
| Boolean setInt(@NonNull String key, @NonNull Object value); | ||
|
|
||
| @NonNull | ||
| Boolean setDouble(@NonNull String key, @NonNull Double value); | ||
|
|
||
| @NonNull | ||
| Boolean setStringList(@NonNull String key, @NonNull List<String> value); | ||
|
|
||
| @NonNull | ||
| Boolean clearWithPrefix(@NonNull String prefix); | ||
|
|
||
| @NonNull | ||
| Map<String, Object> getAllWithPrefix(@NonNull String prefix); | ||
|
|
||
| /** The codec used by SharedPreferencesApi. */ | ||
| static @NonNull MessageCodec<Object> getCodec() { | ||
| return new StandardMessageCodec(); | ||
| } | ||
| /** | ||
| * Sets up an instance of `SharedPreferencesApi` to handle messages through the | ||
| * `binaryMessenger`. | ||
| */ | ||
| static void setup( | ||
| @NonNull BinaryMessenger binaryMessenger, @Nullable SharedPreferencesApi api) { | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.remove", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String keyArg = (String) args.get(0); | ||
| try { | ||
| Boolean output = api.remove(keyArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.setBool", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String keyArg = (String) args.get(0); | ||
| Boolean valueArg = (Boolean) args.get(1); | ||
| try { | ||
| Boolean output = api.setBool(keyArg, valueArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.setString", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String keyArg = (String) args.get(0); | ||
| String valueArg = (String) args.get(1); | ||
| try { | ||
| Boolean output = api.setString(keyArg, valueArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.setInt", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String keyArg = (String) args.get(0); | ||
| Object valueArg = args.get(1); | ||
| try { | ||
| Boolean output = api.setInt(keyArg, valueArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.setDouble", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String keyArg = (String) args.get(0); | ||
| Double valueArg = (Double) args.get(1); | ||
| try { | ||
| Boolean output = api.setDouble(keyArg, valueArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.setStringList", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String keyArg = (String) args.get(0); | ||
| List<String> valueArg = (List<String>) args.get(1); | ||
| try { | ||
| Boolean output = api.setStringList(keyArg, valueArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.clearWithPrefix", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String prefixArg = (String) args.get(0); | ||
| try { | ||
| Boolean output = api.clearWithPrefix(prefixArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| { | ||
| BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
| BasicMessageChannel<Object> channel = | ||
| new BasicMessageChannel<>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.SharedPreferencesApi.getAllWithPrefix", | ||
| getCodec(), | ||
| taskQueue); | ||
| if (api != null) { | ||
| channel.setMessageHandler( | ||
| (message, reply) -> { | ||
| ArrayList<Object> wrapped = new ArrayList<Object>(); | ||
| ArrayList<Object> args = (ArrayList<Object>) message; | ||
| String prefixArg = (String) args.get(0); | ||
| try { | ||
| Map<String, Object> output = api.getAllWithPrefix(prefixArg); | ||
| wrapped.add(0, output); | ||
| } catch (Throwable exception) { | ||
| ArrayList<Object> wrappedError = wrapError(exception); | ||
| wrapped = wrappedError; | ||
| } | ||
| reply.reply(wrapped); | ||
| }); | ||
| } else { | ||
| channel.setMessageHandler(null); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.