package com.ifpdos.factorytest.auto;

import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.util.Log;
import com.cvte.vman.VmanMiddleWare;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import com.ifpdos.factorytest.App;
import com.ifpdos.factorytest.R;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class WifiTestTask extends TestTask {
    private static final String TAG = "WifiTestTask";

    @Override // com.ifpdos.factorytest.auto.TestTask
    public boolean startTest() {
        boolean zFindWifiUsb;
        try {
            zFindWifiUsb = findWifiUsb();
        } catch (Throwable th) {
            Log.d(TAG, "findWifiUsb error", th);
            zFindWifiUsb = false;
        }
        if (zFindWifiUsb || findPcieWifi()) {
            setTestResult(TestTaskStatusEnum.PASS);
            return true;
        }
        setTestResult(TestTaskStatusEnum.FAIL);
        return false;
    }

    private static class ListWifiUsbConfig {
        List<WifiUsbConfig> wifi;

        private ListWifiUsbConfig() {
        }
    }

    private static class WifiUsbConfig {
        String description;
        String pid;
        boolean support;
        String vid;

        private WifiUsbConfig() {
        }

        public String getPid() {
            return this.pid;
        }

        public void setPid(String str) {
            this.pid = str;
        }

        public String getVid() {
            return this.vid;
        }

        public void setVid(String str) {
            this.vid = str;
        }

        public boolean isSupport() {
            return this.support;
        }

        public void setSupport(boolean z) {
            this.support = z;
        }

        public String getDescription() {
            return this.description;
        }

        public void setDescription(String str) {
            this.description = str;
        }

        public String toString() {
            return "WifiUsbConfig{pid='" + this.pid + "', vid='" + this.vid + "', support=" + this.support + ", description='" + this.description + "'}";
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r2v1, types: [boolean] */
    /* JADX WARN: Type inference failed for: r2v2, types: [java.io.Closeable] */
    /* JADX WARN: Type inference failed for: r2v3 */
    /* JADX WARN: Type inference failed for: r2v4 */
    /* JADX WARN: Type inference failed for: r2v5, types: [java.io.Closeable] */
    /* JADX WARN: Type inference failed for: r2v6, types: [java.io.Closeable, java.io.FileInputStream, java.io.InputStream] */
    /* JADX WARN: Type inference failed for: r3v0 */
    /* JADX WARN: Type inference failed for: r3v1 */
    /* JADX WARN: Type inference failed for: r3v2, types: [java.io.Closeable] */
    /* JADX WARN: Type inference failed for: r3v3 */
    /* JADX WARN: Type inference failed for: r7v0, types: [com.ifpdos.factorytest.auto.WifiTestTask] */
    private ListWifiUsbConfig getConfig() throws Throwable {
        InputStreamReader inputStreamReader;
        File file = new File("/system/etc/module_config.json");
        ?? Exists = file.exists();
        ?? r3 = 0;
        r3 = 0;
        try {
            if (Exists == 0) {
                return null;
            }
            try {
                Exists = new FileInputStream(file);
                try {
                    inputStreamReader = new InputStreamReader(Exists);
                    try {
                        ListWifiUsbConfig listWifiUsbConfig = (ListWifiUsbConfig) new Gson().fromJson(new JsonParser().parse(inputStreamReader), ListWifiUsbConfig.class);
                        safeClose(inputStreamReader);
                        safeClose(Exists);
                        return listWifiUsbConfig;
                    } catch (Exception e) {
                        e = e;
                        Log.d(TAG, "读取配置文件出错：" + e.getMessage());
                        safeClose(inputStreamReader);
                        safeClose(Exists);
                        return null;
                    }
                } catch (Exception e2) {
                    e = e2;
                    inputStreamReader = null;
                } catch (Throwable th) {
                    th = th;
                    safeClose(r3);
                    safeClose(Exists);
                    throw th;
                }
            } catch (Exception e3) {
                e = e3;
                inputStreamReader = null;
                Exists = 0;
            } catch (Throwable th2) {
                th = th2;
                Exists = 0;
            }
        } catch (Throwable th3) {
            th = th3;
            r3 = file;
        }
    }

    private boolean findWifiUsb() {
        for (UsbDevice usbDevice : ((UsbManager) App.getInstance().getSystemService("usb")).getDeviceList().values()) {
            if (isWifiUsbDevice(usbDevice.getProductId(), usbDevice.getVendorId())) {
                return true;
            }
        }
        return false;
    }

    private boolean findPcieWifi() {
        try {
            return VmanMiddleWare.getInstance().getNetworkCtrl().getWifiDongleStatus();
        } catch (Exception e) {
            Log.e(TAG, "findPcieWifi: error", e);
            return false;
        }
    }

    private boolean isWifiUsbDevice(int i, int i2) {
        for (WifiUsbConfig wifiUsbConfig : ((ListWifiUsbConfig) Objects.requireNonNull(getConfig())).wifi) {
            int iIntValue = Integer.valueOf(wifiUsbConfig.pid.replaceFirst("0x", ""), 16).intValue();
            int iIntValue2 = Integer.valueOf(wifiUsbConfig.vid.replaceFirst("0x", ""), 16).intValue();
            if (wifiUsbConfig.support && iIntValue == i && iIntValue2 == i2) {
                return true;
            }
        }
        return false;
    }

    private void safeClose(Closeable closeable) {
        if (closeable == null) {
            return;
        }
        try {
            closeable.close();
        } catch (IOException unused) {
        }
    }

    @Override // com.ifpdos.factorytest.auto.TestTask
    public String getTestName(Context context) {
        return context.getString(R.string.str_wireless_network_card);
    }
}
