registerCmd(new VolumeCmd());
registerCmd(new AsecCmd());
registerCmd(new ObbCmd());
- registerCmd(new ShareCmd());
registerCmd(new StorageCmd());
registerCmd(new XwarpCmd());
registerCmd(new CryptfsCmd());
return 0;
}
-CommandListener::ShareCmd::ShareCmd() :
- VoldCommand("share") {
-}
-
-int CommandListener::ShareCmd::runCommand(SocketClient *cli,
- int argc, char **argv) {
- dumpArgs(argc, argv, -1);
-
- if (argc < 2) {
- cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing Argument", false);
- return 0;
- }
-
- VolumeManager *vm = VolumeManager::Instance();
- int rc = 0;
-
- if (!strcmp(argv[1], "status")) {
- bool avail = false;
-
- if (vm->shareAvailable(argv[2], &avail)) {
- cli->sendMsg(
- ResponseCode::OperationFailed, "Failed to determine share availability", true);
- } else {
- cli->sendMsg(ResponseCode::ShareStatusResult,
- (avail ? "Share available" : "Share unavailable"), false);
- }
- } else {
- cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown share cmd", false);
- }
-
- return 0;
-}
-
CommandListener::StorageCmd::StorageCmd() :
VoldCommand("storage") {
}
mVolumes = new VolumeCollection();
mActiveContainers = new AsecIdCollection();
mBroadcaster = NULL;
- mUsbMassStorageEnabled = false;
- mUsbConnected = false;
mUmsSharingCount = 0;
mSavedDirtyRatio = -1;
// set dirty ratio to 0 when UMS is active
mUmsDirtyRatio = 0;
-
- readInitialState();
-}
-
-void VolumeManager::readInitialState() {
- FILE *fp;
- char state[255];
-
- /*
- * Read the initial mass storage enabled state
- */
- if ((fp = fopen("/sys/devices/virtual/usb_composite/usb_mass_storage/enable", "r"))) {
- if (fgets(state, sizeof(state), fp)) {
- mUsbMassStorageEnabled = !strncmp(state, "1", 1);
- } else {
- SLOGE("Failed to read usb_mass_storage enabled state (%s)", strerror(errno));
- }
- fclose(fp);
- } else {
- SLOGD("USB mass storage support is not enabled in the kernel");
- }
-
- /*
- * Read the initial USB connected state
- */
- if ((fp = fopen("/sys/devices/virtual/switch/usb_configuration/state", "r"))) {
- if (fgets(state, sizeof(state), fp)) {
- mUsbConnected = !strncmp(state, "1", 1);
- } else {
- SLOGE("Failed to read usb_configuration switch (%s)", strerror(errno));
- }
- fclose(fp);
- } else {
- SLOGD("usb_configuration switch is not enabled in the kernel");
- }
}
VolumeManager::~VolumeManager() {
return 0;
}
-void VolumeManager::notifyUmsAvailable(bool available) {
- char msg[255];
-
- snprintf(msg, sizeof(msg), "Share method ums now %s",
- (available ? "available" : "unavailable"));
- SLOGD(msg);
- getBroadcaster()->sendBroadcast(ResponseCode::ShareAvailabilityChange,
- msg, false);
-}
-
-void VolumeManager::handleSwitchEvent(NetlinkEvent *evt) {
- const char *devpath = evt->findParam("DEVPATH");
- const char *name = evt->findParam("SWITCH_NAME");
- const char *state = evt->findParam("SWITCH_STATE");
-
- if (!name || !state) {
- SLOGW("Switch %s event missing name/state info", devpath);
- return;
- }
-
- bool oldAvailable = massStorageAvailable();
- if (!strcmp(name, "usb_configuration")) {
- mUsbConnected = !strcmp(state, "1");
- SLOGD("USB %s", mUsbConnected ? "connected" : "disconnected");
- bool newAvailable = massStorageAvailable();
- if (newAvailable != oldAvailable) {
- notifyUmsAvailable(newAvailable);
- }
- }
-}
-void VolumeManager::handleUsbCompositeEvent(NetlinkEvent *evt) {
- const char *function = evt->findParam("FUNCTION");
- const char *enabled = evt->findParam("ENABLED");
-
- if (!function || !enabled) {
- SLOGW("usb_composite event missing function/enabled info");
- return;
- }
-
- if (!strcmp(function, "usb_mass_storage")) {
- bool oldAvailable = massStorageAvailable();
- mUsbMassStorageEnabled = !strcmp(enabled, "1");
- SLOGD("usb_mass_storage function %s", mUsbMassStorageEnabled ? "enabled" : "disabled");
- bool newAvailable = massStorageAvailable();
- if (newAvailable != oldAvailable) {
- notifyUmsAvailable(newAvailable);
- }
- }
-}
-
void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
const char *devpath = evt->findParam("DEVPATH");
return 0;
}
-int VolumeManager::shareAvailable(const char *method, bool *avail) {
-
- if (strcmp(method, "ums")) {
- errno = ENOSYS;
- return -1;
- }
-
- *avail = massStorageAvailable();
- return 0;
-}
-
int VolumeManager::shareEnabled(const char *label, const char *method, bool *enabled) {
Volume *v = lookupVolume(label);
return 0;
}
-int VolumeManager::simulate(const char *cmd, const char *arg) {
-
- if (!strcmp(cmd, "ums")) {
- if (!strcmp(arg, "connect")) {
- notifyUmsAvailable(true);
- } else if (!strcmp(arg, "disconnect")) {
- notifyUmsAvailable(false);
- } else {
- errno = EINVAL;
- return -1;
- }
- } else {
- errno = EINVAL;
- return -1;
- }
- return 0;
-}
-
int VolumeManager::shareVolume(const char *label, const char *method) {
Volume *v = lookupVolume(label);
VolumeCollection *mVolumes;
AsecIdCollection *mActiveContainers;
- bool mUsbMassStorageEnabled;
- bool mUsbConnected;
bool mDebug;
// for adjusting /proc/sys/vm/dirty_ratio when UMS is active
int stop();
void handleBlockEvent(NetlinkEvent *evt);
- void handleSwitchEvent(NetlinkEvent *evt);
- void handleUsbCompositeEvent(NetlinkEvent *evt);
int addVolume(Volume *v);
int unmountVolume(const char *label, bool force);
int shareVolume(const char *label, const char *method);
int unshareVolume(const char *label, const char *method);
- int shareAvailable(const char *method, bool *avail);
int shareEnabled(const char *path, const char *method, bool *enabled);
- int simulate(const char *cmd, const char *arg);
int formatVolume(const char *label);
/* ASEC */
VolumeManager();
void readInitialState();
bool isMountpointMounted(const char *mp);
-
- inline bool massStorageAvailable() const { return mUsbMassStorageEnabled && mUsbConnected; }
- void notifyUmsAvailable(bool available);
};
extern "C" {