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.google.gson.JsonParser;
import com.ifpdos.autotest.api.IWB;
import com.ifpdos.autotest.h0;
import com.ifpdos.autotest.model.BrightnessRangeEnum;
import com.ifpdos.autotest.model.GammaModeEnum;
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: WB3588Impl.java */
/* JADX INFO: loaded from: classes.dex */
public class t implements IWB {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final GammaModeEnum f2122a = GammaModeEnum.GAMMA_2_2;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final com.seewo.sdk.interfaces.h f2123b = com.seewo.sdk.interfaces.h.PICTURE_USER;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final BrightnessRangeEnum f2124c = BrightnessRangeEnum.HDMI_RGB_AUTO;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final com.seewo.sdk.interfaces.g f2125d = com.seewo.sdk.interfaces.g.MS_COLOR_TEMP_NATURE;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final Map<String, Integer> f2126e = new a();
    private Context i;
    private int j;
    private String k;
    private final boolean n;
    private int o;
    private com.seewo.sdk.interfaces.h p;
    private int q;
    private int r;
    private GammaModeEnum s;
    private BrightnessRangeEnum t;
    private com.seewo.sdk.interfaces.g u;
    private boolean v;
    private boolean w;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private boolean f2127f = true;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private boolean f2128g = false;
    private boolean h = false;
    private boolean m = false;
    private VmanMiddleWare l = VmanMiddleWare.getInstance();

    /* JADX INFO: compiled from: WB3588Impl.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 t(Context context) {
        this.j = Integer.MAX_VALUE;
        this.k = null;
        this.o = 50;
        this.p = f2123b;
        this.q = 50;
        this.r = 50;
        this.s = f2122a;
        this.t = f2124c;
        this.u = f2125d;
        this.i = context;
        this.j = b.c.c.d.f1449a.b();
        this.k = c();
        boolean zContains = com.seewo.vcommons.data.d.j("ro.cvte.flavor.name", "").toLowerCase().contains("avocor");
        this.n = zContains;
        Log.d("WB3588Impl", "origin ColorSpace is " + this.k + ", mIsAvocorProCustom = " + zContains);
        if (zContains) {
            b.c.c.g gVar = b.c.c.g.f1452a;
            this.p = gVar.f();
            this.o = gVar.d();
            this.r = com.ifpdos.autotest.okhttp.e.k();
            this.q = gVar.e();
            this.s = com.ifpdos.autotest.okhttp.e.h();
            this.t = com.ifpdos.autotest.okhttp.e.b();
            this.u = gVar.b();
            Log.d("WB3588Impl", "init params: mPictureMode = " + this.p + ", mContrast" + this.o + ", mSaturation" + this.r + ", mHue" + this.q + ", mGammaMode" + this.s + ", mBrightnessRange" + this.t + ", mColorTemp" + this.u);
        }
    }

    private boolean a() {
        b(false);
        b.c.c.d.f1449a.c(this.j);
        h0.l().m();
        b(true);
        h0.l().G();
        com.ifpdos.autotest.o0.e.i(this.i);
        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.i.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("WB3588Impl", "getColorSpace failed", e2);
            return null;
        }
    }

    private boolean d(int i, int i2, int i3) {
        Log.i("WB3588Impl", "openPixelPicture: " + this.m);
        if (!this.m) {
            this.m = true;
            this.f2127f = this.l.getPQCtrl().getPQPqEnable();
            this.l.getPQCtrl().setPQPqEnable(false);
            this.f2128g = com.ifpdos.autotest.okhttp.e.d();
            this.h = com.ifpdos.autotest.okhttp.e.e();
            this.v = com.ifpdos.autotest.okhttp.e.i();
            this.w = com.ifpdos.autotest.okhttp.e.a();
            com.ifpdos.autotest.okhttp.e.p(false);
            com.ifpdos.autotest.okhttp.e.q(false);
            com.ifpdos.autotest.okhttp.e.v(false);
            com.ifpdos.autotest.okhttp.e.m(false);
            b.c.c.g gVar = b.c.c.g.f1452a;
            gVar.h(99);
            gVar.h(100);
            this.l.getPQCtrl().setAWBPartitionEnable(true);
            h0.l().C("ng");
            if (this.n) {
                gVar.n(f2123b);
                gVar.k(50);
                com.ifpdos.autotest.okhttp.e.w(50);
                gVar.m(50);
                com.ifpdos.autotest.okhttp.e.u(f2122a);
                com.ifpdos.autotest.okhttp.e.n(f2124c);
                gVar.i(f2125d);
            }
            Log.i("WB3588Impl", "setPQPqEnable false, mDynamicContrastEnable = " + this.f2128g + ", mEnergyStarEnable = " + this.h + ", mLocalDimming = " + this.v + ", mAutoLight = " + this.w);
        }
        b(false);
        closeNoSignalSleepTime();
        h0.l().o();
        h0.l().D(i, i2, i3);
        return true;
    }

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

    private boolean f(int i, int i2, int i3) {
        return b.c.c.g.f1452a.j(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("WB3588Impl", "exitStandPictureMode: ");
        if (this.k == null) {
            return true;
        }
        Log.d("WB3588Impl", "reset ColorSpace " + this.k);
        e(this.k);
        return true;
    }

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

    @Override // com.ifpdos.autotest.api.IWB
    public com.seewo.sdk.interfaces.g getColorTemp() {
        com.seewo.sdk.interfaces.g gVarB = b.c.c.g.f1452a.b();
        Log.d("WB3588Impl", "getColorTemp: " + gVarB);
        return gVarB;
    }

    @Override // com.ifpdos.autotest.api.IWB
    public int[] getColorTempRGBValue(com.seewo.sdk.interfaces.g gVar) {
        Log.d("WB3588Impl", "getColorTempRGBValue: " + gVar);
        return b.c.c.g.f1452a.c(gVar);
    }

    @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("WB3588Impl", "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.j);
        this.i.sendBroadcast(new Intent("com.ifpdos.autotest.end"));
        com.seewo.vcommons.data.d.r(false);
        if (this.m) {
            this.l.getPQCtrl().setPQPqEnable(this.f2127f);
            com.ifpdos.autotest.okhttp.e.p(this.f2128g);
            com.ifpdos.autotest.okhttp.e.q(this.h);
            com.ifpdos.autotest.okhttp.e.v(this.v);
            com.ifpdos.autotest.okhttp.e.m(this.w);
        }
        Log.i("WB3588Impl", "mDisablePq = " + this.m + ", setPQPqEnable = " + this.f2127f + ", mDynamicContrastEnable = " + this.f2128g + ", mEnergyStarEnable = " + this.h + ", mLocalDimming = " + this.v + ", mAutoLight = " + this.w);
        this.m = false;
        if (this.n) {
            b.c.c.g gVar = b.c.c.g.f1452a;
            gVar.n(this.p);
            gVar.k(this.o);
            com.ifpdos.autotest.okhttp.e.w(this.r);
            gVar.m(this.q);
            com.ifpdos.autotest.okhttp.e.u(this.s);
            com.ifpdos.autotest.okhttp.e.n(this.t);
            gVar.i(this.u);
        }
        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("WB3588Impl", "save colorTemp = " + gVar + ", r = " + i + ", g = " + i2 + ", b = " + i3);
        return com.seewo.sdk.interfaces.g.isSetTempIndex(gVar) ? com.ifpdos.autotest.o0.g.b(gVar, i, i2, i3) : setColorTemp(gVar) && f(i, i2, i3);
    }

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

    @Override // com.ifpdos.autotest.api.IWB
    public boolean setColorTemp(com.seewo.sdk.interfaces.g gVar) {
        Log.i("WB3588Impl", "setColorTemp: " + gVar);
        return b.c.c.g.f1452a.i(gVar);
    }

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

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

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

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