package com.ifpdos.debugmenu.action;

import android.app.KeyguardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.UserManager;
import android.view.View;
import c.n.a;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.AndroidEnableAction;
import com.ifpdos.debugmenu.action.base.ItemSwitchAction;
import com.ifpdos.debugmenu.event.ActivityEvent;
import com.seewo.sdk.SDKDeviceHelper;
import com.seewo.sdk.SDKSourceHelper;
import com.seewo.sdk.interfaces.ISDKSourceHelper;
import com.seewo.sdk.model.SDKSourceModel;
import com.seewo.sdk.util.RLog;
import d.f.a.s1.e;
import d.i.f.c.c;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class AndroidEnableAction extends ItemSwitchAction {
    private static final String PERSIST_SYS_SHOW_NOTIFYBAR = "persist.sys.show_notifybar";
    private static final String PERSIST_SYS_SHOW_STATUSBAR = "persist.sys.show_statusbar";
    private final List<String> flavorList;
    private boolean isEdlaFlavor;
    private final boolean mIsNeedToShowNotifyBar;

    public AndroidEnableAction(Context context) {
        super(context);
        ArrayList arrayList = new ArrayList();
        this.flavorList = arrayList;
        this.isEdlaFlavor = false;
        String strE = c.e("ro.cvte.flavor.name");
        if (strE != null) {
            this.isEdlaFlavor = strE.contains("edla") || "cleartouch".equals(strE);
        }
        initFlavorList();
        this.mIsNeedToShowNotifyBar = arrayList.contains(strE) || this.isEdlaFlavor;
    }

    private void edlaFlavorSwitch(boolean z) {
        if (z) {
            setAndroidEnable(true);
            return;
        }
        if (!isOwner()) {
            final e eVar = new e() { // from class: d.f.a.p1.g
                @Override // d.f.a.s1.e
                public final void call() {
                    this.a.h();
                }
            };
            final e eVar2 = new e() { // from class: d.f.a.p1.h
                /* JADX WARN: Multi-variable type inference failed */
                @Override // d.f.a.s1.e
                public final void call() {
                    AndroidEnableAction androidEnableAction = this.a;
                    androidEnableAction.mSave = null;
                    ((d.f.a.j2.e.j) androidEnableAction.mViewModel).f();
                    c.n.a.o();
                }
            };
            k.c.a.c.c().g(new ActivityEvent.ShowDebugMenuDialog(R.string.str_enable_android_title, R.string.str_back_to_admin, R.string.str_goto_screen_lock_setting, R.string.cancel, new e() { // from class: d.f.a.r2.h
                @Override // d.f.a.s1.e
                public final void call() {
                    d.f.a.s1.e eVar3 = eVar;
                    if (eVar3 != null) {
                        eVar3.call();
                    }
                }
            }, new DialogInterface.OnCancelListener() { // from class: d.f.a.r2.p
                @Override // android.content.DialogInterface.OnCancelListener
                public final void onCancel(DialogInterface dialogInterface) {
                    d.f.a.s1.e eVar3 = eVar2;
                    if (eVar3 != null) {
                        eVar3.call();
                    }
                }
            }));
        } else {
            if (!isDeviceSecured()) {
                setAndroidEnable(false);
                return;
            }
            e eVar3 = new e() { // from class: d.f.a.p1.f
                @Override // d.f.a.s1.e
                public final void call() {
                    this.a.i();
                }
            };
            final e eVar4 = new e() { // from class: d.f.a.p1.e
                /* JADX WARN: Multi-variable type inference failed */
                @Override // d.f.a.s1.e
                public final void call() {
                    AndroidEnableAction androidEnableAction = this.a;
                    Objects.requireNonNull(androidEnableAction);
                    c.n.a.o();
                    androidEnableAction.mSave = null;
                    ((d.f.a.j2.e.j) androidEnableAction.mViewModel).f();
                }
            };
            k.c.a.c.c().g(new ActivityEvent.ShowDebugMenuDialog(R.string.str_enable_android_title, R.string.str_clear_screen_lock_tips, R.string.str_goto_screen_lock_setting, R.string.str_keep_screen_lock, eVar3, new DialogInterface.OnCancelListener() { // from class: d.f.a.r2.n
                @Override // android.content.DialogInterface.OnCancelListener
                public final void onCancel(DialogInterface dialogInterface) {
                    eVar4.call();
                }
            }, new View.OnClickListener() { // from class: d.f.a.p1.i
                @Override // android.view.View.OnClickListener
                public final void onClick(View view) {
                    this.f2765b.j(view);
                }
            }));
        }
    }

    private void initFlavorList() {
        this.flavorList.add("i3_pro");
    }

    private boolean isDeviceSecured() {
        return ((KeyguardManager) this.mContext.getSystemService("keyguard")).isKeyguardSecure();
    }

    private boolean isOwner() {
        return ((UserManager) this.mContext.getSystemService("user")).isSystemUser();
    }

    private void openSecuritySettings() {
        k.c.a.c.c().g(new ActivityEvent.StartActivityWithIntent(new Intent("android.settings.SECURITY_SETTINGS")));
    }

    private void openUserSettings() {
        k.c.a.c.c().g(new ActivityEvent.StartActivityWithIntent(new Intent("android.settings.USER_SETTINGS")));
    }

    private void setAndroidEnable(boolean z) {
        k.c.a.c.c().g(new ActivityEvent.ShowToast("reboot to work..."));
        boolean z2 = isKeepToolbar() || z;
        if (z) {
            SDKDeviceHelper.I.setAndroidEnable(true, true);
        } else {
            setSourceVisibleIfNecessary();
            SDKDeviceHelper.I.setAndroidEnable(false, z2);
        }
        if (this.mIsNeedToShowNotifyBar) {
            String str = z ? "true" : "false";
            c.l(PERSIST_SYS_SHOW_NOTIFYBAR, str);
            c.l(PERSIST_SYS_SHOW_STATUSBAR, str);
        }
    }

    private void setSourceVisibleIfNecessary() {
        int i2 = 0;
        for (SDKSourceModel sDKSourceModel : SDKSourceHelper.I.getExistentSourceModelList()) {
            if (sDKSourceModel.visible && sDKSourceModel.sourceItem != ISDKSourceHelper.SDKSourceItem.ANDROID) {
                i2++;
            }
        }
        if (i2 == 0) {
            RLog.i("SetAndroidEnabled", "set HDMI1 source visible to true");
            SDKSourceHelper.I.setSourceVisible(ISDKSourceHelper.SDKSourceItem.HDMI1, true);
        }
    }

    public /* synthetic */ void h() {
        a.o();
        openUserSettings();
    }

    public /* synthetic */ void i() {
        a.o();
        openSecuritySettings();
    }

    public boolean isKeepToolbar() {
        return false;
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSwitchAction
    public boolean isOn(Context context) {
        return c.i();
    }

    public /* synthetic */ void j(View view) {
        a.o();
        setAndroidEnable(false);
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSwitchAction
    public void onSwitch(Context context, boolean z) {
        if (this.isEdlaFlavor) {
            edlaFlavorSwitch(z);
        } else {
            setAndroidEnable(z);
        }
    }
}
