Skip to content

Commit

Permalink
update pigeon - remove enum wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrinneal committed Aug 30, 2023
1 parent b4985e2 commit 57b13c1
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 206 deletions.
4 changes: 4 additions & 0 deletions packages/local_auth/local_auth_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.34

* Updates pigeon to 11.0.0 and removes enum wrappers.

## 1.0.33

* Adds pub topics to package metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.flutter.plugins.localauth.Messages.AuthClassificationWrapper;
import io.flutter.plugins.localauth.Messages.AuthOptions;
import io.flutter.plugins.localauth.Messages.AuthResult;
import io.flutter.plugins.localauth.Messages.AuthResultWrapper;
import io.flutter.plugins.localauth.Messages.AuthStrings;
import io.flutter.plugins.localauth.Messages.LocalAuthApi;
import io.flutter.plugins.localauth.Messages.Result;
Expand All @@ -51,7 +50,7 @@ public class LocalAuthPlugin implements FlutterPlugin, ActivityAware, LocalAuthA
private Lifecycle lifecycle;
private BiometricManager biometricManager;
private KeyguardManager keyguardManager;
Result<AuthResultWrapper> lockRequestResult;
Result<AuthResult> lockRequestResult;
private final PluginRegistry.ActivityResultListener resultListener =
new PluginRegistry.ActivityResultListener() {
@Override
Expand Down Expand Up @@ -132,28 +131,24 @@ public LocalAuthPlugin() {}
public void authenticate(
@NonNull AuthOptions options,
@NonNull AuthStrings strings,
@NonNull Result<AuthResultWrapper> result) {
@NonNull Result<AuthResult> result) {
if (authInProgress.get()) {
result.success(
new AuthResultWrapper.Builder().setValue(AuthResult.ERROR_ALREADY_IN_PROGRESS).build());
result.success(AuthResult.ERROR_ALREADY_IN_PROGRESS);
return;
}

if (activity == null || activity.isFinishing()) {
result.success(
new AuthResultWrapper.Builder().setValue(AuthResult.ERROR_NO_ACTIVITY).build());
result.success(AuthResult.ERROR_NO_ACTIVITY);
return;
}

if (!(activity instanceof FragmentActivity)) {
result.success(
new AuthResultWrapper.Builder().setValue(AuthResult.ERROR_NOT_FRAGMENT_ACTIVITY).build());
result.success(AuthResult.ERROR_NOT_FRAGMENT_ACTIVITY);
return;
}

if (!isDeviceSupported()) {
result.success(
new AuthResultWrapper.Builder().setValue(AuthResult.ERROR_NOT_AVAILABLE).build());
result.success(AuthResult.ERROR_NOT_AVAILABLE);
return;
}

Expand All @@ -167,7 +162,7 @@ public void authenticate(

@VisibleForTesting
public @NonNull AuthCompletionHandler createAuthCompletionHandler(
@NonNull final Result<AuthResultWrapper> result) {
@NonNull final Result<AuthResult> result) {
return authResult -> onAuthenticationCompleted(result, authResult);
}

Expand All @@ -189,9 +184,9 @@ public void sendAuthenticationRequest(
authHelper.authenticate();
}

void onAuthenticationCompleted(Result<AuthResultWrapper> result, AuthResult value) {
void onAuthenticationCompleted(Result<AuthResult> result, AuthResult value) {
if (authInProgress.compareAndSet(true, false)) {
result.success(new AuthResultWrapper.Builder().setValue(value).build());
result.success(value);
}
}

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.4), do not edit directly.
// Autogenerated from Pigeon (v11.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.localauth;
Expand Down Expand Up @@ -489,55 +489,6 @@ ArrayList<Object> toList() {
}
}

/** Generated class from Pigeon that represents data sent in messages. */
public static final class AuthResultWrapper {
private @NonNull AuthResult value;

public @NonNull AuthResult getValue() {
return value;
}

public void setValue(@NonNull AuthResult setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"value\" is null.");
}
this.value = setterArg;
}

/** Constructor is non-public to enforce null safety; use Builder. */
AuthResultWrapper() {}

public static final class Builder {

private @Nullable AuthResult value;

public @NonNull Builder setValue(@NonNull AuthResult setterArg) {
this.value = setterArg;
return this;
}

public @NonNull AuthResultWrapper build() {
AuthResultWrapper pigeonReturn = new AuthResultWrapper();
pigeonReturn.setValue(value);
return pigeonReturn;
}
}

@NonNull
ArrayList<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<Object>(1);
toListResult.add(value == null ? null : value.index);
return toListResult;
}

static @NonNull AuthResultWrapper fromList(@NonNull ArrayList<Object> list) {
AuthResultWrapper pigeonResult = new AuthResultWrapper();
Object value = list.get(0);
pigeonResult.setValue(value == null ? null : AuthResult.values()[(int) value]);
return pigeonResult;
}
}

/** Generated class from Pigeon that represents data sent in messages. */
public static final class AuthClassificationWrapper {
private @NonNull AuthClassification value;
Expand Down Expand Up @@ -582,7 +533,7 @@ ArrayList<Object> toList() {
static @NonNull AuthClassificationWrapper fromList(@NonNull ArrayList<Object> list) {
AuthClassificationWrapper pigeonResult = new AuthClassificationWrapper();
Object value = list.get(0);
pigeonResult.setValue(value == null ? null : AuthClassification.values()[(int) value]);
pigeonResult.setValue(AuthClassification.values()[(int) value]);
return pigeonResult;
}
}
Expand All @@ -607,8 +558,6 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
case (byte) 129:
return AuthOptions.fromList((ArrayList<Object>) readValue(buffer));
case (byte) 130:
return AuthResultWrapper.fromList((ArrayList<Object>) readValue(buffer));
case (byte) 131:
return AuthStrings.fromList((ArrayList<Object>) readValue(buffer));
default:
return super.readValueOfType(type, buffer);
Expand All @@ -623,11 +572,8 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
} else if (value instanceof AuthOptions) {
stream.write(129);
writeValue(stream, ((AuthOptions) value).toList());
} else if (value instanceof AuthResultWrapper) {
stream.write(130);
writeValue(stream, ((AuthResultWrapper) value).toList());
} else if (value instanceof AuthStrings) {
stream.write(131);
stream.write(130);
writeValue(stream, ((AuthStrings) value).toList());
} else {
super.writeValue(stream, value);
Expand Down Expand Up @@ -665,7 +611,7 @@ public interface LocalAuthApi {
void authenticate(
@NonNull AuthOptions options,
@NonNull AuthStrings strings,
@NonNull Result<AuthResultWrapper> result);
@NonNull Result<AuthResult> result);

/** The codec used by LocalAuthApi. */
static @NonNull MessageCodec<Object> getCodec() {
Expand All @@ -676,7 +622,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable LocalAuthA
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.LocalAuthApi.isDeviceSupported", getCodec());
binaryMessenger,
"dev.flutter.pigeon.local_auth_android.LocalAuthApi.isDeviceSupported",
getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Expand All @@ -698,7 +646,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable LocalAuthA
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.LocalAuthApi.deviceCanSupportBiometrics",
"dev.flutter.pigeon.local_auth_android.LocalAuthApi.deviceCanSupportBiometrics",
getCodec());
if (api != null) {
channel.setMessageHandler(
Expand All @@ -720,7 +668,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable LocalAuthA
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.LocalAuthApi.stopAuthentication", getCodec());
binaryMessenger,
"dev.flutter.pigeon.local_auth_android.LocalAuthApi.stopAuthentication",
getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Expand All @@ -742,7 +692,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable LocalAuthA
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.LocalAuthApi.getEnrolledBiometrics",
"dev.flutter.pigeon.local_auth_android.LocalAuthApi.getEnrolledBiometrics",
getCodec());
if (api != null) {
channel.setMessageHandler(
Expand All @@ -764,18 +714,20 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable LocalAuthA
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.LocalAuthApi.authenticate", getCodec());
binaryMessenger,
"dev.flutter.pigeon.local_auth_android.LocalAuthApi.authenticate",
getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
AuthOptions optionsArg = (AuthOptions) args.get(0);
AuthStrings stringsArg = (AuthStrings) args.get(1);
Result<AuthResultWrapper> resultCallback =
new Result<AuthResultWrapper>() {
public void success(AuthResultWrapper result) {
wrapped.add(0, result);
Result<AuthResult> resultCallback =
new Result<AuthResult>() {
public void success(AuthResult result) {
wrapped.add(0, result.index);
reply.reply(wrapped);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.flutter.plugins.localauth.Messages.AuthClassificationWrapper;
import io.flutter.plugins.localauth.Messages.AuthOptions;
import io.flutter.plugins.localauth.Messages.AuthResult;
import io.flutter.plugins.localauth.Messages.AuthResultWrapper;
import io.flutter.plugins.localauth.Messages.AuthStrings;
import io.flutter.plugins.localauth.Messages.Result;
import java.util.List;
Expand Down Expand Up @@ -72,48 +71,48 @@ public void authenticate_returnsErrorWhenAuthInProgress() {
final LocalAuthPlugin plugin = new LocalAuthPlugin();
plugin.authInProgress.set(true);
@SuppressWarnings("unchecked")
final Result<AuthResultWrapper> mockResult = mock(Result.class);
final Result<AuthResult> mockResult = mock(Result.class);
plugin.authenticate(defaultOptions, dummyStrings, mockResult);
ArgumentCaptor<AuthResultWrapper> captor = ArgumentCaptor.forClass(AuthResultWrapper.class);
ArgumentCaptor<AuthResult> captor = ArgumentCaptor.forClass(AuthResult.class);
verify(mockResult).success(captor.capture());
assertEquals(AuthResult.ERROR_ALREADY_IN_PROGRESS, captor.getValue().getValue());
assertEquals(AuthResult.ERROR_ALREADY_IN_PROGRESS, captor.getValue());
}

@Test
public void authenticate_returnsErrorWithNoForegroundActivity() {
final LocalAuthPlugin plugin = new LocalAuthPlugin();
@SuppressWarnings("unchecked")
final Result<AuthResultWrapper> mockResult = mock(Result.class);
final Result<AuthResult> mockResult = mock(Result.class);

plugin.authenticate(defaultOptions, dummyStrings, mockResult);
ArgumentCaptor<AuthResultWrapper> captor = ArgumentCaptor.forClass(AuthResultWrapper.class);
ArgumentCaptor<AuthResult> captor = ArgumentCaptor.forClass(AuthResult.class);
verify(mockResult).success(captor.capture());
assertEquals(AuthResult.ERROR_NO_ACTIVITY, captor.getValue().getValue());
assertEquals(AuthResult.ERROR_NO_ACTIVITY, captor.getValue());
}

@Test
public void authenticate_returnsErrorWhenActivityNotFragmentActivity() {
final LocalAuthPlugin plugin = new LocalAuthPlugin();
setPluginActivity(plugin, buildMockActivityWithContext(mock(NativeActivity.class)));
@SuppressWarnings("unchecked")
final Result<AuthResultWrapper> mockResult = mock(Result.class);
final Result<AuthResult> mockResult = mock(Result.class);
plugin.authenticate(defaultOptions, dummyStrings, mockResult);
ArgumentCaptor<AuthResultWrapper> captor = ArgumentCaptor.forClass(AuthResultWrapper.class);
ArgumentCaptor<AuthResult> captor = ArgumentCaptor.forClass(AuthResult.class);
verify(mockResult).success(captor.capture());
assertEquals(AuthResult.ERROR_NOT_FRAGMENT_ACTIVITY, captor.getValue().getValue());
assertEquals(AuthResult.ERROR_NOT_FRAGMENT_ACTIVITY, captor.getValue());
}

@Test
public void authenticate_returnsErrorWhenDeviceNotSupported() {
final LocalAuthPlugin plugin = new LocalAuthPlugin();
setPluginActivity(plugin, buildMockActivityWithContext(mock(FragmentActivity.class)));
@SuppressWarnings("unchecked")
final Result<AuthResultWrapper> mockResult = mock(Result.class);
final Result<AuthResult> mockResult = mock(Result.class);

plugin.authenticate(defaultOptions, dummyStrings, mockResult);
ArgumentCaptor<AuthResultWrapper> captor = ArgumentCaptor.forClass(AuthResultWrapper.class);
ArgumentCaptor<AuthResult> captor = ArgumentCaptor.forClass(AuthResult.class);
verify(mockResult).success(captor.capture());
assertEquals(AuthResult.ERROR_NOT_AVAILABLE, captor.getValue().getValue());
assertEquals(AuthResult.ERROR_NOT_AVAILABLE, captor.getValue());
}

@Test
Expand All @@ -138,7 +137,7 @@ public void authenticate_properlyConfiguresBiometricOnlyAuthenticationRequest()
allowCredentialsCaptor.capture(),
any(AuthCompletionHandler.class));
@SuppressWarnings("unchecked")
final Result<AuthResultWrapper> mockResult = mock(Result.class);
final Result<AuthResult> mockResult = mock(Result.class);

final AuthOptions options =
new AuthOptions.Builder()
Expand Down Expand Up @@ -172,7 +171,7 @@ public void authenticate_properlyConfiguresBiometricAndDeviceCredentialAuthentic
allowCredentialsCaptor.capture(),
any(AuthCompletionHandler.class));
@SuppressWarnings("unchecked")
final Result<AuthResultWrapper> mockResult = mock(Result.class);
final Result<AuthResult> mockResult = mock(Result.class);

plugin.authenticate(defaultOptions, dummyStrings, mockResult);
assertTrue(allowCredentialsCaptor.getValue());
Expand Down Expand Up @@ -201,7 +200,7 @@ public void authenticate_properlyConfiguresDeviceCredentialOnlyAuthenticationReq
allowCredentialsCaptor.capture(),
any(AuthCompletionHandler.class));
@SuppressWarnings("unchecked")
final Result<AuthResultWrapper> mockResult = mock(Result.class);
final Result<AuthResult> mockResult = mock(Result.class);

plugin.authenticate(defaultOptions, dummyStrings, mockResult);
assertTrue(allowCredentialsCaptor.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ class LocalAuthAndroid extends LocalAuthPlatform {
AuthenticationOptions options = const AuthenticationOptions(),
}) async {
assert(localizedReason.isNotEmpty);
final AuthResult result = (await _api.authenticate(
AuthOptions(
biometricOnly: options.biometricOnly,
sensitiveTransaction: options.sensitiveTransaction,
sticky: options.stickyAuth,
useErrorDialgs: options.useErrorDialogs),
_pigeonStringsFromAuthMessages(localizedReason, authMessages)))
.value;
final AuthResult result = await _api.authenticate(
AuthOptions(
biometricOnly: options.biometricOnly,
sensitiveTransaction: options.sensitiveTransaction,
sticky: options.stickyAuth,
useErrorDialgs: options.useErrorDialogs),
_pigeonStringsFromAuthMessages(localizedReason, authMessages));
// TODO(stuartmorgan): Replace this with structured errors, coordinated
// across all platform implementations, per
// https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#platform-exception-handling
Expand Down
Loading

0 comments on commit 57b13c1

Please sign in to comment.