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: WB9681Impl.java */
/* JADX INFO: loaded from: classes.dex */
public class v implements IWB {

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private boolean f2142g = false;

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

    /* JADX INFO: compiled from: WB9681Impl.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);
        }
    }

    public v(Context context) {
        this.f2137b = true;
        this.f2139d = Integer.MAX_VALUE;
        this.f2140e = null;
        this.f2138c = context;
        this.f2139d = b.c.c.d.f1449a.b();
        this.f2140e = c();
        Log.d("WB9681Impl", "origin ColorSpace is " + this.f2140e);
        this.f2137b = this.f2141f.getPQCtrl().getPQPqEnable();
        this.f2141f.getPQCtrl().setPQPqEnable(true);
    }

    private boolean a() {
        b(false);
        b.c.c.d.f1449a.c(this.f2139d);
        h0.l().m();
        b(true);
        com.ifpdos.autotest.o0.e.i(this.f2138c);
        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.f2138c.sendBroadcast(intent);
    }

    private String c() {
        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("WB9681Impl", "getColorSpace failed", e2);
            return null;
        }
    }

    private void d(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("WB9681Impl", "setColorSpace " + str + " failed", e2);
        }
    }

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

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

    private boolean g(int i, int i2, int i3) {
        h0.l().o();
        b(false);
        closeNoSignalSleepTime();
        Log.i("WB9681Impl", "9666 openPixelPictureVman " + i + " " + i2 + " " + i3);
        return this.f2141f.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("WB9681Impl", "exitStandPictureMode: ");
        if (this.f2140e == null) {
            return true;
        }
        Log.d("WB9681Impl", "reset ColorSpace " + this.f2140e);
        d(this.f2140e);
        return true;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public int get3DLutIndex() {
        String strC = c();
        int iIntValue = f2136a.get(strC).intValue();
        Log.i("WB9681Impl", strC + " : " + iIntValue);
        return iIntValue;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public com.seewo.sdk.interfaces.g getColorTemp() {
        int colorTempMode = VmanMiddleWare.getInstance().getPQCtrl().getColorTempMode();
        Log.d("WB9681Impl", "getColorTemp: colorTempMode = " + colorTempMode);
        return com.seewo.sdk.interfaces.g.values()[colorTempMode];
    }

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

    @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("WB9681Impl", "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.f2139d);
        this.f2138c.sendBroadcast(new Intent("com.ifpdos.autotest.end"));
        com.seewo.vcommons.data.d.r(false);
        this.f2141f.getPQCtrl().setPQPqEnable(this.f2137b);
        this.f2141f.getPQCtrl().setTestPatternEnable(EnumPatternType.PENNEL, 0);
        Log.i("WB9681Impl", "setPQPqEnable = " + this.f2137b);
        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) {
        Log.d("WB9681Impl", "save: r = " + i + ", g = " + i2 + ", b = " + i3 + ", mColorSpace = " + this.f2140e);
        return com.seewo.sdk.interfaces.g.isSetTempIndex(gVar) ? com.ifpdos.autotest.o0.g.b(gVar, i, i2, i3) : f(gVar) && e(i, i2, i3);
    }

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

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

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

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

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setPatternByUser(int i, int i2, int i3) {
        return g(i, i2, i3);
    }

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setStandPictureMode() {
        Log.i("WB9681Impl", "setStandPictureMode: ");
        com.seewo.vcommons.data.d.r(true);
        Log.d("WB9681Impl", "set ColorSpace COLOR_SPACE_OPTION_STANDARD");
        d("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;
    }
}
