package com.ifpdos.factorytest;

import android.util.Log;
import com.ifpdos.factorytest.ConfigParser;
import com.seewo.vcommons.utils.ShellCommandUtils;
import java.io.FileWriter;

/* JADX INFO: loaded from: classes.dex */
public class TestResultParser {
    static boolean mBtMacFailed = false;
    static boolean mWifiMacFailed = false;

    private static class TestResultMap {
        ConfigParser.IDS mId;
        String mName;

        public TestResultMap(String str, ConfigParser.IDS ids) {
            this.mName = str;
            this.mId = ids;
        }
    }

    static void parseTestResults(TestItem[] testItemArr, String str) {
        if (str == null) {
            return;
        }
        mWifiMacFailed = false;
        mBtMacFailed = false;
        for (String str2 : str.replace(ShellCommandUtils.COMMAND_LINE_END, "").replace("\r", "").split(";")) {
            parseOneResult(testItemArr, str2);
        }
    }

    static void parseOneResult(TestItem[] testItemArr, String str) {
        for (int i = 0; i < testItemArr.length; i++) {
            try {
                String strName = testItemArr[i].mId.name();
                if (str.startsWith(strName + "=")) {
                    String strSubstring = str.substring(strName.length() + 1);
                    if (strSubstring.equals("pass")) {
                        setTestItemStatusById(testItemArr, testItemArr[i].mId, true);
                    } else if (strSubstring.equals("fail")) {
                        setTestItemStatusById(testItemArr, testItemArr[i].mId, false);
                    }
                }
            } catch (Exception e) {
                Log.e("Roger", "e=" + e);
                return;
            }
        }
    }

    static void setTestItemStatusById(TestItem[] testItemArr, ConfigParser.IDS ids, boolean z) {
        if (ids == ConfigParser.IDS.WIFI && mWifiMacFailed) {
            z = false;
        }
        if (ids == ConfigParser.IDS.BLUETOOTH && mBtMacFailed) {
            z = false;
        }
        for (int i = 0; i < testItemArr.length; i++) {
            if (testItemArr[i].mId == ids) {
                TestItem testItem = testItemArr[i];
                testItem.testDone(z, testItem.mTagDone);
            }
        }
    }

    static String loadTestResult(int i, String str) {
        return Common.textFileReader(str + "cvte_factory_test_result_mode_" + i + ".ini");
    }

    static void saveTestResult(int i, TestItem[] testItemArr, String str) {
        String str2;
        if (i == 3) {
            i = 0;
        }
        try {
            FileWriter fileWriter = new FileWriter(str + "cvte_factory_test_result_mode_" + i + ".ini");
            for (int i2 = 0; i2 < testItemArr.length; i2++) {
                if (testItemArr[i2].mTested) {
                    String str3 = testItemArr[i2].mId.name() + "=";
                    if (testItemArr[i2].mResult) {
                        str2 = str3 + "pass;\n";
                    } else {
                        str2 = str3 + "fail;\n";
                    }
                    try {
                        fileWriter.write(str2, 0, str2.length());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            try {
                fileWriter.flush();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        } catch (Exception e3) {
            e3.printStackTrace();
        }
    }
}
