64 lines
2.9 KiB
Java
64 lines
2.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 com.discord.app.AppLog;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.google.android.gms.common.api.Status;
|
|
import d0.g0.t;
|
|
import d0.z.d.m;
|
|
import java.util.Objects;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.text.MatchResult;
|
|
import kotlin.text.Regex;
|
|
/* compiled from: SmsAuthCodeBroadcastReceiver.kt */
|
|
public final class SmsAuthCodeBroadcastReceiver extends BroadcastReceiver {
|
|
private final Function1<CharSequence, Unit> onReceiveCallback;
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: kotlin.jvm.functions.Function1<? super java.lang.CharSequence, kotlin.Unit> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public SmsAuthCodeBroadcastReceiver(Function1<? super CharSequence, Unit> function1) {
|
|
m.checkNotNullParameter(function1, "onReceiveCallback");
|
|
this.onReceiveCallback = function1;
|
|
}
|
|
|
|
public final CharSequence extractCode(String str) {
|
|
m.checkNotNullParameter(str, "message");
|
|
MatchResult find$default = Regex.find$default(new Regex("Your Discord security code is: (\\d{3} \\d{3})"), str, 0, 2, null);
|
|
if (find$default != null) {
|
|
return t.replace$default(find$default.getGroupValues().get(1), " ", "", false, 4, (Object) null);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public final Function1<CharSequence, Unit> getOnReceiveCallback() {
|
|
return this.onReceiveCallback;
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public void onReceive(Context context, Intent intent) {
|
|
Bundle extras;
|
|
m.checkNotNullParameter(intent, "intent");
|
|
if (m.areEqual("com.google.android.gms.auth.api.phone.SMS_RETRIEVED", intent.getAction()) && (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");
|
|
int i = ((Status) obj).o;
|
|
if (i == 0) {
|
|
Object obj2 = extras.get("com.google.android.gms.auth.api.phone.EXTRA_SMS_MESSAGE");
|
|
Objects.requireNonNull(obj2, "null cannot be cast to non-null type kotlin.String");
|
|
CharSequence extractCode = extractCode((String) obj2);
|
|
if (extractCode != null) {
|
|
this.onReceiveCallback.invoke(extractCode);
|
|
} else {
|
|
Logger.d$default(AppLog.g, "SmsAuthCodeBroadcastReceiver", "Failed to extract code from SMS.", null, 4, null);
|
|
}
|
|
} else if (i == 15) {
|
|
Logger.d$default(AppLog.g, "SmsAuthCodeBroadcastReceiver", "Timeout waiting for SMS.", null, 4, null);
|
|
}
|
|
}
|
|
}
|
|
}
|