From dd77aca35d430065cc34aa121d3e5c392239b86a Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 16 Sep 2023 16:16:32 +0200 Subject: [PATCH] Migrate Basement/Fido SafeParcelables to use processor instead of reflection This improves speed and should help against ProGuard optimizing away our code --- .../android/gms/common/ConnectionResult.java | 27 ++- .../google/android/gms/common/Feature.java | 27 ++- .../common/GoogleCertificatesLookupQuery.java | 31 +-- .../gms/common/GoogleCertificatesQuery.java | 28 ++- .../google/android/gms/common/api/Scope.java | 26 ++- .../google/android/gms/common/api/Status.java | 30 +-- .../gms/common/internal/ConnectionInfo.java | 18 +- .../common/internal/GetServiceRequest.java | 34 ++-- .../internal/ValidateAccountRequest.java | 16 +- .../internal/safeparcel/SafeParcelable.java | 8 + .../microg/safeparcel/AutoSafeParcelable.java | 6 +- .../gms/fido/fido2/api/common/Attachment.java | 5 +- .../AttestationConveyancePreference.java | 5 +- .../api/common/AuthenticationExtensions.java | 40 +++- ...AuthenticationExtensionsClientOutputs.java | 26 ++- ...henticationExtensionsCredPropsOutputs.java | 4 +- .../AuthenticatorAssertionResponse.java | 27 ++- .../AuthenticatorAttestationResponse.java | 25 ++- .../common/AuthenticatorErrorResponse.java | 29 ++- .../api/common/AuthenticatorResponse.java | 4 +- .../AuthenticatorSelectionCriteria.java | 38 ++-- ...serPublicKeyCredentialCreationOptions.java | 31 ++- ...wserPublicKeyCredentialRequestOptions.java | 30 ++- .../api/common/CableAuthenticationData.java | 23 ++- .../common/CableAuthenticationExtension.java | 17 +- .../gms/fido/fido2/api/common/ErrorCode.java | 2 +- .../fido2/api/common/FidoAppIdExtension.java | 20 +- .../api/common/FidoCredentialDetails.java | 18 +- .../fido2/api/common/PublicKeyCredential.java | 64 ++++--- .../PublicKeyCredentialCreationOptions.java | 62 +++--- .../common/PublicKeyCredentialDescriptor.java | 29 ++- .../common/PublicKeyCredentialParameters.java | 25 ++- .../PublicKeyCredentialRequestOptions.java | 51 +++-- .../common/PublicKeyCredentialRpEntity.java | 24 ++- .../api/common/PublicKeyCredentialType.java | 3 +- .../common/PublicKeyCredentialUserEntity.java | 29 ++- .../fido/fido2/api/common/RequestOptions.java | 4 +- .../fido/fido2/api/common/TokenBinding.java | 28 ++- .../UserVerificationMethodExtension.java | 22 ++- .../common/UserVerificationRequirement.java | 3 +- .../gms/fido/fido2/api/common/UvmEntries.java | 29 ++- .../gms/fido/fido2/api/common/UvmEntry.java | 38 ++-- .../SourceDirectTransferResult.java | 23 ++- .../SourceStartDirectTransferOptions.java | 22 ++- .../google/android/gms/games/PlayerLevel.java | 6 +- .../microg/safeparcel/SafeParcelProcessor.kt | 177 +++++++++++++++--- 46 files changed, 874 insertions(+), 360 deletions(-) diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/ConnectionResult.java b/play-services-basement/src/main/java/com/google/android/gms/common/ConnectionResult.java index 5177385b5c..58d8aaf40c 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/ConnectionResult.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/ConnectionResult.java @@ -12,8 +12,12 @@ import android.app.PendingIntent; import android.content.Intent; import android.content.IntentSender; +import android.os.Parcel; import android.text.TextUtils; -import org.microg.safeparcel.AutoSafeParcelable; +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import java.util.Arrays; @@ -21,7 +25,8 @@ * Contains all possible error codes for when a client fails to connect to Google Play services. * These error codes are used by {@link GoogleApiClient.OnConnectionFailedListener}. */ -public class ConnectionResult extends AutoSafeParcelable { +@SafeParcelable.Class +public class ConnectionResult extends AbstractSafeParcelable { /** * The connection was successful. */ @@ -158,12 +163,12 @@ public class ConnectionResult extends AutoSafeParcelable { public static final int DRIVE_EXTERNAL_STORAGE_REQUIRED = 1500; @Field(1) - private final int versionCode = 1; - @Field(2) + int versionCode = 1; + @Field(value = 2, getterName = "getErrorCode") private int statusCode; - @Field(3) + @Field(value = 3, getterName = "getResolution") private PendingIntent resolution; - @Field(4) + @Field(value = 4, getterName = "getErrorMessage") private String message; private ConnectionResult() { @@ -195,7 +200,8 @@ public ConnectionResult(int statusCode, PendingIntent resolution) { * @param resolution A pending intent that will resolve the issue when started, or null. * @param message An additional error message for the connection result, or null. */ - public ConnectionResult(int statusCode, PendingIntent resolution, String message) { + @Constructor + public ConnectionResult(@Param(2) int statusCode, @Param(3) PendingIntent resolution, @Param(4) String message) { this.statusCode = statusCode; this.resolution = resolution; this.message = message; @@ -342,5 +348,10 @@ public void startResolutionForResult(Activity activity, int requestCode) throws } } - public static final Creator CREATOR = new AutoCreator<>(ConnectionResult.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(ConnectionResult.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/Feature.java b/play-services-basement/src/main/java/com/google/android/gms/common/Feature.java index 0a5b0813d0..f95bd7fd88 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/Feature.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/Feature.java @@ -5,20 +5,26 @@ package com.google.android.gms.common; -import org.microg.safeparcel.AutoSafeParcelable; - -public class Feature extends AutoSafeParcelable { - @Field(1) +import android.os.Parcel; +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; + +@SafeParcelable.Class +public class Feature extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getName") private String name; @Field(2) - private int oldVersion; - @Field(3) + int oldVersion; + @Field(value = 3, getterName = "getVersion", defaultValue = "-1") private long version = -1; private Feature() { } - public Feature(String name, long version) { + @Constructor + public Feature(@Param(1) String name, @Param(3) long version) { this.name = name; this.version = version; } @@ -32,5 +38,10 @@ public long getVersion() { return version; } - public static final Creator CREATOR = new AutoSafeParcelable.AutoCreator<>(Feature.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(Feature.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesLookupQuery.java b/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesLookupQuery.java index 4fc54a1975..ab8da97a61 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesLookupQuery.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesLookupQuery.java @@ -6,25 +6,29 @@ package com.google.android.gms.common; import android.content.Context; -import android.os.IBinder; +import android.os.Parcel; +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.dynamic.IObjectWrapper; import com.google.android.gms.dynamic.ObjectWrapper; -import org.microg.safeparcel.AutoSafeParcelable; -public class GoogleCertificatesLookupQuery extends AutoSafeParcelable { - @Field(1) - private String callingPackage; +@SafeParcelable.Class +public class GoogleCertificatesLookupQuery extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getCallingPackage") + String callingPackage; @Field(2) - private boolean allowTestKeys; + boolean allowTestKeys; @Field(3) - private boolean ignoreTestKeysOverride; + boolean ignoreTestKeysOverride; @Field(4) - private IObjectWrapper contextWrapper; + IObjectWrapper contextWrapper; private Context context; @Field(5) - private boolean isChimeraPackage; + boolean isChimeraPackage; @Field(6) - private boolean includeHashesInErrorMessage; + boolean includeHashesInErrorMessage; public String getCallingPackage() { return callingPackage; @@ -37,5 +41,10 @@ public Context getContext() { return context; } - public static final Creator CREATOR = findCreator(GoogleCertificatesLookupQuery.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(GoogleCertificatesLookupQuery.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesQuery.java b/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesQuery.java index 395311df69..dce40a905f 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesQuery.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/GoogleCertificatesQuery.java @@ -6,27 +6,30 @@ package com.google.android.gms.common; import android.os.IBinder; +import android.os.Parcel; import android.os.RemoteException; - +import androidx.annotation.NonNull; import com.google.android.gms.common.internal.CertData; import com.google.android.gms.common.internal.ICertData; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.dynamic.IObjectWrapper; import com.google.android.gms.dynamic.ObjectWrapper; - import org.microg.gms.common.Hide; -import org.microg.safeparcel.AutoSafeParcelable; @Hide -public class GoogleCertificatesQuery extends AutoSafeParcelable { - @Field(1) - private String callingPackage; +@SafeParcelable.Class +public class GoogleCertificatesQuery extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getCallingPackage") + String callingPackage; @Field(2) - private IBinder certDataBinder; + IBinder certDataBinder; private CertData certData; @Field(3) - private boolean allowTestKeys; + boolean allowTestKeys; @Field(4) - private boolean ignoreTestKeysOverride; + boolean ignoreTestKeysOverride; public String getCallingPackage() { return callingPackage; @@ -65,5 +68,10 @@ public CertData getCertData() { return certData; } - public static final Creator CREATOR = new AutoCreator(GoogleCertificatesQuery.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(GoogleCertificatesQuery.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/api/Scope.java b/play-services-basement/src/main/java/com/google/android/gms/common/api/Scope.java index d99932b223..37165e36ab 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/api/Scope.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/api/Scope.java @@ -16,19 +16,23 @@ package com.google.android.gms.common.api; +import android.os.Parcel; +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; -import org.microg.safeparcel.SafeParceled; /** * Describes an OAuth 2.0 scope to request. This has security implications for the user, and * requesting additional scopes will result in authorization dialogs. */ @PublicApi -public class Scope extends AutoSafeParcelable { - @SafeParceled(1) - private int versionCode = 1; - @SafeParceled(2) +@SafeParcelable.Class +public class Scope extends AbstractSafeParcelable { + @Field(1) + int versionCode = 1; + @Field(value = 2, getterName = "getScopeUri") private final String scopeUri; private Scope() { @@ -38,7 +42,8 @@ private Scope() { /** * Creates a new scope with the given URI. */ - public Scope(String scopeUri) { + @Constructor + public Scope(@Param(2) String scopeUri) { this.scopeUri = scopeUri; } @@ -61,5 +66,10 @@ public String toString() { return scopeUri; } - public static final Creator CREATOR = new AutoCreator(Scope.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(Scope.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/api/Status.java b/play-services-basement/src/main/java/com/google/android/gms/common/api/Status.java index 2b6862f121..af1c543ca2 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/api/Status.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/api/Status.java @@ -21,18 +21,20 @@ import android.content.Intent; import android.content.IntentSender; import android.content.IntentSender.SendIntentException; - +import android.os.Parcel; import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; -import org.microg.safeparcel.SafeParceled; /** * Represents the results of work. */ @PublicApi -public final class Status extends AutoSafeParcelable implements Result { +@SafeParcelable.Class +public final class Status extends AbstractSafeParcelable implements Result { @PublicApi(exclude = true) public static final Status INTERNAL_ERROR = new Status(CommonStatusCodes.INTERNAL_ERROR, "Internal error"); @PublicApi(exclude = true) @@ -40,16 +42,16 @@ public final class Status extends AutoSafeParcelable implements Result { @PublicApi(exclude = true) public static final Status SUCCESS = new Status(CommonStatusCodes.SUCCESS, "Success"); - @SafeParceled(1000) - private int versionCode = 1; + @Field(1000) + int versionCode = 1; - @SafeParceled(1) + @Field(value = 1, getterName = "getStatusCode") private final int statusCode; - @SafeParceled(2) + @Field(value = 2, getterName = "getStatusMessage") private final String statusMessage; - @SafeParceled(3) + @Field(value = 3, getterName = "getResolution") private final PendingIntent resolution; private Status() { @@ -84,7 +86,8 @@ public Status(int statusCode, String statusMessage) { * @param statusMessage The message associated with this status, or null. * @param resolution A pending intent that will resolve the issue when started, or null. */ - public Status(int statusCode, String statusMessage, PendingIntent resolution) { + @Constructor + public Status(@Param(1) int statusCode, @Param(2) String statusMessage, @Param(3) PendingIntent resolution) { this.statusCode = statusCode; this.statusMessage = statusMessage; this.resolution = resolution; @@ -184,5 +187,10 @@ public String toString() { return ToStringHelper.name("Status").field("code", statusCode).field("message", statusMessage).field("resolution", resolution).end(); } - public static final Creator CREATOR = new AutoCreator(Status.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(Status.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/internal/ConnectionInfo.java b/play-services-basement/src/main/java/com/google/android/gms/common/internal/ConnectionInfo.java index 5afe6d1033..19326d08fb 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/internal/ConnectionInfo.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/internal/ConnectionInfo.java @@ -6,12 +6,15 @@ package com.google.android.gms.common.internal; import android.os.Bundle; - +import android.os.Parcel; +import androidx.annotation.NonNull; import com.google.android.gms.common.Feature; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; -import org.microg.safeparcel.AutoSafeParcelable; - -public class ConnectionInfo extends AutoSafeParcelable { +@SafeParcelable.Class +public class ConnectionInfo extends AbstractSafeParcelable { @Field(1) public Bundle params; @Field(2) @@ -19,5 +22,10 @@ public class ConnectionInfo extends AutoSafeParcelable { @Field(3) public int unknown3; - public static final Creator CREATOR = new AutoSafeParcelable.AutoCreator<>(ConnectionInfo.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(ConnectionInfo.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/internal/GetServiceRequest.java b/play-services-basement/src/main/java/com/google/android/gms/common/internal/GetServiceRequest.java index 103cd3b444..6ff0d84972 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/internal/GetServiceRequest.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/internal/GetServiceRequest.java @@ -19,20 +19,22 @@ import android.accounts.Account; import android.os.Bundle; import android.os.IBinder; - +import android.os.Parcel; +import androidx.annotation.NonNull; import com.google.android.gms.common.Feature; import com.google.android.gms.common.api.Scope; - +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.Constants; import org.microg.gms.common.GmsService; -import org.microg.safeparcel.AutoSafeParcelable; -import org.microg.safeparcel.SafeParceled; import java.util.Arrays; -public class GetServiceRequest extends AutoSafeParcelable { +@SafeParcelable.Class +public class GetServiceRequest extends AbstractSafeParcelable { @Field(1) - private int versionCode = 6; + int versionCode = 6; @Field(2) public final int serviceId; @Field(3) @@ -49,26 +51,27 @@ public class GetServiceRequest extends AutoSafeParcelable { public Account account; @Field(9) @Deprecated - private long field9; + long field9; @Field(10) public Feature[] defaultFeatures; @Field(11) public Feature[] apiFeatures; @Field(12) - private boolean supportsConnectionInfo; + boolean supportsConnectionInfo; @Field(13) - private int field13; + int field13; @Field(14) - private boolean field14; + boolean field14; @Field(15) - private String attributionTag; + String attributionTag; private GetServiceRequest() { serviceId = -1; gmsVersion = Constants.GMS_VERSION_CODE; } - public GetServiceRequest(int serviceId) { + @Constructor + public GetServiceRequest(@Param(2) int serviceId) { this.serviceId = serviceId; this.gmsVersion = Constants.GMS_VERSION_CODE; this.supportsConnectionInfo = true; @@ -86,5 +89,10 @@ public String toString() { '}'; } - public static Creator CREATOR = new AutoCreator(GetServiceRequest.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static SafeParcelableCreatorAndWriter CREATOR = findCreator(GetServiceRequest.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/internal/ValidateAccountRequest.java b/play-services-basement/src/main/java/com/google/android/gms/common/internal/ValidateAccountRequest.java index 7133729167..1cf0ecc19f 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/internal/ValidateAccountRequest.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/internal/ValidateAccountRequest.java @@ -16,8 +16,18 @@ package com.google.android.gms.common.internal; -import org.microg.safeparcel.AutoSafeParcelable; +import android.os.Parcel; +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; -public class ValidateAccountRequest extends AutoSafeParcelable { - public static Creator CREATOR = new AutoCreator(ValidateAccountRequest.class); +@SafeParcelable.Class +public class ValidateAccountRequest extends AbstractSafeParcelable { + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static SafeParcelableCreatorAndWriter CREATOR = findCreator(ValidateAccountRequest.class); } diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/SafeParcelable.java b/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/SafeParcelable.java index 9583d01751..0d8d1cc044 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/SafeParcelable.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/SafeParcelable.java @@ -43,5 +43,13 @@ public interface SafeParcelable extends Parcelable { boolean useDirectList() default false; long versionCode() default -1; + + String defaultValue() default ""; + + String type() default ""; + + String getterName() default ""; + + String getter() default ""; } } diff --git a/play-services-basement/src/main/java/org/microg/safeparcel/AutoSafeParcelable.java b/play-services-basement/src/main/java/org/microg/safeparcel/AutoSafeParcelable.java index 09e0ccbf0a..cc66bc64c3 100644 --- a/play-services-basement/src/main/java/org/microg/safeparcel/AutoSafeParcelable.java +++ b/play-services-basement/src/main/java/org/microg/safeparcel/AutoSafeParcelable.java @@ -16,13 +16,13 @@ public abstract class AutoSafeParcelable extends AbstractSafeParcelable { @SuppressWarnings("unchecked") @Override - public void writeToParcel(Parcel out, int flags) { + public void writeToParcel(Parcel dest, int flags) { Creator creator = SafeParcelReflectionUtil.getCreator(this.getClass()); if (creator instanceof SafeParcelableCreatorAndWriter) { - ((SafeParcelableCreatorAndWriter) (SafeParcelableCreatorAndWriter) creator).writeToParcel(this, out, flags); + ((SafeParcelableCreatorAndWriter) (SafeParcelableCreatorAndWriter) creator).writeToParcel(this, dest, flags); } else { Log.w(TAG, "AutoSafeParcelable is not using SafeParcelableCreatorAndWriter"); - SafeParcelReflectionUtil.writeObject(this, out, flags); + SafeParcelReflectionUtil.writeObject(this, dest, flags); } } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/Attachment.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/Attachment.java index 34caae66fb..ed47561270 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/Attachment.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/Attachment.java @@ -7,8 +7,7 @@ import android.os.Parcel; import android.os.Parcelable; - -import org.microg.gms.common.PublicApi; +import org.microg.gms.common.Hide; /** * Clients may communicate with authenticators using a variety of mechanisms. We define authenticators that are @@ -41,7 +40,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(toString()); } - @PublicApi(exclude = true) + @Hide public static Attachment fromString(String attachment) throws UnsupportedAttachmentException { for (Attachment value : values()) { if (value.value.equals(attachment)) return value; diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AttestationConveyancePreference.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AttestationConveyancePreference.java index 9c3893f211..70c573c8a0 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AttestationConveyancePreference.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AttestationConveyancePreference.java @@ -10,9 +10,8 @@ import android.os.Parcel; import android.os.Parcelable; - import androidx.annotation.NonNull; -import org.microg.gms.common.PublicApi; +import org.microg.gms.common.Hide; /** * An enum describing the relying party's preference for attestation conveyance. @@ -44,7 +43,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(toString()); } - @PublicApi(exclude = true) + @Hide @NonNull public static AttestationConveyancePreference fromString(String attachment) throws UnsupportedAttestationConveyancePreferenceException { for (AttestationConveyancePreference value : values()) { diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensions.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensions.java index d920472379..d5a97b611c 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensions.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensions.java @@ -8,11 +8,15 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; +import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -24,22 +28,36 @@ * for each supported extension. */ @PublicApi -public class AuthenticationExtensions extends AutoSafeParcelable { - @Field(2) +@SafeParcelable.Class +public class AuthenticationExtensions extends AbstractSafeParcelable { + @Field(value = 2, getterName = "getFidoAppIdExtension") @Nullable private FidoAppIdExtension fidoAppIdExtension; - @Field(3) + @Field(value = 3, getterName = "getCableAuthenticationExtension") @Nullable private CableAuthenticationExtension cableAuthenticationExtension; - @Field(4) + @Field(value = 4, getterName = "getUserVerificationMethodExtension") @Nullable private UserVerificationMethodExtension userVerificationMethodExtension; + @Constructor + public AuthenticationExtensions(@Param(2) @Nullable FidoAppIdExtension fidoAppIdExtension, @Param(3) @Nullable CableAuthenticationExtension cableAuthenticationExtension, @Param(4) @Nullable UserVerificationMethodExtension userVerificationMethodExtension) { + this.fidoAppIdExtension = fidoAppIdExtension; + this.cableAuthenticationExtension = cableAuthenticationExtension; + this.userVerificationMethodExtension = userVerificationMethodExtension; + } + @Nullable public FidoAppIdExtension getFidoAppIdExtension() { return fidoAppIdExtension; } + @Hide + @Nullable + public CableAuthenticationExtension getCableAuthenticationExtension() { + return cableAuthenticationExtension; + } + @Nullable public UserVerificationMethodExtension getUserVerificationMethodExtension() { return userVerificationMethodExtension; @@ -111,12 +129,14 @@ public Builder setUserVerificationMethodExtension(@Nullable UserVerificationMeth */ @NonNull public AuthenticationExtensions build() { - AuthenticationExtensions extensions = new AuthenticationExtensions(); - extensions.fidoAppIdExtension = fidoAppIdExtension; - extensions.userVerificationMethodExtension = userVerificationMethodExtension; - return extensions; + return new AuthenticationExtensions(fidoAppIdExtension, null, userVerificationMethodExtension); } } - public static final Creator CREATOR = new AutoCreator<>(AuthenticationExtensions.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(AuthenticationExtensions.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsClientOutputs.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsClientOutputs.java index ed2505db82..53c90f408b 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsClientOutputs.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsClientOutputs.java @@ -8,11 +8,14 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -20,11 +23,17 @@ * This container class represents client output for extensions that can be passed into FIDO2 APIs. */ @PublicApi -public class AuthenticationExtensionsClientOutputs extends AutoSafeParcelable { - @Field(1) +@SafeParcelable.Class +public class AuthenticationExtensionsClientOutputs extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getUvmEntries") @Nullable private UvmEntries uvmEntries; + @Constructor + AuthenticationExtensionsClientOutputs(@Param(1)@Nullable UvmEntries uvmEntries) { + this.uvmEntries = uvmEntries; + } + @Nullable public UvmEntries getUvmEntries() { return uvmEntries; @@ -91,11 +100,14 @@ public Builder setUserVerificationMethodEntries(@Nullable UvmEntries uvmEntries) */ @NonNull public AuthenticationExtensionsClientOutputs build() { - AuthenticationExtensionsClientOutputs extensions = new AuthenticationExtensionsClientOutputs(); - extensions.uvmEntries = uvmEntries; - return extensions; + return new AuthenticationExtensionsClientOutputs(uvmEntries); } } - public static final Creator CREATOR = new AutoCreator<>(AuthenticationExtensionsClientOutputs.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(AuthenticationExtensionsClientOutputs.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsCredPropsOutputs.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsCredPropsOutputs.java index 0088d3215c..0dd5f6f648 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsCredPropsOutputs.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticationExtensionsCredPropsOutputs.java @@ -23,8 +23,8 @@ */ @SafeParcelable.Class public class AuthenticationExtensionsCredPropsOutputs extends AbstractSafeParcelable { - @Field(1) - boolean rk; + @Field(value = 1, getterName = "getIsDiscoverableCredential") + private boolean rk; @Constructor public AuthenticationExtensionsCredPropsOutputs(@Param(1) boolean rk) { diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAssertionResponse.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAssertionResponse.java index d8f461c969..e4da7b2288 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAssertionResponse.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAssertionResponse.java @@ -8,8 +8,11 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; @@ -21,26 +24,29 @@ * of a private key as well as evidence of user consent to a specific transaction. */ @PublicApi +@SafeParcelable.Class public class AuthenticatorAssertionResponse extends AuthenticatorResponse { - @Field(2) + @Field(value = 2, getterName = "getKeyHandle") @NonNull private byte[] keyHandle; - @Field(3) + @Field(value = 3, getterName = "getClientDataJSON") @NonNull private byte[] clientDataJSON; - @Field(4) + @Field(value = 4, getterName = "getAuthenticatorData") @NonNull private byte[] authenticatorData; - @Field(5) + @Field(value = 5, getterName = "getSignature") @NonNull private byte[] signature; - @Field(6) + @Field(value = 6, getterName = "getUserHandle") @Nullable private byte[] userHandle; - private AuthenticatorAssertionResponse() {} + private AuthenticatorAssertionResponse() { + } - public AuthenticatorAssertionResponse(@NonNull byte[] keyHandle, @NonNull byte[] clientDataJSON, @NonNull byte[] authenticatorData, @NonNull byte[] signature, @Nullable byte[] userHandle) { + @Constructor + public AuthenticatorAssertionResponse(@Param(2) @NonNull byte[] keyHandle, @Param(3) @NonNull byte[] clientDataJSON, @Param(4) @NonNull byte[] authenticatorData, @Param(5) @NonNull byte[] signature, @Param(6) @Nullable byte[] userHandle) { this.keyHandle = keyHandle; this.clientDataJSON = clientDataJSON; this.authenticatorData = authenticatorData; @@ -120,5 +126,10 @@ public static AuthenticatorAssertionResponse deserializeFromBytes(byte[] seriali return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } - public static final Creator CREATOR = new AutoCreator<>(AuthenticatorAssertionResponse.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(AuthenticatorAssertionResponse.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAttestationResponse.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAttestationResponse.java index a87bbdbd8e..4aeb1798f0 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAttestationResponse.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorAttestationResponse.java @@ -8,7 +8,10 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; @@ -20,24 +23,27 @@ * Represents a newly-created scoped credential, aka the response from a registration request. */ @PublicApi +@SafeParcelable.Class public class AuthenticatorAttestationResponse extends AuthenticatorResponse { - @Field(2) + @Field(value = 2, getterName = "getKeyHandle") @NonNull private byte[] keyHandle; - @Field(3) + @Field(value = 3, getterName = "getClientDataJSON") @NonNull private byte[] clientDataJSON; - @Field(4) + @Field(value = 4, getterName = "getAttestationObject") @NonNull private byte[] attestationObject; - @Field(5) + @Field(value = 5, getterName = "getTransports") @NonNull private String[] transports; - private AuthenticatorAttestationResponse() {} + private AuthenticatorAttestationResponse() { + } @Hide - public AuthenticatorAttestationResponse(@NonNull byte[] keyHandle, @NonNull byte[] clientDataJSON, @NonNull byte[] attestationObject, @NonNull String[] transports) { + @Constructor + public AuthenticatorAttestationResponse(@Param(2) @NonNull byte[] keyHandle, @Param(3) @NonNull byte[] clientDataJSON, @Param(4) @NonNull byte[] attestationObject, @Param(5) @NonNull String[] transports) { this.keyHandle = keyHandle; this.clientDataJSON = clientDataJSON; this.attestationObject = attestationObject; @@ -110,5 +116,10 @@ public static AuthenticatorAttestationResponse deserializeFromBytes(byte[] seria return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } - public static final Creator CREATOR = new AutoCreator<>(AuthenticatorAttestationResponse.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(AuthenticatorAttestationResponse.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorErrorResponse.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorErrorResponse.java index 112cef642b..981e939f6d 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorErrorResponse.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorErrorResponse.java @@ -8,8 +8,11 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; @@ -21,14 +24,15 @@ * The response after an error occurred. */ @PublicApi +@SafeParcelable.Class public class AuthenticatorErrorResponse extends AuthenticatorResponse { - @Field(2) + @Field(value = 2, getterName = "getErrorCode") @NonNull private ErrorCode errorCode; - @Field(3) + @Field(value = 3, getterName = "getErrorMessage") @Nullable private String errorMessage; - @Field(4) + @Field(value = 4, getterName = "getInternalErrorCode") private int internalErrorCode; private AuthenticatorErrorResponse() { @@ -40,6 +44,13 @@ public AuthenticatorErrorResponse(@NonNull ErrorCode errorCode, @Nullable String this.errorMessage = errorMessage; } + @Constructor + AuthenticatorErrorResponse(@Param(2) @NonNull ErrorCode errorCode, @Param(3) @Nullable String errorMessage, @Param(4) int internalErrorCode) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.internalErrorCode = internalErrorCode; + } + @Override @NonNull public byte[] getClientDataJSON() { @@ -60,6 +71,11 @@ public String getErrorMessage() { return errorMessage; } + @Hide + public int getInternalErrorCode() { + return internalErrorCode; + } + @Override @NonNull public byte[] serializeToBytes() { @@ -98,5 +114,10 @@ public static AuthenticatorErrorResponse deserializeFromBytes(byte[] serializedB return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } - public static final Creator CREATOR = new AutoCreator<>(AuthenticatorErrorResponse.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(AuthenticatorErrorResponse.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorResponse.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorResponse.java index c247b58b96..24e2f3a48a 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorResponse.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorResponse.java @@ -9,12 +9,12 @@ package com.google.android.gms.fido.fido2.api.common; import androidx.annotation.NonNull; -import org.microg.safeparcel.AutoSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; /** * Authenticators respond to relying party requests by returning an object derived from this interface. */ -public abstract class AuthenticatorResponse extends AutoSafeParcelable { +public abstract class AuthenticatorResponse extends AbstractSafeParcelable { @NonNull public abstract byte[] getClientDataJSON(); diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorSelectionCriteria.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorSelectionCriteria.java index dd7915e796..9ad09bfaa2 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorSelectionCriteria.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/AuthenticatorSelectionCriteria.java @@ -8,12 +8,14 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.Hide; -import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -21,20 +23,29 @@ * Relying Parties may use {@link AuthenticatorSelectionCriteria} to specify their requirements regarding authenticator * attributes. */ -public class AuthenticatorSelectionCriteria extends AutoSafeParcelable { - @Field(2) +@SafeParcelable.Class +public class AuthenticatorSelectionCriteria extends AbstractSafeParcelable { + @Field(value = 2, getterName = "getAttachment") @Nullable private Attachment attachment; - @Field(3) + @Field(value = 3, getterName = "getRequireResidentKey") @Nullable private Boolean requireResidentKey; - @Field(4) + @Field(value = 4, getterName = "getRequireUserVerification") @Nullable private UserVerificationRequirement requireUserVerification; - @Field(5) + @Field(value = 5, getterName = "getResidentKeyRequirement") @Nullable private ResidentKeyRequirement residentKeyRequirement; + @Constructor + AuthenticatorSelectionCriteria(@Param(2) @Nullable Attachment attachment, @Param(3) @Nullable Boolean requireResidentKey, @Param(4) @Nullable UserVerificationRequirement requireUserVerification, @Param(5) @Nullable ResidentKeyRequirement residentKeyRequirement) { + this.attachment = attachment; + this.requireResidentKey = requireResidentKey; + this.requireUserVerification = requireUserVerification; + this.residentKeyRequirement = residentKeyRequirement; + } + @Nullable public Attachment getAttachment() { return attachment; @@ -135,13 +146,14 @@ public Builder setResidentKeyRequirement(@Nullable ResidentKeyRequirement reside @NonNull public AuthenticatorSelectionCriteria build() { - AuthenticatorSelectionCriteria criteria = new AuthenticatorSelectionCriteria(); - criteria.attachment = attachment; - criteria.requireResidentKey = requireResidentKey; - criteria.residentKeyRequirement = residentKeyRequirement; - return criteria; + return new AuthenticatorSelectionCriteria(attachment, requireResidentKey, null, residentKeyRequirement); } } - public static final Creator CREATOR = new AutoCreator<>(AuthenticatorSelectionCriteria.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(AuthenticatorSelectionCriteria.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialCreationOptions.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialCreationOptions.java index a41a68abf7..707edcd6ad 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialCreationOptions.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialCreationOptions.java @@ -7,9 +7,13 @@ import android.net.Uri; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; +import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; @@ -19,17 +23,25 @@ * Parameters to a make credential request from a Web browser. */ @PublicApi +@SafeParcelable.Class public class BrowserPublicKeyCredentialCreationOptions extends BrowserRequestOptions { - @Field(2) + @Field(value = 2, getterName = "getPublicKeyCredentialCreationOptions") @NonNull private PublicKeyCredentialCreationOptions delegate; - @Field(3) + @Field(value = 3, getterName = "getOrigin") @NonNull private Uri origin; - @Field(4) + @Field(value = 4, getterName = "getClientDataHash") @Nullable private byte[] clientDataHash; + @Constructor + BrowserPublicKeyCredentialCreationOptions(@Param(2) @NonNull PublicKeyCredentialCreationOptions delegate, @Param(3) @NonNull Uri origin, @Param(4) @Nullable byte[] clientDataHash) { + this.delegate = delegate; + this.origin = origin; + this.clientDataHash = clientDataHash; + } + @Override @Nullable public AuthenticationExtensions getAuthenticationExtensions() { @@ -157,11 +169,7 @@ public BrowserPublicKeyCredentialCreationOptions.Builder setPublicKeyCredentialC */ @NonNull public BrowserPublicKeyCredentialCreationOptions build() { - BrowserPublicKeyCredentialCreationOptions options = new BrowserPublicKeyCredentialCreationOptions(); - options.delegate = delegate; - options.origin = origin; - options.clientDataHash = clientDataHash; - return options; + return new BrowserPublicKeyCredentialCreationOptions(delegate, origin, clientDataHash); } } @@ -169,5 +177,10 @@ public static BrowserPublicKeyCredentialCreationOptions deserializeFromBytes(byt return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } - public static final Creator CREATOR = new AutoCreator<>(BrowserPublicKeyCredentialCreationOptions.class); + @Override + public void writeToParcel(Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(BrowserPublicKeyCredentialCreationOptions.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialRequestOptions.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialRequestOptions.java index 3e58b8e5fe..14d2af40a5 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialRequestOptions.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/BrowserPublicKeyCredentialRequestOptions.java @@ -7,8 +7,11 @@ import android.net.Uri; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; @@ -19,17 +22,25 @@ * Parameters for a signature request from a Web Browser. */ @PublicApi +@SafeParcelable.Class public class BrowserPublicKeyCredentialRequestOptions extends BrowserRequestOptions { - @Field(2) + @Field(value = 2, getterName = "getPublicKeyCredentialRequestOptions") @NonNull private PublicKeyCredentialRequestOptions delegate; - @Field(3) + @Field(value = 3, getterName = "getOrigin") @NonNull private Uri origin; - @Field(4) + @Field(value = 4, getterName = "getClientDataHash") @Nullable private byte[] clientDataHash; + @Constructor + BrowserPublicKeyCredentialRequestOptions(@Param(2) @NonNull PublicKeyCredentialRequestOptions delegate, @Param(3) @NonNull Uri origin, @Param(4) @Nullable byte[] clientDataHash) { + this.delegate = delegate; + this.origin = origin; + this.clientDataHash = clientDataHash; + } + @Override @Nullable public AuthenticationExtensions getAuthenticationExtensions() { @@ -158,11 +169,7 @@ public Builder setPublicKeyCredentialRequestOptions(@NonNull PublicKeyCredential */ @NonNull public BrowserPublicKeyCredentialRequestOptions build() { - BrowserPublicKeyCredentialRequestOptions options = new BrowserPublicKeyCredentialRequestOptions(); - options.delegate = delegate; - options.origin = origin; - options.clientDataHash = clientDataHash; - return options; + return new BrowserPublicKeyCredentialRequestOptions(delegate, origin, clientDataHash); } } @@ -170,5 +177,10 @@ public static BrowserPublicKeyCredentialRequestOptions deserializeFromBytes(byte return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } - public static final Creator CREATOR = new AutoCreator<>(BrowserPublicKeyCredentialRequestOptions.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(BrowserPublicKeyCredentialRequestOptions.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationData.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationData.java index 4f61daa0ef..fc50849731 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationData.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationData.java @@ -5,21 +5,30 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; -import org.microg.safeparcel.AutoSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; -public class CableAuthenticationData extends AutoSafeParcelable { +@SafeParcelable.Class +public class CableAuthenticationData extends AbstractSafeParcelable { @Field(1) - private long version; + long version; @Field(2) @NonNull - private byte[] clientEid; + byte[] clientEid; @Field(3) @NonNull - private byte[] authenticatorEid; + byte[] authenticatorEid; @Field(4) @NonNull - private byte[] sessionPreKey; + byte[] sessionPreKey; - public static final Creator CREATOR = new AutoCreator<>(CableAuthenticationData.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(CableAuthenticationData.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationExtension.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationExtension.java index e5b837673d..74b4434ea3 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationExtension.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/CableAuthenticationExtension.java @@ -5,15 +5,24 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; -import org.microg.safeparcel.AutoSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import java.util.List; -public class CableAuthenticationExtension extends AutoSafeParcelable { +@SafeParcelable.Class +public class CableAuthenticationExtension extends AbstractSafeParcelable { @Field(1) @NonNull - private List cableAuthentication; + List cableAuthentication; - public static final Creator CREATOR = new AutoCreator<>(CableAuthenticationExtension.class); + @Override + public void writeToParcel(Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(CableAuthenticationExtension.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/ErrorCode.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/ErrorCode.java index 444b534ca4..1f69dc7730 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/ErrorCode.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/ErrorCode.java @@ -75,7 +75,7 @@ public enum ErrorCode implements Parcelable { this.code = code; } - @PublicApi(exclude = true) + @Hide public int getCode() { return code; } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoAppIdExtension.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoAppIdExtension.java index e7cee27f0a..d19d9b5e17 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoAppIdExtension.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoAppIdExtension.java @@ -8,9 +8,12 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -24,15 +27,17 @@ * Note that this extension is only valid if used during the get() call; other usage should result in client error. */ @PublicApi -public class FidoAppIdExtension extends AutoSafeParcelable { - @Field(2) +@SafeParcelable.Class +public class FidoAppIdExtension extends AbstractSafeParcelable { + @Field(value = 2, getterName = "getAppId") @NonNull private String appId; private FidoAppIdExtension() { } - public FidoAppIdExtension(@NonNull String appId) { + @Constructor + public FidoAppIdExtension(@Param(2) @NonNull String appId) { this.appId = appId; } @@ -56,5 +61,10 @@ public int hashCode() { return Arrays.hashCode(new Object[]{appId}); } - public static final Creator CREATOR = new AutoCreator<>(FidoAppIdExtension.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(FidoAppIdExtension.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoCredentialDetails.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoCredentialDetails.java index 13840c6eb7..61c25b9d7a 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoCredentialDetails.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/FidoCredentialDetails.java @@ -11,9 +11,10 @@ import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Objects; @@ -21,22 +22,23 @@ * Contains the attributes of a single FIDO credential that are returned to the caller in response to a * {@link Fido2PrivilegedApiClient#getCredentialList(String)} call. */ -public class FidoCredentialDetails extends AutoSafeParcelable { - @Field(1) +@SafeParcelable.Class +public class FidoCredentialDetails extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getUserName") @Nullable private String userName; - @Field(2) + @Field(value = 2, getterName = "getUserDisplayName") @Nullable private String userDisplayName; - @Field(3) + @Field(value = 3, getterName = "getUserId") @Nullable private byte[] userId; - @Field(4) + @Field(value = 4, getterName = "getCredentialId") @NonNull private byte[] credentialId; - @Field(5) + @Field(value = 5, getterName = "getIsDiscoverable") private boolean discoverable; - @Field(6) + @Field(value = 6, getterName = "getIsPaymentCredential") private boolean paymentCredential; private FidoCredentialDetails() { diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredential.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredential.java index 3539d16c10..d7738066b8 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredential.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredential.java @@ -8,12 +8,15 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -22,32 +25,49 @@ * assertion is requested. */ @PublicApi -public class PublicKeyCredential extends AutoSafeParcelable { - @Field(1) +@SafeParcelable.Class +public class PublicKeyCredential extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getId") @NonNull private String id; - @Field(2) + @Field(value = 2, getterName = "getType") @NonNull private String type; - @Field(3) + @Field(value = 3, getterName = "getRawId") @NonNull private byte[] rawId; - @Field(4) + @Field(value = 4, getter = "$object.getResponse() instanceof $type ? ($type) $object.getResponse() : null") @Nullable private AuthenticatorAttestationResponse registerResponse; - @Field(5) + @Field(value = 5, getter = "$object.getResponse() instanceof $type ? ($type) $object.getResponse() : null") @Nullable private AuthenticatorAssertionResponse signResponse; - @Field(6) + @Field(value = 6, getter = "$object.getResponse() instanceof $type ? ($type) $object.getResponse() : null") @Nullable private AuthenticatorErrorResponse errorResponse; - @Field(7) + @Field(value = 7, getterName = "getClientExtensionResults") @Nullable private AuthenticationExtensionsClientOutputs clientExtensionResults; - @Field(8) + @Field(value = 8, getterName = "getAuthenticatorAttachment") @Nullable private String authenticatorAttachment; + PublicKeyCredential(@NonNull String id, @NonNull String type, @NonNull byte[] rawId, @NonNull AuthenticatorResponse response, @Nullable AuthenticationExtensionsClientOutputs clientExtensionResults, @Nullable String authenticatorAttachment) { + this(id, type, rawId, response instanceof AuthenticatorAttestationResponse ? (AuthenticatorAttestationResponse) response : null, response instanceof AuthenticatorAssertionResponse ? (AuthenticatorAssertionResponse) response : null, response instanceof AuthenticatorErrorResponse ? (AuthenticatorErrorResponse) response : null, clientExtensionResults, authenticatorAttachment); + } + + @Constructor + PublicKeyCredential(@Param(1) @NonNull String id, @Param(2) @NonNull String type, @Param(3) @NonNull byte[] rawId, @Param(4) @Nullable AuthenticatorAttestationResponse registerResponse, @Param(5) @Nullable AuthenticatorAssertionResponse signResponse, @Param(6) @Nullable AuthenticatorErrorResponse errorResponse, @Param(7) @Nullable AuthenticationExtensionsClientOutputs clientExtensionResults, @Param(8) @Nullable String authenticatorAttachment) { + this.id = id; + this.type = type; + this.rawId = rawId; + this.registerResponse = registerResponse; + this.signResponse = signResponse; + this.errorResponse = errorResponse; + this.clientExtensionResults = clientExtensionResults; + this.authenticatorAttachment = authenticatorAttachment; + } + /** * Returns the authenticator attachment of this credential. */ @@ -66,7 +86,7 @@ public String getId() { return id; } - @Nullable + @NonNull public byte[] getRawId() { return rawId; } @@ -153,20 +173,7 @@ public Builder setResponse(@NonNull AuthenticatorResponse response) { * Builds the {@link PublicKeyCredential} object. */ public PublicKeyCredential build() { - PublicKeyCredential credential = new PublicKeyCredential(); - credential.id = id; - credential.type = PublicKeyCredentialType.PUBLIC_KEY.toString(); - credential.rawId = rawId; - credential.clientExtensionResults = extensionsClientOutputs; - credential.authenticatorAttachment = authenticatorAttachment; - if (response instanceof AuthenticatorAttestationResponse) { - credential.registerResponse = (AuthenticatorAttestationResponse) response; - } else if (response instanceof AuthenticatorAssertionResponse) { - credential.signResponse = (AuthenticatorAssertionResponse) response; - } else if (response instanceof AuthenticatorErrorResponse) { - credential.errorResponse = (AuthenticatorErrorResponse) response; - } - return credential; + return new PublicKeyCredential(id, PublicKeyCredentialType.PUBLIC_KEY.toString(), rawId, response, extensionsClientOutputs, authenticatorAttachment); } } @@ -215,6 +222,11 @@ public static PublicKeyCredential deserializeFromBytes(byte[] serializedBytes) { return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + @Hide - public static final Creator CREATOR = new AutoCreator<>(PublicKeyCredential.class); + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(PublicKeyCredential.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialCreationOptions.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialCreationOptions.java index 7f6f5868a1..13ab9ef951 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialCreationOptions.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialCreationOptions.java @@ -5,8 +5,11 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; @@ -19,41 +22,57 @@ * This class is used to supply options when creating a new credential. */ @PublicApi +@SafeParcelable.Class public class PublicKeyCredentialCreationOptions extends RequestOptions { - @Field(2) + @Field(value = 2, getterName = "getRp") @NonNull private PublicKeyCredentialRpEntity rp; - @Field(3) + @Field(value = 3, getterName = "getUser") @NonNull private PublicKeyCredentialUserEntity user; - @Field(4) + @Field(value = 4, getterName = "getChallenge") @NonNull private byte[] challenge; - @Field(5) + @Field(value = 5, getterName = "getParameters") @NonNull private List parameters; - @Field(6) + @Field(value = 6, getterName = "getTimeoutSeconds") @Nullable private Double timeoutSeconds; - @Field(7) + @Field(value = 7, getterName = "getExcludeList") @Nullable private List excludeList; - @Field(8) + @Field(value = 8, getterName = "getAuthenticatorSelection") @Nullable private AuthenticatorSelectionCriteria authenticatorSelection; - @Field(9) + @Field(value = 9, getterName = "getRequestId") @Nullable private Integer requestId; - @Field(10) + @Field(value = 10, getterName = "getTokenBinding") @Nullable private TokenBinding tokenBinding; - @Field(11) + @Field(value = 11, getterName = "getAttestationConveyancePreference") @Nullable private AttestationConveyancePreference attestationConveyancePreference; - @Field(12) + @Field(value = 12, getterName = "getAuthenticationExtensions") @Nullable private AuthenticationExtensions authenticationExtensions; + @Constructor + PublicKeyCredentialCreationOptions(@Param(2) @NonNull PublicKeyCredentialRpEntity rp, @Param(3) @NonNull PublicKeyCredentialUserEntity user, @Param(4) @NonNull byte[] challenge, @Param(5) @NonNull List parameters, @Param(6) @Nullable Double timeoutSeconds, @Param(7) @Nullable List excludeList, @Param(8) @Nullable AuthenticatorSelectionCriteria authenticatorSelection, @Param(9) @Nullable Integer requestId, @Param(10) @Nullable TokenBinding tokenBinding, @Param(11) @Nullable AttestationConveyancePreference attestationConveyancePreference, @Param(12) @Nullable AuthenticationExtensions authenticationExtensions) { + this.rp = rp; + this.user = user; + this.challenge = challenge; + this.parameters = parameters; + this.timeoutSeconds = timeoutSeconds; + this.excludeList = excludeList; + this.authenticatorSelection = authenticatorSelection; + this.requestId = requestId; + this.tokenBinding = tokenBinding; + this.attestationConveyancePreference = attestationConveyancePreference; + this.authenticationExtensions = authenticationExtensions; + } + @Nullable public AttestationConveyancePreference getAttestationConveyancePreference() { return attestationConveyancePreference; @@ -297,19 +316,7 @@ public Builder setUser(@NonNull PublicKeyCredentialUserEntity user) { * Builds the {@link PublicKeyCredentialCreationOptions} object. */ public PublicKeyCredentialCreationOptions build() { - PublicKeyCredentialCreationOptions options = new PublicKeyCredentialCreationOptions(); - options.rp = rp; - options.user = user; - options.challenge = challenge; - options.parameters = parameters; - options.timeoutSeconds = timeoutSeconds; - options.excludeList = excludeList; - options.authenticatorSelection = authenticatorSelection; - options.requestId = requestId; - options.tokenBinding = tokenBinding; - options.attestationConveyancePreference = attestationConveyancePreference; - options.authenticationExtensions = authenticationExtensions; - return options; + return new PublicKeyCredentialCreationOptions(rp, user, challenge, parameters, timeoutSeconds, excludeList, authenticatorSelection, requestId, tokenBinding, attestationConveyancePreference, authenticationExtensions); } } @@ -324,6 +331,11 @@ public static PublicKeyCredentialCreationOptions deserializeFromBytes(byte[] ser return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + @Hide - public static final Creator CREATOR = new AutoCreator<>(PublicKeyCredentialCreationOptions.class); + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(PublicKeyCredentialCreationOptions.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialDescriptor.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialDescriptor.java index ee93eb12d7..5067145fa1 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialDescriptor.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialDescriptor.java @@ -8,13 +8,15 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.fido.common.Transport; - import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; import java.util.List; @@ -24,14 +26,15 @@ * parameter to the registration or authentication method. */ @PublicApi -public class PublicKeyCredentialDescriptor extends AutoSafeParcelable { - @Field(2) +@SafeParcelable.Class +public class PublicKeyCredentialDescriptor extends AbstractSafeParcelable { + @Field(value = 2, getterName = "getType") @NonNull private PublicKeyCredentialType type; - @Field(3) + @Field(value = 3, getterName = "getId") @NonNull private byte[] id; - @Field(4) + @Field(value = 4, getterName = "getTransports") @Nullable private List transports; @@ -48,6 +51,13 @@ public PublicKeyCredentialDescriptor(@NonNull String type, @NonNull byte[] id, @ this.transports = transports; } + @Constructor + PublicKeyCredentialDescriptor(@Param(2) @NonNull PublicKeyCredentialType type, @Param(3) @NonNull byte[] id, @Param(4) @Nullable List transports) { + this.type = type; + this.id = id; + this.transports = transports; + } + @NonNull public byte[] getId() { return id; @@ -108,5 +118,10 @@ public UnsupportedPubKeyCredDescriptorException(String message, Throwable cause) } } - public static final Creator CREATOR = new AutoCreator<>(PublicKeyCredentialDescriptor.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(PublicKeyCredentialDescriptor.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialParameters.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialParameters.java index 5846f7e0ec..0f4c660301 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialParameters.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialParameters.java @@ -8,11 +8,14 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -20,11 +23,12 @@ * This class supplies additional parameters when creating a new credential. */ @PublicApi -public class PublicKeyCredentialParameters extends AutoSafeParcelable { - @Field(2) +@SafeParcelable.Class +public class PublicKeyCredentialParameters extends AbstractSafeParcelable { + @Field(value = 2, getterName = "getType") @NonNull private PublicKeyCredentialType type; - @Field(3) + @Field(value = 3, getterName = "getAlgorithm") @NonNull private COSEAlgorithmIdentifier algorithm; @@ -44,6 +48,12 @@ public PublicKeyCredentialParameters(@NonNull String type, int algorithm) { } } + @Constructor + PublicKeyCredentialParameters(@Param(2) @NonNull PublicKeyCredentialType type, @Param(3) @NonNull COSEAlgorithmIdentifier algorithm) { + this.type = type; + this.algorithm = algorithm; + } + @NonNull public COSEAlgorithmIdentifier getAlgorithm() { return algorithm; @@ -88,6 +98,11 @@ public String toString() { .end(); } + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + @Hide - public static final Creator CREATOR = new AutoCreator<>(PublicKeyCredentialParameters.class); + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(PublicKeyCredentialParameters.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRequestOptions.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRequestOptions.java index 9b9e655229..df3069c288 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRequestOptions.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRequestOptions.java @@ -8,8 +8,11 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; @@ -22,34 +25,47 @@ * This class is used to supply an authentication request with the data it needs to generate an assertion. */ @PublicApi +@SafeParcelable.Class public class PublicKeyCredentialRequestOptions extends RequestOptions { - @Field(2) + @Field(value = 2, getterName = "getChallenge") @NonNull private byte[] challenge; - @Field(3) + @Field(value = 3, getterName = "getTimeoutSeconds") @Nullable private Double timeoutSeconds; - @Field(4) + @Field(value = 4, getterName = "getRpId") @NonNull private String rpId; - @Field(5) + @Field(value = 5, getterName = "getAllowList") @Nullable private List allowList; - @Field(6) + @Field(value = 6, getterName = "getRequestId") @Nullable private Integer requestId; - @Field(7) + @Field(value = 7, getterName = "getTokenBinding") @Nullable private TokenBinding tokenBinding; - @Field(8) + @Field(value = 8, getterName = "getRequireUserVerification") @Nullable private UserVerificationRequirement requireUserVerification; - @Field(9) + @Field(value = 9, getterName = "getAuthenticationExtensions") @Nullable private AuthenticationExtensions authenticationExtensions; @Field(10) @Nullable - private Long longRequestId; + Long longRequestId; + + @Constructor + public PublicKeyCredentialRequestOptions(@Param(2)@NonNull byte[] challenge,@Param(3) @Nullable Double timeoutSeconds, @Param(4)@NonNull String rpId, @Param(5)@Nullable List allowList,@Param(6) @Nullable Integer requestId,@Param(7) @Nullable TokenBinding tokenBinding,@Param(8) @Nullable UserVerificationRequirement requireUserVerification, @Param(9)@Nullable AuthenticationExtensions authenticationExtensions) { + this.challenge = challenge; + this.timeoutSeconds = timeoutSeconds; + this.rpId = rpId; + this.allowList = allowList; + this.requestId = requestId; + this.tokenBinding = tokenBinding; + this.requireUserVerification = requireUserVerification; + this.authenticationExtensions = authenticationExtensions; + } @Nullable public List getAllowList() { @@ -228,15 +244,7 @@ public Builder setTokenBinding(@Nullable TokenBinding tokenBinding) { * Builds the {@link PublicKeyCredentialRequestOptions} object. */ public PublicKeyCredentialRequestOptions build() { - PublicKeyCredentialRequestOptions options = new PublicKeyCredentialRequestOptions(); - options.challenge = challenge; - options.timeoutSeconds = timeoutSeconds; - options.rpId = rpId; - options.allowList = allowList; - options.requestId = requestId; - options.tokenBinding = tokenBinding; - options.authenticationExtensions = authenticationExtensions; - return options; + return new PublicKeyCredentialRequestOptions(challenge, timeoutSeconds, rpId, allowList, requestId, tokenBinding, null, authenticationExtensions); } } @@ -251,6 +259,11 @@ public static PublicKeyCredentialRequestOptions deserializeFromBytes(byte[] seri return SafeParcelableSerializer.deserializeFromBytes(serializedBytes, CREATOR); } + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + @Hide - public static final Creator CREATOR = new AutoCreator<>(PublicKeyCredentialRequestOptions.class); + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(PublicKeyCredentialRequestOptions.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRpEntity.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRpEntity.java index a018a2055b..4f83728910 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRpEntity.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialRpEntity.java @@ -5,12 +5,15 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -18,21 +21,23 @@ * Represents the information about a relying party with which a credential is associated. */ @PublicApi -public class PublicKeyCredentialRpEntity extends AutoSafeParcelable { - @Field(2) +@SafeParcelable.Class +public class PublicKeyCredentialRpEntity extends AbstractSafeParcelable { + @Field(value = 2, getterName = "getId") @NonNull private String id; - @Field(3) + @Field(value = 3, getterName = "getName") @NonNull private String name; - @Field(4) + @Field(value = 4, getterName = "getIcon") @Nullable private String icon; private PublicKeyCredentialRpEntity() { } - public PublicKeyCredentialRpEntity(@NonNull String id, @NonNull String name, @Nullable String icon) { + @Constructor + public PublicKeyCredentialRpEntity(@Param(2)@NonNull String id, @Param(3)@NonNull String name, @Param(4)@Nullable String icon) { this.id = id; this.name = name; this.icon = icon; @@ -80,6 +85,11 @@ public String toString() { .end(); } + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + @Hide - public static final Creator CREATOR = new AutoCreator<>(PublicKeyCredentialRpEntity.class); + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(PublicKeyCredentialRpEntity.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialType.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialType.java index 601b1f993b..1d68e87551 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialType.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialType.java @@ -12,6 +12,7 @@ import android.os.Parcelable; import androidx.annotation.NonNull; +import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; /** @@ -42,7 +43,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(toString()); } - @PublicApi(exclude = true) + @Hide public static PublicKeyCredentialType fromString(String type) throws UnsupportedPublicKeyCredTypeException { for (PublicKeyCredentialType value : values()) { if (value.value.equals(type)) return value; diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialUserEntity.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialUserEntity.java index f4012b9875..0470ea279a 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialUserEntity.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/PublicKeyCredentialUserEntity.java @@ -8,11 +8,15 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; +import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -20,24 +24,26 @@ * This class is used to supply additional parameters about the user account when creating a new Credential. */ @PublicApi -public class PublicKeyCredentialUserEntity extends AutoSafeParcelable { - @Field(2) +@SafeParcelable.Class +public class PublicKeyCredentialUserEntity extends AbstractSafeParcelable { + @Field(value = 2, getterName = "getId") @NonNull private byte[] id; - @Field(3) + @Field(value = 3, getterName = "getName") @NonNull private String name; - @Field(4) + @Field(value = 4, getterName = "getIcon") @Nullable private String icon; - @Field(5) + @Field(value = 5, getterName = "getDisplayName") @NonNull private String displayName; private PublicKeyCredentialUserEntity() { } - public PublicKeyCredentialUserEntity(@NonNull byte[] id, @NonNull String name, @Nullable String icon, @NonNull String displayName) { + @Constructor + public PublicKeyCredentialUserEntity(@Param(2) @NonNull byte[] id, @Param(3) @NonNull String name, @Param(4) @Nullable String icon, @Param(5) @NonNull String displayName) { this.id = id; this.name = name; this.icon = icon; @@ -93,6 +99,11 @@ public String toString() { .end(); } - @PublicApi(exclude = true) - public static final Creator CREATOR = new AutoCreator<>(PublicKeyCredentialUserEntity.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + @Hide + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(PublicKeyCredentialUserEntity.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/RequestOptions.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/RequestOptions.java index d08d855ab7..98785c0396 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/RequestOptions.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/RequestOptions.java @@ -10,15 +10,15 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; /** * An abstract class representing FIDO2 request options. */ @PublicApi -public abstract class RequestOptions extends AutoSafeParcelable { +public abstract class RequestOptions extends AbstractSafeParcelable { @NonNull public abstract byte[] getChallenge(); @Nullable diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/TokenBinding.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/TokenBinding.java index 3c9a279fec..3cfc0a3fbb 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/TokenBinding.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/TokenBinding.java @@ -10,15 +10,16 @@ import android.os.Parcel; import android.os.Parcelable; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.json.JSONException; import org.json.JSONObject; import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; import org.microg.gms.utils.ToStringHelper; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -26,7 +27,8 @@ * Represents the Token binding information provided by the relying party. */ @PublicApi -public class TokenBinding extends AutoSafeParcelable { +@SafeParcelable.Class +public class TokenBinding extends AbstractSafeParcelable { /** * A singleton instance representing that token binding is not supported by the client. */ @@ -38,10 +40,10 @@ public class TokenBinding extends AutoSafeParcelable { @NonNull public static final TokenBinding SUPPORTED = new TokenBinding(TokenBindingStatus.SUPPORTED, null); - @Field(2) + @Field(value = 2, getterName = "getTokenBindingStatus") @NonNull private TokenBindingStatus status; - @Field(3) + @Field(value = 3, getterName = "getTokenBindingId") @Nullable private String tokenBindingId; @@ -56,7 +58,8 @@ public TokenBinding(@Nullable String tokenBindingId) { this.tokenBindingId = tokenBindingId; } - private TokenBinding(@NonNull TokenBindingStatus status, @Nullable String tokenBindingId) { + @Constructor + TokenBinding(@Param(2) @NonNull TokenBindingStatus status, @Param(3) @Nullable String tokenBindingId) { this.status = status; this.tokenBindingId = tokenBindingId; } @@ -69,6 +72,12 @@ public String getTokenBindingId() { return tokenBindingId; } + @Hide + @NonNull + public TokenBindingStatus getTokenBindingStatus() { + return status; + } + /** * Returns the stringified {@link TokenBinding.TokenBindingStatus} associated with this instance. */ @@ -187,6 +196,11 @@ public UnsupportedTokenBindingStatusException(String message) { } } + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + @Hide - public static final Creator CREATOR = new AutoCreator<>(TokenBinding.class); + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(TokenBinding.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationMethodExtension.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationMethodExtension.java index 9427bfa5e6..7a5b624288 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationMethodExtension.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationMethodExtension.java @@ -8,9 +8,12 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -23,11 +26,17 @@ * Note that this extension can be used in only sign calls. */ @PublicApi -public class UserVerificationMethodExtension extends AutoSafeParcelable { - @Field(1) +@SafeParcelable.Class +public class UserVerificationMethodExtension extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getUvm") @NonNull private boolean uvm; + @Constructor + UserVerificationMethodExtension(@Param(1) boolean uvm) { + this.uvm = uvm; + } + @NonNull public boolean getUvm() { return uvm; @@ -48,5 +57,10 @@ public int hashCode() { return Arrays.hashCode(new Object[]{uvm}); } - public static final Creator CREATOR = new AutoCreator<>(UserVerificationMethodExtension.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(UserVerificationMethodExtension.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationRequirement.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationRequirement.java index 1bba395c97..6fda81b500 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationRequirement.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UserVerificationRequirement.java @@ -8,6 +8,7 @@ import android.os.Parcel; import android.os.Parcelable; +import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; public enum UserVerificationRequirement implements Parcelable { @@ -36,7 +37,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(toString()); } - @PublicApi(exclude = true) + @Hide public static UserVerificationRequirement fromString(String attachment) throws UnsupportedUserVerificationRequirementException { for (UserVerificationRequirement value : values()) { if (value.value.equals(attachment)) return value; diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntries.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntries.java index ed4a475be6..ab6f2fdfdf 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntries.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntries.java @@ -8,10 +8,14 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; +import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.ArrayList; import java.util.Arrays; @@ -22,8 +26,9 @@ * Represents up to three user verification methods used by the authenticator. */ @PublicApi -public class UvmEntries extends AutoSafeParcelable { - @Field(1) +@SafeParcelable.Class +public class UvmEntries extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getUvmEntryList") @Nullable private List uvmEntryList; @@ -32,6 +37,11 @@ public List getUvmEntryList() { return uvmEntryList; } + @Constructor + UvmEntries(@Param(1) @Nullable List uvmEntryList) { + this.uvmEntryList = uvmEntryList; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -75,12 +85,15 @@ public Builder addUvmEntry(@Nullable UvmEntry uvmEntry) { @NonNull public UvmEntries build() { - UvmEntries uvmEntries = new UvmEntries(); - uvmEntries.uvmEntryList = new ArrayList<>(uvmEntryList); - return uvmEntries; + return new UvmEntries(new ArrayList<>(uvmEntryList)); } } - @PublicApi(exclude = true) - public static Creator CREATOR = new AutoCreator<>(UvmEntries.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + @Hide + public static SafeParcelableCreatorAndWriter CREATOR = findCreator(UvmEntries.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntry.java b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntry.java index 1f8e5d3d26..f933048318 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntry.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/fido2/api/common/UvmEntry.java @@ -8,8 +8,13 @@ package com.google.android.gms.fido.fido2.api.common; +import android.os.Parcel; +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; +import org.microg.gms.common.Hide; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -17,14 +22,22 @@ * Represents a single User Verification Method Entry */ @PublicApi -public class UvmEntry extends AutoSafeParcelable { - @Field(1) +@SafeParcelable.Class +public class UvmEntry extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getUserVerificationMethod") private int userVerificationMethod; - @Field(2) + @Field(value = 2, getterName = "getKeyProtectionType") private short keyProtectionType; - @Field(3) + @Field(value = 3, getterName = "getMatcherProtectionType") private short matcherProtectionType; + @Constructor + UvmEntry(@Param(1) int userVerificationMethod, @Param(2) short keyProtectionType, @Param(3) short matcherProtectionType) { + this.userVerificationMethod = userVerificationMethod; + this.keyProtectionType = keyProtectionType; + this.matcherProtectionType = matcherProtectionType; + } + public int getUserVerificationMethod() { return userVerificationMethod; } @@ -78,14 +91,15 @@ public Builder setMatcherProtectionType(short matcherProtectionType) { } public UvmEntry build() { - UvmEntry entry = new UvmEntry(); - entry.userVerificationMethod = userVerificationMethod; - entry.keyProtectionType = keyProtectionType; - entry.matcherProtectionType = matcherProtectionType; - return entry; + return new UvmEntry(userVerificationMethod, keyProtectionType, matcherProtectionType); } } - @PublicApi(exclude = true) - public static final Creator CREATOR = new AutoCreator<>(UvmEntry.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + @Hide + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(UvmEntry.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceDirectTransferResult.java b/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceDirectTransferResult.java index 4ab8c58a45..ae8aa5973c 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceDirectTransferResult.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceDirectTransferResult.java @@ -10,24 +10,28 @@ import android.app.Activity; import android.content.Intent; - +import android.os.Parcel; +import androidx.annotation.NonNull; import com.google.android.gms.common.api.Status; - +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; import org.microg.gms.common.PublicApi; -import org.microg.safeparcel.AutoSafeParcelable; /** * Result returned from the UI activity in {@link Activity#onActivityResult(int, int, Intent)} after the direct transfer finishes. */ @PublicApi -public class SourceDirectTransferResult extends AutoSafeParcelable { - @Field(1) +@SafeParcelable.Class +public class SourceDirectTransferResult extends AbstractSafeParcelable { + @Field(value = 1, getterName = "getStatus") private Status status; private SourceDirectTransferResult() { } - public SourceDirectTransferResult(Status status) { + @Constructor + public SourceDirectTransferResult(@Param(1) Status status) { this.status = status; } @@ -38,5 +42,10 @@ public Status getStatus() { return status; } - public static final Creator CREATOR = new AutoCreator<>(SourceDirectTransferResult.class); + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(SourceDirectTransferResult.class); } diff --git a/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceStartDirectTransferOptions.java b/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceStartDirectTransferOptions.java index 50aaf81ec3..11ae1f3d48 100644 --- a/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceStartDirectTransferOptions.java +++ b/play-services-fido/src/main/java/com/google/android/gms/fido/sourcedevice/SourceStartDirectTransferOptions.java @@ -8,12 +8,15 @@ package com.google.android.gms.fido.sourcedevice; -import org.microg.safeparcel.AutoSafeParcelable; +import android.os.Parcel; +import androidx.annotation.NonNull; +import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable; +import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter; /** * Customized options to start direct transfer. */ -public class SourceStartDirectTransferOptions extends AutoSafeParcelable { +public class SourceStartDirectTransferOptions extends AbstractSafeParcelable { /** * Value of the callerType if the caller is unknown. */ @@ -23,7 +26,7 @@ public class SourceStartDirectTransferOptions extends AutoSafeParcelable { */ public static final int CALLER_TYPE_BROWSER = 2; - @Field(1) + @Field(value = 1, getterName = "getCallerType") private int callerType; private SourceStartDirectTransferOptions() { @@ -32,9 +35,18 @@ private SourceStartDirectTransferOptions() { /** * Constructor for the {@link SourceStartDirectTransferOptions}. */ - public SourceStartDirectTransferOptions(int callerType) { + public SourceStartDirectTransferOptions(@Param(1) int callerType) { this.callerType = callerType; } - public static final Creator CREATOR = new AutoCreator<>(SourceStartDirectTransferOptions.class); + public int getCallerType() { + return callerType; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + CREATOR.writeToParcel(this, dest, flags); + } + + public static final SafeParcelableCreatorAndWriter CREATOR = findCreator(SourceStartDirectTransferOptions.class); } diff --git a/play-services-games/src/main/java/com/google/android/gms/games/PlayerLevel.java b/play-services-games/src/main/java/com/google/android/gms/games/PlayerLevel.java index a56d0d2ee5..8aebb833e9 100644 --- a/play-services-games/src/main/java/com/google/android/gms/games/PlayerLevel.java +++ b/play-services-games/src/main/java/com/google/android/gms/games/PlayerLevel.java @@ -23,11 +23,11 @@ */ @SafeParcelable.Class public class PlayerLevel extends AbstractSafeParcelable { - @Field(1) + @Field(value = 1, getterName = "getLevelNumber") private final int levelNumber; - @Field(2) + @Field(value = 2, getterName = "getMinXp") private final long minXp; - @Field(3) + @Field(value = 3, getterName = "getMaxXp") private final long maxXp; @Constructor diff --git a/safe-parcel-processor/src/main/kotlin/org/microg/safeparcel/SafeParcelProcessor.kt b/safe-parcel-processor/src/main/kotlin/org/microg/safeparcel/SafeParcelProcessor.kt index 2dea018214..51aa786ae0 100644 --- a/safe-parcel-processor/src/main/kotlin/org/microg/safeparcel/SafeParcelProcessor.kt +++ b/safe-parcel-processor/src/main/kotlin/org/microg/safeparcel/SafeParcelProcessor.kt @@ -5,7 +5,7 @@ package org.microg.safeparcel import javax.annotation.processing.AbstractProcessor -import javax.annotation.processing.Messager +import javax.annotation.processing.ProcessingEnvironment import javax.annotation.processing.RoundEnvironment import javax.annotation.processing.SupportedAnnotationTypes import javax.annotation.processing.SupportedSourceVersion @@ -24,14 +24,24 @@ const val SafeParcelWriter = "com.google.android.gms.common.internal.safeparcel. const val SafeParcelableCreatorAndWriter = "com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter" const val Field = "java.lang.reflect.Field" +const val Constructor = "java.lang.reflect.Constructor" const val Log = "android.util.Log" const val Parcel = "android.os.Parcel" +const val Parcelable = "android.os.Parcelable" +const val IInterface = "android.os.IInterface" val NATIVE_SUPPORTED_TYPES = setOf( "int", "byte", "short", "boolean", "long", "float", "double", "java.lang.Boolean", "java.lang.Byte", "java.lang.Char", "java.lang.Short", "java.lang.Integer", "java.lang.Long", "java.lang.Float", "java.lang.Double", - "java.lang.String", "android.os.Bundle" + "java.lang.String", "android.os.Bundle", "android.os.IBinder", + "int[]", "byte[]", "byte[][]", "float[]", "java.lang.String[]", + "java.util.List", "java.util.ArrayList", + +// "java.util.List", "java.util.List", +// "java.util.ArrayList", "java.util.ArrayList", +// "java.util.List", "java.util.List", "java.util.List", +// "java.util.ArrayList", "java.util.ArrayList", "java.util.ArrayList", ) @SupportedSourceVersion(SourceVersion.RELEASE_8) @@ -39,9 +49,10 @@ val NATIVE_SUPPORTED_TYPES = setOf( class SafeParcelProcessor : AbstractProcessor() { override fun process(set: Set, roundEnvironment: RoundEnvironment): Boolean { val safeParcelableClassTypeElement = set.firstOrNull() ?: return false + classes@ for (classElement in roundEnvironment.getElementsAnnotatedWith(safeParcelableClassTypeElement)) { val clazz = ClassInfo(classElement) - if (clazz.check(processingEnv.messager)) { + if (clazz.check(processingEnv)) { processingEnv.filer.createSourceFile(clazz.fullCreatorName, clazz.classElement).openWriter().use { it.write(clazz.generateCreator()) } } } @@ -69,9 +80,9 @@ class ClassInfo(val classElement: Element) { .let { if (it.size == 2) it.first { it.parameters.isNotEmpty() } else it.firstOrNull() } ?.let { ConstructorInfo(this, it) } - fun check(messager: Messager): Boolean { - fun note(message: String) = messager.printMessage(Diagnostic.Kind.NOTE, message) - fun error(message: String) = messager.printMessage(Diagnostic.Kind.ERROR, message) + fun check(processingEnv: ProcessingEnvironment): Boolean { + fun note(message: String) = processingEnv.messager.printMessage(Diagnostic.Kind.NOTE, message) + fun error(message: String) = processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, message) if (constructor == null) { error("No suitable constructor found for $fullName") return false @@ -89,11 +100,25 @@ class ClassInfo(val classElement: Element) { } for (field in fields) { if (field.type !in NATIVE_SUPPORTED_TYPES) { - error("Field ${field.name} in $fullName has unsupported type.") - return false + val typeName = field.listItemType ?: field.type + val type = runCatching { processingEnv.typeUtils.getDeclaredType(processingEnv.elementUtils.getTypeElement(typeName)) }.getOrNull() + val parcelable = processingEnv.typeUtils.getDeclaredType(processingEnv.elementUtils.getTypeElement(Parcelable)) + val iinterface = processingEnv.typeUtils.getDeclaredType(processingEnv.elementUtils.getTypeElement(IInterface)) + if (type != null && processingEnv.typeUtils.isAssignable(type, parcelable)) { + field.isParcelable = true + } else if (type != null && processingEnv.typeUtils.isAssignable(type, iinterface)) { + field.isIInterface = true + } else { + error("Field ${field.name} in $fullName has unsupported type ${if (typeName != field.type) "$typeName if ${field.type}" else field.type}.") + return false + } } - if (field.isPrivate) { - note("Using reflection when accessing ${field.name} in $fullName. Consider adding it to the @Constructor and making the field package-visible for improved performance.") + val readReflect = field.isPrivate && field.getter == null + val writeReflect = field.isPrivate && !constructor.fieldIds.contains(field.id) + when { + readReflect && writeReflect -> note("Using reflection when accessing ${field.name} in $fullName. Consider adding it to the @Constructor and a getter to the annotation for improved performance.") + writeReflect -> note("Using reflection when writing ${field.name} in $fullName. Consider adding it to the @Constructor for improved performance.") + readReflect -> note("Using reflection when reading ${field.name} in $fullName. Consider adding a getter to the annotation for improved performance.") } } return true @@ -185,7 +210,7 @@ class ConstructorInfo(val clazz: ClassInfo, val constructorElement: ExecutableEl val invocation by lazy { if (isPrivate) { listOf( - "Constructor<${clazz.fullName}> constructor = ${clazz.fullName}.class.getConstructor(${argTypes.map { "$it.class" }.joinToString(", ")});", + "$Constructor<${clazz.fullName}> constructor = ${clazz.fullName}.class.getConstructor(${argTypes.map { "$it.class" }.joinToString(", ")});", "constructor.setAccessible(true);", "object = constructor.newInstance(${args.joinToString(", ")});" ) @@ -197,7 +222,17 @@ class ConstructorInfo(val clazz: ClassInfo, val constructorElement: ExecutableEl class FieldInfo(val clazz: ClassInfo, val fieldElement: VariableElement) { val name by lazy { fieldElement.simpleName.toString() } - val type by lazy { fieldElement.asType().toString() } + val type by lazy { + fieldElement.annotationMirrors + .first { it.annotationType.toString() == "$SafeParcelable.Field" } + .elementValues + .filter { it.key.simpleName.toString() == "type" } + .firstNotNullOfOrNull { it.value.value } + ?.toString()?.takeIf { it.isNotEmpty() } + ?: fieldElement.asType().toString() + } + var isParcelable: Boolean = false + var isIInterface: Boolean = false val isPrivate by lazy { fieldElement.modifiers.contains(Modifier.PRIVATE) } val id by lazy { @@ -217,30 +252,102 @@ class FieldInfo(val clazz: ClassInfo, val fieldElement: VariableElement) { ?.toString() ?.toBoolean() == true } + val useValueParcel by lazy { + fieldElement.annotationMirrors + .first { it.annotationType.toString() == "$SafeParcelable.Field" } + .elementValues + .filter { it.key.simpleName.toString() == "useValueParcel" } + .firstNotNullOfOrNull { it.value.value } + ?.toString() + ?.toBoolean() == true + } + val getter by lazy { + fieldElement.annotationMirrors + .first { it.annotationType.toString() == "$SafeParcelable.Field" } + .elementValues + .filter { it.key.simpleName.toString() == "getter" } + .firstNotNullOfOrNull { it.value.value } + ?.toString()?.takeIf { it.isNotEmpty() } + ?.replace("\$object", "object") + ?.replace("\$type", type) + ?: fieldElement.annotationMirrors + .first { it.annotationType.toString() == "$SafeParcelable.Field" } + .elementValues + .filter { it.key.simpleName.toString() == "getterName" } + .firstNotNullOfOrNull { it.value.value } + ?.toString()?.takeIf { it.isNotEmpty() } + ?.let { "object.$it()" } + } + val subType by lazy { + fieldElement.annotationMirrors + .first { it.annotationType.toString() == "$SafeParcelable.Field" } + .elementValues + .filter { it.key.simpleName.toString() == "subClass" } + .firstNotNullOfOrNull { it.value.value } + ?.toString()?.takeIf { it.isNotEmpty() } + } + val isList by lazy { type.startsWith("java.util.List<") || type.startsWith("java.util.ArrayList<") } + val isArray by lazy { type.endsWith("[]") } + val listItemType by lazy { + subType ?: when { + type.startsWith("java.util.List<") -> type.substring(15, type.length - 1) + type.startsWith("java.util.ArrayList<") -> type.substring(20, type.length - 1) + type.endsWith("[]") -> type.substring(0, type.length - 2) + else -> null + } + } val variableName by lazy { "_$name\$000" } val variableDeclaration by lazy { "$type $variableName;" } val defaultValue by lazy { - when (type) { - "boolean" -> "false" - "byte", "char", "short", "int", "long", "float", "double" -> "0" - else -> "null" - } + fieldElement.annotationMirrors + .first { it.annotationType.toString() == "$SafeParcelable.Field" } + .elementValues + .filter { it.key.simpleName.toString() == "defaultValue" } + .firstNotNullOfOrNull { it.value.value } + ?.toString()?.takeIf { it.isNotEmpty() } + ?: when (type) { + "boolean" -> "false" + "byte", "char", "short", "int", "long", "float", "double" -> "0" + else -> "null" + } } val setVariableDefault by lazy { "$variableName = $defaultValue;" } val readVariableFromParcel by lazy { when (type) { - "int" -> "$variableName = $SafeParcelReader.readInt(parcel, header)" - "byte" -> "$variableName = $SafeParcelReader.readByte(parcel, header)" - "short" -> "$variableName = $SafeParcelReader.readShort(parcel, header)" - "boolean" -> "$variableName = $SafeParcelReader.readBool(parcel, header)" - "long" -> "$variableName = $SafeParcelReader.readLong(parcel, header)" - "float" -> "$variableName = $SafeParcelReader.readFloat(parcel, header)" - "double" -> "$variableName = $SafeParcelReader.readDouble(parcel, header)" + "int", "java.lang.Integer" -> "$variableName = $SafeParcelReader.readInt(parcel, header)" + "byte", "java.lang.Byte" -> "$variableName = $SafeParcelReader.readByte(parcel, header)" + "short", "java.lang.Short" -> "$variableName = $SafeParcelReader.readShort(parcel, header)" + "boolean", "java.lang.Boolean" -> "$variableName = $SafeParcelReader.readBool(parcel, header)" + "long", "java.lang.Long" -> "$variableName = $SafeParcelReader.readLong(parcel, header)" + "float", "java.lang.Float" -> "$variableName = $SafeParcelReader.readFloat(parcel, header)" + "double", "java.lang.Double" -> "$variableName = $SafeParcelReader.readDouble(parcel, header)" "java.lang.String" -> "$variableName = $SafeParcelReader.readString(parcel, header)" "android.os.Bundle" -> "$variableName = $SafeParcelReader.readBundle(parcel, header, ${clazz.fullName}.class.getClassLoader())" - else -> "$SafeParcelReader.skip(parcel, header)" + "android.os.IBinder" -> "$variableName = $SafeParcelReader.readBinder(parcel, header)" + "java.lang.String[]" -> "$variableName = $SafeParcelReader.readStringArray(parcel, header)" + "byte[]" -> "$variableName = $SafeParcelReader.readByteArray(parcel, header)" + "byte[][]" -> "$variableName = $SafeParcelReader.readByteArrayArray(parcel, header)" + "float[]" -> "$variableName = $SafeParcelReader.readFloatArray(parcel, header)" + "int[]" -> "$variableName = $SafeParcelReader.readIntArray(parcel, header)" + "java.util.List", "java.util.ArrayList" -> when { + !useValueParcel -> "$variableName = $SafeParcelReader.readStringList(parcel, header)" + else -> "$variableName = $SafeParcelReader.readList(parcel, header, String.class.getClassloader())" + } +// "java.util.List", "java.util.ArrayList" -> "$variableName = $SafeParcelReader.readIntegerList(parcel, header)" +// "java.util.List", "java.util.ArrayList" -> "$variableName = $SafeParcelReader.readBooleanList(parcel, header)" +// "java.util.List", "java.util.ArrayList" -> "$variableName = $SafeParcelReader.readLongList(parcel, header)" +// "java.util.List", "java.util.ArrayList" -> "$variableName = $SafeParcelReader.readFloatList(parcel, header)" +// "java.util.List", "java.util.ArrayList" -> "$variableName = $SafeParcelReader.readDoubleList(parcel, header)" + else -> when { + isList && isParcelable && !useValueParcel -> "$variableName = $SafeParcelReader.readParcelableList(parcel, header, $listItemType.CREATOR)" + isArray && isParcelable -> "$variableName = $SafeParcelReader.readParcelableArray(parcel, header, $listItemType.CREATOR)" + isList -> "$variableName = $SafeParcelReader.readList(parcel, header, $listItemType.class.getClassloader())" + isParcelable -> "$variableName = $SafeParcelReader.readParcelable(parcel, header, $type.CREATOR)" + !isList && isIInterface -> "$variableName = $type.Stub.asInterface($SafeParcelReader.readBinder(parcel, header))" + else -> throw UnsupportedOperationException("Field $name in ${clazz.fullName} has unsupported type $type.") + } } } val readVariableFromParcelCase by lazy { "case $id: $readVariableFromParcel; break;" } @@ -250,7 +357,16 @@ class FieldInfo(val clazz: ClassInfo, val fieldElement: VariableElement) { "java.lang.Boolean", "java.lang.Byte", "java.lang.Char", "java.lang.Short", "java.lang.Integer", "java.lang.Long", "java.lang.Float", "java.lang.Double" -> "$SafeParcelWriter.write(parcel, $id, $variableName);" - else -> "$SafeParcelWriter.write(parcel, $id, $variableName, $mayNull);" + "java.util.List", "java.util.ArrayList" -> when { + !useValueParcel -> "$SafeParcelWriter.writeStringList(parcel, $id, $variableName, $mayNull);" + else -> "$SafeParcelWriter.write(parcel, $id, $variableName, $mayNull);" + } + + else -> when { + isParcelable -> "$SafeParcelWriter.write(parcel, $id, $variableName, flags, $mayNull);" + isIInterface -> "$SafeParcelWriter.write(parcel, $id, $variableName.asBinder(), $mayNull);" + else -> "$SafeParcelWriter.write(parcel, $id, $variableName, $mayNull);" + } } } @@ -283,14 +399,15 @@ class FieldInfo(val clazz: ClassInfo, val fieldElement: VariableElement) { } val setVariableFromField by lazy { - if (isPrivate) { - listOf( + when { + getter != null -> listOf("$variableName = $getter;") + isPrivate -> listOf( "$Field $reflectionFieldName = ${clazz.fullName}.class.getDeclaredField(\"$name\");", "$reflectionFieldName.setAccessible(true);", "$variableName = $reflectionFieldGetter(object);" ) - } else { - listOf("$variableName = object.$name;") + + else -> listOf("$variableName = object.$name;") } } val setFieldFromVariable by lazy {