- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
267 lines
16 KiB
Java
267 lines
16 KiB
Java
package androidx.credentials.playservices.controllers.GetSignInIntent;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.CancellationSignal;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.ResultReceiver;
|
|
import android.util.Log;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.credentials.CredentialManagerCallback;
|
|
import androidx.credentials.CredentialOption;
|
|
import androidx.credentials.GetCredentialRequest;
|
|
import androidx.credentials.GetCredentialResponse;
|
|
import androidx.credentials.exceptions.GetCredentialCancellationException;
|
|
import androidx.credentials.exceptions.GetCredentialException;
|
|
import androidx.credentials.exceptions.GetCredentialInterruptedException;
|
|
import androidx.credentials.exceptions.GetCredentialUnknownException;
|
|
import androidx.credentials.exceptions.GetCredentialUnsupportedException;
|
|
import androidx.credentials.playservices.CredentialProviderPlayServicesImpl;
|
|
import androidx.credentials.playservices.HiddenActivity;
|
|
import androidx.credentials.playservices.controllers.CredentialProviderBaseController;
|
|
import androidx.credentials.playservices.controllers.CredentialProviderController;
|
|
import com.google.android.gms.auth.api.identity.GetSignInIntentRequest;
|
|
import com.google.android.gms.auth.api.identity.Identity;
|
|
import com.google.android.gms.auth.api.identity.SignInCredential;
|
|
import com.google.android.gms.common.api.ApiException;
|
|
import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption;
|
|
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential;
|
|
import java.util.concurrent.Executor;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function2;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlin.jvm.internal.Ref;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class CredentialProviderGetSignInIntentController extends CredentialProviderController<GetCredentialRequest, GetSignInIntentRequest, SignInCredential, GetCredentialResponse, GetCredentialException> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String TAG = "GetSignInIntent";
|
|
public CredentialManagerCallback<GetCredentialResponse, GetCredentialException> callback;
|
|
private CancellationSignal cancellationSignal;
|
|
private final Context context;
|
|
public Executor executor;
|
|
private final CredentialProviderGetSignInIntentController$resultReceiver$1 resultReceiver;
|
|
|
|
@VisibleForTesting
|
|
public static /* synthetic */ void getCallback$annotations() {
|
|
}
|
|
|
|
@VisibleForTesting
|
|
private static /* synthetic */ void getCancellationSignal$annotations() {
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public static /* synthetic */ void getExecutor$annotations() {
|
|
}
|
|
|
|
public static final CredentialProviderGetSignInIntentController getInstance(Context context) {
|
|
return Companion.getInstance(context);
|
|
}
|
|
|
|
public final void setCallback(CredentialManagerCallback<GetCredentialResponse, GetCredentialException> credentialManagerCallback) {
|
|
Intrinsics.checkNotNullParameter(credentialManagerCallback, "<set-?>");
|
|
this.callback = credentialManagerCallback;
|
|
}
|
|
|
|
public final void setExecutor(Executor executor) {
|
|
Intrinsics.checkNotNullParameter(executor, "<set-?>");
|
|
this.executor = executor;
|
|
}
|
|
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
/* JADX WARN: Type inference failed for: r0v2, types: [androidx.credentials.playservices.controllers.GetSignInIntent.CredentialProviderGetSignInIntentController$resultReceiver$1] */
|
|
public CredentialProviderGetSignInIntentController(Context context) {
|
|
super(context);
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
this.context = context;
|
|
final Handler handler = new Handler(Looper.getMainLooper());
|
|
this.resultReceiver = new ResultReceiver(handler) { // from class: androidx.credentials.playservices.controllers.GetSignInIntent.CredentialProviderGetSignInIntentController$resultReceiver$1
|
|
@Override // android.os.ResultReceiver
|
|
public void onReceiveResult(int i, Bundle resultData) {
|
|
CancellationSignal cancellationSignal;
|
|
boolean maybeReportErrorFromResultReceiver;
|
|
Intrinsics.checkNotNullParameter(resultData, "resultData");
|
|
CredentialProviderGetSignInIntentController credentialProviderGetSignInIntentController = CredentialProviderGetSignInIntentController.this;
|
|
CredentialProviderGetSignInIntentController$resultReceiver$1$onReceiveResult$1 credentialProviderGetSignInIntentController$resultReceiver$1$onReceiveResult$1 = new CredentialProviderGetSignInIntentController$resultReceiver$1$onReceiveResult$1(CredentialProviderBaseController.Companion);
|
|
Executor executor = CredentialProviderGetSignInIntentController.this.getExecutor();
|
|
CredentialManagerCallback<GetCredentialResponse, GetCredentialException> callback = CredentialProviderGetSignInIntentController.this.getCallback();
|
|
cancellationSignal = CredentialProviderGetSignInIntentController.this.cancellationSignal;
|
|
maybeReportErrorFromResultReceiver = credentialProviderGetSignInIntentController.maybeReportErrorFromResultReceiver(resultData, credentialProviderGetSignInIntentController$resultReceiver$1$onReceiveResult$1, executor, callback, cancellationSignal);
|
|
if (maybeReportErrorFromResultReceiver) {
|
|
return;
|
|
}
|
|
CredentialProviderGetSignInIntentController.this.handleResponse$credentials_play_services_auth_release(resultData.getInt(CredentialProviderBaseController.ACTIVITY_REQUEST_CODE_TAG), i, (Intent) resultData.getParcelable(CredentialProviderBaseController.RESULT_DATA_TAG));
|
|
}
|
|
};
|
|
}
|
|
|
|
public final CredentialManagerCallback<GetCredentialResponse, GetCredentialException> getCallback() {
|
|
CredentialManagerCallback<GetCredentialResponse, GetCredentialException> credentialManagerCallback = this.callback;
|
|
if (credentialManagerCallback != null) {
|
|
return credentialManagerCallback;
|
|
}
|
|
Intrinsics.throwUninitializedPropertyAccessException("callback");
|
|
return null;
|
|
}
|
|
|
|
public final Executor getExecutor() {
|
|
Executor executor = this.executor;
|
|
if (executor != null) {
|
|
return executor;
|
|
}
|
|
Intrinsics.throwUninitializedPropertyAccessException("executor");
|
|
return null;
|
|
}
|
|
|
|
@Override // androidx.credentials.playservices.controllers.CredentialProviderController
|
|
public void invokePlayServices(GetCredentialRequest request, CredentialManagerCallback<GetCredentialResponse, GetCredentialException> callback, Executor executor, CancellationSignal cancellationSignal) {
|
|
Intrinsics.checkNotNullParameter(request, "request");
|
|
Intrinsics.checkNotNullParameter(callback, "callback");
|
|
Intrinsics.checkNotNullParameter(executor, "executor");
|
|
this.cancellationSignal = cancellationSignal;
|
|
setCallback(callback);
|
|
setExecutor(executor);
|
|
if (CredentialProviderPlayServicesImpl.Companion.cancellationReviewer$credentials_play_services_auth_release(cancellationSignal)) {
|
|
return;
|
|
}
|
|
try {
|
|
GetSignInIntentRequest convertRequestToPlayServices = convertRequestToPlayServices(request);
|
|
Intent intent = new Intent(this.context, (Class<?>) HiddenActivity.class);
|
|
intent.putExtra(CredentialProviderBaseController.REQUEST_TAG, convertRequestToPlayServices);
|
|
generateHiddenActivityIntent(this.resultReceiver, intent, CredentialProviderBaseController.SIGN_IN_INTENT_TAG);
|
|
this.context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
if (e instanceof GetCredentialUnsupportedException) {
|
|
CredentialProviderController.cancelOrCallbackExceptionOrResult(cancellationSignal, new CredentialProviderGetSignInIntentController$invokePlayServices$1(this, e));
|
|
} else {
|
|
CredentialProviderController.cancelOrCallbackExceptionOrResult(cancellationSignal, new CredentialProviderGetSignInIntentController$invokePlayServices$2(this));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.credentials.playservices.controllers.CredentialProviderController
|
|
@VisibleForTesting
|
|
public GetSignInIntentRequest convertRequestToPlayServices(GetCredentialRequest request) {
|
|
Intrinsics.checkNotNullParameter(request, "request");
|
|
if (request.getCredentialOptions().size() != 1) {
|
|
throw new GetCredentialUnsupportedException("GetSignInWithGoogleOption cannot be combined with other options.");
|
|
}
|
|
CredentialOption credentialOption = request.getCredentialOptions().get(0);
|
|
Intrinsics.checkNotNull(credentialOption, "null cannot be cast to non-null type com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption");
|
|
GetSignInWithGoogleOption getSignInWithGoogleOption = (GetSignInWithGoogleOption) credentialOption;
|
|
GetSignInIntentRequest build = GetSignInIntentRequest.builder().setServerClientId(getSignInWithGoogleOption.getServerClientId()).filterByHostedDomain(getSignInWithGoogleOption.getHostedDomainFilter()).setNonce(getSignInWithGoogleOption.getNonce()).build();
|
|
Intrinsics.checkNotNullExpressionValue(build, "build(...)");
|
|
return build;
|
|
}
|
|
|
|
@Override // androidx.credentials.playservices.controllers.CredentialProviderController
|
|
public GetCredentialResponse convertResponseToCredentialManager(SignInCredential response) {
|
|
GoogleIdTokenCredential googleIdTokenCredential;
|
|
Intrinsics.checkNotNullParameter(response, "response");
|
|
if (response.getGoogleIdToken() != null) {
|
|
googleIdTokenCredential = createGoogleIdCredential(response);
|
|
} else {
|
|
Log.w(TAG, "Credential returned but no google Id found");
|
|
googleIdTokenCredential = null;
|
|
}
|
|
if (googleIdTokenCredential == null) {
|
|
throw new GetCredentialUnknownException("When attempting to convert get response, null credential found");
|
|
}
|
|
return new GetCredentialResponse(googleIdTokenCredential);
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public final GoogleIdTokenCredential createGoogleIdCredential(SignInCredential response) {
|
|
Intrinsics.checkNotNullParameter(response, "response");
|
|
GoogleIdTokenCredential.Builder builder = new GoogleIdTokenCredential.Builder();
|
|
String id = response.getId();
|
|
Intrinsics.checkNotNullExpressionValue(id, "getId(...)");
|
|
GoogleIdTokenCredential.Builder id2 = builder.setId(id);
|
|
try {
|
|
String googleIdToken = response.getGoogleIdToken();
|
|
Intrinsics.checkNotNull(googleIdToken);
|
|
id2.setIdToken(googleIdToken);
|
|
if (response.getDisplayName() != null) {
|
|
id2.setDisplayName(response.getDisplayName());
|
|
}
|
|
if (response.getGivenName() != null) {
|
|
id2.setGivenName(response.getGivenName());
|
|
}
|
|
if (response.getFamilyName() != null) {
|
|
id2.setFamilyName(response.getFamilyName());
|
|
}
|
|
if (response.getPhoneNumber() != null) {
|
|
id2.setPhoneNumber(response.getPhoneNumber());
|
|
}
|
|
if (response.getProfilePictureUri() != null) {
|
|
id2.setProfilePictureUri(response.getProfilePictureUri());
|
|
}
|
|
return id2.build();
|
|
} catch (Exception unused) {
|
|
throw new GetCredentialUnknownException("When attempting to convert get response, null Google ID Token found");
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Type inference failed for: r5v2, types: [T, androidx.credentials.exceptions.GetCredentialUnknownException] */
|
|
/* JADX WARN: Type inference failed for: r5v7, types: [T, androidx.credentials.exceptions.GetCredentialInterruptedException] */
|
|
/* JADX WARN: Type inference failed for: r5v9, types: [T, androidx.credentials.exceptions.GetCredentialCancellationException] */
|
|
public final void handleResponse$credentials_play_services_auth_release(int i, int i2, Intent intent) {
|
|
CredentialProviderBaseController.Companion companion = CredentialProviderBaseController.Companion;
|
|
if (i != companion.getCONTROLLER_REQUEST_CODE$credentials_play_services_auth_release()) {
|
|
Log.w(TAG, "Returned request code " + companion.getCONTROLLER_REQUEST_CODE$credentials_play_services_auth_release() + " which does not match what was given " + i);
|
|
return;
|
|
}
|
|
if (CredentialProviderController.maybeReportErrorResultCodeGet(i2, new Function2() { // from class: androidx.credentials.playservices.controllers.GetSignInIntent.CredentialProviderGetSignInIntentController$handleResponse$1
|
|
@Override // kotlin.jvm.functions.Function2
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
|
|
invoke((CancellationSignal) obj, (Function0) obj2);
|
|
return Unit.INSTANCE;
|
|
}
|
|
|
|
public final void invoke(CancellationSignal cancellationSignal, Function0 f) {
|
|
Intrinsics.checkNotNullParameter(f, "f");
|
|
CredentialProviderController.Companion companion2 = CredentialProviderController.Companion;
|
|
CredentialProviderController.cancelOrCallbackExceptionOrResult(cancellationSignal, f);
|
|
}
|
|
}, new CredentialProviderGetSignInIntentController$handleResponse$2(this), this.cancellationSignal)) {
|
|
return;
|
|
}
|
|
try {
|
|
SignInCredential signInCredentialFromIntent = Identity.getSignInClient(this.context).getSignInCredentialFromIntent(intent);
|
|
Intrinsics.checkNotNullExpressionValue(signInCredentialFromIntent, "getSignInCredentialFromIntent(...)");
|
|
CredentialProviderController.cancelOrCallbackExceptionOrResult(this.cancellationSignal, new CredentialProviderGetSignInIntentController$handleResponse$3(this, convertResponseToCredentialManager(signInCredentialFromIntent)));
|
|
} catch (GetCredentialException e) {
|
|
CredentialProviderController.cancelOrCallbackExceptionOrResult(this.cancellationSignal, new CredentialProviderGetSignInIntentController$handleResponse$5(this, e));
|
|
} catch (ApiException e2) {
|
|
Ref.ObjectRef objectRef = new Ref.ObjectRef();
|
|
objectRef.element = new GetCredentialUnknownException(e2.getMessage());
|
|
if (e2.getStatusCode() == 16) {
|
|
objectRef.element = new GetCredentialCancellationException(e2.getMessage());
|
|
} else if (CredentialProviderBaseController.Companion.getRetryables().contains(Integer.valueOf(e2.getStatusCode()))) {
|
|
objectRef.element = new GetCredentialInterruptedException(e2.getMessage());
|
|
}
|
|
CredentialProviderController.cancelOrCallbackExceptionOrResult(this.cancellationSignal, new CredentialProviderGetSignInIntentController$handleResponse$4(this, objectRef));
|
|
} catch (Throwable th) {
|
|
CredentialProviderController.cancelOrCallbackExceptionOrResult(this.cancellationSignal, new CredentialProviderGetSignInIntentController$handleResponse$6(this, new GetCredentialUnknownException(th.getMessage())));
|
|
}
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
|
|
public final CredentialProviderGetSignInIntentController getInstance(Context context) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
return new CredentialProviderGetSignInIntentController(context);
|
|
}
|
|
}
|
|
}
|