package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.base.ItemButtonAction;
import com.ifpdos.debugmenu.event.ActivityEvent;
import com.seewo.sdk.SDKAudioHelper;
import com.seewo.sdk.SDKConfigureHelper;
import d.b.a.a.a;
import d.f.a.c1;
import d.f.a.p2.p0;
import d.f.a.p2.t0;
import d.f.a.r2.j3.f;
import d.f.a.r2.n2;
import d.f.a.r2.u2;
import d.f.a.s1.e;
import d.i.a.a.d;
import d.i.f.a.a;
import java.io.File;
import java.util.HashMap;
import k.c.a.c;

/* JADX INFO: loaded from: classes.dex */
public class TvResetAction extends ItemButtonAction implements c1 {
    private static final int LANEMODE_2 = 0;
    private static final int LANEMODE_4 = 1;
    private static final String TAG = "TvResetAction";
    private long curTime;
    public e initTVCallBack;
    private e mActionFinishCallback;
    private Context mContext;
    private Runnable mInitTVRunnable;
    private boolean mIsConfirm;
    private volatile boolean mIsDialogShowing;
    private boolean mIsShutDown;
    private Thread mThread;
    private p0 upgradeHandler;

    public TvResetAction(Context context) {
        super(context);
        this.mIsConfirm = false;
        this.upgradeHandler = t0.a;
        this.mIsDialogShowing = false;
        this.mIsShutDown = false;
        this.curTime = 0L;
        this.initTVCallBack = new e() { // from class: com.ifpdos.debugmenu.action.TvResetAction.1
            @Override // d.f.a.s1.e
            public void call() {
                if (!TvResetAction.this.mIsConfirm) {
                    a.X(c.c());
                }
                if (TvResetAction.this.mThread != null) {
                    TvResetAction.this.mThread.interrupt();
                }
                TvResetAction.this.mThread = new Thread(TvResetAction.this.mInitTVRunnable);
                TvResetAction.this.mThread.start();
            }
        };
        this.mInitTVRunnable = new Runnable() { // from class: com.ifpdos.debugmenu.action.TvResetAction.2
            @Override // java.lang.Runnable
            public void run() {
                d.i.f.c.c.l("persist.sys.factory.reset.flag", "true");
                c.c().g(new ActivityEvent.ShowProgressDialog(true));
                if (d.i.f.b.a.f()) {
                    n2.i(TvResetAction.this.mContext);
                    n2.h();
                }
                if (d.i.f.b.a.c()) {
                    d.i.c.a.b("rmmod XQDTouchMA");
                }
                SDKConfigureHelper.I.setMachineActivation(false);
                SDKAudioHelper.I.setMute(true);
                HashMap map = new HashMap();
                map.put("isClearData", "true");
                map.put("isPcOff", "true");
                map.put("isShutDown", TvResetAction.this.mIsShutDown ? "true" : "false");
                d.f.a.r2.j3.e.a.c("/v1/system/reset/system", map, new f(TvResetAction.this.mContext));
                try {
                    Thread.sleep(60000L);
                } catch (InterruptedException e2) {
                    d.b(TvResetAction.TAG, e2);
                    Thread.currentThread().interrupt();
                }
                c.c().g(new ActivityEvent.ShowProgressDialog(false));
                a.I(R.string.str_debug_inittv_error_hint, 1, c.c());
                if (TvResetAction.this.mActionFinishCallback != null) {
                    TvResetAction.this.mActionFinishCallback.call();
                }
            }
        };
        this.mContext = context;
    }

    private boolean isIsConfigShutDown() {
        return this.mCustomConfig.equals("1");
    }

    private void restoreDefaultAnimation() {
        if (d.i.f.b.a.a() && a.C0058a.a == 5) {
            restoreFile("/etc/bootanimation.zip", "/atv/bootvideo/bootanimation.zip");
        }
    }

    private void restoreFile(String str, String str2) {
        if (new File(str).exists()) {
            startCopyFile(str, str2);
        }
    }

    private final void safeSleep(long j2) {
        try {
            Thread.sleep(j2);
        } catch (InterruptedException unused) {
        }
    }

    private void showDialog() {
        if (this.mIsDialogShowing) {
            return;
        }
        this.mIsDialogShowing = true;
        View viewInflate = LayoutInflater.from(this.mContext).inflate(R.layout.tv_reset_dialog, (ViewGroup) null, false);
        Button button = (Button) viewInflate.findViewById(R.id.reboot_button);
        Button button2 = (Button) viewInflate.findViewById(R.id.off_button);
        button.setOnClickListener(new View.OnClickListener() { // from class: d.f.a.p1.e7
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f2721b.i(view);
            }
        });
        button2.setOnClickListener(new View.OnClickListener() { // from class: d.f.a.p1.d7
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f2707b.j(view);
            }
        });
        viewInflate.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() { // from class: d.f.a.p1.z6
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                d.b.a.a.a.W(k.c.a.c.c());
            }
        });
        c.c().g(new ActivityEvent.ShowNormalDialog(viewInflate, new DialogInterface.OnCancelListener() { // from class: d.f.a.p1.b7
            @Override // android.content.DialogInterface.OnCancelListener
            public final void onCancel(DialogInterface dialogInterface) {
                this.f2682b.k(dialogInterface);
            }
        }));
    }

    private void startCopyFile(String str, String str2) {
        String str3 = u2.a;
        if (!d.b.a.a.a.a0(str2)) {
            d.i.c.a.c(d.b.a.a.a.p("touch ", str2) + " && " + d.b.a.a.a.p("chown system ", str2) + " && " + d.b.a.a.a.p("chmod 0660 ", str2), true);
        }
        u2.c(str, str2);
        d.i.c.a.b("chmod 644 " + str2);
    }

    public int getResetDialogHint() {
        String strX = c.n.a.x();
        return (strX == null || strX.isEmpty()) ? R.string.str_debug_inittv_no_sn_hint : R.string.str_debug_inittv_hint;
    }

    public int getResetDialogTips() {
        return R.string.str_debug_inittv_hint;
    }

    public int getResetDialogTitle() {
        return R.string.str_debug_inittv;
    }

    public /* synthetic */ void h(DialogInterface dialogInterface) {
        e eVar = this.mActionFinishCallback;
        if (eVar != null) {
            eVar.call();
        }
    }

    public /* synthetic */ void i(View view) {
        this.mIsShutDown = false;
        this.initTVCallBack.call();
    }

    public /* synthetic */ void j(View view) {
        this.mIsShutDown = true;
        this.initTVCallBack.call();
    }

    public /* synthetic */ void k(DialogInterface dialogInterface) {
        this.mIsDialogShowing = false;
        e eVar = this.mActionFinishCallback;
        if (eVar != null) {
            eVar.call();
        }
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemButtonAction, d.f.a.j2.e.e.a
    public void onClick(Context context, d.f.a.j2.e.e eVar) {
        if (!n2.a()) {
            c.c().g(new ActivityEvent.ShowWarningToast(R.string.str_debug_inittv_sn_error));
            return;
        }
        if (n2.f()) {
            View viewInflate = LayoutInflater.from(this.mContext).inflate(R.layout.tv_reset_preloader_b_dialog, (ViewGroup) null, false);
            ((Button) viewInflate.findViewById(R.id.confirm_button)).setOnClickListener(new View.OnClickListener() { // from class: d.f.a.p1.a7
                @Override // android.view.View.OnClickListener
                public final void onClick(View view) {
                    d.b.a.a.a.X(k.c.a.c.c());
                }
            });
            c.c().g(new ActivityEvent.ShowNormalDialog(viewInflate, true));
        } else if (isIsConfigShutDown()) {
            showDialog();
        } else {
            c.c().g(new ActivityEvent.ShowDebugMenuDialog(R.string.str_debug_inittv, getResetDialogHint(), this.initTVCallBack));
        }
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemButtonAction, d.f.a.j2.e.e.a
    public void onLongClick(Context context, d.f.a.j2.e.e eVar) {
    }

    @Override // d.f.a.c1
    public void quickAction(e eVar) {
        if (!n2.a()) {
            c.c().g(new ActivityEvent.ShowWarningToast(R.string.str_debug_inittv_sn_error));
            eVar.call();
            return;
        }
        this.mActionFinishCallback = eVar;
        if (this.mIsConfirm) {
            this.initTVCallBack.call();
        } else if (isIsConfigShutDown()) {
            showDialog();
        } else {
            c.c().g(new ActivityEvent.ShowCenterDebugMenuDialog(getResetDialogTitle(), getResetDialogTips(), this.initTVCallBack, new DialogInterface.OnCancelListener() { // from class: d.f.a.p1.c7
                @Override // android.content.DialogInterface.OnCancelListener
                public final void onCancel(DialogInterface dialogInterface) {
                    this.f2693b.h(dialogInterface);
                }
            }));
        }
    }

    public void setConfirm() {
        this.mIsConfirm = true;
    }

    public boolean shouldEraseSdCard() {
        return true;
    }
}
