292 lines
13 KiB
Java
292 lines
13 KiB
Java
package com.discord.utilities.auth;
|
|
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentSender;
|
|
import androidx.fragment.app.Fragment;
|
|
import c.d.b.a.a;
|
|
import c.i.a.f.c.a.d.d;
|
|
import c.i.a.f.e.k.l;
|
|
import c.i.a.f.e.k.t;
|
|
import c.i.a.f.e.k.w;
|
|
import c.i.a.f.h.c.g;
|
|
import c.i.a.f.h.c.h;
|
|
import c.i.a.f.h.c.k;
|
|
import c.i.a.f.n.b0;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.models.domain.ModelAuditLogEntry;
|
|
import com.discord.stores.StoreNotices;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreUser;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.widgets.settings.account.WidgetSettingsAccount;
|
|
import com.discord.widgets.tabs.WidgetTabsHost;
|
|
import com.google.android.gms.auth.api.credentials.Credential;
|
|
import com.google.android.gms.auth.api.credentials.CredentialRequest;
|
|
import com.google.android.gms.auth.api.credentials.CredentialsClient;
|
|
import com.google.android.gms.common.api.ResolvableApiException;
|
|
import com.google.android.gms.tasks.TaskCompletionSource;
|
|
import d0.e0.c;
|
|
import d0.t.n;
|
|
import d0.z.d.a0;
|
|
import d0.z.d.m;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
/* compiled from: GoogleSmartLockManager.kt */
|
|
public final class GoogleSmartLockManager {
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final String DISCORD_ACCOUNT_IDENTITY = "https://discord.com/";
|
|
public static final int GOOGLE_SMART_LOCK_REQUEST_CODE_RESOLVE = 4008;
|
|
public static final int GOOGLE_SMART_LOCK_REQUEST_CODE_RESOLVE_FOR_REQUEST = 4009;
|
|
public static final boolean SET_DISCORD_ACCOUNT_DETAILS = true;
|
|
public static final String SMART_LOCK_NOTICE_NAME = "smartlock_resolution_";
|
|
private CredentialsClient credentialsClient;
|
|
private final List<c<? extends AppFragment>> resolvableFragments;
|
|
private final GoogleSmartLockRepo smartLockRepo;
|
|
|
|
/* compiled from: GoogleSmartLockManager.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final void handleResult(int i, Intent intent) {
|
|
if (i == -1 && intent != null) {
|
|
Credential credential = (Credential) intent.getParcelableExtra("com.google.android.gms.credentials.Credential");
|
|
String str = null;
|
|
String str2 = credential != null ? credential.i : null;
|
|
if (credential != null) {
|
|
str = credential.m;
|
|
}
|
|
if (str2 != null && str != null) {
|
|
GoogleSmartLockRepo.Companion.getINSTANCE().setSmartLockLogin(str2, str);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* compiled from: GoogleSmartLockManager.kt */
|
|
public static final class SmartLockCredentials {
|
|
|
|
/* renamed from: id reason: collision with root package name */
|
|
private final String f2190id;
|
|
private final String password;
|
|
|
|
public SmartLockCredentials(String str, String str2) {
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_ID);
|
|
m.checkNotNullParameter(str2, "password");
|
|
this.f2190id = str;
|
|
this.password = str2;
|
|
}
|
|
|
|
public static /* synthetic */ SmartLockCredentials copy$default(SmartLockCredentials smartLockCredentials, String str, String str2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
str = smartLockCredentials.f2190id;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
str2 = smartLockCredentials.password;
|
|
}
|
|
return smartLockCredentials.copy(str, str2);
|
|
}
|
|
|
|
public final String component1() {
|
|
return this.f2190id;
|
|
}
|
|
|
|
public final String component2() {
|
|
return this.password;
|
|
}
|
|
|
|
public final SmartLockCredentials copy(String str, String str2) {
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_ID);
|
|
m.checkNotNullParameter(str2, "password");
|
|
return new SmartLockCredentials(str, str2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof SmartLockCredentials)) {
|
|
return false;
|
|
}
|
|
SmartLockCredentials smartLockCredentials = (SmartLockCredentials) obj;
|
|
return m.areEqual(this.f2190id, smartLockCredentials.f2190id) && m.areEqual(this.password, smartLockCredentials.password);
|
|
}
|
|
|
|
public final String getId() {
|
|
return this.f2190id;
|
|
}
|
|
|
|
public final String getPassword() {
|
|
return this.password;
|
|
}
|
|
|
|
public int hashCode() {
|
|
String str = this.f2190id;
|
|
int i = 0;
|
|
int hashCode = (str != null ? str.hashCode() : 0) * 31;
|
|
String str2 = this.password;
|
|
if (str2 != null) {
|
|
i = str2.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder P = a.P("SmartLockCredentials(id=");
|
|
P.append(this.f2190id);
|
|
P.append(", password=");
|
|
return a.H(P, this.password, ")");
|
|
}
|
|
}
|
|
|
|
public GoogleSmartLockManager(Context context, GoogleSmartLockRepo googleSmartLockRepo) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(googleSmartLockRepo, "smartLockRepo");
|
|
this.smartLockRepo = googleSmartLockRepo;
|
|
this.resolvableFragments = n.listOf((Object[]) new c[]{a0.getOrCreateKotlinClass(WidgetTabsHost.class), a0.getOrCreateKotlinClass(WidgetSettingsAccount.class)});
|
|
d.a aVar = new d.a();
|
|
aVar.b = Boolean.TRUE;
|
|
CredentialsClient credentialsClient = new CredentialsClient(context, new d(aVar, null));
|
|
m.checkNotNullExpressionValue(credentialsClient, "Credentials.getClient(context, options)");
|
|
this.credentialsClient = credentialsClient;
|
|
if (googleSmartLockRepo.getDisableAutoLogin()) {
|
|
CredentialsClient credentialsClient2 = this.credentialsClient;
|
|
Objects.requireNonNull(credentialsClient2);
|
|
c.i.a.f.c.a.d.c cVar = c.i.a.f.c.a.a.g;
|
|
c.i.a.f.e.h.c cVar2 = credentialsClient2.g;
|
|
Objects.requireNonNull((h) cVar);
|
|
AnimatableValueParser.z(cVar2, "client must not be null");
|
|
l.a(cVar2.b(new k(cVar2)));
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ GoogleSmartLockManager(Context context, GoogleSmartLockRepo googleSmartLockRepo, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(context, (i & 2) != 0 ? GoogleSmartLockRepo.Companion.getINSTANCE() : googleSmartLockRepo);
|
|
}
|
|
|
|
public static final /* synthetic */ CredentialsClient access$getCredentialsClient$p(GoogleSmartLockManager googleSmartLockManager) {
|
|
return googleSmartLockManager.credentialsClient;
|
|
}
|
|
|
|
public static final /* synthetic */ List access$getResolvableFragments$p(GoogleSmartLockManager googleSmartLockManager) {
|
|
return googleSmartLockManager.resolvableFragments;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$resolveResult(GoogleSmartLockManager googleSmartLockManager, Fragment fragment, int i, ResolvableApiException resolvableApiException) {
|
|
googleSmartLockManager.resolveResult(fragment, i, resolvableApiException);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$resolveResult(GoogleSmartLockManager googleSmartLockManager, ResolvableApiException resolvableApiException, String str) {
|
|
googleSmartLockManager.resolveResult(resolvableApiException, str);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setCredentialsClient$p(GoogleSmartLockManager googleSmartLockManager, CredentialsClient credentialsClient) {
|
|
googleSmartLockManager.credentialsClient = credentialsClient;
|
|
}
|
|
|
|
private final void resolveResult(Fragment fragment, int i, ResolvableApiException resolvableApiException) {
|
|
try {
|
|
if ((resolvableApiException.mStatus.o != 4) && !fragment.isDetached() && !fragment.isRemoving()) {
|
|
PendingIntent pendingIntent = resolvableApiException.mStatus.q;
|
|
m.checkNotNullExpressionValue(pendingIntent, "rae.resolution");
|
|
fragment.startIntentSenderForResult(pendingIntent.getIntentSender(), i, null, 0, 0, 0, null);
|
|
}
|
|
} catch (IntentSender.SendIntentException e) {
|
|
AppLog.g.w("Google Smart Lock", "Failed to send resolution.", e);
|
|
} catch (Exception e2) {
|
|
AppLog.g.w("Google Smart Lock", "Failed to resolve", e2);
|
|
}
|
|
}
|
|
|
|
private final void resolveResult(ResolvableApiException resolvableApiException, String str) {
|
|
try {
|
|
if (resolvableApiException.mStatus.o != 4) {
|
|
StoreStream.Companion.getNotices().requestToShow(new StoreNotices.Notice(SMART_LOCK_NOTICE_NAME + str, null, 0, 0, false, this.resolvableFragments, 0, false, 0, new GoogleSmartLockManager$resolveResult$notice$1(this, resolvableApiException), 134, null));
|
|
}
|
|
} catch (IntentSender.SendIntentException e) {
|
|
AppLog.g.w("Google Smart Lock", "Failed to send resolution.", e);
|
|
} catch (Exception e2) {
|
|
AppLog.g.w("Google Smart Lock", "Failed to resolve", e2);
|
|
}
|
|
}
|
|
|
|
public final void deleteCredentials(String str) {
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_ID);
|
|
if (this.smartLockRepo.getEnabled()) {
|
|
CredentialsClient credentialsClient = this.credentialsClient;
|
|
Credential credential = new Credential(str, null, null, null, null, null, null, null);
|
|
Objects.requireNonNull(credentialsClient);
|
|
c.i.a.f.c.a.d.c cVar = c.i.a.f.c.a.a.g;
|
|
c.i.a.f.e.h.c cVar2 = credentialsClient.g;
|
|
Objects.requireNonNull((h) cVar);
|
|
AnimatableValueParser.z(cVar2, "client must not be null");
|
|
AnimatableValueParser.z(credential, "credential must not be null");
|
|
l.a(cVar2.b(new c.i.a.f.h.c.l(cVar2, credential)));
|
|
}
|
|
}
|
|
|
|
public final GoogleSmartLockRepo getSmartLockRepo() {
|
|
return this.smartLockRepo;
|
|
}
|
|
|
|
public final void requestCredentials(AppFragment appFragment, int i) {
|
|
m.checkNotNullParameter(appFragment, "fragment");
|
|
CredentialRequest credentialRequest = new CredentialRequest(4, true, new String[]{DISCORD_ACCOUNT_IDENTITY}, null, null, false, null, null, false);
|
|
CredentialsClient credentialsClient = this.credentialsClient;
|
|
Objects.requireNonNull(credentialsClient);
|
|
c.i.a.f.c.a.d.c cVar = c.i.a.f.c.a.a.g;
|
|
c.i.a.f.e.h.c cVar2 = credentialsClient.g;
|
|
Objects.requireNonNull((h) cVar);
|
|
AnimatableValueParser.z(cVar2, "client must not be null");
|
|
AnimatableValueParser.z(credentialRequest, "request must not be null");
|
|
c.i.a.f.e.h.j.d a = cVar2.a(new g(cVar2, credentialRequest));
|
|
w wVar = new w(new c.i.a.f.c.a.d.a());
|
|
l.b bVar = l.a;
|
|
TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
|
|
a.c(new t(a, taskCompletionSource, wVar, bVar));
|
|
b0<TResult> b0Var = taskCompletionSource.a;
|
|
GoogleSmartLockManager$requestCredentials$1 googleSmartLockManager$requestCredentials$1 = new GoogleSmartLockManager$requestCredentials$1(this, appFragment, i);
|
|
Objects.requireNonNull(b0Var);
|
|
b0Var.c(c.i.a.f.n.g.a, googleSmartLockManager$requestCredentials$1);
|
|
}
|
|
|
|
public final void saveCredentials(String str, String str2) {
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_ID);
|
|
m.checkNotNullParameter(str2, "password");
|
|
if (this.smartLockRepo.getEnabled()) {
|
|
Observable Y = StoreUser.observeMe$default(StoreStream.Companion.getUsers(), false, 1, null).Y(1);
|
|
m.checkNotNullExpressionValue(Y, "StoreStream.getUsers().observeMe().take(1)");
|
|
ObservableExtensionsKt.appSubscribe$default(Y, GoogleSmartLockManager.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new GoogleSmartLockManager$saveCredentials$1(this, str, str2), 62, (Object) null);
|
|
}
|
|
}
|
|
|
|
public final void updateAccountInfo(String str, String str2) {
|
|
m.checkNotNullParameter(str2, "newPassword");
|
|
if (this.smartLockRepo.getEnabled()) {
|
|
String pendingIdChange = this.smartLockRepo.getPendingIdChange();
|
|
if (pendingIdChange != null) {
|
|
deleteCredentials(pendingIdChange);
|
|
this.smartLockRepo.setPendingIdChange(null);
|
|
}
|
|
if (str == null) {
|
|
str = StoreStream.Companion.getAuthentication().getSavedLogin();
|
|
}
|
|
if (str != null) {
|
|
saveCredentials(str, str2);
|
|
}
|
|
}
|
|
}
|
|
}
|