- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
409 lines
19 KiB
Java
409 lines
19 KiB
Java
package com.google.android.gms.auth;
|
|
|
|
import android.accounts.Account;
|
|
import android.accounts.AccountManager;
|
|
import android.annotation.SuppressLint;
|
|
import android.annotation.TargetApi;
|
|
import android.app.PendingIntent;
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.IBinder;
|
|
import android.os.Parcelable;
|
|
import android.os.RemoteException;
|
|
import android.os.SystemClock;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RequiresPermission;
|
|
import com.google.android.gms.common.BlockingServiceConnection;
|
|
import com.google.android.gms.common.GoogleApiAvailability;
|
|
import com.google.android.gms.common.GooglePlayServicesIncorrectManifestValueException;
|
|
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
|
|
import com.google.android.gms.common.GooglePlayServicesRepairableException;
|
|
import com.google.android.gms.common.GooglePlayServicesUtilLight;
|
|
import com.google.android.gms.common.api.ApiException;
|
|
import com.google.android.gms.common.internal.GmsClientSupervisor;
|
|
import com.google.android.gms.common.internal.Preconditions;
|
|
import com.google.android.gms.common.internal.ShowFirstParty;
|
|
import com.google.android.gms.common.logging.Logger;
|
|
import com.google.android.gms.internal.auth.zzbw;
|
|
import com.google.android.gms.internal.auth.zzby;
|
|
import com.google.android.gms.internal.auth.zzdc;
|
|
import com.google.android.gms.internal.auth.zzht;
|
|
import com.google.android.gms.internal.auth.zzhw;
|
|
import com.google.android.gms.tasks.Task;
|
|
import com.google.android.gms.tasks.Tasks;
|
|
import java.io.IOException;
|
|
import java.net.URISyntaxException;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.concurrent.CancellationException;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
@ShowFirstParty
|
|
/* loaded from: classes2.dex */
|
|
public class zzl {
|
|
public static final int CHANGE_TYPE_ACCOUNT_ADDED = 1;
|
|
public static final int CHANGE_TYPE_ACCOUNT_REMOVED = 2;
|
|
public static final int CHANGE_TYPE_ACCOUNT_RENAMED_FROM = 3;
|
|
public static final int CHANGE_TYPE_ACCOUNT_RENAMED_TO = 4;
|
|
public static final String GOOGLE_ACCOUNT_TYPE = "com.google";
|
|
public static final String KEY_SUPPRESS_PROGRESS_SCREEN = "suppressProgressScreen";
|
|
|
|
@ShowFirstParty
|
|
public static final String WORK_ACCOUNT_TYPE = "com.google.work";
|
|
|
|
@ShowFirstParty
|
|
public static final String[] zza = {"com.google", "com.google.work", "cn.google"};
|
|
|
|
@ShowFirstParty
|
|
@SuppressLint({"InlinedApi"})
|
|
public static final String zzb = "androidPackageName";
|
|
private static final ComponentName zzc = new ComponentName("com.google.android.gms", "com.google.android.gms.auth.GetToken");
|
|
private static final Logger zzd = zzd.zza("GoogleAuthUtil");
|
|
|
|
public static void clearToken(Context context, String str) throws GoogleAuthException, IOException {
|
|
zze(context, str, 0L);
|
|
}
|
|
|
|
public static List<AccountChangeEvent> getAccountChangeEvents(Context context, int i, String str) throws GoogleAuthException, IOException {
|
|
Preconditions.checkNotEmpty(str, "accountName must be provided");
|
|
Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock");
|
|
zzk(context, 8400000);
|
|
AccountChangeEventsRequest accountChangeEventsRequest = new AccountChangeEventsRequest();
|
|
accountChangeEventsRequest.setAccountName(str);
|
|
accountChangeEventsRequest.setEventIndex(i);
|
|
zzdc.zzd(context);
|
|
if (zzhw.zzd() && zzp(context)) {
|
|
try {
|
|
AccountChangeEventsResponse accountChangeEventsResponse = (AccountChangeEventsResponse) zzi(com.google.android.gms.internal.auth.zzh.zza(context).zzb(accountChangeEventsRequest), "account change events retrieval");
|
|
zzj(accountChangeEventsResponse);
|
|
return accountChangeEventsResponse.getEvents();
|
|
} catch (ApiException e) {
|
|
zzl(e, "account change events retrieval");
|
|
}
|
|
}
|
|
return (List) zzh(context, zzc, new zzi(accountChangeEventsRequest), 0L, null);
|
|
}
|
|
|
|
public static String getAccountId(Context context, String str) throws GoogleAuthException, IOException {
|
|
Preconditions.checkNotEmpty(str, "accountName must be provided");
|
|
Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock");
|
|
zzk(context, 8400000);
|
|
return getToken(context, str, "^^_account_id_^^", new Bundle());
|
|
}
|
|
|
|
public static String getToken(Context context, Account account, String str) throws IOException, UserRecoverableAuthException, GoogleAuthException {
|
|
return getToken(context, account, str, new Bundle());
|
|
}
|
|
|
|
@RequiresPermission("android.permission.MANAGE_ACCOUNTS")
|
|
@Deprecated
|
|
public static void invalidateToken(Context context, String str) {
|
|
AccountManager.get(context).invalidateAuthToken("com.google", str);
|
|
}
|
|
|
|
@ShowFirstParty
|
|
@TargetApi(23)
|
|
public static Bundle removeAccount(Context context, final Account account) throws GoogleAuthException, IOException {
|
|
Preconditions.checkNotNull(context);
|
|
zzo(account);
|
|
zzk(context, 8400000);
|
|
zzdc.zzd(context);
|
|
if (zzhw.zze() && zzp(context)) {
|
|
try {
|
|
Bundle bundle = (Bundle) zzi(com.google.android.gms.internal.auth.zzh.zza(context).zzd(account), "account removal");
|
|
zzj(bundle);
|
|
return bundle;
|
|
} catch (ApiException e) {
|
|
zzl(e, "account removal");
|
|
}
|
|
}
|
|
return (Bundle) zzh(context, zzc, new zzk() { // from class: com.google.android.gms.auth.zzf
|
|
@Override // com.google.android.gms.auth.zzk
|
|
public final Object zza(IBinder iBinder) {
|
|
Bundle zzf = com.google.android.gms.internal.auth.zze.zzb(iBinder).zzf(account);
|
|
if (zzf != null) {
|
|
return zzf;
|
|
}
|
|
throw new IOException("Service call returned null.");
|
|
}
|
|
}, 0L, null);
|
|
}
|
|
|
|
@TargetApi(26)
|
|
public static Boolean requestGoogleAccountsAccess(Context context) throws GoogleAuthException, IOException {
|
|
Preconditions.checkNotNull(context);
|
|
zzk(context, 11400000);
|
|
String str = context.getApplicationInfo().packageName;
|
|
zzdc.zzd(context);
|
|
if (zzhw.zze() && zzp(context)) {
|
|
try {
|
|
Bundle bundle = (Bundle) zzi(com.google.android.gms.internal.auth.zzh.zza(context).zze(str), "google accounts access request");
|
|
String string = bundle.getString("Error");
|
|
Intent intent = (Intent) bundle.getParcelable("userRecoveryIntent");
|
|
PendingIntent pendingIntent = (PendingIntent) bundle.getParcelable("userRecoveryPendingIntent");
|
|
if (zzby.SUCCESS.equals(zzby.zza(string))) {
|
|
return Boolean.TRUE;
|
|
}
|
|
zzn(context, "requestGoogleAccountsAccess", string, intent, pendingIntent);
|
|
throw new GoogleAuthException("Invalid state. Shouldn't happen");
|
|
} catch (ApiException e) {
|
|
zzl(e, "google accounts access request");
|
|
}
|
|
}
|
|
return (Boolean) zzh(context, zzc, new zzj(str, context), 0L, null);
|
|
}
|
|
|
|
@ShowFirstParty
|
|
public static TokenData zza(final Context context, final Account account, final String str, Bundle bundle, long j, @Nullable Executor executor) throws IOException, GoogleAuthException {
|
|
Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock");
|
|
Preconditions.checkNotEmpty(str, "Scope cannot be empty or null.");
|
|
zzo(account);
|
|
zzk(context, 8400000);
|
|
final Bundle bundle2 = bundle == null ? new Bundle() : new Bundle(bundle);
|
|
zzm(context, bundle2);
|
|
zzdc.zzd(context);
|
|
if (zzhw.zze() && zzp(context)) {
|
|
try {
|
|
Bundle bundle3 = (Bundle) zzi(com.google.android.gms.internal.auth.zzh.zza(context).zzc(account, str, bundle2), "token retrieval");
|
|
zzj(bundle3);
|
|
return zzg(context, "getTokenWithDetails", bundle3);
|
|
} catch (ApiException e) {
|
|
zzl(e, "token retrieval");
|
|
}
|
|
}
|
|
return (TokenData) zzh(context, zzc, new zzk() { // from class: com.google.android.gms.auth.zzg
|
|
@Override // com.google.android.gms.auth.zzk
|
|
public final Object zza(IBinder iBinder) {
|
|
return zzl.zzb(account, str, bundle2, context, iBinder);
|
|
}
|
|
}, 0L, null);
|
|
}
|
|
|
|
public static /* synthetic */ TokenData zzb(Account account, String str, Bundle bundle, Context context, IBinder iBinder) throws RemoteException, IOException, GoogleAuthException {
|
|
Bundle zze = com.google.android.gms.internal.auth.zze.zzb(iBinder).zze(account, str, bundle);
|
|
if (zze != null) {
|
|
return zzg(context, "getTokenWithDetails", zze);
|
|
}
|
|
throw new IOException("Service call returned null");
|
|
}
|
|
|
|
public static /* bridge */ /* synthetic */ Object zzc(Object obj) {
|
|
zzj(obj);
|
|
return obj;
|
|
}
|
|
|
|
@ShowFirstParty
|
|
public static void zze(Context context, String str, long j) throws GoogleAuthException, IOException {
|
|
Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock");
|
|
zzk(context, 8400000);
|
|
Bundle bundle = new Bundle();
|
|
zzm(context, bundle);
|
|
zzdc.zzd(context);
|
|
if (zzhw.zze() && zzp(context)) {
|
|
com.google.android.gms.internal.auth.zzg zza2 = com.google.android.gms.internal.auth.zzh.zza(context);
|
|
zzbw zzbwVar = new zzbw();
|
|
zzbwVar.zza(str);
|
|
try {
|
|
zzi(zza2.zza(zzbwVar), "clear token");
|
|
return;
|
|
} catch (ApiException e) {
|
|
zzl(e, "clear token");
|
|
}
|
|
}
|
|
zzh(context, zzc, new zzh(str, bundle), 0L, null);
|
|
}
|
|
|
|
private static TokenData zzg(Context context, String str, Bundle bundle) throws GoogleAuthException, IOException {
|
|
TokenData tokenData;
|
|
Parcelable.Creator<TokenData> creator = TokenData.CREATOR;
|
|
ClassLoader classLoader = TokenData.class.getClassLoader();
|
|
if (classLoader != null) {
|
|
bundle.setClassLoader(classLoader);
|
|
}
|
|
Bundle bundle2 = bundle.getBundle("tokenDetails");
|
|
if (bundle2 == null) {
|
|
tokenData = null;
|
|
} else {
|
|
if (classLoader != null) {
|
|
bundle2.setClassLoader(classLoader);
|
|
}
|
|
tokenData = (TokenData) bundle2.getParcelable("TokenData");
|
|
}
|
|
if (tokenData != null) {
|
|
return tokenData;
|
|
}
|
|
zzn(context, "getTokenWithDetails", bundle.getString("Error"), (Intent) bundle.getParcelable("userRecoveryIntent"), (PendingIntent) bundle.getParcelable("userRecoveryPendingIntent"));
|
|
throw new GoogleAuthException("Invalid state. Shouldn't happen");
|
|
}
|
|
|
|
private static Object zzh(Context context, ComponentName componentName, zzk zzkVar, long j, @Nullable Executor executor) throws IOException, GoogleAuthException {
|
|
BlockingServiceConnection blockingServiceConnection = new BlockingServiceConnection();
|
|
GmsClientSupervisor gmsClientSupervisor = GmsClientSupervisor.getInstance(context);
|
|
try {
|
|
try {
|
|
if (!gmsClientSupervisor.bindService(componentName, blockingServiceConnection, "GoogleAuthUtil", null)) {
|
|
throw new IOException("Could not bind to service.");
|
|
}
|
|
try {
|
|
return zzkVar.zza(blockingServiceConnection.getService());
|
|
} catch (RemoteException | InterruptedException | TimeoutException e) {
|
|
throw new IOException("Error on service connection.", e);
|
|
}
|
|
} finally {
|
|
gmsClientSupervisor.unbindService(componentName, blockingServiceConnection, "GoogleAuthUtil");
|
|
}
|
|
} catch (SecurityException e2) {
|
|
Log.w("GoogleAuthUtil", String.format("SecurityException while bind to auth service: %s", e2.getMessage()));
|
|
throw new IOException("SecurityException while binding to Auth service.", e2);
|
|
}
|
|
}
|
|
|
|
private static Object zzi(Task task, String str) throws IOException, ApiException {
|
|
try {
|
|
return Tasks.await(task);
|
|
} catch (InterruptedException e) {
|
|
String format = String.format("Interrupted while waiting for the task of %s to finish.", str);
|
|
zzd.w(format, new Object[0]);
|
|
throw new IOException(format, e);
|
|
} catch (CancellationException e2) {
|
|
String format2 = String.format("Canceled while waiting for the task of %s to finish.", str);
|
|
zzd.w(format2, new Object[0]);
|
|
throw new IOException(format2, e2);
|
|
} catch (ExecutionException e3) {
|
|
Throwable cause = e3.getCause();
|
|
if (cause instanceof ApiException) {
|
|
throw ((ApiException) cause);
|
|
}
|
|
String format3 = String.format("Unable to get a result for %s due to ExecutionException.", str);
|
|
zzd.w(format3, new Object[0]);
|
|
throw new IOException(format3, e3);
|
|
}
|
|
}
|
|
|
|
private static Object zzj(Object obj) throws IOException {
|
|
if (obj != null) {
|
|
return obj;
|
|
}
|
|
zzd.w("Service call returned null.", new Object[0]);
|
|
throw new IOException("Service unavailable.");
|
|
}
|
|
|
|
private static void zzk(Context context, int i) throws GoogleAuthException {
|
|
try {
|
|
GooglePlayServicesUtilLight.ensurePlayServicesAvailable(context.getApplicationContext(), i);
|
|
} catch (GooglePlayServicesIncorrectManifestValueException e) {
|
|
e = e;
|
|
throw new GoogleAuthException(e.getMessage(), e);
|
|
} catch (GooglePlayServicesNotAvailableException e2) {
|
|
e = e2;
|
|
throw new GoogleAuthException(e.getMessage(), e);
|
|
} catch (GooglePlayServicesRepairableException e3) {
|
|
throw new GooglePlayServicesAvailabilityException(e3.getConnectionStatusCode(), e3.getMessage(), e3.getIntent());
|
|
}
|
|
}
|
|
|
|
private static void zzl(ApiException apiException, String str) {
|
|
zzd.w("%s failed via GoogleAuthServiceClient, falling back to previous approach:\n%s", str, Log.getStackTraceString(apiException));
|
|
}
|
|
|
|
private static void zzm(Context context, Bundle bundle) {
|
|
String str = context.getApplicationInfo().packageName;
|
|
bundle.putString("clientPackageName", str);
|
|
String str2 = zzb;
|
|
if (TextUtils.isEmpty(bundle.getString(str2))) {
|
|
bundle.putString(str2, str);
|
|
}
|
|
bundle.putLong("service_connection_start_time_millis", SystemClock.elapsedRealtime());
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static void zzn(Context context, String str, @Nullable String str2, @Nullable Intent intent, @Nullable PendingIntent pendingIntent) throws GoogleAuthException, IOException {
|
|
zzby zza2 = zzby.zza(str2);
|
|
Logger logger = zzd;
|
|
logger.w(String.format("[GoogleAuthUtil] error status:%s with method:%s", zza2, str), new Object[0]);
|
|
if (!zzby.BAD_AUTHENTICATION.equals(zza2) && !zzby.CAPTCHA.equals(zza2) && !zzby.NEED_PERMISSION.equals(zza2) && !zzby.NEED_REMOTE_CONSENT.equals(zza2) && !zzby.NEEDS_BROWSER.equals(zza2) && !zzby.USER_CANCEL.equals(zza2) && !zzby.DEVICE_MANAGEMENT_REQUIRED.equals(zza2) && !zzby.DM_INTERNAL_ERROR.equals(zza2) && !zzby.DM_SYNC_DISABLED.equals(zza2) && !zzby.DM_ADMIN_BLOCKED.equals(zza2) && !zzby.DM_ADMIN_PENDING_APPROVAL.equals(zza2) && !zzby.DM_STALE_SYNC_REQUIRED.equals(zza2) && !zzby.DM_DEACTIVATED.equals(zza2) && !zzby.DM_REQUIRED.equals(zza2) && !zzby.THIRD_PARTY_DEVICE_MANAGEMENT_REQUIRED.equals(zza2) && !zzby.DM_SCREENLOCK_REQUIRED.equals(zza2)) {
|
|
if (!zzby.NETWORK_ERROR.equals(zza2) && !zzby.SERVICE_UNAVAILABLE.equals(zza2) && !zzby.INTNERNAL_ERROR.equals(zza2) && !zzby.AUTH_SECURITY_ERROR.equals(zza2) && !zzby.ACCOUNT_NOT_PRESENT.equals(zza2)) {
|
|
throw new GoogleAuthException(str2);
|
|
}
|
|
throw new IOException(str2);
|
|
}
|
|
zzdc.zzd(context);
|
|
if (!zzht.zzc()) {
|
|
throw new UserRecoverableAuthException(str2, intent);
|
|
}
|
|
if (pendingIntent != null && intent != null) {
|
|
throw UserRecoverableAuthException.zza(str2, intent, pendingIntent);
|
|
}
|
|
if (GoogleApiAvailability.getInstance().getApkVersion(context) >= Integer.MAX_VALUE && pendingIntent == null) {
|
|
logger.e(String.format("Recovery PendingIntent is missing on current Gms version: %s for method: %s. It should always be present on or above Gms version %s. This indicates a bug in Gms implementation.", Integer.MAX_VALUE, str, Integer.MAX_VALUE), new Object[0]);
|
|
}
|
|
if (intent == null) {
|
|
logger.e(String.format("no recovery Intent found with status=%s for method=%s. This shouldn't happen", str2, str), new Object[0]);
|
|
}
|
|
throw new UserRecoverableAuthException(str2, intent);
|
|
}
|
|
|
|
private static boolean zzp(Context context) {
|
|
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context, 17895000) != 0) {
|
|
return false;
|
|
}
|
|
List zzq = zzhw.zzb().zzq();
|
|
String str = context.getApplicationInfo().packageName;
|
|
Iterator it = zzq.iterator();
|
|
while (it.hasNext()) {
|
|
if (((String) it.next()).equals(str)) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static String getToken(Context context, Account account, String str, Bundle bundle) throws IOException, UserRecoverableAuthException, GoogleAuthException {
|
|
zzo(account);
|
|
return zza(context, account, str, bundle, 0L, null).zza();
|
|
}
|
|
|
|
public static void zzf(Intent intent) {
|
|
if (intent == null) {
|
|
throw new IllegalArgumentException("Callback cannot be null.");
|
|
}
|
|
try {
|
|
Intent.parseUri(intent.toUri(1), 1);
|
|
} catch (URISyntaxException unused) {
|
|
throw new IllegalArgumentException("Parameter callback contains invalid data. It must be serializable using toUri() and parseUri().");
|
|
}
|
|
}
|
|
|
|
private static void zzo(Account account) {
|
|
if (account == null) {
|
|
throw new IllegalArgumentException("Account cannot be null");
|
|
}
|
|
if (TextUtils.isEmpty(account.name)) {
|
|
throw new IllegalArgumentException("Account name cannot be empty!");
|
|
}
|
|
String[] strArr = zza;
|
|
for (int i = 0; i < 3; i++) {
|
|
if (strArr[i].equals(account.type)) {
|
|
return;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException("Account type not supported");
|
|
}
|
|
|
|
@Deprecated
|
|
public static String getToken(Context context, String str, String str2) throws IOException, UserRecoverableAuthException, GoogleAuthException {
|
|
return getToken(context, new Account(str, "com.google"), str2);
|
|
}
|
|
|
|
@Deprecated
|
|
public static String getToken(Context context, String str, String str2, Bundle bundle) throws IOException, UserRecoverableAuthException, GoogleAuthException {
|
|
return getToken(context, new Account(str, "com.google"), str2, bundle);
|
|
}
|
|
}
|