Search in sources :

Example 1 with TextToast

use of com.ryuunoakaihitomi.rebootmenu.util.TextToast in project rebootmenu by ryuunoakaihitomi.

the class UnRootMode method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        UIUtils.transparentStatusBar(this);
    mainDialog = UIUtils.LoadDialog(ConfigManager.get(ConfigManager.WHITE_THEME), this);
    mainDialog.setTitle(getString(R.string.unroot_title));
    String[] uiTextList;
    DialogInterface.OnClickListener mainListener = new DialogInterface.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            switch(i) {
                case 0:
                    lockscreen();
                    break;
                case 1:
                    // 调用系统电源菜单无需二次确认
                    accessbilityon(UnRootMode.this);
                    break;
                case 2:
                    initCN();
                    reboot(devicePolicyManager, componentName, UnRootMode.this);
                    break;
                case 3:
                    mainDialog.setTitle(getString(R.string.confirm_operation));
                    mainDialog.setItems(null, null);
                    mainDialog.setNeutralButton(R.string.yes, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // 警告:在26中弃用,之后可能只能使用wipeData解除。在今后可能要移除重启功能。
                            devicePolicyManager.clearDeviceOwnerApp(getPackageName());
                            new TextToast(getApplicationContext(), getString(R.string.clear_owner_notice));
                            finish();
                        }
                    });
                    UIUtils.alphaShow(mainDialog.create(), UIUtils.TransparentLevel.CONFIRM);
            }
        }
    };
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        // 检查Device Owner
        if (devicePolicyManager.isDeviceOwnerApp(getPackageName()))
            uiTextList = new String[] { getString(R.string.lockscreen), getString(R.string.system_power_dialog), getString(R.string.reboot), getString(R.string.clear_owner) };
        else {
            uiTextList = new String[] { getString(R.string.lockscreen), getString(R.string.system_power_dialog) };
            new TextToast(getApplicationContext(), true, getString(R.string.device_owner_disabled));
        }
    } else // Android7.0以下不支持设备管理器重启
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        uiTextList = new String[] { getString(R.string.lockscreen), getString(R.string.system_power_dialog) };
        new TextToast(getApplicationContext(), getString(R.string.nougat_notice));
    } else {
        // Android5.0以下不支持系统电源菜单
        uiTextList = new String[] { getString(R.string.lockscreen) };
        new TextToast(getApplicationContext(), getString(R.string.lollipop_notice));
    }
    mainDialog.setItems(uiTextList, mainListener);
    // 是否需要退出键
    if (!ConfigManager.get(ConfigManager.CANCELABLE))
        mainDialog.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        });
    // 帮助
    mainDialog.setNegativeButton(R.string.help, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            UIUtils.helpDialog(UnRootMode.this, mainDialog, ConfigManager.get(ConfigManager.CANCELABLE), ConfigManager.get(ConfigManager.WHITE_THEME));
        }
    });
    // egg
    mainDialog.setNeutralButton(" ", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            new TextToast(getApplicationContext(), true, "とまれかくもあはれ\nほたるほたるおいで");
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://music.163.com/#/song?id=22765874"));
            startActivity(intent);
            finish();
        }
    });
    // 不按退出的退出监听
    mainDialog.setCancelable(ConfigManager.get(ConfigManager.CANCELABLE));
    mainDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface p1) {
            new TextToast(getApplicationContext(), false, getString(R.string.exit_notice));
            finish();
        }
    });
    UIUtils.alphaShow(mainDialog.create(), UIUtils.TransparentLevel.NORMAL);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(broadcastReceiver, intentFilter);
}
Also used : IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) TextToast(com.ryuunoakaihitomi.rebootmenu.util.TextToast) Intent(android.content.Intent)

Example 2 with TextToast

use of com.ryuunoakaihitomi.rebootmenu.util.TextToast in project rebootmenu by ryuunoakaihitomi.

the class UnRootMode method accessbilityon.

/**
 * 打开辅助服务设置或者发送执行广播
 *
 * @param activity a
 */
static void accessbilityon(Activity activity) {
    if (!isAccessibilitySettingsOn(activity.getApplicationContext())) {
        new TextToast(activity.getApplicationContext(), activity.getString(R.string.service_disabled));
        Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
        activity.startActivity(intent);
    } else {
        activity.sendBroadcast(new Intent(activity.getString(R.string.service_action_key)));
    }
    activity.finish();
}
Also used : TextToast(com.ryuunoakaihitomi.rebootmenu.util.TextToast) Intent(android.content.Intent)

Example 3 with TextToast

use of com.ryuunoakaihitomi.rebootmenu.util.TextToast in project rebootmenu by ryuunoakaihitomi.

the class RootMode method onCreate.

@SuppressWarnings("DanglingJavadoc")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 只有API Level 23或以上才需要做此妥协
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        UIUtils.transparentStatusBar(this);
    }
    final AlertDialog.Builder mainDialog = UIUtils.LoadDialog(ConfigManager.get(ConfigManager.WHITE_THEME), this);
    mainDialog.setTitle(getString(R.string.root_title));
    // 默认模式功能列表
    final String[] uiTextList = { getString(R.string.reboot), getString(R.string.shutdown), getString(R.string.recovery), getString(R.string.fastboot), getString(R.string.hot_reboot), getString(R.string.reboot_ui), getString(R.string.safety), getString(R.string.lockscreen) };
    // 默认模式命令列表
    final String[] shellList = { "svc power reboot", "svc power shutdown", "svc power reboot recovery", "svc power reboot bootloader", "setprop ctl.restart zygote", "busybox pkill com.android.systemui", "setprop persist.sys.safemode 1", "input keyevent 26" };
    // 强制模式功能列表
    final String[] uiTextListForce = { "*" + uiTextList[0], "*" + uiTextList[1], "*" + uiTextList[2], "*" + uiTextList[3], uiTextList[4], uiTextList[5], "*" + uiTextList[6], uiTextList[7] };
    // 强制模式命令列表
    final String[] shellListForce = { "reboot", "reboot -p", "reboot recovery", "reboot bootloader", shellList[4], shellList[5], shellList[6], shellList[7] };
    // 不按退出的退出监听
    final DialogInterface.OnCancelListener exitListener = new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface p1) {
            new TextToast(getApplicationContext(), false, getString(R.string.exit_notice));
            finish();
        }
    };
    // 功能监听
    final DialogInterface.OnClickListener mainListener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, final int i) {
            // 锁屏就直接锁了,不需要确认。
            if (i != 7 && !ConfigManager.get(ConfigManager.NO_NEED_TO_COMFIRM)) {
                // 确认界面显示(?YN)
                final String[] confirmList = { getString(R.string.confirm_operation), getString(R.string.yes), getString(R.string.no) };
                // 在后面显示刚刚选择的功能名称
                if (!isForceMode)
                    mainDialog.setTitle(getString(R.string.confirm_operation) + " " + uiTextList[i]);
                else
                    mainDialog.setTitle(getString(R.string.confirm_operation) + " " + uiTextListForce[i]);
                // 点击是或者否的监听
                DialogInterface.OnClickListener confirmListener = new DialogInterface.OnClickListener() {

                    @Override
                    public // iConfirm不和i混淆
                    void onClick(DialogInterface dialogInterface, int iConfirm) {
                        // 若否
                        if (iConfirm == 1) {
                            new TextToast(getApplicationContext(), getString(R.string.no_seleted_notice));
                            finish();
                        } else
                            exeKernel(shellList, shellListForce, i);
                    }
                };
                // YN
                String[] confirmSelect = { confirmList[1], confirmList[2] };
                mainDialog.setItems(confirmSelect, confirmListener);
                // 取消之前设置的底部按钮
                mainDialog.setNeutralButton(null, null);
                mainDialog.setPositiveButton(null, null);
                mainDialog.setNegativeButton(null, null);
                UIUtils.alphaShow(mainDialog.create(), UIUtils.TransparentLevel.CONFIRM);
            } else
                // 直接执行(无需确认)
                exeKernel(shellList, shellListForce, i);
        }
    };
    mainDialog.setItems(uiTextList, mainListener);
    // 是否需要退出键
    if (!ConfigManager.get(ConfigManager.CANCELABLE))
        mainDialog.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        });
    // 帮助
    mainDialog.setNegativeButton(R.string.help, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            UIUtils.helpDialog(RootMode.this, mainDialog, ConfigManager.get(ConfigManager.CANCELABLE), ConfigManager.get(ConfigManager.WHITE_THEME));
        }
    });
    /**
     * 经代码查阅对比,发现在Android4.3中加入了svc控制关机的功能。
     *
     * @see https://github.com/aosp-mirror/platform_frameworks_base/commit/62aad7f66fcd673831029eb96dd49c95f76b17bd
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        mainDialog.setNeutralButton(R.string.mode_switch, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                // 没问题就按照用户的选择
                if (!isForceMode) {
                    mainDialog.setItems(uiTextListForce, mainListener);
                    isForceMode = true;
                    new TextToast(getApplicationContext(), getString(R.string.force_mode));
                } else {
                    mainDialog.setItems(uiTextList, mainListener);
                    isForceMode = false;
                    new TextToast(getApplicationContext(), getString(R.string.normal_mode));
                }
                UIUtils.alphaShow(mainDialog.create(), UIUtils.TransparentLevel.NORMAL);
            }
        });
    } else {
        // 不能兼容就只能选择强制
        mainDialog.setItems(uiTextListForce, mainListener);
        isForceMode = true;
        new TextToast(getApplicationContext(), getString(R.string.normal_not_support));
    }
    // 是否取消(与是否需要退出键相对)
    mainDialog.setCancelable(ConfigManager.get(ConfigManager.CANCELABLE));
    mainDialog.setOnCancelListener(exitListener);
    UIUtils.alphaShow(mainDialog.create(), UIUtils.TransparentLevel.NORMAL);
    // 亮屏监听,防止在应用开启熄屏又亮屏时显示警告toast
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(broadcastReceiver, intentFilter);
}
Also used : AlertDialog(android.app.AlertDialog) IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) TextToast(com.ryuunoakaihitomi.rebootmenu.util.TextToast)

Example 4 with TextToast

use of com.ryuunoakaihitomi.rebootmenu.util.TextToast in project rebootmenu by ryuunoakaihitomi.

the class RootMode method onRestart.

// 目前已知的问题有启动失败和主题应用失败
@Override
protected void onRestart() {
    // 由于onRestart比SCREEN_ON更早执行,因此在此设置延迟
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (!isScreenOn)
                new TextToast(getApplicationContext(), getString(R.string.activity_onrestart_notice));
            isScreenOn = false;
        }
    }, 1000);
    super.onRestart();
}
Also used : TextToast(com.ryuunoakaihitomi.rebootmenu.util.TextToast) Handler(android.os.Handler)

Example 5 with TextToast

use of com.ryuunoakaihitomi.rebootmenu.util.TextToast in project rebootmenu by ryuunoakaihitomi.

the class Shortcut method onCreate.

// 来自UnRootMode.java -- 结束
@TargetApi(Build.VERSION_CODES.N_MR1)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    componentName = new ComponentName(this, AdminReceiver.class);
    devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
    // shortcut功能选项
    final int REBOOT = 2;
    final int SHUTDOWN = 3;
    final int RECOVERY = 8;
    final int FASTBOOT = 9;
    final int REBOOT_UI = 4;
    final int UR_REBOOT = 10;
    final int LOCKSCREEN = 5;
    final int UR_LOCKSCREEN = 6;
    final int UR_POWERDIALOG = 7;
    int param = getIntent().getIntExtra(extraTag, -1);
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    switch(param) {
        // Root模式下的快捷方式
        case ROOT:
            ShortcutInfo fastboot = new ShortcutInfo.Builder(this, "r_ffb").setShortLabel("*" + getString(R.string.fastboot_short)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_sort_by_size)).setIntent(new Intent(action).putExtra(extraTag, FASTBOOT)).setRank(5).build();
            ShortcutInfo recovery = new ShortcutInfo.Builder(this, "r_frr").setShortLabel("*" + getString(R.string.recovery_short)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_today)).setIntent(new Intent(action).putExtra(extraTag, RECOVERY)).setRank(4).build();
            ShortcutInfo reboot = new ShortcutInfo.Builder(this, "r_fr").setShortLabel("*" + getString(R.string.reboot)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_rotate)).setIntent(new Intent(action).putExtra(extraTag, REBOOT)).setRank(3).build();
            ShortcutInfo shutdown = new ShortcutInfo.Builder(this, "r_fs").setShortLabel("*" + getString(R.string.shutdown)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_delete)).setIntent(new Intent(action).putExtra(extraTag, SHUTDOWN)).setRank(2).build();
            ShortcutInfo rebootui = new ShortcutInfo.Builder(this, "r_ru").setShortLabel(getString(R.string.reboot_ui)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_view)).setIntent(new Intent(action).putExtra(extraTag, REBOOT_UI)).setRank(1).build();
            ShortcutInfo lockscreen = new ShortcutInfo.Builder(this, "r_l").setShortLabel(getString(R.string.lockscreen)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_slideshow)).setIntent(new Intent(action).putExtra(extraTag, LOCKSCREEN)).setRank(0).build();
            assert shortcutManager != null;
            // 无论如何,没有root不能用shell锁屏和重启UI,所以在不检查root模式下的无root模式改为增加fast boot。
            if (ShellUtils.isRoot())
                shortcutManager.setDynamicShortcuts(Arrays.asList(recovery, reboot, shutdown, rebootui, lockscreen));
            else
                shortcutManager.setDynamicShortcuts(Arrays.asList(fastboot, recovery, reboot, shutdown));
            finish();
            break;
        // 免root模式下的快捷方式
        case UNROOT:
            boolean isDevOwner = devicePolicyManager.isDeviceOwnerApp(getPackageName());
            ShortcutInfo ur_reboot = null;
            if (isDevOwner)
                ur_reboot = new ShortcutInfo.Builder(this, "ur_r").setShortLabel(getString(R.string.reboot)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_rotate)).setIntent(new Intent(action).putExtra(extraTag, UR_REBOOT)).setRank(2).build();
            ShortcutInfo ur_lockscreen = new ShortcutInfo.Builder(this, "ur_l").setShortLabel(getString(R.string.lockscreen)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_slideshow)).setIntent(new Intent(action).putExtra(extraTag, UR_LOCKSCREEN)).setRank(1).build();
            ShortcutInfo ur_powerdialog = new ShortcutInfo.Builder(this, "ur_p").setShortLabel(getString(R.string.system_power_dialog)).setIcon(Icon.createWithResource(this, android.R.drawable.ic_menu_preferences)).setIntent(new Intent(action).putExtra(extraTag, UR_POWERDIALOG)).setRank(0).build();
            assert shortcutManager != null;
            if (isDevOwner)
                shortcutManager.setDynamicShortcuts(Arrays.asList(ur_lockscreen, ur_powerdialog, ur_reboot));
            else
                shortcutManager.setDynamicShortcuts(Arrays.asList(ur_lockscreen, ur_powerdialog));
            finish();
            break;
        // 快捷方式使用强制执行
        case FASTBOOT:
            rebootExec("bootloader");
            break;
        case RECOVERY:
            rebootExec("recovery");
            break;
        case REBOOT:
            rebootExec(null);
            break;
        case SHUTDOWN:
            rebootExec("-p");
            break;
        case REBOOT_UI:
            ShellUtils.suCmdExec("busybox pkill com.android.systemui");
            finish();
            break;
        case LOCKSCREEN:
            ShellUtils.suCmdExec("input keyevent 26");
            finish();
            break;
        // 免root模式
        case UR_LOCKSCREEN:
            lockscreen();
            break;
        case UR_POWERDIALOG:
            UnRootMode.accessbilityon(Shortcut.this);
            break;
        case UR_REBOOT:
            if (devicePolicyManager.isDeviceOwnerApp(getPackageName()))
                UnRootMode.reboot(devicePolicyManager, componentName, this);
            else {
                int random = new Random().nextInt(99);
                // 保留日志
                new DebugLog("DEVICE_OWNER_DISABLED from SHORTCUT random=" + random, DebugLog.LogLevel.V);
                new TextToast(getApplicationContext(), random > 50, getString(R.string.device_owner_disabled));
                finish();
            }
        default:
            finish();
    }
}
Also used : DebugLog(com.ryuunoakaihitomi.rebootmenu.util.DebugLog) ShortcutInfo(android.content.pm.ShortcutInfo) Random(java.util.Random) ShortcutManager(android.content.pm.ShortcutManager) TextToast(com.ryuunoakaihitomi.rebootmenu.util.TextToast) ComponentName(android.content.ComponentName) Intent(android.content.Intent) TargetApi(android.annotation.TargetApi)

Aggregations

TextToast (com.ryuunoakaihitomi.rebootmenu.util.TextToast)6 Intent (android.content.Intent)3 DialogInterface (android.content.DialogInterface)2 IntentFilter (android.content.IntentFilter)2 Handler (android.os.Handler)2 TargetApi (android.annotation.TargetApi)1 AlertDialog (android.app.AlertDialog)1 ComponentName (android.content.ComponentName)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 ShortcutManager (android.content.pm.ShortcutManager)1 DebugLog (com.ryuunoakaihitomi.rebootmenu.util.DebugLog)1 Random (java.util.Random)1