package com.ifpdos.autotest.lancontrol.module.other.e;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import com.cvte.vman.VmanMiddleWare;
import com.ifpdos.autotest.api.IUtils;
import com.ifpdos.autotest.h0;
import com.ifpdos.autotest.l0.a;
import com.seewo.sdk.model.SDKSourceModel;
import com.seewo.vtv.interfaces.ISleepHelper;
import com.seewo.vtv.interfaces.ISourceHelper;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/* JADX INFO: compiled from: Utils3588Impl.java */
/* JADX INFO: loaded from: classes.dex */
public class r implements IUtils, a.b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private Context f2112a;

    /* JADX INFO: compiled from: Utils3588Impl.java */
    static /* synthetic */ class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        static final /* synthetic */ int[] f2113a;

        static {
            int[] iArr = new int[ISourceHelper.SourceItem.values().length];
            f2113a = iArr;
            try {
                iArr[ISourceHelper.SourceItem.HDMI1.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f2113a[ISourceHelper.SourceItem.HDMI2.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f2113a[ISourceHelper.SourceItem.HDMI3.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                f2113a[ISourceHelper.SourceItem.HDMI4.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f2113a[ISourceHelper.SourceItem.ANDROID.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                f2113a[ISourceHelper.SourceItem.PC.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                f2113a[ISourceHelper.SourceItem.TYPE_C1.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                f2113a[ISourceHelper.SourceItem.TYPE_C2.ordinal()] = 8;
            } catch (NoSuchFieldError unused8) {
            }
        }
    }

    public r(Context context) {
        this.f2112a = context;
        com.ifpdos.autotest.l0.a.d().c(this.f2112a);
        com.ifpdos.autotest.l0.a.d().e(this);
    }

    private String b() {
        String modelName;
        if (com.ifpdos.autotest.k0.g.d.a()) {
            try {
                modelName = VmanMiddleWare.getInstance().getDevcieCtrl().getModelName();
            } catch (Exception e2) {
                Log.e("Utils3588Impl", "invoke vman getModelName error", e2);
                modelName = "";
            }
        } else {
            modelName = "";
        }
        if (TextUtils.isEmpty(modelName)) {
            return com.seewo.vcommons.data.d.a();
        }
        Log.d("Utils3588Impl", "getProductModel from vman: " + modelName);
        return modelName;
    }

    private boolean c() {
        int i = b.c.e.a.b.f1524a;
        return i == 11 || i == 12 || (i == 9 && Build.VERSION.SDK_INT > 33);
    }

    @Override // com.ifpdos.autotest.l0.a.b
    public void a(boolean z) {
        List<com.ifpdos.autotest.l0.b> listB = com.ifpdos.autotest.l0.a.d().b();
        for (int i = 0; i < listB.size(); i++) {
            b.c.c.l.b.d("Utils3588Impl", "problemCode=" + String.format(listB.get(i).a(), new Object[0]) + "\n");
        }
        if (!z) {
            b.c.c.l.b.d("Utils3588Impl", "Hardware Test End Fail");
            SystemProperties.set("persist.sys.hardware.test.result", "false");
            return;
        }
        b.c.c.l.b.d("Utils3588Impl", "Hardware Test End Succeed");
        if (listB.isEmpty()) {
            SystemProperties.set("persist.sys.hardware.test.result", "true");
        } else {
            SystemProperties.set("persist.sys.hardware.test.result", "false");
        }
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean changeSource(ISourceHelper.SourceItem sourceItem) {
        h0.l().o();
        boolean z = false;
        switch (a.f2113a[sourceItem.ordinal()]) {
            case 1:
                b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.HDMI1);
                break;
            case 2:
                b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.HDMI2);
                break;
            case 3:
                b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.HDMI3);
                break;
            case 4:
                b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.HDMI4);
                break;
            case 5:
                Iterator<SDKSourceModel> it = b.c.c.h.f1453a.d().iterator();
                while (true) {
                    if (it.hasNext()) {
                        if (it.next().sourceItem == com.seewo.sdk.interfaces.k.ANDROID) {
                            z = true;
                        }
                    }
                }
                Log.i("Utils3588Impl", "changeSource: sourceExist = " + z);
                if (!z) {
                    b.c.c.h hVar = b.c.c.h.f1453a;
                    com.seewo.sdk.interfaces.k kVarF = hVar.f();
                    Log.i("Utils3588Impl", "changeSource: mainSource = " + kVarF.name());
                    hVar.a(kVarF);
                } else {
                    b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.ANDROID);
                }
                break;
            case 6:
                b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.PC);
                break;
            case 7:
                b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.TYPE_C1);
                break;
            case 8:
                b.c.c.h.f1453a.a(com.seewo.sdk.interfaces.k.TYPE_C2);
                break;
            default:
                return false;
        }
        b.c.a.a.b.a(1000L);
        return true;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean changeSourceExt(ISourceHelper.SourceItem sourceItem, long j) {
        return changeSource(sourceItem);
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public void enterFactoryAutoTestMode() {
        b.c.c.l.b.d("Utils3588Impl", "enter Factory Auto Test Mode");
        this.f2112a.sendBroadcast(new Intent("com.ifpdos.autotest.start"));
        b.c.c.d.f1449a.c(59940);
        SystemProperties.set("persist.sys.factory.auto.test.mode", "1");
        SystemProperties.set("sys.factory.auto.test.mode", "1");
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public void exitFactoryAutoTestMode() {
        b.c.c.l.b.d("Utils3588Impl", "exit Factory Auto Test Mode");
        this.f2112a.sendBroadcast(new Intent("com.ifpdos.autotest.end"));
        b.c.c.d.f1449a.c(ISleepHelper.NORMAL_NO_SIGNAL_TIME);
        SystemProperties.set("persist.sys.factory.auto.test.mode", "0");
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public String getBoardType() {
        String strC = b.c.d.d.b.n() ? com.seewo.vcommons.data.d.c() : com.seewo.vcommons.data.d.b();
        return strC == null ? "" : strC;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public int getCurrentLuxSensorValue() {
        return b.c.c.e.f1450a.a();
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean getHardwareTestResult() {
        return SystemProperties.get("persist.sys.hardware.test.result", "false").equals("true");
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public String getMac() {
        return b.c.c.f.f1451a.c();
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public String getMcuPVersion() {
        return b.c.c.j.f1455a.a();
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public String getOriginalProductModel() {
        this.f2112a.sendBroadcast(new Intent("com.ifpdos.autotest.start"));
        com.ifpdos.autotest.k0.d.b.f(false);
        if (c()) {
            Log.i("Utils3588Impl", "reset white balance result = " + VmanMiddleWare.getInstance().getPQCtrl().resetWhiteBalance());
        }
        return b();
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public List<String> getProblemCodeList() {
        ArrayList arrayList = new ArrayList();
        List<com.ifpdos.autotest.l0.b> listB = com.ifpdos.autotest.l0.a.d().b();
        for (int i = 0; i < listB.size(); i++) {
            arrayList.add(String.format(listB.get(i).a(), new Object[0]));
        }
        return arrayList;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public String getRouterVersion() {
        try {
            FutureTask futureTask = new FutureTask(new Callable() { // from class: com.ifpdos.autotest.lancontrol.module.other.e.d
                @Override // java.util.concurrent.Callable
                public final Object call() {
                    return b.c.c.j.f1455a.b();
                }
            });
            new Thread(futureTask).start();
            return ((String) futureTask.get()).trim();
        } catch (Exception e2) {
            e2.printStackTrace();
            return "";
        }
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public long getSystemUpTime() {
        return SystemClock.uptimeMillis() / 1000;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public int getTransferMode() {
        return 2;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public String getVendorProductModel() {
        this.f2112a.sendBroadcast(new Intent("com.ifpdos.autotest.start"));
        com.ifpdos.autotest.k0.d.b.f(false);
        return SystemProperties.get("ro.product.vendor.model", "");
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean muteAisleSound() {
        try {
            Runtime.getRuntime().exec("tinymix 0 0");
            return true;
        } catch (IOException e2) {
            e2.printStackTrace();
            return true;
        }
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public void sendBackKey() {
        b.c.c.i.f1454a.a(4);
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean startAndroidNetworkTest(String str) throws InterruptedException {
        String line;
        String str2 = "ping -c 1 -W 1 " + str;
        b.c.c.l.b.d("Utils3588Impl", "command=" + str2);
        Process processExec = null;
        int iWaitFor = -1;
        try {
            processExec = Runtime.getRuntime().exec(str2);
            try {
                iWaitFor = processExec.waitFor();
            } catch (InterruptedException e2) {
                e2.printStackTrace();
            }
        } catch (IOException e3) {
            e3.printStackTrace();
        }
        if (iWaitFor == 0) {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(processExec.getInputStream()));
            do {
                try {
                    line = bufferedReader.readLine();
                    if (line != null) {
                        b.c.c.l.b.d("Utils3588Impl", "str=" + line);
                    }
                } catch (IOException e4) {
                    e4.printStackTrace();
                }
            } while (!line.startsWith("1 packets transmitted, 1 received"));
            return true;
        }
        return false;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean startHardwareTest() {
        b.c.c.l.b.d("Utils3588Impl", "start Hardware Test");
        com.ifpdos.autotest.l0.a.d().f(false);
        return true;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean unmuteAisleSound() {
        try {
            Runtime.getRuntime().exec("tinymix 0 1");
            return true;
        } catch (IOException e2) {
            e2.printStackTrace();
            return true;
        }
    }
}
