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

import android.content.Context;
import android.content.Intent;
import android.os.SystemProperties;
import android.util.Log;
import com.cvte.vman.VmanMiddleWare;
import com.cvte.vman.types.EnumPatternType;
import com.google.gson.JsonParser;
import com.ifpdos.autotest.api.IWB;
import com.ifpdos.autotest.h0;
import com.seewo.libmcuservice.constant.ITVStateConstants;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;

/* JADX INFO: compiled from: WB9666Impl.java */
/* JADX INFO: loaded from: classes.dex */
public class u implements IWB {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final Map<String, Integer> f2129a = new a();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final Map<com.seewo.sdk.interfaces.g, Integer> f2130b = new b();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private boolean f2131c;

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private String f2134f;
    private boolean h = false;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private VmanMiddleWare f2135g = VmanMiddleWare.getInstance();

    /* JADX INFO: compiled from: WB9666Impl.java */
    class a extends HashMap<String, Integer> {
        a() {
            put("COLOR_SPACE_OPTION_SRGB", 0);
            put("COLOR_SPACE_OPTION_ADOBE_RGB", 1);
            put("COLOR_SPACE_OPTION_DISPLAY_P3", 2);
            put("COLOR_SPACE_OPTION_DCI_P3", 3);
            put("COLOR_SPACE_OPTION_HDR_BT2020", 4);
            put("COLOR_SPACE_OPTION_STANDARD", 5);
        }
    }

    /* JADX INFO: compiled from: WB9666Impl.java */
    class b extends HashMap<com.seewo.sdk.interfaces.g, Integer> {
        b() {
            put(com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_0, 6);
            put(com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_1, 5);
            put(com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_2, 4);
            put(com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_3, 3);
            put(com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_4, 2);
            put(com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_5, 1);
            put(com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_6, 0);
        }
    }

    public u(Context context) {
        this.f2131c = true;
        this.f2133e = Integer.MAX_VALUE;
        this.f2134f = null;
        this.f2132d = context;
        this.f2133e = b.c.c.d.f1449a.b();
        this.f2134f = e();
        Log.d("WB9666Impl", "origin ColorSpace is " + this.f2134f);
        this.f2131c = this.f2135g.getPQCtrl().getPQPqEnable();
        this.f2135g.getPQCtrl().setPQPqEnable(true);
    }

    private boolean a() {
        b(false);
        b.c.c.d.f1449a.c(this.f2133e);
        h0.l().m();
        b(true);
        com.ifpdos.autotest.o0.e.i(this.f2132d);
        h0.l().G();
        return true;
    }

    private void b(boolean z) {
        Intent intent = new Intent("com.cvte.intent.action_CONTROL_NO_SIGNAL");
        intent.putExtra("key_no_signal", z);
        this.f2132d.sendBroadcast(intent);
    }

    private int[] c(int i, int i2, int i3) {
        int i4;
        int i5;
        int i6;
        int i7;
        if (i > 128 || i2 > 128 || i3 > 128) {
            i4 = i == 0 ? 0 : ((i + 1) * 4) - 1;
            i5 = i2 == 0 ? 0 : ((i2 + 1) * 4) - 1;
            if (i3 != 0) {
                i6 = (i3 + 1) * 4;
                i7 = i6 - 1;
            }
            i7 = 0;
        } else {
            i4 = i == 0 ? 0 : (i * 8) - 1;
            i5 = i2 == 0 ? 0 : (i2 * 8) - 1;
            if (i3 != 0) {
                i6 = i3 * 8;
                i7 = i6 - 1;
            }
            i7 = 0;
        }
        return new int[]{i4, i5, i7};
    }

    private int[] d(int i, int i2, int i3) {
        return new int[]{i == 0 ? 0 : (i * 2) - 1, i2 == 0 ? 0 : (i2 * 2) - 1, i3 == 0 ? 0 : (i3 * 2) - 1};
    }

    private String e() {
        try {
            return new JsonParser().parse(b.b.e.a.f.e().build().newCall(new Request.Builder().url(b.b.e.a.f.a("/v1/picture/color/space")).build()).execute().body().string()).getAsJsonObject().get(ITVStateConstants.KEY_VOICE_VALUE).getAsString();
        } catch (Exception e2) {
            Log.d("WB9666Impl", "getColorSpace failed", e2);
            return null;
        }
    }

    private int f(com.seewo.sdk.interfaces.g gVar) {
        return f2130b.getOrDefault(gVar, 0).intValue();
    }

    private void g(String str) {
        try {
            b.b.e.a.f.e().build().newCall(new Request.Builder().url(b.b.e.a.f.a("/v1/picture/color/space")).post(RequestBody.create(MediaType.parse("application/json;charset=utf-8"), String.format("{\"value\":\"%s\"}", str))).build()).execute();
        } catch (Exception e2) {
            Log.d("WB9666Impl", "setColorSpace " + str + " failed", e2);
        }
    }

    private boolean h(int i, int i2, int i3) {
        return b.c.c.g.f1452a.j(i, i2, i3);
    }

    private boolean i(com.seewo.sdk.interfaces.g gVar) {
        int iF = f(gVar);
        int colorTempMode = VmanMiddleWare.getInstance().getPQCtrl().setColorTempMode(iF);
        Log.i("WB9666Impl", "9666 setColorTemp ordinal=" + iF + "; result=" + colorTempMode);
        return colorTempMode == 0;
    }

    private boolean j(int i, int i2, int i3) {
        h0.l().o();
        b(false);
        closeNoSignalSleepTime();
        Log.i("WB9666Impl", "9666 openPixelPictureVman " + i + " " + i2 + " " + i3);
        return this.f2135g.getPQCtrl().setTestPattern(EnumPatternType.PENNEL, i, i2, i3);
    }

    @Override // com.ifpdos.autotest.api.IWB
    public String checkMd5() {
        File file = new File("/data/" + SystemProperties.get("persist.sys.file.name"));
        return file.exists() ? com.ifpdos.autotest.lancontrol.module.other.f.c.c(file) : "";
    }

    @Override // com.ifpdos.autotest.api.IWB
    public void closeNoSignalSleepTime() {
        b.c.c.d.f1449a.c(Integer.MAX_VALUE);
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean endTranFile() {
        com.ifpdos.autotest.k0.d.b.f(false);
        return true;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean executeShell(String str) {
        return b.c.d.d.d.a(str).f1514a == 0;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean exitStandPictureMode() {
        Log.i("WB9666Impl", "exitStandPictureMode: ");
        if (this.f2134f == null) {
            return true;
        }
        Log.d("WB9666Impl", "reset ColorSpace " + this.f2134f);
        g(this.f2134f);
        return true;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public int get3DLutIndex() {
        String strE = e();
        int iIntValue = f2129a.get(strE).intValue();
        Log.i("WB9666Impl", strE + " : " + iIntValue);
        return iIntValue;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public com.seewo.sdk.interfaces.g getColorTemp() {
        int colorTempMode = VmanMiddleWare.getInstance().getPQCtrl().getColorTempMode();
        Log.d("WB9666Impl", "getColorTemp: colorTempMode = " + colorTempMode);
        for (Map.Entry<com.seewo.sdk.interfaces.g, Integer> entry : f2130b.entrySet()) {
            if (entry.getValue().intValue() == colorTempMode) {
                return entry.getKey();
            }
        }
        return null;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public int[] getColorTempRGBValue(com.seewo.sdk.interfaces.g gVar) {
        return VmanMiddleWare.getInstance().getPQCtrl().getPresetColorTempMode(0, f2130b.get(gVar).intValue());
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean mergeFile() {
        if (b.c.e.a.b.f1524a != 10) {
            return b.c.d.d.d.a("cp data/3dlut.bin /mnt/vendor/factory/").f1514a == 0 && b.c.d.d.d.a("sync").f1514a == 0;
        }
        Log.d("WB9666Impl", "cp by system on 1516");
        SystemProperties.set("ctl.start", "pq");
        return true;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean quit() {
        b.c.c.d.f1449a.c(this.f2133e);
        this.f2132d.sendBroadcast(new Intent("com.ifpdos.autotest.end"));
        com.seewo.vcommons.data.d.r(false);
        this.f2135g.getPQCtrl().setPQPqEnable(this.f2131c);
        this.f2135g.getPQCtrl().setTestPatternEnable(EnumPatternType.PENNEL, 0);
        Log.i("WB9666Impl", "setPQPqEnable = " + this.f2131c);
        return a();
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean result(String str) {
        h0.l().C(str);
        return true;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean save(com.seewo.sdk.interfaces.g gVar, int i, int i2, int i3) {
        int[] iArrC = c(i, i2, i3);
        j(iArrC[0], iArrC[1], iArrC[2]);
        Log.d("WB9666Impl", "save: r = " + i + ", g = " + i2 + ", b = " + i3 + ",rgb[0] = " + iArrC[0] + ", rgb[1] = " + iArrC[1] + ", rgb[2] = " + iArrC[2] + ", mColorSpace = " + this.f2134f);
        int[] iArrD = d(i, i2, i3);
        return i(gVar) && h(iArrD[0], iArrD[1], iArrD[2]);
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean set3DLutIndex(int i) {
        for (Map.Entry<String, Integer> entry : f2129a.entrySet()) {
            if (entry.getValue().intValue() == i) {
                Log.i("WB9666Impl", "set3DLutIndex: " + i + " -> " + entry.getKey());
                g(entry.getKey());
                return true;
            }
        }
        return false;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setColorTemp(com.seewo.sdk.interfaces.g gVar) {
        return i(gVar);
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setMasterPictureMode() {
        Log.i("WB9666Impl", "setMasterPictureMode: ");
        return true;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setPattern() {
        return j(1023, 1023, 1023);
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setPatternByUser(int i, int i2, int i3) {
        int[] iArrC = c(i, i2, i3);
        return j(iArrC[0], iArrC[1], iArrC[2]);
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setStandPictureMode() {
        Log.i("WB9666Impl", "setStandPictureMode: ");
        com.seewo.vcommons.data.d.r(true);
        Log.d("WB9666Impl", "set ColorSpace COLOR_SPACE_OPTION_STANDARD");
        g("COLOR_SPACE_OPTION_STANDARD");
        return true;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean startTranFile(String str) {
        SystemProperties.set("persist.sys.file.name", str);
        com.ifpdos.autotest.k0.d.b.f(true);
        return true;
    }
}
