diff options
author | San Mehat <san@google.com> | 2010-01-06 14:58:18 -0800 |
---|---|---|
committer | San Mehat <san@google.com> | 2010-01-06 15:36:01 -0800 |
commit | 14e69afdfcefe21c81679a95c476e64ebb276fbe (patch) | |
tree | a516d52a468d63e1b32148eca3036d98e8359d5b /services/java | |
parent | d1265febc4ae20b0e709177735b175acd94b286a (diff) | |
download | frameworks_base-14e69afdfcefe21c81679a95c476e64ebb276fbe.zip frameworks_base-14e69afdfcefe21c81679a95c476e64ebb276fbe.tar.gz frameworks_base-14e69afdfcefe21c81679a95c476e64ebb276fbe.tar.bz2 |
PowerManagerService: When rebooting, ensure external storage is unmounted
Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'services/java')
-rw-r--r-- | services/java/com/android/server/PowerManagerService.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index d740ce1..5a14ba1 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -45,6 +45,9 @@ import android.os.Power; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; +import android.os.ServiceManager; +import android.os.Environment; +import android.os.IMountService; import android.os.SystemClock; import android.provider.Settings.SettingNotFoundException; import android.provider.Settings; @@ -2123,6 +2126,60 @@ class PowerManagerService extends IPowerManager.Stub } } + private void unmountExternalStorage() { + String state = Environment.getExternalStorageState(); + + IMountService mSvc; + + mSvc = IMountService.Stub.asInterface( + ServiceManager.getService("mount")); + if (mSvc == null) { + Log.e(TAG, "MountService unavailable"); + return; + } + + if (state.equals(Environment.MEDIA_SHARED)) { + /* + * If the media is currently shared, unshare it. + * XXX: This is still dangerous!. We should not + * be rebooting at *all* if UMS is enabled, since + * the UMS host could have dirty FAT cache entries + * yet to flush. + */ + try { + mSvc.setMassStorageEnabled(false); + } catch (Exception e) { + Log.e(TAG, "ums disable failed", e); + } + } else if (state.equals(Environment.MEDIA_CHECKING)) { + /* + * If the media is being checked, then we need to wait for + * it to complete before being able to proceed. + */ + while (state.equals(Environment.MEDIA_CHECKING)) { + state = Environment.getExternalStorageState(); + try { + Thread.sleep(1000); + } catch (InterruptedException iex) { + Log.e(TAG, "Interrupted while waiting for media", iex); + break; + } + } + } + + if (state.equals(Environment.MEDIA_MOUNTED)) { + /* + * If the media is mounted, then gracefully unmount it. + */ + try { + String m = Environment.getExternalStorageDirectory().toString(); + mSvc.unmountMedia(m); + } catch (Exception e) { + Log.e(TAG, "external storage unmount failed", e); + } + } + } + /** * Reboot the device immediately, passing 'reason' (may be null) * to the underlying __reboot system call. Should not return. @@ -2130,6 +2187,9 @@ class PowerManagerService extends IPowerManager.Stub public void reboot(String reason) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); + + unmountExternalStorage(); + try { Power.reboot(reason); } catch (IOException e) { |