package com.google.android.gms.auth; import android.accounts.Account; import android.accounts.AccountManager; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.ComponentName; import android.content.Context; import android.os.Bundle; import android.os.RemoteException; import android.os.SystemClock; import android.text.TextUtils; import com.google.android.gms.common.BlockingServiceConnection; 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.internal.GmsClientSupervisor; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.common.logging.Logger; import java.io.IOException; import java.util.List; /* loaded from: classes.dex */ public class zzd { 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"; public static final String WORK_ACCOUNT_TYPE = "com.google.work"; private static final String[] ACCEPTABLE_ACCOUNT_TYPES = {"com.google", "com.google.work", "cn.google"}; @SuppressLint({"InlinedApi"}) public static final String KEY_CALLER_UID = "callerUid"; @SuppressLint({"InlinedApi"}) public static final String KEY_ANDROID_PACKAGE_NAME = "androidPackageName"; private static final ComponentName zzm = new ComponentName("com.google.android.gms", "com.google.android.gms.auth.GetToken"); private static final Logger zzn = new Logger("Auth", "GoogleAuthUtil"); zzd() { } public static void clearToken(Context context, String str) { Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock"); ensurePlayServicesAvailable(context, 8400000); Bundle bundle = new Bundle(); String str2 = context.getApplicationInfo().packageName; bundle.putString("clientPackageName", str2); String str3 = KEY_ANDROID_PACKAGE_NAME; if (!bundle.containsKey(str3)) { bundle.putString(str3, str2); } zza(context, zzm, new zzf(str, bundle)); } private static void ensurePlayServicesAvailable(Context context, int i10) { try { GooglePlayServicesUtilLight.ensurePlayServicesAvailable(context.getApplicationContext(), i10); } catch (GooglePlayServicesNotAvailableException e10) { throw new GoogleAuthException(e10.getMessage()); } catch (GooglePlayServicesRepairableException e11) { throw new GooglePlayServicesAvailabilityException(e11.getConnectionStatusCode(), e11.getMessage(), e11.getIntent()); } } public static List getAccountChangeEvents(Context context, int i10, String str) { Preconditions.checkNotEmpty(str, "accountName must be provided"); Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock"); ensurePlayServicesAvailable(context, 8400000); return (List) zza(context, zzm, new zzg(str, i10)); } public static String getAccountId(Context context, String str) { Preconditions.checkNotEmpty(str, "accountName must be provided"); Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock"); ensurePlayServicesAvailable(context, 8400000); return getToken(context, str, "^^_account_id_^^", new Bundle()); } @Deprecated public static String getToken(Context context, String str, String str2) { return getToken(context, new Account(str, "com.google"), str2); } @Deprecated public static void invalidateToken(Context context, String str) { AccountManager.get(context).invalidateAuthToken("com.google", str); } @TargetApi(23) public static Bundle removeAccount(Context context, Account account) { Preconditions.checkNotNull(context); zzb(account); ensurePlayServicesAvailable(context, 8400000); return (Bundle) zza(context, zzm, new zzh(account)); } @TargetApi(26) public static Boolean requestGoogleAccountsAccess(Context context) { Preconditions.checkNotNull(context); ensurePlayServicesAvailable(context, 11400000); return (Boolean) zza(context, zzm, new zzi(context.getApplicationInfo().packageName)); } /* JADX INFO: Access modifiers changed from: private */ public static T zza(T t10) { if (t10 != null) { return t10; } zzn.w("GoogleAuthUtil", "Binder call returned null."); throw new IOException("Service unavailable."); } public static TokenData zzb(Context context, Account account, String str, Bundle bundle) { Preconditions.checkNotMainThread("Calling this from your main thread can lead to deadlock"); Preconditions.checkNotEmpty(str, "Scope cannot be empty or null."); zzb(account); ensurePlayServicesAvailable(context, 8400000); Bundle bundle2 = bundle == null ? new Bundle() : new Bundle(bundle); String str2 = context.getApplicationInfo().packageName; bundle2.putString("clientPackageName", str2); String str3 = KEY_ANDROID_PACKAGE_NAME; if (TextUtils.isEmpty(bundle2.getString(str3))) { bundle2.putString(str3, str2); } bundle2.putLong("service_connection_start_time_millis", SystemClock.elapsedRealtime()); return (TokenData) zza(context, zzm, new zze(account, str, bundle2)); } @Deprecated public static String getToken(Context context, String str, String str2, Bundle bundle) { return getToken(context, new Account(str, "com.google"), str2, bundle); } private static T zza(Context context, ComponentName componentName, zzj zzjVar) { BlockingServiceConnection blockingServiceConnection = new BlockingServiceConnection(); GmsClientSupervisor gmsClientSupervisor = GmsClientSupervisor.getInstance(context); try { if (gmsClientSupervisor.bindService(componentName, blockingServiceConnection, "GoogleAuthUtil")) { try { return zzjVar.zzb(blockingServiceConnection.getService()); } catch (RemoteException | InterruptedException e10) { zzn.i("GoogleAuthUtil", "Error on service connection.", e10); throw new IOException("Error on service connection.", e10); } } throw new IOException("Could not bind to service."); } finally { gmsClientSupervisor.unbindService(componentName, blockingServiceConnection, "GoogleAuthUtil"); } } public static String getToken(Context context, Account account, String str) { return getToken(context, account, str, new Bundle()); } public static String getToken(Context context, Account account, String str, Bundle bundle) { zzb(account); return zzb(context, account, str, bundle).zzb(); } private static void zzb(Account account) { if (account != null) { if (!TextUtils.isEmpty(account.name)) { for (String str : ACCEPTABLE_ACCOUNT_TYPES) { if (str.equals(account.type)) { return; } } throw new IllegalArgumentException("Account type not supported"); } throw new IllegalArgumentException("Account name cannot be empty!"); } throw new IllegalArgumentException("Account cannot be null"); } }