Loading core/java/android/os/IMountService.aidl +1 −2 Original line number Diff line number Diff line Loading @@ -104,8 +104,7 @@ interface IMountService String[] getSecureContainerList(); /** * Shuts down the MountService and gracefully unmounts * all external media. * Shuts down the MountService and gracefully unmounts all external media. */ void shutdown(); } core/java/android/os/Power.java +17 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package android.os; import java.io.IOException; import android.os.ServiceManager; import android.os.IMountService; /** * Class that provides access to some of the power management functions. Loading Loading @@ -97,5 +99,19 @@ public class Power * @throws IOException if reboot fails for some reason (eg, lack of * permission) */ public static native void reboot(String reason) throws IOException; public static void reboot(String reason) throws IOException { IMountService mSvc = IMountService.Stub.asInterface( ServiceManager.getService("mount")); if (mSvc != null) { try { mSvc.shutdown(); } catch (Exception e) { } } rebootNative(reason); } private static native void rebootNative(String reason) throws IOException ; } core/jni/android_os_Power.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ static JNINativeMethod method_table[] = { { "setLastUserActivityTimeout", "(J)I", (void*)setLastUserActivityTimeout }, { "setScreenState", "(Z)I", (void*)setScreenState }, { "shutdown", "()V", (void*)android_os_Power_shutdown }, { "reboot", "(Ljava/lang/String;)V", (void*)android_os_Power_reboot }, { "rebootNative", "(Ljava/lang/String;)V", (void*)android_os_Power_reboot }, }; int register_android_os_Power(JNIEnv *env) Loading services/java/com/android/server/MountService.java +15 −1 Original line number Diff line number Diff line Loading @@ -215,7 +215,7 @@ class MountService extends IMountService.Stub { throw new SecurityException("Requires SHUTDOWN permission"); } Log.i(TAG, "Shutting down"); Log.d(TAG, "Shutting down"); String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_SHARED)) { Loading Loading @@ -259,6 +259,20 @@ class MountService extends IMountService.Stub { try { String m = Environment.getExternalStorageDirectory().toString(); unmountMedia(m); int retries = 12; while (!state.equals(Environment.MEDIA_UNMOUNTED) && (retries-- >=0)) { try { Thread.sleep(1000); } catch (InterruptedException iex) { Log.e(TAG, "Interrupted while waiting for media", iex); break; } state = Environment.getExternalStorageState(); } if (retries == 0) { Log.e(TAG, "Timed out waiting for media to unmount"); } } catch (Exception e) { Log.e(TAG, "external storage unmount failed", e); } Loading Loading
core/java/android/os/IMountService.aidl +1 −2 Original line number Diff line number Diff line Loading @@ -104,8 +104,7 @@ interface IMountService String[] getSecureContainerList(); /** * Shuts down the MountService and gracefully unmounts * all external media. * Shuts down the MountService and gracefully unmounts all external media. */ void shutdown(); }
core/java/android/os/Power.java +17 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package android.os; import java.io.IOException; import android.os.ServiceManager; import android.os.IMountService; /** * Class that provides access to some of the power management functions. Loading Loading @@ -97,5 +99,19 @@ public class Power * @throws IOException if reboot fails for some reason (eg, lack of * permission) */ public static native void reboot(String reason) throws IOException; public static void reboot(String reason) throws IOException { IMountService mSvc = IMountService.Stub.asInterface( ServiceManager.getService("mount")); if (mSvc != null) { try { mSvc.shutdown(); } catch (Exception e) { } } rebootNative(reason); } private static native void rebootNative(String reason) throws IOException ; }
core/jni/android_os_Power.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ static JNINativeMethod method_table[] = { { "setLastUserActivityTimeout", "(J)I", (void*)setLastUserActivityTimeout }, { "setScreenState", "(Z)I", (void*)setScreenState }, { "shutdown", "()V", (void*)android_os_Power_shutdown }, { "reboot", "(Ljava/lang/String;)V", (void*)android_os_Power_reboot }, { "rebootNative", "(Ljava/lang/String;)V", (void*)android_os_Power_reboot }, }; int register_android_os_Power(JNIEnv *env) Loading
services/java/com/android/server/MountService.java +15 −1 Original line number Diff line number Diff line Loading @@ -215,7 +215,7 @@ class MountService extends IMountService.Stub { throw new SecurityException("Requires SHUTDOWN permission"); } Log.i(TAG, "Shutting down"); Log.d(TAG, "Shutting down"); String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_SHARED)) { Loading Loading @@ -259,6 +259,20 @@ class MountService extends IMountService.Stub { try { String m = Environment.getExternalStorageDirectory().toString(); unmountMedia(m); int retries = 12; while (!state.equals(Environment.MEDIA_UNMOUNTED) && (retries-- >=0)) { try { Thread.sleep(1000); } catch (InterruptedException iex) { Log.e(TAG, "Interrupted while waiting for media", iex); break; } state = Environment.getExternalStorageState(); } if (retries == 0) { Log.e(TAG, "Timed out waiting for media to unmount"); } } catch (Exception e) { Log.e(TAG, "external storage unmount failed", e); } Loading