Skip to content

Commit

Permalink
Migrate Basement/Fido SafeParcelables to use processor instead of ref…
Browse files Browse the repository at this point in the history
…lection

This improves speed and should help against ProGuard optimizing away our code
  • Loading branch information
mar-v-in committed Sep 16, 2023
1 parent 23080f8 commit dd77aca
Show file tree
Hide file tree
Showing 46 changed files with 874 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
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;

/**
* 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.
*/
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -342,5 +348,10 @@ public void startResolutionForResult(Activity activity, int requestCode) throws
}
}

public static final Creator<ConnectionResult> CREATOR = new AutoCreator<>(ConnectionResult.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<ConnectionResult> CREATOR = findCreator(ConnectionResult.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -32,5 +38,10 @@ public long getVersion() {
return version;
}

public static final Creator<Feature> CREATOR = new AutoSafeParcelable.AutoCreator<>(Feature.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<Feature> CREATOR = findCreator(Feature.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,5 +41,10 @@ public Context getContext() {
return context;
}

public static final Creator<GoogleCertificatesLookupQuery> CREATOR = findCreator(GoogleCertificatesLookupQuery.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<GoogleCertificatesLookupQuery> CREATOR = findCreator(GoogleCertificatesLookupQuery.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,5 +68,10 @@ public CertData getCertData() {
return certData;
}

public static final Creator<GoogleCertificatesQuery> CREATOR = new AutoCreator<GoogleCertificatesQuery>(GoogleCertificatesQuery.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<GoogleCertificatesQuery> CREATOR = findCreator(GoogleCertificatesQuery.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}

Expand All @@ -61,5 +66,10 @@ public String toString() {
return scopeUri;
}

public static final Creator<Scope> CREATOR = new AutoCreator<Scope>(Scope.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<Scope> CREATOR = findCreator(Scope.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,37 @@
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)
public static final Status CANCELED = new Status(CommonStatusCodes.CANCELED, "Cancelled");
@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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Status> CREATOR = new AutoCreator<Status>(Status.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<Status> CREATOR = findCreator(Status.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@
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)
public Feature[] features;
@Field(3)
public int unknown3;

public static final Creator<ConnectionInfo> CREATOR = new AutoSafeParcelable.AutoCreator<>(ConnectionInfo.class);
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static final SafeParcelableCreatorAndWriter<ConnectionInfo> CREATOR = findCreator(ConnectionInfo.class);
}
Loading

0 comments on commit dd77aca

Please sign in to comment.