Java Code Examples for android.os.PowerManager#reboot()

The following examples show how to use android.os.PowerManager#reboot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModPowerMenu.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private static void doReboot(Context context, int mode) {
    final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (mode == 0) {
        pm.reboot(null);
    } else if (mode == 1) {
        Utils.performSoftReboot();
    } else if (mode == 2) {
        replaceRecoveryMessage();
        pm.reboot("recovery");
    } else if (mode == 3) {
        pm.reboot("bootloader");
    }
}
 
Example 2
Source File: Device.java    From turbo-editor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reboots the device into the recovery.<br /><br />
 * 
 * This method first tries using the {@link PowerManager}, if that fails it fallbacks on using the reboot command from toolbox.<br /><br />
 * 
 * Note that using the {@link PowerManager} requires your app to optain the 'REBOOT' permission. If you don't want this, just parse NULL as {@link Context} 
 * and the method will use the fallback. This however is more likely to fail, as many toolbox versions does not support the reboot command. 
 * And since only the kernel can write to the CBC, we need a native caller to invoke this. So there is no fallback for missing toolbox support when it comes 
 * to rebooting into the recovery. 
 * 
 * @param context
 *     A {@link Context} or NULL to skip using the {@link PowerManager}
 */
public Boolean rebootRecovery(Context context) {
	if (context != null) {
		try {
			PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
			pm.reboot(null);
			
			/*
			 * This will never be reached if the reboot is successful
			 */
			return false;	
		
		} catch (Throwable e) {}
	}
	
	Result result = mShell.execute("toolbox reboot recovery");
	
	return result != null && result.wasSuccessful();
}
 
Example 3
Source File: RecoverySystemService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override // Binder call
public void rebootRecoveryWithCommand(String command) {
    if (DEBUG) Slog.d(TAG, "rebootRecoveryWithCommand: [" + command + "]");
    synchronized (sRequestLock) {
        if (!setupOrClearBcb(true, command)) {
            return;
        }

        // Having set up the BCB, go ahead and reboot.
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        pm.reboot(PowerManager.REBOOT_RECOVERY);
    }
}
 
Example 4
Source File: DeviceUtils.java    From XKnife-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 重启
 * <p>需系统权限 {@code <android:sharedUserId="android.uid.system"/>}</p>
 *
 * @param context the context
 * @param reason  传递给内核来请求特殊的引导模式,如"recovery"
 */
public static void reboot(Context context, String reason) {
    if (context != null) {
        PowerManager mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        try {
            mPowerManager.reboot(reason);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 5
Source File: DeviceUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * 重启
 * <p>需系统权限 {@code <android:sharedUserId="android.uid.system"/>}</p>
 *
 * @param reason  传递给内核来请求特殊的引导模式,如"recovery"
 */
public static void reboot(String reason) {
    PowerManager mPowerManager = (PowerManager) Utils.getContext().getSystemService(Context.POWER_SERVICE);
    try {
        mPowerManager.reboot(reason);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: EMMSystemService.java    From product-emm with Apache License 2.0 5 votes vote down vote up
/**
 * Rebooting the device.
 */
private void rebootDevice() {
    Log.i(TAG, "Reboot request initiated by admin.");
    try {
        Thread.sleep(5000);
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        powerManager.reboot(null);
    } catch (InterruptedException e) {
        Log.e(TAG, "Reboot initiating thread interrupted." + e);
    }
}
 
Example 7
Source File: SystemCommands.java    From orWall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO: Not ready yet
 */
@TargetApi(8)
public void reboot() {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    pm.reboot("recovery");
    pm.reboot(null);

    // not working:
    // reboot(null);
}
 
Example 8
Source File: SystemCommands.java    From AOSPBrowserInstaller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO: Not ready yet
 */
@TargetApi(8)
public void reboot() {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    pm.reboot("recovery");
    pm.reboot(null);

    // not working:
    // reboot(null);
}
 
Example 9
Source File: DeviceUtils.java    From Android-utils with Apache License 2.0 4 votes vote down vote up
public static void reboot(final String reason) {
    PowerManager pm = (PowerManager) UtilsApp.getApp().getSystemService(Context.POWER_SERVICE);
    // noinspection ConstantConditions
    pm.reboot(reason);
}
 
Example 10
Source File: DangerousUtils.java    From AndroidUtilCode with Apache License 2.0 3 votes vote down vote up
/**
 * Reboot the device.
 * <p>Requires root permission
 * or hold {@code android:sharedUserId="android.uid.system"},
 * {@code <uses-permission android:name="android.permission.REBOOT" />}</p>
 *
 * @param reason code to pass to the kernel (e.g., "recovery") to
 *               request special boot modes, or null.
 * @return {@code true}: success<br>{@code false}: fail
 */
public static boolean reboot(final String reason) {
    try {
        PowerManager pm = (PowerManager) Utils.getApp().getSystemService(Context.POWER_SERVICE);
        pm.reboot(reason);
        return true;
    } catch (Exception e) {
        return false;
    }
}