package com.dss.ups.sp51a.ble.manager;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import com.cvte.dss.ups.plugin.IUpsPlugin;
import com.cvte.vman.instance.InvokeCmd;
import com.dss.ups.sp51a.ble.R;
import com.dss.ups.sp51a.ble.manager.SettingsHelper;
import g.i.a.b.e.d;
import g.i.a.c.a0.c;
import g.i.a.c.a0.e;
import g.i.a.c.l.b;
import g.i.a.c.l.c;
import g.i.a.c.q.a;
import g.i.a.c.q.f;
import g.i.a.c.q.g;
import g.i.a.c.q.i;
import g.i.a.c.q.k;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlin.coroutines.j.internal.DebugMetadata;
import kotlin.coroutines.j.internal.SuspendLambda;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.o;
import s.coroutines.CoroutineDispatcher;
import s.coroutines.CoroutineScope;
import s.coroutines.Dispatchers;
import s.coroutines.MainCoroutineDispatcher;
import s.coroutines.internal.MainDispatcherLoader;

/* JADX INFO: loaded from: classes.dex */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000m\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007*\u00013\u0018\u0000 F2\u00020\u0001:\u0001FB\u0007¢\u0006\u0004\bE\u0010\u0004J\u000f\u0010\u0003\u001a\u00020\u0002H\u0002¢\u0006\u0004\b\u0003\u0010\u0004J\u0017\u0010\b\u001a\u0004\u0018\u00010\u00072\u0006\u0010\u0006\u001a\u00020\u0005¢\u0006\u0004\b\b\u0010\tJ\u000f\u0010\u000b\u001a\u0004\u0018\u00010\n¢\u0006\u0004\b\u000b\u0010\fJ\u0015\u0010\u000e\u001a\u00020\r2\u0006\u0010\u0006\u001a\u00020\u0005¢\u0006\u0004\b\u000e\u0010\u000fJ\u001d\u0010\u0011\u001a\u00020\r2\u0006\u0010\u0006\u001a\u00020\u00052\u0006\u0010\u0010\u001a\u00020\r¢\u0006\u0004\b\u0011\u0010\u0012J\u001d\u0010\u0015\u001a\u00020\r2\u0006\u0010\u0014\u001a\u00020\u00132\u0006\u0010\u0010\u001a\u00020\r¢\u0006\u0004\b\u0015\u0010\u0016J\r\u0010\u0017\u001a\u00020\u0002¢\u0006\u0004\b\u0017\u0010\u0004J\r\u0010\u0018\u001a\u00020\u0002¢\u0006\u0004\b\u0018\u0010\u0004J\u001d\u0010\u001a\u001a\u00020\r2\u0006\u0010\u0014\u001a\u00020\u00132\u0006\u0010\u0019\u001a\u00020\r¢\u0006\u0004\b\u001a\u0010\u0016J\u0015\u0010\u001d\u001a\u00020\u00022\u0006\u0010\u001c\u001a\u00020\u001b¢\u0006\u0004\b\u001d\u0010\u001eJ\u001f\u0010!\u001a\u0004\u0018\u00010\r2\u0006\u0010\u0014\u001a\u00020\u00132\u0006\u0010 \u001a\u00020\u001f¢\u0006\u0004\b!\u0010\"J\u001d\u0010%\u001a\u00020\r2\u0006\u0010#\u001a\u00020\u001f2\u0006\u0010$\u001a\u00020\r¢\u0006\u0004\b%\u0010&J\r\u0010'\u001a\u00020\u0002¢\u0006\u0004\b'\u0010\u0004J-\u0010+\u001a\u00020\r2\u0006\u0010\u0006\u001a\u00020\u00052\u0006\u0010\u0014\u001a\u00020\u00132\u0006\u0010(\u001a\u00020\u001f2\u0006\u0010*\u001a\u00020)¢\u0006\u0004\b+\u0010,R\u0018\u0010-\u001a\u0004\u0018\u00010)8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b-\u0010.R\u0018\u0010/\u001a\u0004\u0018\u00010\n8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b/\u00100R\u0016\u00101\u001a\u00020\r8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b1\u00102R\u0016\u00104\u001a\u0002038\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b4\u00105R\u0016\u00106\u001a\u00020\u001b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b6\u00107R\u0018\u00109\u001a\u0004\u0018\u0001088\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b9\u0010:R\u0018\u0010;\u001a\u0004\u0018\u00010\u00078\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b;\u0010<R\u0016\u0010>\u001a\u00020=8\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b>\u0010?R\u0018\u0010A\u001a\u0004\u0018\u00010@8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bA\u0010BR\u0018\u0010C\u001a\u0004\u0018\u00010\u00058\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bC\u0010D¨\u0006G"}, d2 = {"Lcom/dss/ups/sp51a/ble/manager/BleSdkManager;", "", "", "configureDevOps", "()V", "Landroid/content/Context;", "context", "Lg/i/a/c/a0/e;", "getDfuAdapter", "(Landroid/content/Context;)Lg/i/a/c/a0/e;", "Lg/i/a/c/q/f;", "getDfuConfig", "()Lg/i/a/c/q/f;", "", "initializeSdk", "(Landroid/content/Context;)Z", "sync", "initialize", "(Landroid/content/Context;Z)Z", "Landroid/bluetooth/BluetoothDevice;", "device", "connect", "(Landroid/bluetooth/BluetoothDevice;Z)Z", "getDeviceInfo", "releaseAdapter", "isHid", "connectRemoteDevice", "", "workMode", "changeWorkMode", "(I)V", "", "filePath", "startOtaProcess", "(Landroid/bluetooth/BluetoothDevice;Ljava/lang/String;)Ljava/lang/Boolean;", "mFilePath", "forceLoad", "checkBinInfo", "(Ljava/lang/String;Z)Z", "releaseSdkResource", "path", "Lcom/cvte/dss/ups/plugin/IUpsPlugin$IUpgradeStatusListener;", "listener", "startOta", "(Landroid/content/Context;Landroid/bluetooth/BluetoothDevice;Ljava/lang/String;Lcom/cvte/dss/ups/plugin/IUpsPlugin$IUpgradeStatusListener;)Z", "mListener", "Lcom/cvte/dss/ups/plugin/IUpsPlugin$IUpgradeStatusListener;", "mDfuConfig", "Lg/i/a/c/q/f;", "isDebug", "Z", "com/dss/ups/sp51a/ble/manager/BleSdkManager$mDfuHelperCallback$1", "mDfuHelperCallback", "Lcom/dss/ups/sp51a/ble/manager/BleSdkManager$mDfuHelperCallback$1;", "mProcessState", "I", "Lg/i/a/c/q/i;", "mOtaDeviceInfo", "Lg/i/a/c/q/i;", "mDfuAdapter", "Lg/i/a/c/a0/e;", "Lcom/dss/ups/sp51a/ble/manager/SdkLock;", "lock", "Lcom/dss/ups/sp51a/ble/manager/SdkLock;", "Lg/i/a/c/q/a;", "mBinInfo", "Lg/i/a/c/q/a;", "mContext", "Landroid/content/Context;", "<init>", "Companion", "lib_release"}, k = 1, mv = {1, 5, 1})
public final class BleSdkManager {
    private static final String TAG = "BleSdkManager";
    private a mBinInfo;
    private Context mContext;
    private e mDfuAdapter;
    private f mDfuConfig;
    private IUpsPlugin.IUpgradeStatusListener mListener;
    private i mOtaDeviceInfo;
    private int mProcessState;
    private boolean isDebug = true;
    private final SdkLock lock = new SdkLock();
    private final BleSdkManager$mDfuHelperCallback$1 mDfuHelperCallback = new c.b() { // from class: com.dss.ups.sp51a.ble.manager.BleSdkManager$mDfuHelperCallback$1
        @Override // g.i.a.c.a0.c.b
        public void onError(int type, int code) {
            super.onError(type, code);
            if (this.this$0.mContext == null || this.this$0.mListener == null) {
                return;
            }
            DfuHelperImpl dfuHelperImpl = DfuHelperImpl.INSTANCE;
            Context context = this.this$0.mContext;
            o.c(context);
            String error = dfuHelperImpl.parseError(context, type, code);
            StringBuilder sbI = g.a.a.a.a.I("onError: type:", type, ", code:", code, ", ");
            sbI.append(error);
            Log.e("BleSdkManager", sbI.toString());
            IUpsPlugin.IUpgradeStatusListener iUpgradeStatusListener = this.this$0.mListener;
            o.c(iUpgradeStatusListener);
            iUpgradeStatusListener.onFailed(error);
            this.this$0.releaseSdkResource();
        }

        @Override // g.i.a.c.a0.c.b
        public void onProcessStateChanged(int state, k throughput) {
            String strL;
            super.onProcessStateChanged(state, throughput);
            if (this.this$0.mContext == null) {
                throw new IllegalStateException("context is null");
            }
            this.this$0.mProcessState = state;
            if (state == 258) {
                Log.e("BleSdkManager", "onProcessStateChanged: PROGRESS_IMAGE_ACTIVE_SUCCESS, 固件激活成功");
                if (this.this$0.mListener != null) {
                    IUpsPlugin.IUpgradeStatusListener iUpgradeStatusListener = this.this$0.mListener;
                    o.c(iUpgradeStatusListener);
                    iUpgradeStatusListener.onComplete();
                }
                this.this$0.releaseSdkResource();
                return;
            }
            if (state == 260) {
                strL = "onProcessStateChanged: PROGRESS_PROCESSING_ERROR, 处理错误...";
            } else if (state == 523) {
                strL = "onProcessStateChanged: PROGRESS_PENDING_ACTIVE_IMAGE, 等待激活固件...";
            } else if (state != 524) {
                switch (state) {
                    case InvokeCmd.CMD_XBUG_SET_VMAN_SERVICE_LOG_LEVEL /* 513 */:
                        strL = "onProcessStateChanged: PROGRESS_INITIALIZE, 初始化...";
                        break;
                    case InvokeCmd.CMD_XBUG_GET_VMAN_SERVICE_LOG_LEVEL /* 514 */:
                        strL = "onProcessStateChanged: PROGRESS_STARTED, 启动中...";
                        break;
                    case InvokeCmd.CMD_XBUG_SET_XBUG_DUMP_CVTE_LOG /* 515 */:
                    case InvokeCmd.CMD_XBUG_GET_LOG_NODE_INFO /* 519 */:
                        strL = "onProcessStateChanged: PROGRESS_SCAN_REMOTE, 搜索设备...";
                        break;
                    case InvokeCmd.CMD_XBUG_VMAN_FUNTION_CHECK_TIMEOUT_BASE_SET /* 516 */:
                    case 520:
                        strL = "onProcessStateChanged: PROGRESS_CONNECT_REMOTE, 连接设备...";
                        break;
                    case InvokeCmd.CMD_XBUG_VMAN_FUNTION_CHECK_TIMEOUT_BASE_GET /* 517 */:
                        strL = "onProcessStateChanged: PROGRESS_PREPARE_OTA_ENVIRONMENT, 准备升级环境...";
                        break;
                    case InvokeCmd.CMD_XBUG_GET_VMAN_FUNTION_TIME_OUT_LIST /* 518 */:
                        strL = "onProcessStateChanged: PROGRESS_REMOTE_ENTER_OTA, 进入升级模式...";
                        break;
                    case 521:
                        strL = "onProcessStateChanged: PROGRESS_START_DFU_PROCESS, 正在升级...";
                        break;
                    default:
                        strL = o.l("onProcessStateChanged: other ", Integer.valueOf(state));
                        break;
                }
            } else {
                strL = "onProcessStateChanged: PROGRESS_ACTIVE_IMAGE_AND_RESET, 固件激活中...";
            }
            Log.e("BleSdkManager", strL);
        }

        @Override // g.i.a.c.a0.c.b
        public void onProgressChanged(g dfuProgressInfo) {
            super.onProgressChanged(dfuProgressInfo);
            if (this.this$0.mProcessState != 521 || dfuProgressInfo == null) {
                return;
            }
            StringBuilder sbF = g.a.a.a.a.F("onProgressChanged: ");
            sbF.append(dfuProgressInfo.f());
            sbF.append(", ");
            sbF.append(dfuProgressInfo.f5712n);
            Log.e("BleSdkManager", sbF.toString());
            if (this.this$0.mListener != null) {
                IUpsPlugin.IUpgradeStatusListener iUpgradeStatusListener = this.this$0.mListener;
                o.c(iUpgradeStatusListener);
                iUpgradeStatusListener.onProcess(dfuProgressInfo.f5712n);
            }
        }

        @Override // g.i.a.c.a0.c.b
        public void onStateChanged(int state) {
            super.onStateChanged(state);
            if (state == 257) {
                Log.e("BleSdkManager", "state STATE_INIT_BINDING_SERVICE");
            }
            if (state == 258) {
                Log.e("BleSdkManager", "state STATE_INIT_OK");
                this.this$0.lock.notifyInitialize(true);
            } else if (state == 527) {
                Log.e("BleSdkManager", "state STATE_PREPARED");
                this.this$0.lock.notifyConnect(true);
                this.this$0.getDeviceInfo();
            } else if (state == 4097 || state == 4098) {
                Log.e("BleSdkManager", "state STATE_DISCONNECTED|STATE_CONNECT_FAILED");
            }
        }
    };

    /* JADX INFO: renamed from: com.dss.ups.sp51a.ble.manager.BleSdkManager$initializeSdk$1, reason: invalid class name */
    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\u008a@¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Ls/a/b0;", "", "<anonymous>", "(Ls/a/b0;)Z"}, k = 3, mv = {1, 5, 1})
    @DebugMetadata(c = "com.dss.ups.sp51a.ble.manager.BleSdkManager$initializeSdk$1", f = "BleSdkManager.kt", l = {90}, m = "invokeSuspend")
    public static final class AnonymousClass1 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Boolean>, Object> {
        public final /* synthetic */ Context $context;
        public int label;

        /* JADX INFO: renamed from: com.dss.ups.sp51a.ble.manager.BleSdkManager$initializeSdk$1$1, reason: invalid class name and collision with other inner class name */
        @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\u008a@¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Ls/a/b0;", "", "<anonymous>", "(Ls/a/b0;)V"}, k = 3, mv = {1, 5, 1})
        @DebugMetadata(c = "com.dss.ups.sp51a.ble.manager.BleSdkManager$initializeSdk$1$1", f = "BleSdkManager.kt", l = {}, m = "invokeSuspend")
        public static final class C00091 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
            public final /* synthetic */ Context $context;
            public int label;
            public final /* synthetic */ BleSdkManager this$0;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            public C00091(BleSdkManager bleSdkManager, Context context, Continuation<? super C00091> continuation) {
                super(2, continuation);
                this.this$0 = bleSdkManager;
                this.$context = context;
            }

            @Override // kotlin.coroutines.j.internal.BaseContinuationImpl
            public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
                return new C00091(this.this$0, this.$context, continuation);
            }

            @Override // kotlin.jvm.functions.Function2
            public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
                return ((C00091) create(coroutineScope, continuation)).invokeSuspend(Unit.a);
            }

            @Override // kotlin.coroutines.j.internal.BaseContinuationImpl
            public final Object invokeSuspend(Object obj) throws Throwable {
                if (this.label != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                g.h.a.i.G3(obj);
                this.this$0.mDfuAdapter = e.p(this.$context.getApplicationContext());
                return Unit.a;
            }
        }

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass1(Context context, Continuation<? super AnonymousClass1> continuation) {
            super(2, continuation);
            this.$context = context;
        }

        @Override // kotlin.coroutines.j.internal.BaseContinuationImpl
        public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
            return BleSdkManager.this.new AnonymousClass1(this.$context, continuation);
        }

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Boolean> continuation) {
            return ((AnonymousClass1) create(coroutineScope, continuation)).invokeSuspend(Unit.a);
        }

        @Override // kotlin.coroutines.j.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            CoroutineSingletons coroutineSingletons = CoroutineSingletons.COROUTINE_SUSPENDED;
            int i2 = this.label;
            if (i2 == 0) {
                g.h.a.i.G3(obj);
                CoroutineDispatcher coroutineDispatcher = Dispatchers.a;
                MainCoroutineDispatcher mainCoroutineDispatcher = MainDispatcherLoader.f9355b;
                C00091 c00091 = new C00091(BleSdkManager.this, this.$context, null);
                this.label = 1;
                if (kotlin.reflect.w.internal.y0.n.c2.c.S0(mainCoroutineDispatcher, c00091, this) == coroutineSingletons) {
                    return coroutineSingletons;
                }
            } else {
                if (i2 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                g.h.a.i.G3(obj);
            }
            Log.e(BleSdkManager.TAG, "GattDfuAdapter.getInstance(context).initialize...");
            e eVar = BleSdkManager.this.mDfuAdapter;
            o.c(eVar);
            return Boolean.valueOf(eVar.j(BleSdkManager.this.mDfuHelperCallback));
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:25:0x0079, code lost:
    
        r8 = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x007a, code lost:
    
        if (r8 >= r6) goto L76;
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x007c, code lost:
    
        r7[r8 / 2] = (byte) ((java.lang.Character.digit(r0.charAt(r8), 16) << 4) + java.lang.Character.digit(r0.charAt(r8 + 1), 16));
     */
    /* JADX WARN: Code restructure failed: missing block: B:28:0x0097, code lost:
    
        r8 = r8 + 2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:29:0x009a, code lost:
    
        r5 = r7;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private final void configureDevOps() {
        /*
            Method dump skipped, instruction units count: 906
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.dss.ups.sp51a.ble.manager.BleSdkManager.configureDevOps():void");
    }

    public final void changeWorkMode(int workMode) {
        f dfuConfig = getDfuConfig();
        o.c(dfuConfig);
        dfuConfig.f5697n = workMode;
    }

    public final boolean checkBinInfo(String mFilePath, boolean forceLoad) {
        boolean zIsDfuVersionCheckEnabled;
        o.f(mFilePath, "mFilePath");
        Log.e(TAG, "checkBinInfo: " + mFilePath + ", " + forceLoad);
        if (TextUtils.isEmpty(mFilePath)) {
            this.mBinInfo = null;
            Log.e(TAG, o.l(mFilePath, " is not exist..."));
            return false;
        }
        if (this.mBinInfo == null || forceLoad) {
            try {
                c.b bVar = new c.b();
                bVar.a = this.mContext;
                f dfuConfig = getDfuConfig();
                o.c(dfuConfig);
                bVar.f5547p = dfuConfig.f5697n;
                bVar.f5534c = mFilePath;
                SettingsHelper.Companion companion = SettingsHelper.INSTANCE;
                SettingsHelper companion2 = companion.getInstance();
                o.c(companion2);
                bVar.f5535d = companion2.getFileSuffix();
                bVar.f5542k = this.mOtaDeviceInfo;
                SettingsHelper companion3 = companion.getInstance();
                o.c(companion3);
                bVar.f5545n = companion3.isDfuChipTypeCheckEnabled();
                SettingsHelper companion4 = companion.getInstance();
                o.c(companion4);
                bVar.f5546o = companion4.isDfuImageSectionSizeCheckEnabled();
                if (forceLoad) {
                    zIsDfuVersionCheckEnabled = false;
                } else {
                    SettingsHelper companion5 = companion.getInstance();
                    o.c(companion5);
                    zIsDfuVersionCheckEnabled = companion5.isDfuVersionCheckEnabled();
                }
                SettingsHelper companion6 = companion.getInstance();
                o.c(companion6);
                int dfuVersionCheckMode = companion6.getDfuVersionCheckMode();
                bVar.f5543l = zIsDfuVersionCheckEnabled;
                bVar.f5544m = dfuVersionCheckMode;
                this.mBinInfo = b.n(bVar.a());
            } catch (g.i.a.c.a e2) {
                DfuHelperImpl dfuHelperImpl = DfuHelperImpl.INSTANCE;
                Context context = this.mContext;
                o.c(context);
                Log.e(TAG, dfuHelperImpl.parseErrorCode(context, e2.f5446m));
                return false;
            }
        }
        a aVar = this.mBinInfo;
        if (aVar == null) {
            Log.e(TAG, "LoadFileException fail");
            return false;
        }
        int i2 = aVar.f5650h;
        if (i2 == 4096) {
            Log.e(TAG, o.l("LoadFileException SUCCESS: ", Integer.valueOf(i2)));
            a aVar2 = this.mBinInfo;
            if ((aVar2 == null ? null : aVar2.f5658p) != null) {
                o.c(aVar2);
                if (aVar2.f5658p.size() <= 0) {
                    this.mBinInfo = null;
                    Context context2 = this.mContext;
                    o.c(context2);
                    o.e(context2.getString(R.string.rtk_dfu_no_available_upload_file), "mContext!!.getString(R.string.rtk_dfu_no_available_upload_file)");
                    return false;
                }
            }
            f dfuConfig2 = getDfuConfig();
            o.c(dfuConfig2);
            dfuConfig2.f5701r = mFilePath;
            return true;
        }
        DfuHelperImpl dfuHelperImpl2 = DfuHelperImpl.INSTANCE;
        Context context3 = this.mContext;
        o.c(context3);
        a aVar3 = this.mBinInfo;
        o.c(aVar3);
        String binInfoError = dfuHelperImpl2.parseBinInfoError(context3, aVar3.f5650h);
        StringBuilder sbF = g.a.a.a.a.F("LoadFileException else: ");
        a aVar4 = this.mBinInfo;
        sbF.append(aVar4 == null ? null : Integer.valueOf(aVar4.f5650h));
        sbF.append(", ");
        sbF.append(binInfoError);
        Log.e(TAG, sbF.toString());
        this.mBinInfo = null;
        return false;
    }

    public final synchronized boolean connect(BluetoothDevice device, boolean sync) {
        o.f(device, "device");
        return sync ? SdkLock.waitForConnect$default(this.lock, this, device, 0L, 4, null) : connectRemoteDevice(device, false);
    }

    public final boolean connectRemoteDevice(BluetoothDevice device, boolean isHid) {
        boolean z2;
        boolean z3;
        boolean zL;
        BluetoothDevice bluetoothDeviceH;
        o.f(device, "device");
        Log.e(TAG, o.l("connectRemoteDevice(), ", device.getAddress()));
        UUID uuidFromString = UUID.fromString("0000d0ff-3c17-d293-8e48-14fe2e4da212");
        UUID uuidFromString2 = UUID.fromString("00006287-3c17-d293-8e48-14fe2e4da212");
        String address = device.getAddress();
        SettingsHelper.Companion companion = SettingsHelper.INSTANCE;
        SettingsHelper companion2 = companion.getInstance();
        o.c(companion2);
        int dfuMaxReconnectTimes = companion2.getDfuMaxReconnectTimes();
        SettingsHelper companion3 = companion.getInstance();
        o.c(companion3);
        String otaServiceUUID = companion3.getOtaServiceUUID();
        if (!TextUtils.isEmpty(otaServiceUUID)) {
            uuidFromString = UUID.fromString(otaServiceUUID);
        }
        e eVar = this.mDfuAdapter;
        o.c(eVar);
        g.i.a.c.a0.b bVar = new g.i.a.c.a0.b(address, false, null, false, dfuMaxReconnectTimes, uuidFromString, uuidFromString2, null, 2, false, 1, null);
        if (eVar.f5461o == null) {
            g.h.a.i.X3(eVar.f5458f, "dfu has not been initialized");
            eVar.i();
            z2 = false;
        } else {
            eVar.f5462p = bVar;
            eVar.f5463q = bVar.f5453d;
            StringBuilder sbF = g.a.a.a.a.F("mConnectParams:");
            sbF.append(eVar.f5462p.toString());
            g.h.a.i.U3(sbF.toString());
            z2 = true;
        }
        if (!z2) {
            z3 = false;
        } else if (eVar.f5462p.a == null) {
            g.h.a.i.W3("address is null");
            z3 = false;
        } else {
            z3 = true;
        }
        if (z3) {
            String str = eVar.B;
            if (str != null && !Objects.equals(str, eVar.f5462p.a)) {
                eVar.F.k(eVar.B, eVar.Q);
                eVar.F.a(eVar.B);
            }
            eVar.f5450z = eVar.h(eVar.f5462p.a);
            String str2 = eVar.f5462p.a;
            eVar.B = str2;
            int bondState = 10;
            if (eVar.f5447w != null && (bluetoothDeviceH = eVar.h(str2)) != null) {
                bondState = bluetoothDeviceH.getBondState();
            }
            eVar.A = bondState;
            g.h.a.i.V3(eVar.f5458f, String.format(Locale.US, ">> mBondState: %d", Integer.valueOf(bondState)));
            if (!eVar.f5462p.f5452c || !(zL = eVar.n(eVar.B))) {
                zL = eVar.l(eVar.B);
            }
            if (!zL) {
                eVar.e(4098);
            }
        } else {
            zL = false;
        }
        return zL;
    }

    /* JADX WARN: Removed duplicated region for block: B:53:0x0081  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x0086  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x00d7  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x00db  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void getDeviceInfo() {
        /*
            Method dump skipped, instruction units count: 244
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.dss.ups.sp51a.ble.manager.BleSdkManager.getDeviceInfo():void");
    }

    public final e getDfuAdapter(Context context) {
        o.f(context, "context");
        if (this.mDfuAdapter == null) {
            this.mDfuAdapter = e.p(context);
        }
        return this.mDfuAdapter;
    }

    public final f getDfuConfig() {
        if (this.mDfuConfig == null) {
            this.mDfuConfig = new f();
        }
        return this.mDfuConfig;
    }

    public final synchronized boolean initialize(Context context, boolean sync) {
        o.f(context, "context");
        return sync ? SdkLock.waitForInitialize$default(this.lock, context, this, 0L, 4, null) : initializeSdk(context);
    }

    public final boolean initializeSdk(Context context) throws Throwable {
        o.f(context, "context");
        Log.e(TAG, "RtkConfigure.Builder...");
        g.i.a.b.a aVar = new g.i.a.b.a(null);
        boolean z2 = this.isDebug;
        aVar.a = z2;
        aVar.f5302b = z2;
        aVar.f5303c = "SP51A_OTA";
        Log.e(TAG, "RtkCore.initialize...");
        synchronized (g.h.a.i.class) {
            if (g.h.a.i.a == null) {
                g.h.a.i.a = context.getApplicationContext();
            }
            g.h.a.i.f5270b = aVar.a;
            String str = aVar.f5303c;
            boolean z3 = aVar.f5302b;
            g.h.a.i.f5271c = str;
            g.h.a.i.f5272d = z3;
            g.h.a.i.f5273e = 1;
            g.h.a.i.w0(aVar.toString());
            if (g.i.a.b.e.c.f5337b == null) {
                g.i.a.b.e.c.h(g.h.a.i.a);
            }
            if (g.i.a.b.e.f.a.a.a == null) {
                g.i.a.b.e.f.a.a.a(g.h.a.i.a);
            }
            g.i.a.b.e.b.g(g.h.a.i.a);
            g.h.a.i.U3(String.format("%s:%s:%s", "com.realsil.sdk", "rtk-core", "1.2.8"));
            StringBuilder sb = new StringBuilder();
            sb.append("DeviceInfo{");
            sb.append("SDK_INT: " + Build.VERSION.SDK_INT);
            sb.append("\nDevice name: " + Build.DEVICE);
            sb.append("\nAndroid Version: " + Build.VERSION.RELEASE);
            sb.append("\nManufacture: " + Build.MANUFACTURER);
            sb.append("\nModel: " + Build.MODEL);
            sb.append("\nsupportedABIS: " + Arrays.toString(Build.SUPPORTED_ABIS));
            sb.append("}");
            g.h.a.i.w0(sb.toString());
        }
        Log.e(TAG, "RtkDfu.initialize...");
        g.i.a.c.b.a = this.isDebug;
        g.h.a.i.x0(true, String.format(Locale.US, "{\nLIBRARY_PACKAGE_NAME=%s\n%s:%s:%s\nDEBUG=%b\nBUILD_TYPE=%s\nDEBUG_ENABLE=%b\n}", "com.realsil.sdk.dfu", "com.realsil.sdk", "rtk-dfu", "3.4.1", Boolean.FALSE, "release", Boolean.valueOf(g.i.a.c.b.a)));
        if (g.i.a.b.e.c.f5337b == null) {
            g.i.a.b.e.c.h(context);
        }
        g.i.a.b.e.b.g(context);
        d.a(context);
        int i2 = g.i.a.c.l.e.a.f5561f;
        g.i.a.c.l.e.a.f5561f = 1;
        SettingsHelper.INSTANCE.initialize(context);
        Log.e(TAG, o.l("GattDfuAdapter.getInstance...", Thread.currentThread().getName()));
        kotlin.reflect.w.internal.y0.n.c2.c.y0(null, new AnonymousClass1(context, null), 1, null);
        return true;
    }

    public final void releaseAdapter() {
        List<g.i.a.b.e.a> list;
        Log.e(TAG, "releaseAdapter");
        e eVar = this.mDfuAdapter;
        if (eVar != null) {
            o.c(eVar);
            g.i.a.c.c0.a aVar = eVar.f5461o;
            if (aVar != null) {
                aVar.a();
            } else {
                g.h.a.i.W3("dfu has not been initialized");
                eVar.o();
            }
            e eVar2 = this.mDfuAdapter;
            o.c(eVar2);
            eVar2.f5464r = null;
            eVar2.a();
            g.h.a.i.V3(eVar2.f5458f, "destroy");
            eVar2.f5466t = 0;
            eVar2.f5462p = null;
            eVar2.f5463q = 0;
            Handler handler = eVar2.f5467u;
            if (handler != null) {
                handler.removeCallbacks(null);
            }
            eVar2.f5464r = null;
            g.i.a.c.c0.a aVar2 = eVar2.f5461o;
            if (aVar2 != null) {
                aVar2.f5474b = null;
                aVar2.a();
                aVar2.c();
            }
            eVar2.f5450z = null;
            eVar2.B = null;
            d dVar = eVar2.f5449y;
            if (dVar != null) {
                g.i.a.b.e.e eVar3 = eVar2.C;
                List<g.i.a.b.e.e> list2 = dVar.f5349d;
                if (list2 != null) {
                    list2.remove(eVar3);
                }
            }
            g.i.a.b.e.b bVar = eVar2.f5448x;
            if (bVar != null && (list = bVar.f5328c) != null) {
                list.remove((Object) null);
            }
            g.i.a.b.e.c cVar = eVar2.F;
            if (cVar != null) {
                cVar.k(eVar2.B, eVar2.Q);
            }
            g.i.a.c.p.a aVar3 = eVar2.K;
            if (aVar3 != null) {
                aVar3.a();
            }
            e.E = null;
        }
    }

    public final void releaseSdkResource() {
        Log.e(TAG, "releaseSdkResource");
        this.mOtaDeviceInfo = null;
        this.mBinInfo = null;
        this.mContext = null;
        if (this.mListener != null) {
            this.mListener = null;
        }
        releaseAdapter();
    }

    public final boolean startOta(Context context, BluetoothDevice device, String path, IUpsPlugin.IUpgradeStatusListener listener) {
        String str;
        o.f(context, "context");
        o.f(device, "device");
        o.f(path, "path");
        o.f(listener, "listener");
        this.mContext = context.getApplicationContext();
        this.mListener = listener;
        Log.e(TAG, "sdk initialize");
        if (initialize(context, true)) {
            String address = device.getAddress();
            o.e(address, "device.address");
            Log.e(TAG, o.l("sdk connect, ", address));
            if (connect(device, true)) {
                Log.e(TAG, o.l("check file: ", path));
                if (checkBinInfo(path, true)) {
                    Boolean boolStartOtaProcess = startOtaProcess(device, path);
                    o.c(boolStartOtaProcess);
                    if (boolStartOtaProcess.booleanValue()) {
                        return true;
                    }
                    str = "ota fail";
                } else {
                    str = "check file fail";
                }
            } else {
                str = "connect device fail";
            }
            Log.e(TAG, str);
            releaseSdkResource();
        } else {
            str = "initialize sdk fail";
            Log.e(TAG, "initialize sdk fail");
        }
        listener.onFailed(str);
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:81:0x0153  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x0195  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final java.lang.Boolean startOtaProcess(android.bluetooth.BluetoothDevice r8, java.lang.String r9) {
        /*
            Method dump skipped, instruction units count: 426
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.dss.ups.sp51a.ble.manager.BleSdkManager.startOtaProcess(android.bluetooth.BluetoothDevice, java.lang.String):java.lang.Boolean");
    }
}
