package d.f.a.r2;

import android.text.TextUtils;
import android.util.Log;
import com.cvte.vman.VmanMiddleWare;
import com.cvte.vman.impl.AtCfgControlManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

/* JADX INFO: compiled from: USBAutoWriteConfig.java */
/* JADX INFO: loaded from: classes.dex */
public class e3 {
    public static volatile Boolean a = Boolean.TRUE;

    public static Boolean a() {
        byte[] mac = VmanMiddleWare.getInstance().getAtCfgControl().getMac();
        if (mac.length < 6) {
            return Boolean.FALSE;
        }
        String str = String.format("%02X:%02X:%02X:%02X:%02X:%02X", Byte.valueOf(mac[0]), Byte.valueOf(mac[1]), Byte.valueOf(mac[2]), Byte.valueOf(mac[3]), Byte.valueOf(mac[4]), Byte.valueOf(mac[5]));
        if (TextUtils.isEmpty(str)) {
            Log.d("USBAutoWriteConfig", "mac 为空");
            return Boolean.FALSE;
        }
        String upperCase = str.toUpperCase(Locale.ENGLISH);
        if ("FF:FF:FF:FF:FF:F0".equals(upperCase)) {
            Log.d("USBAutoWriteConfig", "mac 未烧录");
            return Boolean.FALSE;
        }
        if ("FF:FF:FF:FF:FF:F1".equals(upperCase)) {
            Log.d("USBAutoWriteConfig", "mac 烧录长度错误");
            return Boolean.FALSE;
        }
        if ("FF:FF:FF:FF:FF:F3".equals(upperCase)) {
            Log.d("USBAutoWriteConfig", "mac 烧录失败");
            return Boolean.FALSE;
        }
        if ("00:00:00:00:00:00".equals(upperCase)) {
            Log.d("USBAutoWriteConfig", "mac 地址为全0");
            return Boolean.FALSE;
        }
        if (upperCase.length() != 17) {
            Log.d("USBAutoWriteConfig", "mac 长度不为17");
            return Boolean.FALSE;
        }
        if (upperCase.split(":").length == 6) {
            return Boolean.TRUE;
        }
        Log.d("USBAutoWriteConfig", "mac 格式错误");
        return Boolean.FALSE;
    }

    public static Boolean b() {
        String string = VmanMiddleWare.getInstance().getAtCfgControl().getString(AtCfgControlManager.IDX_MACHINE_SN);
        return Boolean.valueOf(!(TextUtils.isEmpty(string) || "".equals(string.trim())));
    }

    public static void c() throws IOException {
        String strQ = u2.q("/MAC/", "MAC.*\\.bin");
        if (TextUtils.isEmpty(strQ) || "".equals(strQ.trim())) {
            Log.i("USBAutoWriteConfig", "mac config path: null");
            return;
        }
        Log.i("USBAutoWriteConfig", "mac config path:" + strQ);
        File file = new File(strQ);
        FileInputStream fileInputStream = new FileInputStream(file);
        byte[] bArr = new byte[fileInputStream.available()];
        fileInputStream.read(bArr);
        fileInputStream.close();
        Log.i("USBAutoWriteConfig", "upgradeMac string: " + String.format("%02X:%02X:%02X:%02X:%02X:%02X", Byte.valueOf(bArr[0]), Byte.valueOf(bArr[1]), Byte.valueOf(bArr[2]), Byte.valueOf(bArr[3]), Byte.valueOf(bArr[4]), Byte.valueOf(bArr[5])));
        if (VmanMiddleWare.getInstance().getAtCfgControl().setMac(bArr)) {
            file.delete();
            Log.d("USBAutoWriteConfig", "set mac success, delete " + strQ);
        }
    }

    public static void d() throws IOException {
        String strQ = u2.q("/SN/", "SN.*\\.bin");
        if (TextUtils.isEmpty(strQ) || "".equals(strQ.trim())) {
            Log.i("USBAutoWriteConfig", "sn config path: null");
            return;
        }
        Log.i("USBAutoWriteConfig", "sn config path:" + strQ);
        File file = new File(strQ);
        FileInputStream fileInputStream = new FileInputStream(file);
        byte[] bArr = new byte[fileInputStream.available()];
        fileInputStream.read(bArr);
        fileInputStream.close();
        String str = new String(bArr, StandardCharsets.UTF_8);
        Log.i("USBAutoWriteConfig", "upgradeSn bytes string:" + str);
        if (VmanMiddleWare.getInstance().getAtCfgControl().setString(AtCfgControlManager.IDX_MACHINE_SN, str)) {
            file.delete();
            Log.d("USBAutoWriteConfig", "set sn success, delete " + strQ);
        }
    }
}
