package g.f.c.b.tea;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import com.cvte.va.sdk.mica.api.DeviceStatusManager;
import com.cvte.va.sdk.mica.api.InitManager;
import com.cvte.va.sdk.mica.api.VolumeManager;
import com.cvte.vman.AoipCtrl;
import com.cvte.vman.VmanMiddleWare;
import com.ifpdos.udi.service.tea.DeviceKeyBody;
import com.ifpdos.udi.service.tea.DeviceProviderNotify;
import com.ifpdos.udi.service.tea.DeviceTypeEnum;
import com.ifpdos.udi.service.tea.HookBody;
import com.ifpdos.udi.service.tea.MicMuteBody;
import com.ifpdos.udi.service.tea.MicPoeBM50Device;
import com.ifpdos.udi.service.tea.TeaDeviceHelper;
import com.tencent.common.ITEAInsideDeviceConnectStateUpdateCbDelegate;
import g.f.c.b.d.pc.utils.InputEventUtils;
import g.f.c.b.d.pc.utils.PropertiesUtils;
import g.f.c.b.tea.BM51UsbTea;
import java.util.Objects;
import kotlin.Metadata;
import kotlin.jvm.internal.o;

/* JADX INFO: renamed from: g.f.c.b.i.x1, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000¦\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\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\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\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\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0016\u0018\u0000 M2\u00020\u00012\u00020\u00022\u00020\u00032\u00020\u00042\u00020\u00052\u00020\u0006:\u0001MB\r\u0012\u0006\u0010\u0007\u001a\u00020\b¢\u0006\u0002\u0010\tJ.\u0010)\u001a\u00020*2\b\u0010+\u001a\u0004\u0018\u00010,2\b\u0010-\u001a\u0004\u0018\u00010,2\u0006\u0010.\u001a\u00020\u001b2\b\u0010/\u001a\u0004\u0018\u00010,H\u0016J\b\u00100\u001a\u00020*H\u0002J\n\u00101\u001a\u0004\u0018\u000102H\u0002J\u001c\u00103\u001a\b\u0012\u0004\u0012\u000205042\u0006\u0010\u0007\u001a\u00020\b2\u0006\u00106\u001a\u000202J\f\u00107\u001a\b\u0012\u0004\u0012\u00020804J\u0010\u00109\u001a\u00020*2\u0006\u0010:\u001a\u00020&H\u0016J\u0010\u0010;\u001a\u00020*2\u0006\u0010<\u001a\u00020&H\u0016J\b\u0010=\u001a\u00020*H\u0016J\u0010\u0010>\u001a\u00020*2\u0006\u0010?\u001a\u00020\u001bH\u0016J\u0010\u0010@\u001a\u00020*2\u0006\u0010A\u001a\u00020&H\u0016J\u0006\u0010B\u001a\u00020*J\b\u0010C\u001a\u00020*H\u0002J\u0010\u0010D\u001a\u00020*2\u0006\u0010E\u001a\u00020\u001bH\u0002J\u0016\u0010F\u001a\u00020\u001b2\u0006\u0010G\u001a\u0002022\u0006\u0010H\u001a\u00020\u001bJ\u0016\u0010I\u001a\u00020\u001b2\u0006\u0010G\u001a\u0002022\u0006\u0010?\u001a\u00020\u001bJ\u0016\u0010J\u001a\u00020\u001b2\u0006\u0010G\u001a\u0002022\u0006\u0010K\u001a\u00020\u001bJ\b\u0010L\u001a\u00020*H\u0002R\u000e\u0010\n\u001a\u00020\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\f\u001a\u00020\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u000e\u001a\u00020\u000fX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0010\u001a\u00020\u0011X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0012\u001a\u00020\u0013X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0014\u001a\u0004\u0018\u00010\u0015X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0016\u001a\u0004\u0018\u00010\u0017X\u0082\u000e¢\u0006\u0002\n\u0000R\u0011\u0010\u0007\u001a\u00020\b¢\u0006\b\n\u0000\u001a\u0004\b\u0018\u0010\u0019R\u000e\u0010\u001a\u001a\u00020\u001bX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001c\u001a\u00020\u001bX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\u001eX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001f\u001a\u00020 X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010!\u001a\u00020\"X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010#\u001a\u00020$X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010%\u001a\u00020&X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010'\u001a\u00020(X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006N"}, d2 = {"Lcom/ifpdos/udi/service/tea/TeaDeviceManager;", "Lcom/cvte/va/sdk/mica/api/DeviceStatusManager$MicMuteStatusCallback;", "Lcom/cvte/va/sdk/mica/api/DeviceStatusManager$MicKeyCodeCallback;", "Lcom/ifpdos/udi/service/tea/BM51UsbTea$MicMuteChangeListener;", "Lcom/ifpdos/udi/service/tea/MicPoeBM50Device$PoeMicMuteChangeListener;", "Lcom/cvte/va/sdk/mica/api/DeviceStatusManager$DeviceConnectionStatusCallback;", "Lcom/tencent/common/ITEAInsideDeviceConnectStateUpdateCbDelegate;", "context", "Landroid/content/Context;", "(Landroid/content/Context;)V", "bm22Dongle", "Lcom/ifpdos/udi/service/tea/BM22Dongle;", "bm22Usb", "Lcom/ifpdos/udi/service/tea/BM22Usb;", "bm50Dongle", "Lcom/ifpdos/udi/service/tea/BM50Dongle;", "bm50Usb", "Lcom/ifpdos/udi/service/tea/BM50Usb;", "bm51Dongle", "Lcom/ifpdos/udi/service/tea/BM51Dongle;", "bm51Usb", "Lcom/ifpdos/udi/service/tea/BM51UsbTea;", "bm51Vman", "Lcom/ifpdos/udi/service/tea/BM51Vman;", "getContext", "()Landroid/content/Context;", "filterMicMuteChange", "", "filterMicMuteNotify", "handler", "Landroid/os/Handler;", "handlerThread", "Landroid/os/HandlerThread;", "mMicMuteStatusReceiver", "Landroid/content/BroadcastReceiver;", "poeDevice", "Lcom/ifpdos/udi/service/tea/MicPoeBM50Device;", "syncMuteToVASDKCount", "", "teaPoeBM51Device", "Lcom/ifpdos/udi/service/tea/TeaPoeBM51Device;", "OnDeviceConnectStateUpdate", "", "p0", "", "p1", "p2", "p3", "enableMvChangeVol", "getCurrentConnectedDevice", "Lcom/ifpdos/udi/service/tea/DeviceTypeEnum;", "getPeripheralDeviceInfo", "", "Lcom/ifpdos/udi/service/tea/PeripheralInfo;", "type", "getUdiHandlerDeviceList", "Lcom/ifpdos/udi/service/tea/PidVidBody;", "onDeviceConnectionStatusCallback", "deviceConnect", "onMicKeyCodeCallback", "keyCode", "onMicMuteChangeFromPoe", "onMicMuteChangeFromTeaSDK", "mute", "onMicMuteStatusChanged", "status", "onMicMuteStatusChangedFromAndroid", "registerMicListener", "setAllDeviceMicMute", "micMute", "setDeviceHook", "deviceTypeEnum", "on", "setDeviceMicMute", "setDeviceRingCall", "enable", "syncMuteToVASDKDevice", "Companion", "tea_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class TeaDeviceManager implements DeviceStatusManager.MicMuteStatusCallback, DeviceStatusManager.MicKeyCodeCallback, BM51UsbTea.c, MicPoeBM50Device.a, DeviceStatusManager.DeviceConnectionStatusCallback, ITEAInsideDeviceConnectStateUpdateCbDelegate {
    public final Context a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public BM51Dongle f4739b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public BM51Vman f4740c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public BM51UsbTea f4741d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final BM50Dongle f4742e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final BM50Usb f4743f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final BM22Dongle f4744g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final BM22Usb f4745h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final MicPoeBM50Device f4746i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final TeaPoeBM51Device f4747j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final HandlerThread f4748k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public Handler f4749l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public volatile boolean f4750m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public volatile boolean f4751n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f4752o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final BroadcastReceiver f4753p;

    /* JADX INFO: renamed from: g.f.c.b.i.x1$a */
    @Metadata(d1 = {"\u0000\u001d\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000*\u0001\u0000\b\n\u0018\u00002\u00020\u0001J\u001c\u0010\u0002\u001a\u00020\u00032\b\u0010\u0004\u001a\u0004\u0018\u00010\u00052\b\u0010\u0006\u001a\u0004\u0018\u00010\u0007H\u0016¨\u0006\b"}, d2 = {"com/ifpdos/udi/service/tea/TeaDeviceManager$mMicMuteStatusReceiver$1", "Landroid/content/BroadcastReceiver;", "onReceive", "", "context", "Landroid/content/Context;", "intent", "Landroid/content/Intent;", "tea_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class a extends BroadcastReceiver {
        public a() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            if (o.a(intent != null ? intent.getAction() : null, "android.media.action.MICROPHONE_MUTE_CHANGED")) {
                if (TeaDeviceManager.this.f4750m) {
                    Log.d("TeaDeviceManager", "filterMicMuteChange is true,return");
                    return;
                }
                if (TeaDeviceManager.this.c() == null) {
                    return;
                }
                final TeaDeviceManager teaDeviceManager = TeaDeviceManager.this;
                Object systemService = teaDeviceManager.a.getSystemService("audio");
                Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.media.AudioManager");
                boolean zIsMicrophoneMute = ((AudioManager) systemService).isMicrophoneMute();
                g.a.a.a.a.k0("Stream mute status changed from android: ", zIsMicrophoneMute, "TeaDeviceManager");
                teaDeviceManager.f4749l.removeCallbacksAndMessages(null);
                teaDeviceManager.f4751n = true;
                teaDeviceManager.d(DeviceTypeEnum.BM50, zIsMicrophoneMute);
                teaDeviceManager.d(DeviceTypeEnum.BM51, zIsMicrophoneMute);
                teaDeviceManager.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.q
                    @Override // java.lang.Runnable
                    public final void run() {
                        TeaDeviceManager teaDeviceManager2 = teaDeviceManager;
                        o.f(teaDeviceManager2, "this$0");
                        Log.d("TeaDeviceManager", "set filterMicMuteNotify false");
                        teaDeviceManager2.f4751n = false;
                    }
                }, 300L);
            }
        }
    }

    public TeaDeviceManager(Context context) {
        o.f(context, "context");
        this.a = context;
        this.f4739b = new BM51Dongle(context);
        this.f4742e = new BM50Dongle(context);
        this.f4743f = new BM50Usb(context);
        this.f4744g = new BM22Dongle(context);
        this.f4745h = new BM22Usb(context);
        this.f4746i = new MicPoeBM50Device(context);
        this.f4747j = new TeaPoeBM51Device(context);
        HandlerThread handlerThread = new HandlerThread("TeaDeviceHandlerThread");
        handlerThread.start();
        this.f4748k = handlerThread;
        this.f4749l = new Handler(handlerThread.getLooper());
        this.f4753p = new a();
        if (PropertiesUtils.a.o()) {
            Log.d("TeaDeviceManager", "teaEnable true,usb BM51Usb");
            BM51UsbTea bM51UsbTea = new BM51UsbTea(context);
            o.f(this, "listener");
            bM51UsbTea.f4676e = this;
            this.f4741d = bM51UsbTea;
        } else {
            Log.d("TeaDeviceManager", "teaEnable false,usb BM51Vman");
            this.f4740c = new BM51Vman(context);
        }
        try {
            DeviceStatusManager.getInstance().setMicKeyCodeCallback(this);
            DeviceStatusManager.getInstance().setMicMuteStatusCallback(this);
            DeviceStatusManager.getInstance().setDeviceConnectionStatusCallback(this);
        } catch (Exception e2) {
            Log.e("TeaDeviceManager", "initVASDK failed", e2);
        }
        if (Build.VERSION.SDK_INT >= 28) {
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.media.action.MICROPHONE_MUTE_CHANGED");
            this.a.registerReceiver(this.f4753p, intentFilter);
        }
        MicPoeBM50Device micPoeBM50Device = this.f4746i;
        Objects.requireNonNull(micPoeBM50Device);
        o.f(this, "listener");
        micPoeBM50Device.f1351i = this;
        TeaDeviceHelper teaDeviceHelper = TeaDeviceHelper.a;
        o.f(this, "listener");
        TeaDeviceHelper.f1374h.add(this);
        if (this.f4743f.b(this.a) || this.f4742e.b(this.a)) {
            Log.d("TeaDeviceManager", "BM50 is connected,enable mv change vol");
            VolumeManager.getInstance().setEnableMvChangeVol(true);
        }
    }

    @Override // com.tencent.common.ITEAInsideDeviceConnectStateUpdateCbDelegate
    public void OnDeviceConnectStateUpdate(String p0, String p1, boolean p2, String p3) {
        TeaDeviceHelper teaDeviceHelper = TeaDeviceHelper.a;
        if (teaDeviceHelper.i()) {
            Object systemService = this.a.getSystemService("audio");
            Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.media.AudioManager");
            boolean zIsMicrophoneMute = ((AudioManager) systemService).isMicrophoneMute();
            g.a.a.a.a.k0("BM51 poe connect,sync system mute state to BM51, mute:", zIsMicrophoneMute, "TeaDeviceManager");
            this.f4751n = true;
            teaDeviceHelper.m(zIsMicrophoneMute);
            this.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.p
                @Override // java.lang.Runnable
                public final void run() {
                    TeaDeviceManager teaDeviceManager = this.f4715f;
                    o.f(teaDeviceManager, "this$0");
                    Log.d("TeaDeviceManager", "set filterMicMuteNotify false");
                    teaDeviceManager.f4751n = false;
                }
            }, 300L);
            this.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.l
                @Override // java.lang.Runnable
                public final void run() {
                    PeripheralDeviceProviderApi peripheralDeviceProviderApi = PeripheralDeviceProviderApi.a;
                    PeripheralDeviceProviderApi.a(new DeviceProviderNotify(DeviceTypeEnum.BM51, true));
                }
            }, 200L);
        }
    }

    @Override // g.f.c.b.tea.BM51UsbTea.c
    public void a(boolean z2) {
        if (this.f4751n) {
            Log.d("TeaDeviceManager", "filterMicMuteNotify is true,return");
            return;
        }
        Object systemService = this.a.getSystemService("audio");
        Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.media.AudioManager");
        if (((AudioManager) systemService).isMicrophoneMute() == z2) {
            Log.d("TeaDeviceManager", "onMicMuteChangeFromTeaSDK: current mute status is same as set status,return");
            return;
        }
        DeviceMicMuteApi deviceMicMuteApi = DeviceMicMuteApi.a;
        DeviceTypeEnum deviceTypeEnum = DeviceTypeEnum.BM51;
        DeviceMicMuteApi.a(deviceTypeEnum, new MicMuteBody(deviceTypeEnum, z2));
        this.f4749l.removeCallbacksAndMessages(null);
        this.f4750m = true;
        this.f4749l.post(new Runnable() { // from class: g.f.c.b.i.s
            @Override // java.lang.Runnable
            public final void run() {
                InputEventUtils.a(91);
            }
        });
        this.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.u
            @Override // java.lang.Runnable
            public final void run() {
                TeaDeviceManager teaDeviceManager = this.f4730f;
                o.f(teaDeviceManager, "this$0");
                Log.d("TeaDeviceManager", "set filterMicMuteChange false");
                teaDeviceManager.f4750m = false;
            }
        }, 300L);
    }

    @Override // com.ifpdos.udi.service.tea.MicPoeBM50Device.a
    public void b() {
        if (this.f4751n) {
            Log.d("TeaDeviceManager", "filterMicMuteNotify is true,return");
            return;
        }
        Object systemService = this.a.getSystemService("audio");
        Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.media.AudioManager");
        boolean z2 = !((AudioManager) systemService).isMicrophoneMute();
        DeviceMicMuteApi deviceMicMuteApi = DeviceMicMuteApi.a;
        DeviceTypeEnum deviceTypeEnum = DeviceTypeEnum.BM50;
        DeviceMicMuteApi.a(deviceTypeEnum, new MicMuteBody(deviceTypeEnum, z2));
        this.f4749l.removeCallbacksAndMessages(null);
        this.f4750m = true;
        this.f4749l.post(new Runnable() { // from class: g.f.c.b.i.v
            @Override // java.lang.Runnable
            public final void run() {
                InputEventUtils.a(91);
            }
        });
        this.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.j
            @Override // java.lang.Runnable
            public final void run() {
                TeaDeviceManager teaDeviceManager = this.f4697f;
                o.f(teaDeviceManager, "this$0");
                Log.d("TeaDeviceManager", "set filterMicMuteChange false");
                teaDeviceManager.f4750m = false;
            }
        }, 300L);
    }

    public final DeviceTypeEnum c() {
        BM51UsbTea bM51UsbTea = this.f4741d;
        if (!(bM51UsbTea != null && bM51UsbTea.b(this.a)) && !this.f4739b.b(this.a)) {
            if (this.f4743f.b(this.a) || this.f4742e.b(this.a) || this.f4746i.h()) {
                return DeviceTypeEnum.BM50;
            }
            if (!this.f4747j.h()) {
                if (this.f4745h.b(this.a) || this.f4744g.b(this.a)) {
                    return DeviceTypeEnum.BM22;
                }
                return null;
            }
        }
        return DeviceTypeEnum.BM51;
    }

    public final boolean d(DeviceTypeEnum deviceTypeEnum, boolean z2) {
        o.f(deviceTypeEnum, "deviceTypeEnum");
        Log.d("TeaDeviceManager", "setDeviceMicMute: " + deviceTypeEnum + ' ' + z2);
        int iOrdinal = deviceTypeEnum.ordinal();
        boolean z3 = false;
        if (iOrdinal == 0) {
            BM51UsbTea bM51UsbTea = this.f4741d;
            if (bM51UsbTea != null && true == bM51UsbTea.b(this.a)) {
                g.a.a.a.a.k0("setDeviceMicMute to BM51 usb ", z2, "TeaDeviceManager");
                BM51UsbTea bM51UsbTea2 = this.f4741d;
                if (bM51UsbTea2 != null) {
                    bM51UsbTea2.i(z2);
                    z3 = true;
                }
            }
            if (this.f4739b.b(this.a)) {
                Log.d("TeaDeviceManager", "setDeviceMicMute to BM51 dongle " + z2);
                DeviceStatusManager.getInstance().setMicMute(z2);
                z3 = true;
            }
            if (!this.f4747j.h()) {
                return z3;
            }
            g.a.a.a.a.k0("setDeviceMicMute to BM51 poe ", z2, "TeaDeviceManager");
            Objects.requireNonNull(this.f4747j);
            Log.d("TeaPoeBM51Device", "setDeviceMicMute:" + z2);
            TeaDeviceHelper.a.m(z2);
        } else {
            if (iOrdinal != 1) {
                return false;
            }
            if (this.f4743f.b(this.a) || this.f4742e.b(this.a)) {
                Log.d("TeaDeviceManager", "setDeviceMicMute to BM50 " + z2);
                DeviceStatusManager.getInstance().setMicMute(z2);
                z3 = true;
            }
            if (!this.f4746i.h()) {
                return z3;
            }
            g.a.a.a.a.k0("setDeviceMicMute to BM50 poe ", z2, "TeaDeviceManager");
            Objects.requireNonNull(this.f4746i);
            AoipCtrl aoipCtrl = VmanMiddleWare.getInstance().getAoipCtrl();
            if (z2) {
                aoipCtrl.mute();
            } else {
                aoipCtrl.unmute();
            }
        }
        return true;
    }

    public final void e() {
        Handler handler;
        Runnable runnable;
        String micSerialNumber = InitManager.getInstance().getMicSerialNumber();
        o.e(micSerialNumber, "getInstance().micSerialNumber");
        if (!(micSerialNumber.length() > 0)) {
            this.f4752o++;
            g.a.a.a.a.p0(g.a.a.a.a.F("syncMuteToVASDKCount retry check sn: "), this.f4752o, "TeaDeviceManager");
            if (this.f4752o >= 60) {
                Log.d("TeaDeviceManager", "syncMuteToVASDKDevice failed,stop sync");
                return;
            } else {
                this.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.w
                    @Override // java.lang.Runnable
                    public final void run() {
                        this.f4736f.e();
                    }
                }, 500L);
                return;
            }
        }
        Object systemService = this.a.getSystemService("audio");
        Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.media.AudioManager");
        boolean zIsMicrophoneMute = ((AudioManager) systemService).isMicrophoneMute();
        Log.d("TeaDeviceManager", "VASDK onUsbOpenSuccess,sync system mute state to mic, mute:" + zIsMicrophoneMute + ",sync volume");
        VolumeManager.getInstance().sysVolUpdate();
        DeviceStatusManager.getInstance().setMicMute(zIsMicrophoneMute);
        if (this.f4743f.b(this.a) || this.f4742e.b(this.a)) {
            handler = this.f4749l;
            runnable = new Runnable() { // from class: g.f.c.b.i.k
                @Override // java.lang.Runnable
                public final void run() {
                    PeripheralDeviceProviderApi peripheralDeviceProviderApi = PeripheralDeviceProviderApi.a;
                    PeripheralDeviceProviderApi.a(new DeviceProviderNotify(DeviceTypeEnum.BM50, true));
                }
            };
        } else {
            if (!this.f4739b.b(this.a)) {
                return;
            }
            handler = this.f4749l;
            runnable = new Runnable() { // from class: g.f.c.b.i.y
                @Override // java.lang.Runnable
                public final void run() {
                    PeripheralDeviceProviderApi peripheralDeviceProviderApi = PeripheralDeviceProviderApi.a;
                    PeripheralDeviceProviderApi.a(new DeviceProviderNotify(DeviceTypeEnum.BM51, true));
                }
            };
        }
        handler.postDelayed(runnable, 200L);
    }

    @Override // com.cvte.va.sdk.mica.api.DeviceStatusManager.DeviceConnectionStatusCallback
    public void onDeviceConnectionStatusCallback(int deviceConnect) {
        g.a.a.a.a.c0("onDeviceConnectionStatusCallback: ", deviceConnect, "TeaDeviceManager");
        if (deviceConnect == 1) {
            this.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.x
                @Override // java.lang.Runnable
                public final void run() {
                    TeaDeviceManager teaDeviceManager = this.f4738f;
                    o.f(teaDeviceManager, "this$0");
                    teaDeviceManager.f4752o = 0;
                    teaDeviceManager.e();
                }
            }, 100L);
        }
    }

    @Override // com.cvte.va.sdk.mica.api.DeviceStatusManager.MicKeyCodeCallback
    public void onMicKeyCodeCallback(int keyCode) {
        Handler handler;
        Runnable runnable;
        DeviceKeyBody deviceKeyBody;
        KeyTypeEnum keyTypeEnum = KeyTypeEnum.KEY_AI;
        DeviceTypeEnum deviceTypeEnumC = c();
        if (deviceTypeEnumC == null) {
            return;
        }
        if (keyCode == 1) {
            Log.d("TeaDeviceManager", "onMicKeyCodeCallback: KEY_OFF_HOOK");
            DeviceHookApi deviceHookApi = DeviceHookApi.a;
            DeviceHookApi.a(deviceTypeEnumC, new HookBody(deviceTypeEnumC, false));
            handler = this.f4749l;
            runnable = new Runnable() { // from class: g.f.c.b.i.n
                @Override // java.lang.Runnable
                public final void run() {
                    InputEventUtils.a(5);
                }
            };
        } else {
            if (keyCode != 2) {
                if (keyCode == 5) {
                    Log.d("TeaDeviceManager", "onMicKeyCodeCallback: KEY_AI_RECORD_SHORT_PRESS");
                    DeviceKeyNotifyApi deviceKeyNotifyApi = DeviceKeyNotifyApi.a;
                    deviceKeyBody = new DeviceKeyBody(deviceTypeEnumC, keyTypeEnum, KeyPressTypeEnum.NORMAL);
                } else {
                    if (keyCode != 6) {
                        return;
                    }
                    Log.d("TeaDeviceManager", "onMicKeyCodeCallback: KEY_AI_RECORD_LONG_PRESS");
                    DeviceKeyNotifyApi deviceKeyNotifyApi2 = DeviceKeyNotifyApi.a;
                    deviceKeyBody = new DeviceKeyBody(deviceTypeEnumC, keyTypeEnum, KeyPressTypeEnum.LONG_PRESS);
                }
                DeviceKeyNotifyApi.a(deviceKeyBody);
                return;
            }
            Log.d("TeaDeviceManager", "onMicKeyCodeCallback: KEY_ON_HOOK");
            DeviceHookApi deviceHookApi2 = DeviceHookApi.a;
            DeviceHookApi.a(deviceTypeEnumC, new HookBody(deviceTypeEnumC, true));
            handler = this.f4749l;
            runnable = new Runnable() { // from class: g.f.c.b.i.r
                @Override // java.lang.Runnable
                public final void run() {
                    InputEventUtils.a(6);
                }
            };
        }
        handler.post(runnable);
    }

    @Override // com.cvte.va.sdk.mica.api.DeviceStatusManager.MicMuteStatusCallback
    public void onMicMuteStatusChanged(int status) {
        if (this.f4751n) {
            Log.d("TeaDeviceManager", "filterMicMuteNotify is true,return");
            return;
        }
        Log.d("TeaDeviceManager", "onMicMuteStatusChanged status: " + status);
        DeviceTypeEnum deviceTypeEnumC = c();
        if (deviceTypeEnumC == null) {
            return;
        }
        boolean z2 = status == 1;
        Object systemService = this.a.getSystemService("audio");
        Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.media.AudioManager");
        if (((AudioManager) systemService).isMicrophoneMute() == z2) {
            Log.d("TeaDeviceManager", "onMicMuteStatusChanged: current mute status is same as set status,return");
            return;
        }
        DeviceMicMuteApi deviceMicMuteApi = DeviceMicMuteApi.a;
        DeviceMicMuteApi.a(deviceTypeEnumC, new MicMuteBody(deviceTypeEnumC, z2));
        this.f4749l.removeCallbacksAndMessages(null);
        this.f4750m = true;
        this.f4749l.post(new Runnable() { // from class: g.f.c.b.i.o
            @Override // java.lang.Runnable
            public final void run() {
                InputEventUtils.a(91);
            }
        });
        this.f4749l.postDelayed(new Runnable() { // from class: g.f.c.b.i.t
            @Override // java.lang.Runnable
            public final void run() {
                TeaDeviceManager teaDeviceManager = this.f4726f;
                o.f(teaDeviceManager, "this$0");
                Log.d("TeaDeviceManager", "set filterMicMuteChange false");
                teaDeviceManager.f4750m = false;
            }
        }, 300L);
    }
}
