package g.i.a.b.e.h;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import g.h.a.i;
import g.i.a.b.f.a;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class c extends g.i.a.b.c.a {

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public g.i.a.b.f.b f5385o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public a.InterfaceC0076a f5386p = new a();

    public class a implements a.InterfaceC0076a {
        public a() {
        }
    }

    public c(Context context, e eVar, d dVar) {
        this.f5307b = context.getApplicationContext();
        this.f5310e = null;
        this.f5308c = eVar;
        this.f5309d = dVar;
        if (super.c()) {
            this.f5385o = new g.i.a.b.f.b(this.f5307b, Build.VERSION.SDK_INT);
        }
    }

    @Override // g.i.a.b.c.a
    public boolean d(BluetoothDevice bluetoothDevice) {
        int i2 = this.f5308c.f5387f;
        if (i2 == 18) {
            if (bluetoothDevice.getType() != 2) {
                return false;
            }
        } else if (i2 == 17 && bluetoothDevice.getType() != 2 && bluetoothDevice.getType() != 3 && bluetoothDevice.getType() != 0) {
            return false;
        }
        if (TextUtils.isEmpty(this.f5308c.f5389n)) {
            if (!this.f5308c.f5391p && TextUtils.isEmpty(bluetoothDevice.getName())) {
                return false;
            }
        } else if (!Objects.equals(this.f5308c.f5389n, bluetoothDevice.getName())) {
            if (!this.f5308c.f5390o) {
                if (this.a) {
                    i.U3(String.format("conflict name: %s", bluetoothDevice.getName()));
                }
                return false;
            }
            if (bluetoothDevice.getName() == null || !bluetoothDevice.getName().contains(this.f5308c.f5389n)) {
                if (this.a) {
                    i.U3(String.format("conflict name: %s", bluetoothDevice.getName()));
                }
                return false;
            }
        }
        return TextUtils.isEmpty(this.f5308c.f5392q) || Objects.equals(this.f5308c.f5392q, bluetoothDevice.getAddress());
    }

    @Override // g.i.a.b.c.a
    public boolean i() {
        h();
        g.i.a.b.f.b bVar = this.f5385o;
        synchronized (bVar) {
            g.i.a.b.f.a aVar = bVar.a;
            if (aVar != null) {
                aVar.f5439e = null;
            }
        }
        if (this.f5385o.a.f5437c) {
            i.V3(false, "stop the le scan");
            if (!this.f5385o.a(null, false)) {
                i.w0("scanLeDevice failed");
                return false;
            }
        }
        a(0);
        return true;
    }

    @Override // g.i.a.b.c.a
    public boolean k() {
        if (!g()) {
            return true;
        }
        StringBuilder sbF = g.a.a.a.a.F("start le scan for ");
        sbF.append(this.f5308c.f5394s);
        sbF.append("ms");
        i.U3(sbF.toString());
        g.i.a.b.f.b bVar = this.f5385o;
        a.InterfaceC0076a interfaceC0076a = this.f5386p;
        synchronized (bVar) {
            g.i.a.b.f.a aVar = bVar.a;
            if (aVar != null) {
                aVar.f5439e = interfaceC0076a;
            }
        }
        if (this.f5385o.a(this.f5308c, true)) {
            f();
            return true;
        }
        i.U3("scanLeDevice failed");
        l();
        return false;
    }

    @Override // g.i.a.b.c.a
    public boolean l() {
        this.f5318m = false;
        return i();
    }
}
