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 d.n0.c.a0;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/* JADX INFO: compiled from: Utils1516Impl.kt */
/* JADX INFO: loaded from: classes.dex */
@d.n
public final class q implements IUtils, a.b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final String f2103a = "Utils1516Impl";

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

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

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

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

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

    /* JADX INFO: compiled from: Utils1516Impl.kt */
    @d.n
    public static final class a implements ISourceHelper.ChangeSourceListener {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ c.a.i<Boolean> f2110b;

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

        a(c.a.i<Boolean> iVar, ISourceHelper.SourceItem sourceItem) {
            this.f2110b = iVar;
            this.f2111c = sourceItem;
        }

        @Override // com.seewo.vtv.interfaces.ISourceHelper.ChangeSourceListener
        public void onChangeSourceFinished(ISourceHelper.SourceItem sourceItem) {
            d.n0.c.s.e(sourceItem, "channel");
            b.c.c.l.b.d(q.this.e(), "Change source finished: " + sourceItem);
            this.f2110b.d(Boolean.valueOf(sourceItem == this.f2111c));
        }

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

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

    /* JADX INFO: Access modifiers changed from: private */
    public static final void c(q qVar, ISourceHelper.SourceItem sourceItem, c.a.i iVar) {
        d.n0.c.s.e(qVar, "this$0");
        d.n0.c.s.e(sourceItem, "$sourceItem");
        d.n0.c.s.e(iVar, "emitter");
        ISourceHelper iSourceHelper = qVar.f2104b;
        d.n0.c.s.b(iSourceHelper);
        if (iSourceHelper.changeSource(qVar.f2108f, sourceItem, qVar.new a(iVar, sourceItem))) {
            return;
        }
        iVar.d(Boolean.FALSE);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final String d() {
        return b.c.c.j.f1455a.b();
    }

    @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();
        int size = listB.size();
        for (int i = 0; i < size; i++) {
            com.ifpdos.autotest.l0.b bVar = listB.get(i);
            String str = this.f2103a;
            StringBuilder sb = new StringBuilder();
            sb.append("\n     problemCode=");
            a0 a0Var = a0.f2623a;
            String strA = bVar.a();
            d.n0.c.s.d(strA, "item.code");
            String str2 = String.format(strA, Arrays.copyOf(new Object[0], 0));
            d.n0.c.s.d(str2, "format(format, *args)");
            sb.append(str2);
            sb.append("\n     \n     ");
            b.c.c.l.b.d(str, d.s0.j.e(sb.toString()));
        }
        if (!z) {
            b.c.c.l.b.d(this.f2103a, "Hardware Test End Fail");
            SystemProperties.set("persist.sys.hardware.test.result", "false");
            return;
        }
        b.c.c.l.b.d(this.f2103a, "Hardware Test End Succeed");
        if (listB.isEmpty()) {
            SystemProperties.set("persist.sys.hardware.test.result", "true");
        } else {
            SystemProperties.set("persist.sys.hardware.test.result", "false");
        }
    }

    public boolean b(final ISourceHelper.SourceItem sourceItem) {
        d.n0.c.s.e(sourceItem, "sourceItem");
        Object objB = c.a.h.c(new c.a.k() { // from class: com.ifpdos.autotest.lancontrol.module.other.e.b
            @Override // c.a.k
            public final void a(c.a.i iVar) {
                q.c(this.f2079a, sourceItem, iVar);
            }
        }).l(5L, TimeUnit.SECONDS, c.a.h.f(Boolean.FALSE)).b();
        d.n0.c.s.d(objB, "create { emitter: Single…           .blockingGet()");
        return ((Boolean) objB).booleanValue();
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean changeSource(ISourceHelper.SourceItem sourceItem) {
        d.n0.c.s.e(sourceItem, "sourceItem");
        Log.d(this.f2103a, "changeSource " + sourceItem);
        if (sourceItem != ISourceHelper.SourceItem.ANDROID) {
            Log.d(this.f2103a, "hide FloatTarget");
            h0.l().o();
        } else {
            Log.d(this.f2103a, "show FloatTarget");
            h0.l().H();
        }
        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);
        ISourceHelper iSourceHelper = this.f2104b;
        d.n0.c.s.b(iSourceHelper);
        int currentSourceId = iSourceHelper.getCurrentSourceId(this.f2108f);
        int i = 0;
        while (true) {
            if (!zB) {
                break;
            }
            i++;
            b.c.c.l.b.d(this.f2103a, "id=" + currentSourceId);
            if (SystemProperties.getInt("sys.complete.source_id", 24) == currentSourceId) {
                b.c.c.l.b.d(this.f2103a, "source is switch complete");
                break;
            }
            b.c.c.l.b.d(this.f2103a, "source is not switch complete");
            b.c.a.a.b.a(100L);
            if (i > 80) {
                zB = false;
                break;
            }
        }
        b.c.a.a.b.a(1000L);
        return zB;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean changeSourceExt(ISourceHelper.SourceItem sourceItem, long j) {
        d.n0.c.s.e(sourceItem, "sourceItem");
        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++;
            ISourceHelper iSourceHelper = this.f2104b;
            d.n0.c.s.b(iSourceHelper);
            if (iSourceHelper.getCurrentSourceIsStable()) {
                b.c.c.l.b.d(this.f2103a, "source is switch complete");
                break;
            }
            b.c.c.l.b.d(this.f2103a, "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;
    }

    public final String e() {
        return this.f2103a;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public void enterFactoryAutoTestMode() {
        b.c.c.l.b.d(this.f2103a, "enter Factory Auto Test Mode");
        Context context = this.f2108f;
        d.n0.c.s.b(context);
        context.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(this.f2103a, "exit Factory Auto Test Mode");
        Context context = this.f2108f;
        d.n0.c.s.b(context);
        context.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 d.n0.c.s.a(SystemProperties.get("persist.sys.hardware.test.result", "false"), "true");
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public String getMac() {
        ISystemInfoHelper iSystemInfoHelper = this.f2107e;
        d.n0.c.s.b(iSystemInfoHelper);
        return iSystemInfoHelper.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() {
        Context context = this.f2108f;
        d.n0.c.s.b(context);
        context.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();
        int size = listB.size();
        for (int i = 0; i < size; i++) {
            com.ifpdos.autotest.l0.b bVar = listB.get(i);
            a0 a0Var = a0.f2623a;
            String strA = bVar.a();
            d.n0.c.s.d(strA, "item.code");
            String str = String.format(strA, Arrays.copyOf(new Object[0], 0));
            d.n0.c.s.d(str, "format(format, *args)");
            arrayList.add(str);
        }
        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.c
                @Override // java.util.concurrent.Callable
                public final Object call() {
                    return q.d();
                }
            });
            new Thread(futureTask).start();
            Object obj = futureTask.get();
            d.n0.c.s.d(obj, "task.get()");
            String str = (String) obj;
            int length = str.length() - 1;
            int i = 0;
            boolean z = false;
            while (i <= length) {
                boolean z2 = d.n0.c.s.f(str.charAt(!z ? i : length), 32) <= 0;
                if (z) {
                    if (!z2) {
                        break;
                    }
                    length--;
                } else if (z2) {
                    i++;
                } else {
                    z = true;
                }
            }
            return str.subSequence(i, length + 1).toString();
        } 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() {
        Context context = this.f2108f;
        if (context != null) {
            context.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) {
        Process processExec;
        String line;
        d.n0.c.s.e(str, "ipAddress");
        String str2 = "ping -c 1 -W 1 " + str;
        b.c.c.l.b.d(this.f2103a, "command=" + str2);
        int iWaitFor = -1;
        try {
            processExec = Runtime.getRuntime().exec(str2);
        } catch (IOException e2) {
            e = e2;
            processExec = null;
        }
        try {
            try {
                iWaitFor = processExec.waitFor();
            } catch (InterruptedException e3) {
                e3.printStackTrace();
            }
        } catch (IOException e4) {
            e = e4;
            e.printStackTrace();
        }
        if (iWaitFor == 0) {
            d.n0.c.s.b(processExec);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(processExec.getInputStream()));
            do {
                try {
                    line = bufferedReader.readLine();
                    d.n0.c.s.d(line, "it");
                    if (line != null) {
                        b.c.c.l.b.d(this.f2103a, "str=" + line);
                    }
                } catch (IOException e5) {
                    e5.printStackTrace();
                }
            } while (!d.s0.q.r(line, "1 packets transmitted, 1 received", false, 2, null));
            return true;
        }
        return false;
    }

    @Override // com.ifpdos.autotest.api.IUtils
    public boolean startHardwareTest() {
        b.c.c.l.b.d(this.f2103a, "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;
        }
    }
}
