118 lines
5.1 KiB
Java
118 lines
5.1 KiB
Java
package c.a.q.k0;
|
|
|
|
import android.bluetooth.BluetoothDevice;
|
|
import android.bluetooth.BluetoothHeadset;
|
|
import android.bluetooth.BluetoothProfile;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import androidx.annotation.MainThread;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.rtcconnection.enums.BluetoothBroadcastAction;
|
|
import com.discord.rtcconnection.enums.BluetoothHeadsetAudioState;
|
|
import com.discord.rtcconnection.enums.BluetoothProfileConnectionState;
|
|
import d0.t.n0;
|
|
import d0.z.d.m;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import org.webrtc.ThreadUtils;
|
|
/* compiled from: BluetoothBroadcastReceiver.kt */
|
|
public final class c extends BroadcastReceiver implements BluetoothProfile.ServiceListener {
|
|
public static final Set<BluetoothBroadcastAction> i = n0.setOf((Object[]) new BluetoothBroadcastAction[]{BluetoothBroadcastAction.HeadsetConnectionStateChanged, BluetoothBroadcastAction.HeadsetAudioStateChanged});
|
|
public static final a j = new a(null);
|
|
public boolean k;
|
|
public BluetoothHeadset l;
|
|
public final Context m;
|
|
public final h n;
|
|
|
|
/* compiled from: BluetoothBroadcastReceiver.kt */
|
|
public static final class a {
|
|
public a(DefaultConstructorMarker defaultConstructorMarker) {
|
|
}
|
|
}
|
|
|
|
public c(Context context, h hVar) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(hVar, "listener");
|
|
this.m = context;
|
|
this.n = hVar;
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
@MainThread
|
|
public void onReceive(Context context, Intent intent) {
|
|
BluetoothBroadcastAction bluetoothBroadcastAction;
|
|
m.checkNotNullParameter(context, "context");
|
|
ThreadUtils.checkIsOnMainThread();
|
|
if (intent != null) {
|
|
BluetoothBroadcastAction.a aVar = BluetoothBroadcastAction.Companion;
|
|
String action = intent.getAction();
|
|
m.checkNotNull(action);
|
|
m.checkNotNullExpressionValue(action, "intent.action!!");
|
|
Objects.requireNonNull(aVar);
|
|
m.checkNotNullParameter(action, "action");
|
|
BluetoothBroadcastAction[] values = BluetoothBroadcastAction.values();
|
|
int i2 = 0;
|
|
while (true) {
|
|
if (i2 >= 5) {
|
|
bluetoothBroadcastAction = null;
|
|
break;
|
|
}
|
|
bluetoothBroadcastAction = values[i2];
|
|
if (m.areEqual(bluetoothBroadcastAction.getAction(), action)) {
|
|
break;
|
|
}
|
|
i2++;
|
|
}
|
|
if (bluetoothBroadcastAction == null) {
|
|
StringBuilder L = c.d.b.a.a.L("unable to parse BluetoothBroadcastAction for action: ");
|
|
L.append(intent.getAction());
|
|
AnimatableValueParser.H1("BluetoothBroadcastReceiver", L.toString());
|
|
return;
|
|
}
|
|
AnimatableValueParser.G1("BluetoothBroadcastReceiver", "onReceive: action = " + bluetoothBroadcastAction);
|
|
try {
|
|
h hVar = this.n;
|
|
int ordinal = bluetoothBroadcastAction.ordinal();
|
|
if (ordinal == 0) {
|
|
hVar.d(context, BluetoothProfileConnectionState.Companion.b(intent));
|
|
} else if (ordinal == 1) {
|
|
hVar.a(context, BluetoothHeadsetAudioState.Companion.b(intent));
|
|
} else if (ordinal != 4) {
|
|
AnimatableValueParser.H1("BluetoothBroadcastReceiver", "unexpected " + bluetoothBroadcastAction);
|
|
} else {
|
|
m.checkNotNullParameter(intent, "$this$getBluetoothDeviceExtra");
|
|
hVar.b((BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE"));
|
|
}
|
|
} catch (Throwable th) {
|
|
AnimatableValueParser.E1("BluetoothBroadcastReceiver", "error handling " + bluetoothBroadcastAction, th);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.bluetooth.BluetoothProfile.ServiceListener
|
|
public void onServiceConnected(int i2, BluetoothProfile bluetoothProfile) {
|
|
ThreadUtils.checkIsOnMainThread();
|
|
if (i2 == 1 && this.k) {
|
|
AnimatableValueParser.D1("BluetoothBroadcastReceiver", "BluetoothProfile.ServiceListener.onServiceConnected");
|
|
if (!(bluetoothProfile instanceof BluetoothHeadset)) {
|
|
bluetoothProfile = null;
|
|
}
|
|
BluetoothHeadset bluetoothHeadset = (BluetoothHeadset) bluetoothProfile;
|
|
this.l = bluetoothHeadset;
|
|
this.n.c(bluetoothHeadset);
|
|
}
|
|
}
|
|
|
|
@Override // android.bluetooth.BluetoothProfile.ServiceListener
|
|
public void onServiceDisconnected(int i2) {
|
|
ThreadUtils.checkIsOnMainThread();
|
|
if (i2 == 1 && this.k) {
|
|
AnimatableValueParser.D1("BluetoothBroadcastReceiver", "BluetoothProfile.ServiceListener.onServiceDisconnected");
|
|
this.l = null;
|
|
this.n.c(null);
|
|
}
|
|
}
|
|
}
|