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

import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.Log;
import com.ifpdos.autotest.api.IUtils;
import com.ifpdos.autotest.h0;
import com.ifpdos.autotest.l0.a;
import com.seewo.vtv.interfaces.IAutoLightHelper;
import com.seewo.vtv.interfaces.IFactoryHelper;
import com.seewo.vtv.interfaces.ISleepHelper;
import com.seewo.vtv.interfaces.ISourceHelper;
import com.seewo.vtv.interfaces.ISystemInfoHelper;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final ISourceHelper f2114a = b.c.e.b.b.d().g();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final IAutoLightHelper f2115b = b.c.e.b.b.d().a();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final IFactoryHelper f2116c = b.c.e.b.b.d().b();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final ISystemInfoHelper f2117d = b.c.e.b.b.d().h();

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

    /* JADX INFO: compiled from: UtilsImpl.java */
    class a implements ISourceHelper.ChangeSourceListener {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ c.a.i f2119a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ ISourceHelper.SourceItem f2120b;

        a(c.a.i iVar, ISourceHelper.SourceItem sourceItem) {
            this.f2119a = iVar;
            this.f2120b = sourceItem;
        }

        @Override // com.seewo.vtv.interfaces.ISourceHelper.ChangeSourceListener
        public void onChangeSourceFinished(ISourceHelper.SourceItem sourceItem) {
            b.c.c.l.b.d("UtilsImpl", "Change source finished: " + sourceItem);
            this.f2119a.d(Boolean.valueOf(sourceItem == this.f2120b));
        }

        @Override // com.seewo.vtv.interfaces.ISourceHelper.ChangeSourceListener
        public void onChangeSourceStart(ISourceHelper.SourceItem sourceItem) {
            b.c.c.l.b.d("UtilsImpl", "Change source to: " + sourceItem);
        }
    }

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

    private boolean b(final ISourceHelper.SourceItem sourceItem) {
        return ((Boolean) c.a.h.c(new c.a.k() { // from class: com.ifpdos.autotest.lancontrol.module.other.e.f
            @Override // c.a.k
            public final void a(c.a.i iVar) throws Exception {
                this.f2084a.d(sourceItem, iVar);
            }
        }).l(5L, TimeUnit.SECONDS, c.a.h.f(Boolean.FALSE)).b()).booleanValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ void d(ISourceHelper.SourceItem sourceItem, c.a.i iVar) throws Exception {
        if (this.f2114a.changeSource(this.f2118e, sourceItem, new a(iVar, sourceItem))) {
            return;
        }
        iVar.d(Boolean.FALSE);
    }

    @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("UtilsImpl", "problemCode=" + String.format(listB.get(i).a(), new Object[0]) + "\n");
        }
        if (!z) {
            b.c.c.l.b.d("UtilsImpl", "Hardware Test End Fail");
            SystemProperties.set("persist.sys.hardware.test.result", "false");
            return;
        }
        b.c.c.l.b.d("UtilsImpl", "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) {
        Log.d("UtilsImpl", "changeSource " + sourceItem);
        boolean z = false;
        if (sourceItem != ISourceHelper.SourceItem.ANDROID) {
            Log.d("UtilsImpl", "hide FloatTarget");
            h0.l().o();
        } else {
            Log.d("UtilsImpl", "show FloatTarget");
            h0.l().I();
            if (!b.c.e.e.e.b()) {
                Log.e("UtilsImpl", "no have android source, refuse change source request");
                return false;
            }
        }
        SystemProperties.set("persist.sys.v_force_channel", "false");
        if (b.c.d.b.a.j() && sourceItem == ISourceHelper.SourceItem.HDMI1) {
            return b(ISourceHelper.SourceItem.HDMI3);
        }
        boolean zB = b(sourceItem);
        int currentSourceId = this.f2114a.getCurrentSourceId(this.f2118e);
        int i = 0;
        do {
            if (zB) {
                i++;
                b.c.c.l.b.d("UtilsImpl", "id=" + currentSourceId);
                if (SystemProperties.getInt("sys.complete.source_id", 24) == currentSourceId) {
                    b.c.c.l.b.d("UtilsImpl", "source is switch complete");
                } else {
                    b.c.c.l.b.d("UtilsImpl", "source is not switch complete");
                    b.c.a.a.b.a(100L);
                }
            }
            z = zB;
            break;
        } while (i <= 80);
        b.c.a.a.b.a(1000L);
        return z;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean changeSourceExt(ISourceHelper.SourceItem sourceItem, long j) {
        if (b.c.d.b.a.j() && sourceItem == ISourceHelper.SourceItem.HDMI1) {
            return b(ISourceHelper.SourceItem.HDMI3);
        }
        boolean zB = b(sourceItem);
        int i = 0;
        while (true) {
            if (!zB) {
                break;
            }
            i++;
            if (this.f2114a.getCurrentSourceIsStable()) {
                b.c.c.l.b.d("UtilsImpl", "source is switch complete");
                break;
            }
            b.c.c.l.b.d("UtilsImpl", "source is not switch complete");
            b.c.a.a.b.a(100L);
            if (i * 100 > j) {
                zB = false;
                break;
            }
        }
        b.c.a.a.b.a(500L);
        return zB;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public void enterFactoryAutoTestMode() {
        b.c.c.l.b.d("UtilsImpl", "enter Factory Auto Test Mode");
        this.f2118e.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("UtilsImpl", "exit Factory Auto Test Mode");
        this.f2118e.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 this.f2117d.getMac();
    }

    @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.f2118e.sendBroadcast(new Intent("com.ifpdos.autotest.start"));
        com.ifpdos.autotest.k0.d.b.f(false);
        return com.seewo.vcommons.data.d.g();
    }

    @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.e
                @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 com.seewo.vcommons.data.d.j("persist.sys.all.aging.time", "0").equals("1") ? com.ifpdos.autotest.o0.c.a(this.f2118e) : SystemClock.uptimeMillis() / 1000;
    }

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

    @Override // com.ifpdos.autotest.api.IUtils
    public String getVendorProductModel() {
        this.f2118e.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("UtilsImpl", "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("UtilsImpl", "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("UtilsImpl", "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;
        }
    }
}
