vold: support "volume list [broadcast]" command

Sometimes when an sdcard is already mounted,
some info like uuid and label are not re-broadcast to new listeners.
The extra argument to list allows late listeners to catch up by asking
volume list to broadcast that info again.

Bug: 16253597
Bug: 16306775
Change-Id: Ie7d0c1132c22d307a5b2a0e50075a3716138d00b
Signed-off-by: Benson Huang <benson.huang@mediatek.com>
(cherry picked from commit 85f4700f44170b772697e627b3075dcb9137e1b7)
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 3a2b559..06daf40 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -260,8 +260,9 @@
     }
 }
 
-int VolumeManager::listVolumes(SocketClient *cli) {
+int VolumeManager::listVolumes(SocketClient *cli, bool broadcast) {
     VolumeCollection::iterator i;
+    char msg[256];
 
     for (i = mVolumes->begin(); i != mVolumes->end(); ++i) {
         char *buffer;
@@ -270,6 +271,20 @@
                  (*i)->getState());
         cli->sendMsg(ResponseCode::VolumeListResult, buffer, false);
         free(buffer);
+        if (broadcast) {
+            if((*i)->getUuid()) {
+                snprintf(msg, sizeof(msg), "%s %s \"%s\"", (*i)->getLabel(),
+                    (*i)->getFuseMountpoint(), (*i)->getUuid());
+                mBroadcaster->sendBroadcast(ResponseCode::VolumeUuidChange,
+                    msg, false);
+            }
+            if((*i)->getUserLabel()) {
+                snprintf(msg, sizeof(msg), "%s %s \"%s\"", (*i)->getLabel(),
+                    (*i)->getFuseMountpoint(), (*i)->getUserLabel());
+                mBroadcaster->sendBroadcast(ResponseCode::VolumeUserLabelChange,
+                    msg, false);
+            }
+        }
     }
     cli->sendMsg(ResponseCode::CommandOkay, "Volumes listed.", false);
     return 0;