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/CommandListener.cpp b/CommandListener.cpp
index d2b061f..5fdee7c 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -131,7 +131,8 @@
int rc = 0;
if (!strcmp(argv[1], "list")) {
- return vm->listVolumes(cli);
+ bool broadcast = argc >= 3 && !strcmp(argv[2], "broadcast");
+ return vm->listVolumes(cli, broadcast);
} else if (!strcmp(argv[1], "debug")) {
if (argc != 3 || (argc == 3 && (strcmp(argv[2], "off") && strcmp(argv[2], "on")))) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume debug <off/on>", false);
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;
diff --git a/VolumeManager.h b/VolumeManager.h
index 07fd00e..0d41b23 100644
--- a/VolumeManager.h
+++ b/VolumeManager.h
@@ -77,7 +77,7 @@
int addVolume(Volume *v);
- int listVolumes(SocketClient *cli);
+ int listVolumes(SocketClient *cli, bool broadcast);
int mountVolume(const char *label);
int unmountVolume(const char *label, bool force, bool revert);
int shareVolume(const char *label, const char *method);