MountService: Suppress media removed notification when enabling UMS
Signed-off-by: San Mehat <san@google.com>
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index c8a6915..d54c4d9 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -127,6 +127,7 @@
private boolean mUmsConnected = false;
private boolean mUmsEnabled = false;
+ private boolean mUmsEnabling = false;
private String mLegacyState = Environment.MEDIA_REMOVED;
@@ -332,13 +333,16 @@
String vp = Environment.getExternalStorageDirectory().getPath();
String vs = getVolumeState(vp);
+ mUmsEnabling = enable;
if (enable && vs.equals(Environment.MEDIA_MOUNTED)) {
unmountVolume(vp);
+ mUmsEnabling = false;
updateUsbMassStorageNotification(true, false);
}
setShareMethodEnabled(vp, "ums", enable);
mUmsEnabled = enable;
+ mUmsEnabling = false;
if (!enable) {
mountVolume(vp);
if (mPromptUms) {
@@ -594,10 +598,14 @@
} else if (newState == VolumeState.NoMedia) {
// NoMedia is handled via Disk Remove events
} else if (newState == VolumeState.Idle) {
- // Don't notify if we're in BAD_REMOVAL, NOFS, or UNMOUNTABLE
+ /*
+ * Don't notify if we're in BAD_REMOVAL, NOFS, UNMOUNTABLE, or
+ * if we're in the process of enabling UMS
+ */
if (!vs.equals(Environment.MEDIA_BAD_REMOVAL) &&
!vs.equals(Environment.MEDIA_NOFS) &&
- !vs.equals(Environment.MEDIA_UNMOUNTABLE)) {
+ !vs.equals(Environment.MEDIA_UNMOUNTABLE) &&
+ !mUmsEnabling) {
notifyMediaUnmounted(mountPoint);
}
} else if (newState == VolumeState.Pending) {