forked from Juby210/discord-jadx
101 lines
4.9 KiB
Java
101 lines
4.9 KiB
Java
package com.discord.widgets.auth;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import c0.g0.w;
|
|
import c0.z.d.m;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.google.android.gms.common.api.Status;
|
|
import java.util.Objects;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
/* compiled from: SmsAuthCodeBroadcastReceiver.kt */
|
|
public final class SmsAuthCodeBroadcastReceiver extends BroadcastReceiver {
|
|
private final Function1<String, Unit> onReceiveCallback;
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: kotlin.jvm.functions.Function1<? super java.lang.String, kotlin.Unit> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public SmsAuthCodeBroadcastReceiver(Function1<? super String, Unit> function1) {
|
|
m.checkNotNullParameter(function1, "onReceiveCallback");
|
|
this.onReceiveCallback = function1;
|
|
}
|
|
|
|
private final String extractCode(String str) {
|
|
String substringBefore$default = w.substringBefore$default(str, "\n\n", (String) null, 2, (Object) null);
|
|
StringBuilder sb = new StringBuilder();
|
|
int length = substringBefore$default.length();
|
|
for (int i = 0; i < length; i++) {
|
|
char charAt = substringBefore$default.charAt(i);
|
|
if (Character.isDigit(charAt)) {
|
|
sb.append(charAt);
|
|
}
|
|
}
|
|
String sb2 = sb.toString();
|
|
m.checkNotNullExpressionValue(sb2, "filterTo(StringBuilder(), predicate).toString()");
|
|
return sb2;
|
|
}
|
|
|
|
private final void extractSecurityCode(Bundle bundle) {
|
|
Object obj = bundle.get("com.google.android.gms.auth.api.phone.EXTRA_SMS_MESSAGE");
|
|
if (obj == null) {
|
|
AppLog appLog = AppLog.g;
|
|
String simpleName = SmsAuthCodeBroadcastReceiver.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName, "javaClass.simpleName");
|
|
Logger.d$default(appLog, simpleName, "Failed to extract code due to empty message.", null, 4, null);
|
|
return;
|
|
}
|
|
String extractCode = extractCode((String) obj);
|
|
if (extractCode.length() == 0) {
|
|
AppLog appLog2 = AppLog.g;
|
|
String simpleName2 = SmsAuthCodeBroadcastReceiver.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName2, "javaClass.simpleName");
|
|
Logger.d$default(appLog2, simpleName2, "Failed to extract code from SMS.", null, 4, null);
|
|
return;
|
|
}
|
|
AppLog appLog3 = AppLog.g;
|
|
String simpleName3 = SmsAuthCodeBroadcastReceiver.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName3, "javaClass.simpleName");
|
|
Logger.d$default(appLog3, simpleName3, "Successfully extracted code from SMS: " + extractCode, null, 4, null);
|
|
this.onReceiveCallback.invoke(extractCode);
|
|
}
|
|
|
|
public final Function1<String, Unit> getOnReceiveCallback() {
|
|
return this.onReceiveCallback;
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public void onReceive(Context context, Intent intent) {
|
|
Bundle extras;
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(intent, "intent");
|
|
String action = intent.getAction();
|
|
if (action != null && action.hashCode() == -1845060944 && action.equals("com.google.android.gms.auth.api.phone.SMS_RETRIEVED") && (extras = intent.getExtras()) != null) {
|
|
Object obj = extras.get("com.google.android.gms.auth.api.phone.EXTRA_STATUS");
|
|
Objects.requireNonNull(obj, "null cannot be cast to non-null type com.google.android.gms.common.api.Status");
|
|
Status status = (Status) obj;
|
|
int i = status.o;
|
|
if (i == 0) {
|
|
AppLog appLog = AppLog.g;
|
|
String simpleName = SmsAuthCodeBroadcastReceiver.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName, "javaClass.simpleName");
|
|
Logger.d$default(appLog, simpleName, "Successfully caught SMS code.", null, 4, null);
|
|
m.checkNotNullExpressionValue(extras, "bundle");
|
|
extractSecurityCode(extras);
|
|
} else if (i != 15) {
|
|
AppLog appLog2 = AppLog.g;
|
|
String simpleName2 = SmsAuthCodeBroadcastReceiver.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName2, "javaClass.simpleName");
|
|
Logger.d$default(appLog2, simpleName2, "Unexpected status code while waiting for SMS code: " + status.o, null, 4, null);
|
|
} else {
|
|
AppLog appLog3 = AppLog.g;
|
|
String simpleName3 = SmsAuthCodeBroadcastReceiver.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName3, "javaClass.simpleName");
|
|
Logger.d$default(appLog3, simpleName3, "Timeout waiting for SMS code.", null, 4, null);
|
|
}
|
|
}
|
|
}
|
|
}
|