Search in sources :

Example 1 with DebugLog

use of com.ryuunoakaihitomi.rebootmenu.util.DebugLog 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)

Example 2 with DebugLog

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

the class SystemPowerDialog method onServiceConnected.

@Override
protected void onServiceConnected() {
    super.onServiceConnected();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(getString(R.string.service_action_key));
        registerReceiver(broadcastReceiver, intentFilter);
        isBroadcastRegistered = true;
    } else {
        new DebugLog("onServiceConnected() + (<- Android 5.0)");
        System.exit(-1);
    }
}
Also used : IntentFilter(android.content.IntentFilter) DebugLog(com.ryuunoakaihitomi.rebootmenu.util.DebugLog)

Aggregations

DebugLog (com.ryuunoakaihitomi.rebootmenu.util.DebugLog)2 TargetApi (android.annotation.TargetApi)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 ShortcutManager (android.content.pm.ShortcutManager)1 TextToast (com.ryuunoakaihitomi.rebootmenu.util.TextToast)1 Random (java.util.Random)1