导航菜单

页面标题

页面副标题

CallApp v2.226 - BluetoothHeadsetManager.java 源代码

正在查看: CallApp v2.226 应用的 BluetoothHeadsetManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.twilio.audioswitch.bluetooth;

import android.bluetooth.BluetoothAdapter;
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 android.content.IntentFilter;
import android.os.Handler;
import android.os.Looper;
import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode;
import com.pubmatic.sdk.common.POBError;
import com.pubmatic.sdk.nativead.POBNativeConstants;
import com.twilio.audioswitch.AudioDevice;
import com.twilio.audioswitch.AudioDeviceManager;
import com.twilio.audioswitch.android.BluetoothDeviceWrapper;
import com.twilio.audioswitch.android.BluetoothIntentProcessor;
import com.twilio.audioswitch.android.BluetoothIntentProcessorImpl;
import com.twilio.audioswitch.android.Logger;
import com.twilio.audioswitch.android.SystemClockWrapper;
import com.twilio.audioswitch.bluetooth.BluetoothHeadsetConnectionListener;
import com.vungle.ads.internal.protos.Sdk$SDKError;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.l0;
import org.jetbrains.annotations.NotNull;

@Metadata(d1 = {"\u0000\u0098\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\t\b\u0000\u0018\u0000 N2\u00020\u00012\u00020\u0002:\u0004NOPQBg\b\u0001\u0012\u0006\u0010\u0003\u001a\u00020\u0004\u0012\u0006\u0010\u0005\u001a\u00020\u0006\u0012\u0006\u0010\u0007\u001a\u00020\b\u0012\u0006\u0010\t\u001a\u00020\n\u0012\n\b\u0002\u0010\u000b\u001a\u0004\u0018\u00010\f\u0012\b\b\u0002\u0010\r\u001a\u00020\u000e\u0012\b\b\u0002\u0010\u000f\u001a\u00020\u0010\u0012\b\b\u0002\u0010\u0011\u001a\u00020\u0012\u0012\n\b\u0002\u0010\u0013\u001a\u0004\u0018\u00010\u0014\u0012\b\b\u0002\u0010\u0015\u001a\u00020\u0016¢\u0006\u0002\u0010\u0017J\u0006\u0010/\u001a\u000200J\b\u00101\u001a\u000200H\u0002J\u0006\u00102\u001a\u000200J\b\u00103\u001a\u000200H\u0002J\u0012\u00104\u001a\u0004\u0018\u0001052\b\u00106\u001a\u0004\u0018\u000107J\n\u00108\u001a\u0004\u0018\u000107H\u0003J\u0006\u00109\u001a\u00020\u0016J\b\u0010:\u001a\u00020\u0016H\u0003J\b\u0010;\u001a\u00020\u0016H\u0002J\b\u0010<\u001a\u00020\u0016H\u0003J\u0012\u0010=\u001a\u00020\u00162\b\u0010>\u001a\u0004\u0018\u000107H\u0002J\u0010\u0010?\u001a\u00020\u00162\u0006\u0010@\u001a\u00020AH\u0002J\u0018\u0010B\u001a\u0002002\u0006\u0010\u0003\u001a\u00020\u00042\u0006\u0010C\u001a\u00020DH\u0016J\u0018\u0010E\u001a\u0002002\u0006\u0010F\u001a\u00020G2\u0006\u0010H\u001a\u00020IH\u0017J\u0010\u0010J\u001a\u0002002\u0006\u0010F\u001a\u00020GH\u0016J\u000e\u0010K\u001a\u0002002\u0006\u0010\u000b\u001a\u00020\fJ\u0006\u0010L\u001a\u000200J\u000e\u0010M\u001a\u0004\u0018\u00010A*\u00020DH\u0002R\u000e\u0010\u0007\u001a\u00020\bX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u0012X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R \u0010\u0018\u001a\u00060\u0019R\u00020\u00008\u0000X\u0081\u0004¢\u0006\u000e\n\u0000\u0012\u0004\b\u001a\u0010\u001b\u001a\u0004\b\u001c\u0010\u001dR \u0010\u001e\u001a\u00060\u001fR\u00020\u00008\u0000X\u0081\u0004¢\u0006\u000e\n\u0000\u0012\u0004\b \u0010\u001b\u001a\u0004\b!\u0010\"R\u000e\u0010\u0015\u001a\u00020\u0016X\u0082\u000e¢\u0006\u0002\n\u0000R\u001c\u0010\u000b\u001a\u0004\u0018\u00010\fX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b#\u0010$\"\u0004\b%\u0010&R\u0010\u0010\u0013\u001a\u0004\u0018\u00010\u0014X\u0082\u000e¢\u0006\u0002\n\u0000R,\u0010)\u001a\u00020(2\u0006\u0010'\u001a\u00020(8\u0000@@X\u0081\u000e¢\u0006\u0014\n\u0000\u0012\u0004\b*\u0010\u001b\u001a\u0004\b+\u0010,\"\u0004\b-\u0010.R\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006R"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager;", "Landroid/bluetooth/BluetoothProfile$ServiceListener;", "Landroid/content/BroadcastReceiver;", POBNativeConstants.NATIVE_CONTEXT, "Landroid/content/Context;", "logger", "Lcom/twilio/audioswitch/android/Logger;", "bluetoothAdapter", "Landroid/bluetooth/BluetoothAdapter;", "audioDeviceManager", "Lcom/twilio/audioswitch/AudioDeviceManager;", "headsetListener", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetConnectionListener;", "bluetoothScoHandler", "Landroid/os/Handler;", "systemClockWrapper", "Lcom/twilio/audioswitch/android/SystemClockWrapper;", "bluetoothIntentProcessor", "Lcom/twilio/audioswitch/android/BluetoothIntentProcessor;", "headsetProxy", "Landroid/bluetooth/BluetoothHeadset;", "hasRegisteredReceivers", "", "(Landroid/content/Context;Lcom/twilio/audioswitch/android/Logger;Landroid/bluetooth/BluetoothAdapter;Lcom/twilio/audioswitch/AudioDeviceManager;Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetConnectionListener;Landroid/os/Handler;Lcom/twilio/audioswitch/android/SystemClockWrapper;Lcom/twilio/audioswitch/android/BluetoothIntentProcessor;Landroid/bluetooth/BluetoothHeadset;Z)V", "disableBluetoothScoJob", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$DisableBluetoothScoJob;", "getDisableBluetoothScoJob$audioswitch_release$annotations", "()V", "getDisableBluetoothScoJob$audioswitch_release", "()Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$DisableBluetoothScoJob;", "enableBluetoothScoJob", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$EnableBluetoothScoJob;", "getEnableBluetoothScoJob$audioswitch_release$annotations", "getEnableBluetoothScoJob$audioswitch_release", "()Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$EnableBluetoothScoJob;", "getHeadsetListener", "()Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetConnectionListener;", "setHeadsetListener", "(Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetConnectionListener;)V", "value", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "headsetState", "getHeadsetState$audioswitch_release$annotations", "getHeadsetState$audioswitch_release", "()Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "setHeadsetState$audioswitch_release", "(Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;)V", "activate", "", "connect", "deactivate", "disconnect", "getHeadset", "Lcom/twilio/audioswitch/AudioDevice$BluetoothHeadset;", "bluetoothHeadsetName", "", "getHeadsetName", "hasActivationError", "hasActiveHeadset", "hasActiveHeadsetChanged", "hasConnectedDevice", "isCorrectIntentAction", "intentAction", "isHeadsetDevice", "deviceWrapper", "Lcom/twilio/audioswitch/android/BluetoothDeviceWrapper;", "onReceive", "intent", "Landroid/content/Intent;", "onServiceConnected", "profile", "", "bluetoothProfile", "Landroid/bluetooth/BluetoothProfile;", "onServiceDisconnected", TtmlNode.START, "stop", "getHeadsetDevice", "Companion", "DisableBluetoothScoJob", "EnableBluetoothScoJob", "HeadsetState", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class BluetoothHeadsetManager extends BroadcastReceiver implements BluetoothProfile.ServiceListener {

    @NotNull
    public static final Companion INSTANCE = new Companion(null);

    @NotNull
    private final BluetoothAdapter bluetoothAdapter;

    @NotNull
    private final BluetoothIntentProcessor bluetoothIntentProcessor;

    @NotNull
    private final Context context;

    @NotNull
    private final DisableBluetoothScoJob disableBluetoothScoJob;

    @NotNull
    private final EnableBluetoothScoJob enableBluetoothScoJob;
    private boolean hasRegisteredReceivers;
    private BluetoothHeadsetConnectionListener headsetListener;
    private BluetoothHeadset headsetProxy;

    @NotNull
    private HeadsetState headsetState;

    @NotNull
    private final Logger logger;

    @Metadata(d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J1\u0010\u0003\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b2\b\u0010\t\u001a\u0004\u0018\u00010\n2\u0006\u0010\u000b\u001a\u00020\fH\u0000¢\u0006\u0002\b\r¨\u0006\u000e"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$Companion;", "", "()V", "newInstance", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager;", POBNativeConstants.NATIVE_CONTEXT, "Landroid/content/Context;", "logger", "Lcom/twilio/audioswitch/android/Logger;", "bluetoothAdapter", "Landroid/bluetooth/BluetoothAdapter;", "audioDeviceManager", "Lcom/twilio/audioswitch/AudioDeviceManager;", "newInstance$audioswitch_release", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class Companion {
        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        public final BluetoothHeadsetManager newInstance$audioswitch_release(@NotNull Context context, @NotNull Logger logger, BluetoothAdapter bluetoothAdapter, @NotNull AudioDeviceManager audioDeviceManager) {
            Intrinsics.checkNotNullParameter(context, POBNativeConstants.NATIVE_CONTEXT);
            Intrinsics.checkNotNullParameter(logger, "logger");
            Intrinsics.checkNotNullParameter(audioDeviceManager, "audioDeviceManager");
            if (bluetoothAdapter == null) {
                logger.d("BluetoothHeadsetManager", "Bluetooth is not supported on this device");
                return null;
            }
            return new BluetoothHeadsetManager(context, logger, bluetoothAdapter, audioDeviceManager, null, null, null, null, null, false, POBError.REQUEST_CANCELLED, null);
        }

        private Companion() {
        }
    }

    @Metadata(d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\b\u0081\u0004\u0018\u00002\u00020\u0001B%\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nJ\b\u0010\u000b\u001a\u00020\fH\u0014J\b\u0010\r\u001a\u00020\fH\u0016R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u000e"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$DisableBluetoothScoJob;", "Lcom/twilio/audioswitch/bluetooth/BluetoothScoJob;", "logger", "Lcom/twilio/audioswitch/android/Logger;", "audioDeviceManager", "Lcom/twilio/audioswitch/AudioDeviceManager;", "bluetoothScoHandler", "Landroid/os/Handler;", "systemClockWrapper", "Lcom/twilio/audioswitch/android/SystemClockWrapper;", "(Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager;Lcom/twilio/audioswitch/android/Logger;Lcom/twilio/audioswitch/AudioDeviceManager;Landroid/os/Handler;Lcom/twilio/audioswitch/android/SystemClockWrapper;)V", "scoAction", "", "scoTimeOutAction", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class DisableBluetoothScoJob extends BluetoothScoJob {

        @NotNull
        private final AudioDeviceManager audioDeviceManager;

        @NotNull
        private final Logger logger;
        final BluetoothHeadsetManager this$0;

        public DisableBluetoothScoJob(@NotNull BluetoothHeadsetManager bluetoothHeadsetManager, @NotNull Logger logger, @NotNull AudioDeviceManager audioDeviceManager, @NotNull Handler handler, SystemClockWrapper systemClockWrapper) {
            super(logger, handler, systemClockWrapper);
            Intrinsics.checkNotNullParameter(logger, "logger");
            Intrinsics.checkNotNullParameter(audioDeviceManager, "audioDeviceManager");
            Intrinsics.checkNotNullParameter(handler, "bluetoothScoHandler");
            Intrinsics.checkNotNullParameter(systemClockWrapper, "systemClockWrapper");
            this.this$0 = bluetoothHeadsetManager;
            this.logger = logger;
            this.audioDeviceManager = audioDeviceManager;
        }

        @Override
        public void scoAction() {
            this.logger.d("BluetoothHeadsetManager", "Attempting to disable bluetooth SCO");
            this.audioDeviceManager.enableBluetoothSco(false);
            this.this$0.setHeadsetState$audioswitch_release(HeadsetState.Connected.INSTANCE);
        }

        @Override
        public void scoTimeOutAction() {
            this.this$0.setHeadsetState$audioswitch_release(HeadsetState.AudioActivationError.INSTANCE);
        }
    }

    @Metadata(d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\b\u0081\u0004\u0018\u00002\u00020\u0001B%\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nJ\b\u0010\u000b\u001a\u00020\fH\u0014J\b\u0010\r\u001a\u00020\fH\u0016R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u000e"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$EnableBluetoothScoJob;", "Lcom/twilio/audioswitch/bluetooth/BluetoothScoJob;", "logger", "Lcom/twilio/audioswitch/android/Logger;", "audioDeviceManager", "Lcom/twilio/audioswitch/AudioDeviceManager;", "bluetoothScoHandler", "Landroid/os/Handler;", "systemClockWrapper", "Lcom/twilio/audioswitch/android/SystemClockWrapper;", "(Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager;Lcom/twilio/audioswitch/android/Logger;Lcom/twilio/audioswitch/AudioDeviceManager;Landroid/os/Handler;Lcom/twilio/audioswitch/android/SystemClockWrapper;)V", "scoAction", "", "scoTimeOutAction", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class EnableBluetoothScoJob extends BluetoothScoJob {

        @NotNull
        private final AudioDeviceManager audioDeviceManager;

        @NotNull
        private final Logger logger;
        final BluetoothHeadsetManager this$0;

        public EnableBluetoothScoJob(@NotNull BluetoothHeadsetManager bluetoothHeadsetManager, @NotNull Logger logger, @NotNull AudioDeviceManager audioDeviceManager, @NotNull Handler handler, SystemClockWrapper systemClockWrapper) {
            super(logger, handler, systemClockWrapper);
            Intrinsics.checkNotNullParameter(logger, "logger");
            Intrinsics.checkNotNullParameter(audioDeviceManager, "audioDeviceManager");
            Intrinsics.checkNotNullParameter(handler, "bluetoothScoHandler");
            Intrinsics.checkNotNullParameter(systemClockWrapper, "systemClockWrapper");
            this.this$0 = bluetoothHeadsetManager;
            this.logger = logger;
            this.audioDeviceManager = audioDeviceManager;
        }

        @Override
        public void scoAction() {
            this.logger.d("BluetoothHeadsetManager", "Attempting to enable bluetooth SCO");
            this.audioDeviceManager.enableBluetoothSco(true);
            this.this$0.setHeadsetState$audioswitch_release(HeadsetState.AudioActivating.INSTANCE);
        }

        @Override
        public void scoTimeOutAction() {
            this.this$0.setHeadsetState$audioswitch_release(HeadsetState.AudioActivationError.INSTANCE);
            BluetoothHeadsetConnectionListener headsetListener = this.this$0.getHeadsetListener();
            if (headsetListener != null) {
                headsetListener.onBluetoothHeadsetActivationError();
            }
        }
    }

    @Metadata(d1 = {"\u0000\"\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b1\u0018\u00002\u00020\u0001:\u0005\u0003\u0004\u0005\u0006\u0007B\u0007\b\u0004¢\u0006\u0002\u0010\u0002\u0082\u0001\u0005\b\t\n\u000b\f¨\u0006\r"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "", "()V", "AudioActivated", "AudioActivating", "AudioActivationError", "Connected", "Disconnected", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$Disconnected;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$Connected;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$AudioActivating;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$AudioActivationError;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$AudioActivated;", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static abstract class HeadsetState {

        @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$AudioActivated;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "()V", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
        public static final class AudioActivated extends HeadsetState {

            @NotNull
            public static final AudioActivated INSTANCE = new AudioActivated();

            private AudioActivated() {
                super(null);
            }
        }

        @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$AudioActivating;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "()V", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
        public static final class AudioActivating extends HeadsetState {

            @NotNull
            public static final AudioActivating INSTANCE = new AudioActivating();

            private AudioActivating() {
                super(null);
            }
        }

        @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$AudioActivationError;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "()V", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
        public static final class AudioActivationError extends HeadsetState {

            @NotNull
            public static final AudioActivationError INSTANCE = new AudioActivationError();

            private AudioActivationError() {
                super(null);
            }
        }

        @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$Connected;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "()V", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
        public static final class Connected extends HeadsetState {

            @NotNull
            public static final Connected INSTANCE = new Connected();

            private Connected() {
                super(null);
            }
        }

        @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState$Disconnected;", "Lcom/twilio/audioswitch/bluetooth/BluetoothHeadsetManager$HeadsetState;", "()V", "audioswitch_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
        public static final class Disconnected extends HeadsetState {

            @NotNull
            public static final Disconnected INSTANCE = new Disconnected();

            private Disconnected() {
                super(null);
            }
        }

        public HeadsetState(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private HeadsetState() {
        }
    }

    public BluetoothHeadsetManager(Context context, Logger logger, BluetoothAdapter bluetoothAdapter, AudioDeviceManager audioDeviceManager, BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener, Handler handler, SystemClockWrapper systemClockWrapper, BluetoothIntentProcessor bluetoothIntentProcessor, BluetoothHeadset bluetoothHeadset, boolean z, int i, DefaultConstructorMarker defaultConstructorMarker) {
        this(context, logger, bluetoothAdapter, audioDeviceManager, (i & 16) != 0 ? null : bluetoothHeadsetConnectionListener, (i & 32) != 0 ? new Handler(Looper.getMainLooper()) : handler, (i & 64) != 0 ? new SystemClockWrapper() : systemClockWrapper, (i & Sdk$SDKError.b.INVALID_TPAT_KEY_VALUE) != 0 ? new BluetoothIntentProcessorImpl() : bluetoothIntentProcessor, (i & 256) != 0 ? null : bluetoothHeadset, (i & 512) != 0 ? false : z);
    }

    private final void connect() {
        if (hasActiveHeadset()) {
            return;
        }
        setHeadsetState$audioswitch_release(HeadsetState.Connected.INSTANCE);
    }

    private final void disconnect() {
        setHeadsetState$audioswitch_release(hasActiveHeadset() ? HeadsetState.AudioActivated.INSTANCE : hasConnectedDevice() ? HeadsetState.Connected.INSTANCE : HeadsetState.Disconnected.INSTANCE);
    }

    public static void getDisableBluetoothScoJob$audioswitch_release$annotations() {
    }

    public static void getEnableBluetoothScoJob$audioswitch_release$annotations() {
    }

    private final BluetoothDeviceWrapper getHeadsetDevice(Intent intent) {
        BluetoothDeviceWrapper bluetoothDevice = this.bluetoothIntentProcessor.getBluetoothDevice(intent);
        if (bluetoothDevice == null || !isHeadsetDevice(bluetoothDevice)) {
            return null;
        }
        return bluetoothDevice;
    }

    private final String getHeadsetName() {
        List<BluetoothDevice> connectedDevices;
        Object obj;
        BluetoothHeadset bluetoothHeadset = this.headsetProxy;
        if (bluetoothHeadset != null && (connectedDevices = bluetoothHeadset.getConnectedDevices()) != null) {
            Intrinsics.checkNotNullExpressionValue(connectedDevices, "connectedDevices");
            if (connectedDevices.size() > 1 && hasActiveHeadset()) {
                Iterator<T> it = connectedDevices.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        obj = null;
                        break;
                    }
                    obj = it.next();
                    if (bluetoothHeadset.isAudioConnected((BluetoothDevice) obj)) {
                        break;
                    }
                }
                BluetoothDevice bluetoothDevice = (BluetoothDevice) obj;
                String name = bluetoothDevice != null ? bluetoothDevice.getName() : null;
                this.logger.d("BluetoothHeadsetManager", "Device size > 1 with device name: " + name);
                return name;
            }
            if (connectedDevices.size() == 1) {
                String name2 = ((BluetoothDevice) CollectionsKt.L(connectedDevices)).getName();
                this.logger.d("BluetoothHeadsetManager", "Device size 1 with device name: " + name2);
                return name2;
            }
            this.logger.d("BluetoothHeadsetManager", "Device size 0");
        }
        return null;
    }

    public static void getHeadsetState$audioswitch_release$annotations() {
    }

    private final boolean hasActiveHeadset() {
        Boolean bool;
        boolean z;
        BluetoothHeadset bluetoothHeadset = this.headsetProxy;
        if (bluetoothHeadset != null) {
            List<BluetoothDevice> connectedDevices = bluetoothHeadset.getConnectedDevices();
            if (connectedDevices != null) {
                Intrinsics.checkNotNullExpressionValue(connectedDevices, "connectedDevices");
                List<BluetoothDevice> list = connectedDevices;
                if (!(list instanceof Collection) || !list.isEmpty()) {
                    Iterator<T> it = list.iterator();
                    while (it.hasNext()) {
                        if (bluetoothHeadset.isAudioConnected((BluetoothDevice) it.next())) {
                            z = true;
                            break;
                        }
                    }
                }
                z = false;
                bool = Boolean.valueOf(z);
            } else {
                bool = null;
            }
            if (bool != null) {
                return bool.booleanValue();
            }
        }
        return false;
    }

    private final boolean hasActiveHeadsetChanged() {
        return Intrinsics.a(this.headsetState, HeadsetState.AudioActivated.INSTANCE) && hasConnectedDevice() && !hasActiveHeadset();
    }

    private final boolean hasConnectedDevice() {
        Boolean bool;
        BluetoothHeadset bluetoothHeadset = this.headsetProxy;
        if (bluetoothHeadset == null) {
            return false;
        }
        List<BluetoothDevice> connectedDevices = bluetoothHeadset.getConnectedDevices();
        if (connectedDevices != null) {
            Intrinsics.checkNotNullExpressionValue(connectedDevices, "connectedDevices");
            bool = Boolean.valueOf(!connectedDevices.isEmpty());
        } else {
            bool = null;
        }
        if (bool != null) {
            return bool.booleanValue();
        }
        return false;
    }

    private final boolean isCorrectIntentAction(String intentAction) {
        return Intrinsics.a(intentAction, "android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED") || Intrinsics.a(intentAction, "android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED") || Intrinsics.a(intentAction, "android.media.ACTION_SCO_AUDIO_STATE_UPDATED");
    }

    private final boolean isHeadsetDevice(BluetoothDeviceWrapper deviceWrapper) {
        Integer deviceClass = deviceWrapper.getDeviceClass();
        if (deviceClass == null) {
            return false;
        }
        int intValue = deviceClass.intValue();
        return intValue == 1032 || intValue == 1028 || intValue == 1056 || intValue == 1048 || intValue == 7936;
    }

    public final void activate() {
        if (Intrinsics.a(this.headsetState, HeadsetState.Connected.INSTANCE) || Intrinsics.a(this.headsetState, HeadsetState.AudioActivationError.INSTANCE)) {
            this.enableBluetoothScoJob.executeBluetoothScoJob();
            return;
        }
        this.logger.w("BluetoothHeadsetManager", "Cannot activate when in the " + l0.a.b(this.headsetState.getClass()).j() + " state");
    }

    public final void deactivate() {
        if (Intrinsics.a(this.headsetState, HeadsetState.AudioActivated.INSTANCE)) {
            this.disableBluetoothScoJob.executeBluetoothScoJob();
            return;
        }
        this.logger.w("BluetoothHeadsetManager", "Cannot deactivate when in the " + l0.a.b(this.headsetState.getClass()).j() + " state");
    }

    @NotNull
    public final DisableBluetoothScoJob getDisableBluetoothScoJob() {
        return this.disableBluetoothScoJob;
    }

    @NotNull
    public final EnableBluetoothScoJob getEnableBluetoothScoJob() {
        return this.enableBluetoothScoJob;
    }

    public final AudioDevice.BluetoothHeadset getHeadset(String bluetoothHeadsetName) {
        if (Intrinsics.a(this.headsetState, HeadsetState.Disconnected.INSTANCE)) {
            return null;
        }
        if (bluetoothHeadsetName == null) {
            bluetoothHeadsetName = getHeadsetName();
        }
        return bluetoothHeadsetName != null ? new AudioDevice.BluetoothHeadset(bluetoothHeadsetName) : new AudioDevice.BluetoothHeadset(null, 1, null);
    }

    public final BluetoothHeadsetConnectionListener getHeadsetListener() {
        return this.headsetListener;
    }

    @NotNull
    public final HeadsetState getHeadsetState() {
        return this.headsetState;
    }

    public final boolean hasActivationError() {
        return Intrinsics.a(this.headsetState, HeadsetState.AudioActivationError.INSTANCE);
    }

    @Override
    public void onReceive(@NotNull Context context, @NotNull Intent intent) {
        Intrinsics.checkNotNullParameter(context, POBNativeConstants.NATIVE_CONTEXT);
        Intrinsics.checkNotNullParameter(intent, "intent");
        if (isCorrectIntentAction(intent.getAction())) {
            BluetoothDeviceWrapper headsetDevice = getHeadsetDevice(intent);
            if (headsetDevice != null) {
                int intExtra = intent.getIntExtra("android.bluetooth.profile.extra.STATE", 0);
                if (intExtra == 0) {
                    this.logger.d("BluetoothHeadsetManager", "Bluetooth headset " + headsetDevice + " disconnected");
                    disconnect();
                    BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener = this.headsetListener;
                    if (bluetoothHeadsetConnectionListener != null) {
                        bluetoothHeadsetConnectionListener.onBluetoothHeadsetStateChanged(headsetDevice.getName(), 0);
                    }
                } else if (intExtra == 2) {
                    this.logger.d("BluetoothHeadsetManager", "Bluetooth headset " + headsetDevice + " connected");
                    connect();
                    BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener2 = this.headsetListener;
                    if (bluetoothHeadsetConnectionListener2 != null) {
                        bluetoothHeadsetConnectionListener2.onBluetoothHeadsetStateChanged(headsetDevice.getName(), 2);
                    }
                } else if (intExtra == 10) {
                    this.logger.d("BluetoothHeadsetManager", "Bluetooth audio disconnected on device " + headsetDevice);
                    this.disableBluetoothScoJob.cancelBluetoothScoJob();
                    if (hasActiveHeadsetChanged()) {
                        this.enableBluetoothScoJob.executeBluetoothScoJob();
                    }
                    BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener3 = this.headsetListener;
                    if (bluetoothHeadsetConnectionListener3 != null) {
                        bluetoothHeadsetConnectionListener3.onBluetoothHeadsetStateChanged(headsetDevice.getName(), 10);
                    }
                } else if (intExtra == 12) {
                    this.logger.d("BluetoothHeadsetManager", "Bluetooth audio connected on device " + headsetDevice);
                    this.enableBluetoothScoJob.cancelBluetoothScoJob();
                    setHeadsetState$audioswitch_release(HeadsetState.AudioActivated.INSTANCE);
                    BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener4 = this.headsetListener;
                    if (bluetoothHeadsetConnectionListener4 != null) {
                        bluetoothHeadsetConnectionListener4.onBluetoothHeadsetStateChanged(headsetDevice.getName(), 12);
                    }
                }
            }
            int intExtra2 = intent.getIntExtra("android.media.extra.SCO_AUDIO_STATE", 0);
            if (intExtra2 == 0) {
                this.logger.d("BluetoothHeadsetManager", "Bluetooth SCO disconnected");
                BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener5 = this.headsetListener;
                if (bluetoothHeadsetConnectionListener5 != null) {
                    bluetoothHeadsetConnectionListener5.onBluetoothScoStateChanged(0);
                    return;
                }
                return;
            }
            if (intExtra2 == 1) {
                this.logger.d("BluetoothHeadsetManager", "Bluetooth SCO connected");
                BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener6 = this.headsetListener;
                if (bluetoothHeadsetConnectionListener6 != null) {
                    bluetoothHeadsetConnectionListener6.onBluetoothScoStateChanged(1);
                    return;
                }
                return;
            }
            if (intExtra2 != 2) {
                return;
            }
            this.logger.d("BluetoothHeadsetManager", "Bluetooth SCO connecting");
            BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener7 = this.headsetListener;
            if (bluetoothHeadsetConnectionListener7 != null) {
                bluetoothHeadsetConnectionListener7.onBluetoothScoStateChanged(2);
            }
        }
    }

    @Override
    public void onServiceConnected(int profile, @NotNull BluetoothProfile bluetoothProfile) {
        Intrinsics.checkNotNullParameter(bluetoothProfile, "bluetoothProfile");
        BluetoothHeadset bluetoothHeadset = (BluetoothHeadset) bluetoothProfile;
        this.headsetProxy = bluetoothHeadset;
        List<BluetoothDevice> connectedDevices = bluetoothHeadset.getConnectedDevices();
        Intrinsics.checkNotNullExpressionValue(connectedDevices, "bluetoothProfile.connectedDevices");
        for (BluetoothDevice bluetoothDevice : connectedDevices) {
            this.logger.d("BluetoothHeadsetManager", "Bluetooth " + bluetoothDevice.getName() + " connected");
        }
        if (hasConnectedDevice()) {
            connect();
            BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener = this.headsetListener;
            if (bluetoothHeadsetConnectionListener != null) {
                BluetoothHeadsetConnectionListener.DefaultImpls.onBluetoothHeadsetStateChanged$default(bluetoothHeadsetConnectionListener, getHeadsetName(), 0, 2, null);
            }
        }
    }

    @Override
    public void onServiceDisconnected(int profile) {
        this.logger.d("BluetoothHeadsetManager", "Bluetooth disconnected");
        setHeadsetState$audioswitch_release(HeadsetState.Disconnected.INSTANCE);
        BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener = this.headsetListener;
        if (bluetoothHeadsetConnectionListener != null) {
            BluetoothHeadsetConnectionListener.DefaultImpls.onBluetoothHeadsetStateChanged$default(bluetoothHeadsetConnectionListener, null, 0, 3, null);
        }
    }

    public final void setHeadsetListener(BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener) {
        this.headsetListener = bluetoothHeadsetConnectionListener;
    }

    public final void setHeadsetState$audioswitch_release(@NotNull HeadsetState headsetState) {
        Intrinsics.checkNotNullParameter(headsetState, "value");
        if (Intrinsics.a(this.headsetState, headsetState)) {
            return;
        }
        this.headsetState = headsetState;
        this.logger.d("BluetoothHeadsetManager", "Headset state changed to " + l0.a.b(headsetState.getClass()).j());
        if (headsetState.equals(HeadsetState.Disconnected.INSTANCE)) {
            this.enableBluetoothScoJob.cancelBluetoothScoJob();
        }
    }

    public final void start(@NotNull BluetoothHeadsetConnectionListener headsetListener) {
        Intrinsics.checkNotNullParameter(headsetListener, "headsetListener");
        this.headsetListener = headsetListener;
        this.bluetoothAdapter.getProfileProxy(this.context, this, 1);
        if (this.hasRegisteredReceivers) {
            return;
        }
        this.context.registerReceiver(this, new IntentFilter("android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED"));
        this.context.registerReceiver(this, new IntentFilter("android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED"));
        this.context.registerReceiver(this, new IntentFilter("android.media.ACTION_SCO_AUDIO_STATE_UPDATED"));
        this.hasRegisteredReceivers = true;
    }

    public final void stop() {
        this.headsetListener = null;
        this.bluetoothAdapter.closeProfileProxy(1, this.headsetProxy);
        if (this.hasRegisteredReceivers) {
            this.context.unregisterReceiver(this);
            this.hasRegisteredReceivers = false;
        }
    }

    public BluetoothHeadsetManager(@NotNull Context context, @NotNull Logger logger, @NotNull BluetoothAdapter bluetoothAdapter, @NotNull AudioDeviceManager audioDeviceManager, BluetoothHeadsetConnectionListener bluetoothHeadsetConnectionListener, @NotNull Handler handler, @NotNull SystemClockWrapper systemClockWrapper, @NotNull BluetoothIntentProcessor bluetoothIntentProcessor, BluetoothHeadset bluetoothHeadset, boolean z) {
        Intrinsics.checkNotNullParameter(context, POBNativeConstants.NATIVE_CONTEXT);
        Intrinsics.checkNotNullParameter(logger, "logger");
        Intrinsics.checkNotNullParameter(bluetoothAdapter, "bluetoothAdapter");
        Intrinsics.checkNotNullParameter(audioDeviceManager, "audioDeviceManager");
        Intrinsics.checkNotNullParameter(handler, "bluetoothScoHandler");
        Intrinsics.checkNotNullParameter(systemClockWrapper, "systemClockWrapper");
        Intrinsics.checkNotNullParameter(bluetoothIntentProcessor, "bluetoothIntentProcessor");
        this.context = context;
        this.logger = logger;
        this.bluetoothAdapter = bluetoothAdapter;
        this.headsetListener = bluetoothHeadsetConnectionListener;
        this.bluetoothIntentProcessor = bluetoothIntentProcessor;
        this.headsetProxy = bluetoothHeadset;
        this.hasRegisteredReceivers = z;
        this.headsetState = HeadsetState.Disconnected.INSTANCE;
        this.enableBluetoothScoJob = new EnableBluetoothScoJob(this, logger, audioDeviceManager, handler, systemClockWrapper);
        this.disableBluetoothScoJob = new DisableBluetoothScoJob(this, logger, audioDeviceManager, handler, systemClockWrapper);
    }
}