package com.seewo.factoryaging;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.widget.FrameLayout;
import android.widget.Toast;
import com.cvte.vman.R;
import com.cvte.vman.VmanMiddleWare;
import com.google.gson.Gson;
import com.seewo.sdk.event.OSEvent;
import com.seewo.sdk.eventbus.OnEventOfOS;
import com.seewo.sdk.eventbus.ThreadMode;
import h.c.d.a.a;
import j.q;
import java.util.LinkedHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;

/* JADX INFO: compiled from: MainActivity.kt */
/* JADX INFO: loaded from: classes.dex */
@j.n
public final class MainActivity extends androidx.appcompat.app.c {
    private final String A;
    private final String B;
    private final ExecutorService C;
    private int D;
    private int E;
    private Runnable F;
    private AlertDialog G;
    private String H;
    private final Handler I;
    private final String J;
    private final String K;
    private String L;
    private String M;
    private boolean N;
    private final int O;
    private boolean P;
    private x Q;
    private boolean R;
    private com.seewo.sdk.interfaces.g S;
    private h0 T;
    private ProgressDialog r;
    private Thread s;
    private final boolean t;
    private String u;
    private boolean v;
    private i.a.k.b w;
    private int x;
    private boolean y;
    private final String z;

    /* JADX INFO: compiled from: MainActivity.kt */
    static final class a extends j.p0.d.s implements j.p0.c.a<j.h0> {
        a() {
            super(0);
        }

        public final void a() {
            com.seewo.factoryaging.d1.b.a.l("/v1/device/energy/save", j.k0.j0.c(j.v.a("enable", "false")));
            MainActivity.this.a0();
            if (!com.seewo.factoryaging.e1.h.a.a()) {
                Log.d("AgingMainActivity", "getDebugMenuRoleModeEnable is false, enable role mode");
                com.seewo.factoryaging.e1.h.a.b(MainActivity.this, true);
            }
            MainActivity.this.m0();
            MainActivity mainActivity = MainActivity.this;
            boolean zI = com.seewo.factoryaging.mic.g.a.i();
            Log.d("AgingMainActivity", "isMicOff: " + zI);
            if (zI) {
                com.seewo.factoryaging.mic.g.a.l(true);
            }
            mainActivity.R = zI;
            if (h.c.d.b.a.b()) {
                Log.w("AgingMainActivity", "disable pir: com.i3_technologies.system.service");
                com.seewo.factoryaging.e1.b.a.a("com.i3_technologies.system.service", false);
            }
            if (com.seewo.factoryaging.e1.f.a.t()) {
                Log.w("AgingMainActivity", "disable metting room: com.benq.meetingroom");
                com.seewo.factoryaging.e1.b.a.a("com.benq.meetingroom", false);
            }
            if (a0.c()) {
                a0.d();
            }
        }

        @Override // j.p0.c.a
        public /* bridge */ /* synthetic */ j.h0 invoke() {
            a();
            return j.h0.a;
        }
    }

    public MainActivity() {
        new LinkedHashMap();
        this.t = com.seewo.vcommons.data.c.j("persist.ctm.cpu.test", false);
        this.u = "logd.logpersistd";
        this.z = "sys.system_dock_visible";
        this.A = "sys.system_dock_visible";
        this.B = "persist.sys.aging.power_on.enable";
        this.C = Executors.newSingleThreadExecutor();
        this.D = SystemProperties.getInt(this.z, 3);
        this.E = SystemProperties.getInt(this.A, 3);
        this.I = new Handler(Looper.getMainLooper());
        this.J = "com.seewo.systemdock.CHANGE_FLAG";
        this.K = "com.cvte.systemdock.FLAG";
        this.L = "-1";
        this.M = "-1";
        this.N = true;
        this.O = com.seewo.factoryaging.e1.f.a.c();
        this.P = true;
        this.Q = x.SHOW;
    }

    private final boolean F() {
        OkHttpClient okHttpClientBuild = h.b.b.a.f.d().callTimeout(3L, TimeUnit.SECONDS).build();
        String json = new Gson().toJson(new u(false));
        RequestBody.Companion companion = RequestBody.Companion;
        j.p0.d.r.e(json, "postJson");
        RequestBody requestBodyCreate = companion.create(json, f0.a());
        Request.Builder builder = new Request.Builder();
        String strA = h.b.b.a.f.a("/v1/touch/ink/enable");
        j.p0.d.r.e(strA, "getFullUrl(CloseInk_URL)");
        try {
            Response responseExecute = okHttpClientBuild.newCall(builder.url(strA).post(requestBodyCreate).build()).execute();
            if (responseExecute.code() == 200) {
                Log.d("AgingMainActivity", "关闭Ink成功");
                return true;
            }
            ResponseBody responseBodyBody = responseExecute.body();
            if (responseBodyBody == null) {
                return false;
            }
            Log.d("AgingMainActivity", "关闭Ink失败 Error Response" + responseBodyBody.string());
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    private final x G() {
        x xVarA;
        w wVar = (w) com.seewo.factoryaging.d1.b.a.f("/v1/debugmenu/floatmenu/edge/mode", w.class);
        if (wVar == null || (xVarA = wVar.a()) == null) {
            xVarA = x.SHOW;
        }
        Log.i("AgingMainActivity", "getFloatMenuMode: " + xVarA);
        return xVarA;
    }

    private final void H() {
        try {
            if (Build.VERSION.SDK_INT >= 30) {
                WindowInsetsController insetsController = getWindow().getInsetsController();
                if (insetsController != null) {
                    insetsController.hide(WindowInsets.Type.navigationBars());
                }
            } else {
                View decorView = getWindow().getDecorView();
                j.p0.d.r.e(decorView, "window.decorView");
                decorView.setSystemUiVisibility(6);
            }
            getWindow().setFlags(1024, 1024);
        } catch (Exception e) {
            Log.e("AgingMainActivity", "hideSystemUI: error " + e);
        }
    }

    private final void I() {
        FactoryAgingApplication.e.d().i(new a());
    }

    private final void R() {
        j0();
        final FrameLayout frameLayout = new FrameLayout(this);
        setContentView(frameLayout);
        new Handler().postDelayed(new Runnable() { // from class: com.seewo.factoryaging.i
            @Override // java.lang.Runnable
            public final void run() {
                MainActivity.S(this.b, frameLayout);
            }
        }, 8000L);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void S(MainActivity mainActivity, FrameLayout frameLayout) {
        j.p0.d.r.f(mainActivity, "this$0");
        j.p0.d.r.f(frameLayout, "$holder");
        ProgressDialog progressDialog = mainActivity.r;
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        mainActivity.x = h.c.c.d.b.b();
        Log.d("AgingMainActivity", "延迟设置音量,保存之前音量:" + mainActivity.x);
        com.seewo.factoryaging.e1.i.a.b(mainActivity.O, true);
        ViewParent parent = frameLayout.getParent();
        if (parent == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.view.ViewGroup");
        }
        ViewGroup viewGroup = (ViewGroup) parent;
        viewGroup.removeView(frameLayout);
        androidx.lifecycle.e eVarB = mainActivity.b();
        j.p0.d.r.e(eVarB, "this@MainActivity.lifecycle");
        viewGroup.addView(new com.seewo.factoryaging.a1.b0(mainActivity, eVarB, null, 0, 12, null));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean T(MainActivity mainActivity, Long l2) {
        j.p0.d.r.f(mainActivity, "this$0");
        j.p0.d.r.f(l2, "x");
        mainActivity.v = mainActivity.F();
        Log.e("AgingMainActivity", "关闭Ink: " + mainActivity.v + " x=" + l2.longValue());
        return l2.longValue() == 3 || mainActivity.v;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean U(MainActivity mainActivity, Long l2) {
        j.p0.d.r.f(mainActivity, "this$0");
        j.p0.d.r.f(l2, "x");
        return l2.longValue() == 3 || mainActivity.v;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void V(MainActivity mainActivity, Long l2) {
        j.p0.d.r.f(mainActivity, "this$0");
        if (mainActivity.v) {
            Toast.makeText(mainActivity, R.string.closeInk_toast_success, 1).show();
        } else {
            Toast.makeText(mainActivity, R.string.closeInk_toast_fail, 1).show();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void W(MainActivity mainActivity) {
        j.p0.d.r.f(mainActivity, "this$0");
        try {
            VmanMiddleWare.getInstance().getTouchCtrl().setTouchBurnMode();
            if (VmanMiddleWare.getInstance().getTouchCtrl().getTouchBurnMode() == 1) {
                Log.d("AgingMainActivity", "upgrade touch success");
                String string = mainActivity.getResources().getString(R.string.str_update_touch_success);
                j.p0.d.r.e(string, "this@MainActivity.resour…str_update_touch_success)");
                h.c.a.b.d.e(mainActivity, string);
            } else {
                Log.d("AgingMainActivity", "upgrade touch failed");
                String string2 = mainActivity.getResources().getString(R.string.str_update_touch_failed);
                j.p0.d.r.e(string2, "this@MainActivity.resour….str_update_touch_failed)");
                h.c.a.b.d.e(mainActivity, string2);
            }
        } catch (Error e) {
            Log.e("AgingMainActivity", "burn ffp touch error", e);
            String string3 = mainActivity.getResources().getString(R.string.str_update_touch_failed);
            j.p0.d.r.e(string3, "this@MainActivity.resour….str_update_touch_failed)");
            h.c.a.b.d.e(mainActivity, string3);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void X(MainActivity mainActivity) {
        j.p0.d.r.f(mainActivity, "this$0");
        AlertDialog alertDialog = mainActivity.G;
        if (alertDialog == null) {
            j.p0.d.r.t("dialog");
            throw null;
        }
        if (alertDialog.isShowing()) {
            AlertDialog alertDialog2 = mainActivity.G;
            if (alertDialog2 != null) {
                alertDialog2.dismiss();
            } else {
                j.p0.d.r.t("dialog");
                throw null;
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Y(MainActivity mainActivity, DialogInterface dialogInterface, int i2) {
        j.p0.d.r.f(mainActivity, "this$0");
        Handler handler = mainActivity.I;
        Runnable runnable = mainActivity.F;
        if (runnable == null) {
            j.p0.d.r.t("dialogCancelRunnable");
            throw null;
        }
        handler.removeCallbacks(runnable);
        if (!mainActivity.y) {
            mainActivity.k0();
        }
        mainActivity.finish();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Z(MainActivity mainActivity, DialogInterface dialogInterface) {
        j.p0.d.r.f(mainActivity, "this$0");
        Handler handler = mainActivity.I;
        Runnable runnable = mainActivity.F;
        if (runnable != null) {
            handler.removeCallbacks(runnable);
        } else {
            j.p0.d.r.t("dialogCancelRunnable");
            throw null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void a0() {
        if (com.seewo.vcommons.data.c.j("persist.sys.guest_mode", false)) {
            Log.i("AgingMainActivity", "Turn on Viewsonic Service");
            com.seewo.factoryaging.d1.b.k(com.seewo.factoryaging.d1.b.a, "/v1/system/data/GUEST_MODE_ENABLE", j.k0.j0.c(j.v.a("value", "true")), null, 4, null);
            com.seewo.factoryaging.d1.b.k(com.seewo.factoryaging.d1.b.a, "/v1/system/data/VIEWSONIC_SERVICE_ENABLE", j.k0.j0.c(j.v.a("value", "true")), null, 4, null);
            Intent intent = new Intent("com.ifpdos.debugmenu.ViewsonicServiceSwitch");
            intent.putExtra("enable", true);
            sendBroadcast(intent);
        }
    }

    private final void b0() {
        com.seewo.sdk.interfaces.g gVar;
        Log.d("AgingMainActivity", "start resetAgingConfigs");
        this.y = true;
        com.seewo.factoryaging.boot.b.a.f(false);
        org.greenrobot.eventbus.c.c().o(new com.seewo.factoryaging.t0.b(this.x));
        sendBroadcast(new Intent("com.cvte.intent.action.stop.factory.age"));
        com.seewo.vcommons.data.c.q(0);
        i.a.k.b bVar = this.w;
        if (bVar != null) {
            bVar.dispose();
        }
        h.c.c.c.d().l(this);
        com.seewo.vcommons.data.c.r("persist.sys.forcebackcamera", this.L);
        com.seewo.vcommons.data.c.r("persist.sys.forcefrontcamera", this.M);
        h0(this.D);
        g0(this.E);
        d0(true);
        i0(true);
        f0(this.P);
        c0(true);
        e0(this.Q);
        com.seewo.factoryaging.mic.g.a.o(true);
        if ((true ^ this.N) != h.c.c.j.a.a()) {
            h.c.c.j.a.b(this.N);
        }
        if (com.seewo.vcommons.data.c.j(this.B, false) && (gVar = this.S) != null) {
            h.c.c.f.a.g(gVar);
        }
        if (this.R) {
            com.seewo.factoryaging.mic.g.a.l(false);
        }
        l0();
        if (com.seewo.factoryaging.c1.d.a.j()) {
            VmanMiddleWare.getInstance().getFaultDetect().stopMemoryTest();
        }
        Log.d("AgingMainActivity", "finish resetAgingConfigs");
    }

    private final void c0(boolean z) {
        Intent intent = new Intent("com.seewo.systemtoolbar.TOOLBAR_VISIBLE_CHANGED");
        intent.putExtra("visible", z);
        sendBroadcast(intent);
        Log.d("AgingMainActivity", "setAiFloatUiStatus: [" + z + ']');
    }

    private final void d0(boolean z) {
        com.seewo.factoryaging.d1.b.k(com.seewo.factoryaging.d1.b.a, "/v1/sidebar/visible", j.k0.k0.g(j.v.a("pid", String.valueOf(Process.myPid())), j.v.a("visible", String.valueOf(z))), null, 4, null);
    }

    private final void e0(x xVar) {
        com.seewo.factoryaging.d1.b.k(com.seewo.factoryaging.d1.b.a, "/v1/debugmenu/floatmenu/edge/mode", j.k0.j0.c(j.v.a("mode", xVar)), null, 4, null);
    }

    private final void f0(boolean z) {
        Intent intent;
        if (z) {
            intent = new Intent("com.ifpdos.systembar.action.show_bar");
        } else {
            intent = new Intent("com.ifpdos.systembar.action.HIDE_BAR");
            intent.putExtra("hide_type", 1);
        }
        sendBroadcast(intent);
        Log.d("AgingMainActivity", "setForeignSideBarStatus: " + z);
    }

    private final void g0(int i2) {
        try {
            SystemProperties.set(this.A, String.valueOf(i2));
            Intent intent = new Intent(this.K);
            intent.putExtra("package_name", getPackageName());
            Log.d("AgingMainActivity", this.K + ':' + String.valueOf(i2));
            sendBroadcast(intent);
        } catch (Exception e) {
            Log.d("AgingMainActivity", "setMaxhubSideBarStatus: error " + e);
        }
    }

    private final void h0(int i2) {
        Intent intent = new Intent(this.J);
        intent.putExtra("package_name", getPackageName());
        Log.d("AgingMainActivity", String.valueOf(i2));
        intent.putExtra("flag", i2);
        sendBroadcast(intent);
    }

    private final void i0(boolean z) {
        com.seewo.factoryaging.d1.b.k(com.seewo.factoryaging.d1.b.a, "/v1/statusbar/visible", j.k0.j0.c(j.v.a("value", String.valueOf(z))), null, 4, null);
    }

    private final void j0() {
        ProgressDialog progressDialog = new ProgressDialog(this);
        this.r = progressDialog;
        if (progressDialog != null) {
            progressDialog.setMessage(getResources().getString(R.string.str_init));
        }
        ProgressDialog progressDialog2 = this.r;
        if (progressDialog2 != null) {
            progressDialog2.setCancelable(false);
        }
        ProgressDialog progressDialog3 = this.r;
        if (progressDialog3 != null) {
            progressDialog3.show();
        }
    }

    private final void k0() {
        this.y = true;
        Log.d("AgingMainActivity", "startCloseFactory start ");
        com.seewo.factoryaging.p0.a.a.g();
        b0();
        sendBroadcast(new Intent("com.cvte.intent.action.stop.factory.age"));
        com.seewo.vcommons.data.c.q(0);
        getWindow().clearFlags(128);
        h.c.c.c.d().l(this);
        Log.d("AgingMainActivity", "startCloseFactory close ");
    }

    private final void l0() {
        if (!com.seewo.factoryaging.e1.f.a.p() || this.T == null) {
            return;
        }
        Log.d("AgingMainActivity", "Restoring original RGB LED state: " + this.T);
        com.seewo.factoryaging.d1.b bVar = com.seewo.factoryaging.d1.b.a;
        h0 h0Var = this.T;
        j.p0.d.r.c(h0Var);
        h0 h0Var2 = this.T;
        j.p0.d.r.c(h0Var2);
        h0 h0Var3 = this.T;
        j.p0.d.r.c(h0Var3);
        h0 h0Var4 = this.T;
        j.p0.d.r.c(h0Var4);
        bVar.l("/v1/device/rgb/led/state", j.k0.k0.g(j.v.a("behavior", h0Var.a()), j.v.a("color", h0Var2.b()), j.v.a("flashOnDuration", h0Var3.d()), j.v.a("flashOffDuration", h0Var4.c()), j.v.a("invoker", "FactoryAging")));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void m0() {
        if (com.seewo.factoryaging.e1.f.a.p()) {
            try {
                this.T = (h0) com.seewo.factoryaging.d1.b.a.f("/v1/device/rgb/led/state", h0.class);
                Log.d("AgingMainActivity", "Saved original RGB LED state: " + this.T);
            } catch (Exception e) {
                Log.e("AgingMainActivity", "Failed to get original RGB LED state: " + e);
            }
            com.seewo.factoryaging.d1.b.a.l("/v1/device/rgb/led/state", j.k0.k0.g(j.v.a("behavior", "ON"), j.v.a("color", "WHITE"), j.v.a("flashOnDuration", "500"), j.v.a("flashOffDuration", "500"), j.v.a("invoker", "FactoryAging")));
        }
    }

    @Override // androidx.appcompat.app.c, g.h.a.d, androidx.core.app.d, android.app.Activity
    protected void onCreate(Bundle bundle) {
        Object objA;
        Log.d("AgingMainActivity", "Start AgingMainActivity");
        requestWindowFeature(1);
        super.onCreate(bundle);
        sendBroadcast(new Intent("com.cvte.intent.action.start.factory.age"));
        R();
        com.seewo.factoryaging.e1.a.c().a(this);
        h.c.b.a aVarE = h.c.b.a.e(this);
        if (aVarE != null) {
            aVarE.b();
        }
        if (com.seewo.factoryaging.boot.b.a.a()) {
            com.seewo.factoryaging.boot.b.a.g(true);
        }
        com.seewo.factoryaging.boot.b.a.f(true);
        String strI = com.seewo.vcommons.data.c.i("persist.sys.forcebackcamera", "-1");
        j.p0.d.r.e(strI, "getProperty(BACK_CAMERA_ID, \"-1\")");
        this.L = strI;
        String strI2 = com.seewo.vcommons.data.c.i("persist.sys.forcefrontcamera", "-1");
        j.p0.d.r.e(strI2, "getProperty(FRONT_CAMERA_ID, \"-1\")");
        this.M = strI2;
        com.seewo.vcommons.data.c.r("persist.sys.forcebackcamera", "-1");
        com.seewo.vcommons.data.c.r("persist.sys.forcefrontcamera", "-1");
        this.N = h.c.c.j.a.a();
        h.c.c.j.a.b(false);
        boolean zA = h.c.c.i.a.a();
        Log.d("AgingMainActivity", "initSwitchStatus: typecPhyStatus = " + zA);
        if (!zA) {
            h.c.c.i.a.b(true);
        }
        if (com.seewo.vcommons.data.c.j(this.B, false) && h.c.c.f.a.e() != com.seewo.sdk.interfaces.g.ON) {
            this.S = h.c.c.f.a.e();
            h.c.c.f.a.g(com.seewo.sdk.interfaces.g.ON);
        }
        if (com.seewo.factoryaging.e1.f.a.w()) {
            this.w = i.a.d.p(0L, 1L, TimeUnit.SECONDS).k(new i.a.m.e() { // from class: com.seewo.factoryaging.f
                @Override // i.a.m.e
                public final boolean test(Object obj) {
                    return MainActivity.T(this.a, (Long) obj);
                }
            }).E(new i.a.m.e() { // from class: com.seewo.factoryaging.c
                @Override // i.a.m.e
                public final boolean test(Object obj) {
                    return MainActivity.U(this.a, (Long) obj);
                }
            }).C(i.a.q.a.b()).u(i.a.j.b.a.a()).x(new i.a.m.c() { // from class: com.seewo.factoryaging.d
                @Override // i.a.m.c
                public final void accept(Object obj) {
                    MainActivity.V(this.a, (Long) obj);
                }
            });
        }
        if (a.b.a == 8) {
            com.seewo.vcommons.data.c.r(this.u, "logcatd");
            if (this.t) {
                for (int i2 = 1; i2 < 5; i2++) {
                    w0 w0Var = new w0();
                    this.s = w0Var;
                    if (w0Var != null) {
                        w0Var.start();
                    }
                }
            }
        }
        if (j.p0.d.r.a(com.seewo.vcommons.data.c.i("persist.sys.ffp.enable", "0"), "1")) {
            Log.d("AgingMainActivity", "start burn ffp touch");
            this.C.submit(new Runnable() { // from class: com.seewo.factoryaging.b
                @Override // java.lang.Runnable
                public final void run() {
                    MainActivity.W(this.b);
                }
            });
        }
        h0(4);
        g0(4);
        d0(false);
        i0(false);
        this.Q = G();
        e0(x.TOUCH_AUTO_HIDE);
        try {
            q.a aVar = j.q.b;
            String str = SystemProperties.get("persist.sys.bar.visibility", HttpUrl.FRAGMENT_ENCODE_SET);
            Log.d("AgingMainActivity", "get PROP_SYSTEMBAR_VISIBLE_STATUS: " + str);
            objA = Boolean.valueOf(str == null || str.length() == 0 ? true : j.p0.d.r.a(str, "0"));
            j.q.a(objA);
        } catch (Throwable th) {
            q.a aVar2 = j.q.b;
            objA = j.r.a(th);
            j.q.a(objA);
        }
        Throwable thC = j.q.c(objA);
        if (thC != null) {
            Log.e("AgingMainActivity", "get PROP_SYSTEMBAR_VISIBLE_STATUS error: " + thC);
            objA = Boolean.TRUE;
        }
        this.P = ((Boolean) objA).booleanValue();
        f0(false);
        c0(false);
        com.seewo.factoryaging.mic.g.a.o(false);
        H();
        Log.d("AgingMainActivity", "isUdiInit: " + FactoryAgingApplication.e.d().f());
        I();
        Settings.System.putString(getContentResolver(), "screen_off_timeout", "2147483647");
        if (com.seewo.factoryaging.p0.c.a.a()) {
            com.seewo.factoryaging.p0.a.a.f(com.seewo.factoryaging.p0.e.a.a());
            this.F = new Runnable() { // from class: com.seewo.factoryaging.h
                @Override // java.lang.Runnable
                public final void run() {
                    MainActivity.X(this.b);
                }
            };
        }
    }

    @Override // android.app.Activity
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.action_bar_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override // androidx.appcompat.app.c, g.h.a.d, android.app.Activity
    protected void onDestroy() {
        super.onDestroy();
        getWindow().clearFlags(128);
        if (a.b.a == 8) {
            com.seewo.vcommons.data.c.r(this.u, "clear");
        }
        if (com.seewo.factoryaging.p0.c.a.a()) {
            com.seewo.factoryaging.p0.a.a.g();
        }
        System.exit(0);
    }

    @Override // androidx.appcompat.app.c, android.app.Activity, android.view.KeyEvent.Callback
    public boolean onKeyDown(int i2, KeyEvent keyEvent) {
        j.p0.d.r.f(keyEvent, "event");
        if (i2 != 4) {
            return super.onKeyDown(i2, keyEvent);
        }
        Log.d("AgingMainActivity", "receive KEYCODE_BACK keyDown");
        if (!com.seewo.factoryaging.p0.c.a.a() && !this.y) {
            Log.d("AgingMainActivity", "close factory aging totally");
            k0();
            finish();
            return super.onKeyDown(i2, keyEvent);
        }
        if (com.seewo.factoryaging.d1.b.a.h() && !this.y) {
            Log.d("AgingMainActivity", "close factory aging totally cause production mode enable");
            k0();
            finish();
            return super.onKeyDown(i2, keyEvent);
        }
        StringBuilder sb = new StringBuilder(getString(R.string.str_quit_aging));
        StringBuilder sb2 = new StringBuilder();
        Log.d("AgingMainActivity", "aging time :" + FactoryAgingApplication.e.a());
        sb.append(' ' + getString(R.string.str_xml_aging_time_head) + " : " + FactoryAgingApplication.e.a());
        if (!com.seewo.factoryaging.p0.a.a.d().isEmpty()) {
            this.H = "-65536";
            sb2.append(getString(R.string.str_detected_error));
            for (v vVar : com.seewo.factoryaging.p0.a.a.d()) {
                sb2.append("\n- " + vVar.c() + ": " + getString(R.string.str_error_times) + ':' + vVar.a() + ',' + getString(R.string.str_detected_first_error) + ':' + vVar.b());
            }
        } else {
            this.H = "-16711936";
            sb2.append("\n\n " + getString(R.string.str_detected_no_error));
        }
        Handler handler = this.I;
        Runnable runnable = this.F;
        if (runnable == null) {
            j.p0.d.r.t("dialogCancelRunnable");
            throw null;
        }
        handler.removeCallbacks(runnable);
        Handler handler2 = this.I;
        Runnable runnable2 = this.F;
        if (runnable2 == null) {
            j.p0.d.r.t("dialogCancelRunnable");
            throw null;
        }
        handler2.postDelayed(runnable2, 15000L);
        AlertDialog.Builder title = new AlertDialog.Builder(this).setTitle(sb);
        StringBuilder sb3 = new StringBuilder();
        sb3.append("<font color=");
        String str = this.H;
        if (str == null) {
            j.p0.d.r.t("dialogContentColor");
            throw null;
        }
        sb3.append(str);
        sb3.append('>');
        String string = sb2.toString();
        j.p0.d.r.e(string, "dialogContent.toString()");
        sb3.append(j.u0.q.z(string, "\n", "<br>", false, 4, null));
        sb3.append("</font>");
        AlertDialog alertDialogShow = title.setMessage(Html.fromHtml(sb3.toString())).setPositiveButton(getString(R.string.str_yes), new DialogInterface.OnClickListener() { // from class: com.seewo.factoryaging.e
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i3) {
                MainActivity.Y(this.b, dialogInterface, i3);
            }
        }).setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: com.seewo.factoryaging.g
            @Override // android.content.DialogInterface.OnDismissListener
            public final void onDismiss(DialogInterface dialogInterface) {
                MainActivity.Z(this.b, dialogInterface);
            }
        }).setNegativeButton(R.string.str_no, (DialogInterface.OnClickListener) null).show();
        j.p0.d.r.e(alertDialogShow, "Builder(this)\n          …)\n                .show()");
        this.G = alertDialogShow;
        return super.onKeyDown(i2, keyEvent);
    }

    @Override // android.app.Activity, android.view.KeyEvent.Callback
    public boolean onKeyUp(int i2, KeyEvent keyEvent) {
        j.p0.d.r.f(keyEvent, "event");
        if (i2 != 4) {
            return super.onKeyUp(i2, keyEvent);
        }
        Log.d("AgingMainActivity", "receive KEYCODE_BACK keyUp");
        return true;
    }

    @Override // android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        j.p0.d.r.f(menuItem, "item");
        if (menuItem.getItemId() == R.id.action_exit) {
            finish();
        }
        return super.onOptionsItemSelected(menuItem);
    }

    @Override // g.h.a.d, android.app.Activity
    protected void onResume() {
        super.onResume();
        getWindow().addFlags(128);
        h.c.c.c.d().j(this);
    }

    @OnEventOfOS(threadMode = ThreadMode.MAIN)
    public final void onScreenStateChanged(OSEvent.ScreenStateChanged screenStateChanged) {
        j.p0.d.r.f(screenStateChanged, "event");
        if (screenStateChanged.isScreenOn) {
            return;
        }
        h.c.c.f.a.h(true);
        Log.i("AgingMainActivity", "Bright Screen ");
    }

    @Override // androidx.appcompat.app.c, g.h.a.d, android.app.Activity
    protected void onStop() {
        super.onStop();
        Log.d("AgingMainActivity", "Aging MainActivity onStop");
        if (!this.y && !SystemProperties.getBoolean("sys.rs232.project.id", false)) {
            b0();
        }
        if (h.c.d.b.a.b()) {
            com.seewo.factoryaging.e1.b.a.a("com.i3_technologies.system.service", true);
            Log.w("AgingMainActivity", "enable pir: com.i3_technologies.system.service");
        }
        if (com.seewo.factoryaging.e1.f.a.t()) {
            com.seewo.factoryaging.e1.b.a.a("com.benq.meetingroom", true);
            Log.w("AgingMainActivity", "enable metting room: com.benq.meetingroom");
        }
        finish();
    }
}
