diff options
-rw-r--r-- | core/java/android/os/IMountService.aidl | 3 | ||||
-rw-r--r-- | core/java/android/os/Power.java | 18 | ||||
-rw-r--r-- | core/jni/android_os_Power.cpp | 2 | ||||
-rw-r--r-- | services/java/com/android/server/MountService.java | 16 |
4 files changed, 34 insertions, 5 deletions
diff --git a/core/java/android/os/IMountService.aidl b/core/java/android/os/IMountService.aidl index f052689..1e79030 100644 --- a/core/java/android/os/IMountService.aidl +++ b/core/java/android/os/IMountService.aidl @@ -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(); } diff --git a/core/java/android/os/Power.java b/core/java/android/os/Power.java index 3679e47..bc76180 100644 --- a/core/java/android/os/Power.java +++ b/core/java/android/os/Power.java @@ -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. @@ -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 ; } diff --git a/core/jni/android_os_Power.cpp b/core/jni/android_os_Power.cpp index df5edba..a46c2dd 100644 --- a/core/jni/android_os_Power.cpp +++ b/core/jni/android_os_Power.cpp @@ -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) diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index cd17bd2..81ebe03 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -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)) { @@ -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); } |