package c0;

import com.vacenter.Taurus.Controller;
import com.vacenter.Taurus.Device;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import u.g;

/* JADX INFO: loaded from: classes2.dex */
public class e {
    public static e a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public List<Device> f965b = new ArrayList();

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

    public static e g() {
        if (a == null) {
            a = new e();
        }
        return a;
    }

    public int a(Device device) {
        g.a("TaurusMicrophoneController", String.format("ability_type:%d name:%s address:%s%n", Integer.valueOf(device.info.abilityType), device.info.name, device.address));
        Iterator<Device> it = this.f965b.iterator();
        while (it.hasNext()) {
            if (d(it.next(), device)) {
                g.a("TaurusMicrophoneController", "Device already exists");
                return -1;
            }
        }
        this.f965b.add(device);
        return 0;
    }

    public String b(String str) {
        String str2;
        String strT;
        if (str != null && !str.isEmpty()) {
            for (Device device : this.f965b) {
                if (device.info.name.startsWith(str)) {
                    StringBuilder sbF = g.a.a.a.a.F("findDeviceAddressByName: dev.address=");
                    sbF.append(device.address);
                    g.a("TaurusMicrophoneController", sbF.toString());
                    str2 = device.address;
                    break;
                }
            }
        } else {
            g.a("TaurusMicrophoneController", "Name is null or empty");
        }
        str2 = "";
        if (str2.isEmpty()) {
            strT = g.a.a.a.a.t("Can't find device: ", str);
        } else if (e() == null) {
            strT = "mController is null";
        } else {
            if (i(str2)) {
                return str2;
            }
            strT = "Can't find device by address";
        }
        g.a("TaurusMicrophoneController", strT);
        return "";
    }

    public String c(String str, String str2) {
        String strB = b(str);
        if (!u.b.b().d(strB)) {
            return this.f966c.sendCustomerString(strB, str2);
        }
        g.a("TaurusMicrophoneController", "Can't find device: " + str);
        return "";
    }

    public boolean d(Device device, Device device2) {
        return device.uuid.equals(device2.uuid) && device.address.equals(device2.address) && device.version.equals(device2.version) && device.info.name.equals(device2.info.name);
    }

    public Controller e() {
        if (this.f966c == null) {
            g.a("TaurusMicrophoneController", "[init]mController is null. start to init gController.");
            this.f966c = b.d().c();
        }
        return this.f966c;
    }

    public boolean f(String str, String str2) {
        String strT = g.a.a.a.a.t("MTR_MODE=", str2);
        g.a("TaurusMicrophoneController", "setByodMode: request_str=" + strT);
        return c(str, strT) != null;
    }

    public String h(String str) {
        g.a("TaurusMicrophoneController", "getVersion: ");
        String strB = b(str);
        if (u.b.b().d(strB)) {
            g.a.a.a.a.h0("[getVersion]can't find device:", str, "TaurusMicrophoneController");
            return "";
        }
        Controller.DeviceConfiguration deviceConfiguration = e().getDeviceConfiguration(strB);
        if (deviceConfiguration == null) {
            g.a("TaurusMicrophoneController", "getVersion: Can't get microphone version.");
            return "";
        }
        StringBuilder sbF = g.a.a.a.a.F("getVersion: version=");
        sbF.append(deviceConfiguration.version);
        g.a("TaurusMicrophoneController", sbF.toString());
        return deviceConfiguration.version;
    }

    public boolean i(String str) {
        g.a("TaurusMicrophoneController", "isDeviceExist: address:" + str);
        if (str == null || str.isEmpty()) {
            g.a("TaurusMicrophoneController", "Address is null or empty");
            return false;
        }
        for (Device device : this.f965b) {
            StringBuilder sbF = g.a.a.a.a.F("isDeviceExist: dev:");
            sbF.append(device.address);
            sbF.append(", dev.address.equals(address)");
            sbF.append(device.address.split(":")[0].equals(str.split(":")[0]));
            g.a("TaurusMicrophoneController", sbF.toString());
            if (device.address.split(":")[0].equals(str.split(":")[0])) {
                return true;
            }
        }
        return false;
    }
}
