Loading core/java/com/android/internal/app/ShutdownThread.java +29 −4 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; import android.os.Vibrator; import android.os.storage.IMountService; import android.os.storage.IMountShutdownObserver; Loading Loading @@ -60,6 +61,9 @@ public final class ShutdownThread extends Thread { private static boolean mReboot; private static String mRebootReason; // Provides shutdown assurance in case the system_server is killed public static final String SHUTDOWN_ACTION_PROPERTY = "sys.shutdown.requested"; // static instance of this thread private static final ShutdownThread sInstance = new ShutdownThread(); Loading Loading @@ -213,6 +217,16 @@ public final class ShutdownThread extends Thread { } }; /* * Write a system property in case the system_server reboots before we * get to the actual hardware restart. If that happens, we'll retry at * the beginning of the SystemServer startup. */ { String reason = (mReboot ? "1" : "0") + (mRebootReason != null ? mRebootReason : ""); SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason); } Log.i(TAG, "Sending shutdown broadcast..."); // First send the high-level shut down broadcast. Loading Loading @@ -342,10 +356,21 @@ public final class ShutdownThread extends Thread { } } if (mReboot) { Log.i(TAG, "Rebooting, reason: " + mRebootReason); rebootOrShutdown(mReboot, mRebootReason); } /** * Do not call this directly. Use {@link #reboot(Context, String, boolean)} * or {@link #shutdown(Context, boolean)} instead. * * @param reboot true to reboot or false to shutdown * @param reason reason for reboot */ public static void rebootOrShutdown(boolean reboot, String reason) { if (reboot) { Log.i(TAG, "Rebooting, reason: " + reason); try { Power.reboot(mRebootReason); Power.reboot(reason); } catch (Exception e) { Log.e(TAG, "Reboot failed, will attempt shutdown instead", e); } Loading services/java/com/android/server/SystemServer.java +19 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server; import com.android.server.am.ActivityManagerService; import com.android.internal.app.ShutdownThread; import com.android.internal.os.BinderInternal; import com.android.internal.os.SamplingProfilerIntegration; import com.trustedlogic.trustednfc.android.server.NfcService; Loading Loading @@ -89,6 +90,24 @@ class ServerThread extends Thread { BinderInternal.disableBackgroundScheduling(true); android.os.Process.setCanSelfBackground(false); // Check whether we failed to shut down last time we tried. { final String shutdownAction = SystemProperties.get( ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); if (shutdownAction != null && shutdownAction.length() > 0) { boolean reboot = (shutdownAction.charAt(0) == '1'); final String reason; if (shutdownAction.length() > 1) { reason = shutdownAction.substring(1, shutdownAction.length()); } else { reason = null; } ShutdownThread.rebootOrShutdown(reboot, reason); } } String factoryTestStr = SystemProperties.get("ro.factorytest"); int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF : Integer.parseInt(factoryTestStr); Loading Loading
core/java/com/android/internal/app/ShutdownThread.java +29 −4 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; import android.os.Vibrator; import android.os.storage.IMountService; import android.os.storage.IMountShutdownObserver; Loading Loading @@ -60,6 +61,9 @@ public final class ShutdownThread extends Thread { private static boolean mReboot; private static String mRebootReason; // Provides shutdown assurance in case the system_server is killed public static final String SHUTDOWN_ACTION_PROPERTY = "sys.shutdown.requested"; // static instance of this thread private static final ShutdownThread sInstance = new ShutdownThread(); Loading Loading @@ -213,6 +217,16 @@ public final class ShutdownThread extends Thread { } }; /* * Write a system property in case the system_server reboots before we * get to the actual hardware restart. If that happens, we'll retry at * the beginning of the SystemServer startup. */ { String reason = (mReboot ? "1" : "0") + (mRebootReason != null ? mRebootReason : ""); SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason); } Log.i(TAG, "Sending shutdown broadcast..."); // First send the high-level shut down broadcast. Loading Loading @@ -342,10 +356,21 @@ public final class ShutdownThread extends Thread { } } if (mReboot) { Log.i(TAG, "Rebooting, reason: " + mRebootReason); rebootOrShutdown(mReboot, mRebootReason); } /** * Do not call this directly. Use {@link #reboot(Context, String, boolean)} * or {@link #shutdown(Context, boolean)} instead. * * @param reboot true to reboot or false to shutdown * @param reason reason for reboot */ public static void rebootOrShutdown(boolean reboot, String reason) { if (reboot) { Log.i(TAG, "Rebooting, reason: " + reason); try { Power.reboot(mRebootReason); Power.reboot(reason); } catch (Exception e) { Log.e(TAG, "Reboot failed, will attempt shutdown instead", e); } Loading
services/java/com/android/server/SystemServer.java +19 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server; import com.android.server.am.ActivityManagerService; import com.android.internal.app.ShutdownThread; import com.android.internal.os.BinderInternal; import com.android.internal.os.SamplingProfilerIntegration; import com.trustedlogic.trustednfc.android.server.NfcService; Loading Loading @@ -89,6 +90,24 @@ class ServerThread extends Thread { BinderInternal.disableBackgroundScheduling(true); android.os.Process.setCanSelfBackground(false); // Check whether we failed to shut down last time we tried. { final String shutdownAction = SystemProperties.get( ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); if (shutdownAction != null && shutdownAction.length() > 0) { boolean reboot = (shutdownAction.charAt(0) == '1'); final String reason; if (shutdownAction.length() > 1) { reason = shutdownAction.substring(1, shutdownAction.length()); } else { reason = null; } ShutdownThread.rebootOrShutdown(reboot, reason); } } String factoryTestStr = SystemProperties.get("ro.factorytest"); int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF : Integer.parseInt(factoryTestStr); Loading