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

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.util.Log;
import io.netty.handler.codec.rtsp.RtspHeaders;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.Lambda;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes.dex */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000L\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\t\u0018\u0000 &2\u00020\u0001:\u0001&B\u0007¢\u0006\u0004\b$\u0010%J#\u0010\u0005\u001a\u00028\u0000\"\u0004\b\u0000\u0010\u00022\f\u0010\u0004\u001a\b\u0012\u0004\u0012\u00028\u00000\u0003H\u0002¢\u0006\u0004\b\u0005\u0010\u0006J'\u0010\u000e\u001a\u00020\r2\u0006\u0010\b\u001a\u00020\u00072\u0006\u0010\n\u001a\u00020\t2\b\b\u0002\u0010\f\u001a\u00020\u000b¢\u0006\u0004\b\u000e\u0010\u000fJ'\u0010\u0012\u001a\u00020\r2\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u0011\u001a\u00020\u00102\b\b\u0002\u0010\f\u001a\u00020\u000b¢\u0006\u0004\b\u0012\u0010\u0013J\u0015\u0010\u0016\u001a\u00020\u00152\u0006\u0010\u0014\u001a\u00020\r¢\u0006\u0004\b\u0016\u0010\u0017J\u0015\u0010\u0018\u001a\u00020\u00152\u0006\u0010\u0014\u001a\u00020\r¢\u0006\u0004\b\u0018\u0010\u0017R\u0016\u0010\u0019\u001a\u00020\r8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0019\u0010\u001aR\u0016\u0010\u001c\u001a\u00020\u001b8\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001c\u0010\u001dR\u001e\u0010 \u001a\n \u001f*\u0004\u0018\u00010\u001e0\u001e8\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b \u0010!R\u001e\u0010\"\u001a\n \u001f*\u0004\u0018\u00010\u001e0\u001e8\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\"\u0010!R\u0016\u0010#\u001a\u00020\r8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b#\u0010\u001a¨\u0006'"}, d2 = {"Lcom/dss/ups/sp51a/ble/manager/SdkLock;", "", "T", "Lkotlin/Function0;", "let", "safeLock", "(Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;", "Landroid/content/Context;", "context", "Lcom/dss/ups/sp51a/ble/manager/BleSdkManager;", "manager", "", RtspHeaders.Values.TIMEOUT, "", "waitForInitialize", "(Landroid/content/Context;Lcom/dss/ups/sp51a/ble/manager/BleSdkManager;J)Z", "Landroid/bluetooth/BluetoothDevice;", "device", "waitForConnect", "(Lcom/dss/ups/sp51a/ble/manager/BleSdkManager;Landroid/bluetooth/BluetoothDevice;J)Z", "result", "", "notifyInitialize", "(Z)V", "notifyConnect", "initResult", "Z", "Ljava/util/concurrent/locks/ReentrantLock;", "lock", "Ljava/util/concurrent/locks/ReentrantLock;", "Ljava/util/concurrent/locks/Condition;", "kotlin.jvm.PlatformType", "connectCondition", "Ljava/util/concurrent/locks/Condition;", "initCondition", "connectResult", "<init>", "()V", "Companion", "lib_release"}, k = 1, mv = {1, 5, 1})
public final class SdkLock {
    public static final String TAG = "SdkLock";
    private final Condition connectCondition;
    private boolean connectResult;
    private final Condition initCondition;
    private boolean initResult;
    private final ReentrantLock lock;

    /* JADX INFO: renamed from: com.dss.ups.sp51a.ble.manager.SdkLock$notifyConnect$1, reason: invalid class name */
    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\b\n\u0002\u0010\u0002\n\u0002\b\u0002\u0010\u0001\u001a\u00020\u0000H\n¢\u0006\u0004\b\u0001\u0010\u0002"}, d2 = {"", "<anonymous>", "()V"}, k = 3, mv = {1, 5, 1})
    public static final class AnonymousClass1 extends Lambda implements Function0<Unit> {
        public final /* synthetic */ boolean $result;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass1(boolean z2) {
            super(0);
            this.$result = z2;
        }

        @Override // kotlin.jvm.functions.Function0
        public /* bridge */ /* synthetic */ Unit invoke() {
            invoke2();
            return Unit.a;
        }

        /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
        public final void invoke2() {
            SdkLock.this.connectResult = this.$result;
            SdkLock.this.connectCondition.signalAll();
        }
    }

    /* JADX INFO: renamed from: com.dss.ups.sp51a.ble.manager.SdkLock$notifyInitialize$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\b\n\u0002\u0010\u0002\n\u0002\b\u0002\u0010\u0001\u001a\u00020\u0000H\n¢\u0006\u0004\b\u0001\u0010\u0002"}, d2 = {"", "<anonymous>", "()V"}, k = 3, mv = {1, 5, 1})
    public static final class C01951 extends Lambda implements Function0<Unit> {
        public final /* synthetic */ boolean $result;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C01951(boolean z2) {
            super(0);
            this.$result = z2;
        }

        @Override // kotlin.jvm.functions.Function0
        public /* bridge */ /* synthetic */ Unit invoke() {
            invoke2();
            return Unit.a;
        }

        /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
        public final void invoke2() {
            SdkLock.this.initResult = this.$result;
            SdkLock.this.initCondition.signalAll();
        }
    }

    /* JADX INFO: renamed from: com.dss.ups.sp51a.ble.manager.SdkLock$waitForConnect$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\b\n\u0002\u0010\u000b\n\u0002\b\u0002\u0010\u0001\u001a\u00020\u0000H\n¢\u0006\u0004\b\u0001\u0010\u0002"}, d2 = {"", "<anonymous>", "()Z"}, k = 3, mv = {1, 5, 1})
    public static final class C01961 extends Lambda implements Function0<Boolean> {
        public final /* synthetic */ BluetoothDevice $device;
        public final /* synthetic */ BleSdkManager $manager;
        public final /* synthetic */ long $timeout;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C01961(BleSdkManager bleSdkManager, BluetoothDevice bluetoothDevice, long j2) {
            super(0);
            this.$manager = bleSdkManager;
            this.$device = bluetoothDevice;
            this.$timeout = j2;
        }

        @Override // kotlin.jvm.functions.Function0
        public /* bridge */ /* synthetic */ Boolean invoke() {
            return Boolean.valueOf(invoke2());
        }

        /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
        public final boolean invoke2() throws InterruptedException {
            SdkLock.this.connectResult = false;
            Log.d(SdkLock.TAG, "waitForConnect");
            if (this.$manager.connectRemoteDevice(this.$device, false)) {
                SdkLock.this.connectCondition.await(this.$timeout, TimeUnit.MILLISECONDS);
            } else {
                Log.e(SdkLock.TAG, "connect Remote Device failed");
            }
            boolean z2 = SdkLock.this.connectResult;
            Log.d(SdkLock.TAG, o.l("waitForConnect result: ", Boolean.valueOf(z2)));
            return z2;
        }
    }

    /* JADX INFO: renamed from: com.dss.ups.sp51a.ble.manager.SdkLock$waitForInitialize$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\b\n\u0002\u0010\u000b\n\u0002\b\u0002\u0010\u0001\u001a\u00020\u0000H\n¢\u0006\u0004\b\u0001\u0010\u0002"}, d2 = {"", "<anonymous>", "()Z"}, k = 3, mv = {1, 5, 1})
    public static final class C01971 extends Lambda implements Function0<Boolean> {
        public final /* synthetic */ Context $context;
        public final /* synthetic */ BleSdkManager $manager;
        public final /* synthetic */ long $timeout;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C01971(BleSdkManager bleSdkManager, Context context, long j2) {
            super(0);
            this.$manager = bleSdkManager;
            this.$context = context;
            this.$timeout = j2;
        }

        @Override // kotlin.jvm.functions.Function0
        public /* bridge */ /* synthetic */ Boolean invoke() {
            return Boolean.valueOf(invoke2());
        }

        /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
        public final boolean invoke2() throws InterruptedException {
            SdkLock.this.initResult = false;
            Log.d(SdkLock.TAG, "waitForInitialize");
            if (this.$manager.initializeSdk(this.$context)) {
                SdkLock.this.initCondition.await(this.$timeout, TimeUnit.MILLISECONDS);
            } else {
                Log.e(SdkLock.TAG, "initialize failed");
            }
            boolean z2 = SdkLock.this.initResult;
            Log.d(SdkLock.TAG, o.l("waitForInitialize result: ", Boolean.valueOf(z2)));
            return z2;
        }
    }

    public SdkLock() {
        ReentrantLock reentrantLock = new ReentrantLock();
        this.lock = reentrantLock;
        this.connectCondition = reentrantLock.newCondition();
        this.initCondition = reentrantLock.newCondition();
    }

    private final <T> T safeLock(Function0<? extends T> let) {
        try {
            this.lock.lock();
            return let.invoke();
        } finally {
            this.lock.unlock();
        }
    }

    public static /* synthetic */ boolean waitForConnect$default(SdkLock sdkLock, BleSdkManager bleSdkManager, BluetoothDevice bluetoothDevice, long j2, int i2, Object obj) {
        if ((i2 & 4) != 0) {
            j2 = 10000;
        }
        return sdkLock.waitForConnect(bleSdkManager, bluetoothDevice, j2);
    }

    public static /* synthetic */ boolean waitForInitialize$default(SdkLock sdkLock, Context context, BleSdkManager bleSdkManager, long j2, int i2, Object obj) {
        if ((i2 & 4) != 0) {
            j2 = 10000;
        }
        return sdkLock.waitForInitialize(context, bleSdkManager, j2);
    }

    public final void notifyConnect(boolean result) {
        safeLock(new AnonymousClass1(result));
    }

    public final void notifyInitialize(boolean result) {
        safeLock(new C01951(result));
    }

    public final boolean waitForConnect(BleSdkManager manager, BluetoothDevice device, long timeout) {
        o.f(manager, "manager");
        o.f(device, "device");
        return ((Boolean) safeLock(new C01961(manager, device, timeout))).booleanValue();
    }

    public final boolean waitForInitialize(Context context, BleSdkManager manager, long timeout) {
        o.f(context, "context");
        o.f(manager, "manager");
        return ((Boolean) safeLock(new C01971(manager, context, timeout))).booleanValue();
    }
}
