From 1e512790bfe13bdf4d174892c8b699b93f7f2203 Mon Sep 17 00:00:00 2001 From: San Mehat Date: Thu, 7 Jan 2010 10:40:29 -0800 Subject: [PATCH] PowerManagerService: Switch to using MountService shutdown for media Signed-off-by: San Mehat --- .../android/server/PowerManagerService.java | 71 +++++-------------- 1 file changed, 16 insertions(+), 55 deletions(-) diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index 5a14ba197edfc..89261a8268d31 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -2126,60 +2126,6 @@ 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. @@ -2188,7 +2134,22 @@ class PowerManagerService extends IPowerManager.Stub { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); - unmountExternalStorage(); + /* + * Manually shutdown the MountService to ensure media is + * put into a safe state. + */ + IMountService mSvc = IMountService.Stub.asInterface( + ServiceManager.getService("mount")); + + if (mSvc != null) { + try { + mSvc.shutdown(); + } catch (Exception e) { + Log.e(TAG, "MountService shutdown failed", e); + } + } else { + Log.w(TAG, "MountService unavailable for shutdown"); + } try { Power.reboot(reason);