MountService: Send UMS_CONNECTED broadcast on boot if UMS connected.

UMS detection is now done wayyyy before the system is booted, so set a flag
to send our intent broadcast once we've booted.

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 2dc12f6..fb17538 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -115,8 +115,9 @@
     private PackageManagerService                 mPms;
     private boolean                               mUmsEnabling;
     private ArrayList<MountServiceBinderListener> mListeners;
-    private boolean                               mBooted;
-    private boolean                               mReady;
+    private boolean                               mBooted = false;
+    private boolean                               mReady = false;
+    private boolean                               mSendUmsConnectedOnBoot = false;
 
     /**
      * Private hash of currently mounted secure containers.
@@ -162,6 +163,14 @@
                                     Log.e(TAG, String.format("Boot-time mount failed (%d)", rc));
                                 }
                             }
+                            /*
+                             * If UMS is connected in boot, send the connected event
+                             * now that we're up.
+                             */
+                            if (mSendUmsConnectedOnBoot) {
+                                sendUmsIntent(true);
+                                mSendUmsConnectedOnBoot = false;
+                            }
                         } catch (Exception ex) {
                             Log.e(TAG, "Boot-time mount exception", ex);
                         }
@@ -636,16 +645,17 @@
         }
 
         if (mBooted == true) {
-            Intent intent;
-            if (avail) {
-                intent = new Intent(Intent.ACTION_UMS_CONNECTED);
-            } else {
-                intent = new Intent(Intent.ACTION_UMS_DISCONNECTED);
-            }
-            mContext.sendBroadcast(intent);
+            sendUmsIntent(avail);
+        } else {
+            mSendUmsConnectedOnBoot = avail;
         }
     }
 
+    private void sendUmsIntent(boolean c) {
+        mContext.sendBroadcast(
+                new Intent((c ? Intent.ACTION_UMS_CONNECTED : Intent.ACTION_UMS_DISCONNECTED)));
+    }
+
     private void validatePermission(String perm) {
         if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
             throw new SecurityException(String.format("Requires %s permission", perm));