diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index fb22df7e4850f..9991f5ba00736 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -479,7 +479,6 @@ public class ZygoteInit { OsConstants.CAP_NET_BIND_SERVICE, OsConstants.CAP_NET_BROADCAST, OsConstants.CAP_NET_RAW, - OsConstants.CAP_SYS_BOOT, OsConstants.CAP_SYS_MODULE, OsConstants.CAP_SYS_NICE, OsConstants.CAP_SYS_RESOURCE, diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java index 1203e027fb915..198851c3dc1d6 100644 --- a/services/java/com/android/server/power/PowerManagerService.java +++ b/services/java/com/android/server/power/PowerManagerService.java @@ -50,6 +50,7 @@ import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; +import android.os.SystemProperties; import android.os.SystemService; import android.os.UserHandle; import android.os.WorkSource; @@ -364,8 +365,6 @@ public final class PowerManagerService extends IPowerManager.Stub private long mLastWarningAboutUserActivityPermission = Long.MIN_VALUE; private native void nativeInit(); - private static native void nativeShutdown(); - private static native void nativeReboot(String reason) throws IOException; private static native void nativeSetPowerState(boolean screenOn, boolean screenBright); private static native void nativeAcquireSuspendBlocker(String name); @@ -2164,18 +2163,26 @@ public final class PowerManagerService extends IPowerManager.Stub * to be clean. Most people should use {@link ShutdownThread} for a clean shutdown. */ public static void lowLevelShutdown() { - nativeShutdown(); + SystemProperties.set("sys.powerctl", "shutdown"); } /** - * Low-level function to reboot the device. + * Low-level function to reboot the device. On success, this function + * doesn't return. If more than 5 seconds passes from the time, + * a reboot is requested, this method returns. * * @param reason code to pass to the kernel (e.g. "recovery"), or null. - * @throws IOException if reboot fails for some reason (eg, lack of - * permission) */ - public static void lowLevelReboot(String reason) throws IOException { - nativeReboot(reason); + public static void lowLevelReboot(String reason) { + if (reason == null) { + reason = ""; + } + SystemProperties.set("sys.powerctl", "reboot," + reason); + try { + Thread.sleep(20000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } @Override // Watchdog.Monitor implementation diff --git a/services/java/com/android/server/power/ShutdownThread.java b/services/java/com/android/server/power/ShutdownThread.java index c7f7390fcb765..ba321bcf59880 100644 --- a/services/java/com/android/server/power/ShutdownThread.java +++ b/services/java/com/android/server/power/ShutdownThread.java @@ -490,11 +490,8 @@ public final class ShutdownThread extends Thread { public static void rebootOrShutdown(boolean reboot, String reason) { if (reboot) { Log.i(TAG, "Rebooting, reason: " + reason); - try { - PowerManagerService.lowLevelReboot(reason); - } catch (Exception e) { - Log.e(TAG, "Reboot failed, will attempt shutdown instead", e); - } + PowerManagerService.lowLevelReboot(reason); + Log.e(TAG, "Reboot failed, will attempt shutdown instead"); } else if (SHUTDOWN_VIBRATE_MS > 0) { // vibrate before shutting down Vibrator vibrator = new SystemVibrator(); diff --git a/services/jni/com_android_server_power_PowerManagerService.cpp b/services/jni/com_android_server_power_PowerManagerService.cpp index 23c33af2b6a72..88b13b539c74f 100644 --- a/services/jni/com_android_server_power_PowerManagerService.cpp +++ b/services/jni/com_android_server_power_PowerManagerService.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include "com_android_server_power_PowerManagerService.h" @@ -189,22 +188,6 @@ static void nativeSetAutoSuspend(JNIEnv *env, jclass clazz, jboolean enable) { } } -static void nativeShutdown(JNIEnv *env, jclass clazz) { - android_reboot(ANDROID_RB_POWEROFF, 0, 0); -} - -static void nativeReboot(JNIEnv *env, jclass clazz, jstring reason) { - if (reason == NULL) { - android_reboot(ANDROID_RB_RESTART, 0, 0); - } else { - const char *chars = env->GetStringUTFChars(reason, NULL); - android_reboot(ANDROID_RB_RESTART2, 0, (char *) chars); - env->ReleaseStringUTFChars(reason, chars); // In case it fails. - } - jniThrowIOException(env, errno); -} - - // ---------------------------------------------------------------------------- static JNINativeMethod gPowerManagerServiceMethods[] = { @@ -221,10 +204,6 @@ static JNINativeMethod gPowerManagerServiceMethods[] = { (void*) nativeSetInteractive }, { "nativeSetAutoSuspend", "(Z)V", (void*) nativeSetAutoSuspend }, - { "nativeShutdown", "()V", - (void*) nativeShutdown }, - { "nativeReboot", "(Ljava/lang/String;)V", - (void*) nativeReboot }, }; #define FIND_CLASS(var, className) \