summaryrefslogtreecommitdiffstats
path: root/mtp/MtpServer.cpp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2014-12-17 03:01:38 +0100
committerEthan Yonker <dees_troy@teamw.in>2014-12-19 23:27:34 +0100
commit726a0206326ca4cf22aa7c59e174a83a0da9727f (patch)
tree5f0275dfed9c51b255e73feaeba609cd7a762da1 /mtp/MtpServer.cpp
parentRecovery init.rc setenforce 0 to make SELinux permissive (diff)
downloadandroid_bootable_recovery-726a0206326ca4cf22aa7c59e174a83a0da9727f.tar
android_bootable_recovery-726a0206326ca4cf22aa7c59e174a83a0da9727f.tar.gz
android_bootable_recovery-726a0206326ca4cf22aa7c59e174a83a0da9727f.tar.bz2
android_bootable_recovery-726a0206326ca4cf22aa7c59e174a83a0da9727f.tar.lz
android_bootable_recovery-726a0206326ca4cf22aa7c59e174a83a0da9727f.tar.xz
android_bootable_recovery-726a0206326ca4cf22aa7c59e174a83a0da9727f.tar.zst
android_bootable_recovery-726a0206326ca4cf22aa7c59e174a83a0da9727f.zip
Diffstat (limited to 'mtp/MtpServer.cpp')
-rwxr-xr-xmtp/MtpServer.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/mtp/MtpServer.cpp b/mtp/MtpServer.cpp
index f4af2b948..f99554b03 100755
--- a/mtp/MtpServer.cpp
+++ b/mtp/MtpServer.cpp
@@ -116,9 +116,13 @@ MtpServer::~MtpServer() {
}
void MtpServer::addStorage(MtpStorage* storage) {
+ android::Mutex::Autolock autoLock(mMutex);
MTPD("addStorage(): storage: %x\n", storage);
+ if (getStorage(storage->getStorageID()) != NULL) {
+ MTPE("MtpServer::addStorage Storage for storage ID %i already exists.\n", storage->getStorageID());
+ return;
+ }
mDatabase->createDB(storage, storage->getStorageID());
- android::Mutex::Autolock autoLock(mMutex);
mStorages.push(storage);
sendStoreAdded(storage->getStorageID());
}
@@ -128,11 +132,31 @@ void MtpServer::removeStorage(MtpStorage* storage) {
for (size_t i = 0; i < mStorages.size(); i++) {
if (mStorages[i] == storage) {
+ MTPD("MtpServer::removeStorage calling sendStoreRemoved\n");
+ // First lock the mutex so that the inotify thread and main
+ // thread do not do anything while we remove the storage
+ // item, and to make sure we don't remove the item while an
+ // operation is in progress
+ mDatabase->lockMutex();
+ // Grab the storage ID before we delete the item from the
+ // database
+ MtpStorageID storageID = storage->getStorageID();
+ // Remove the item from the mStorages from the vector. At
+ // this point the main thread will no longer be able to find
+ // this storage item anymore.
mStorages.removeAt(i);
- sendStoreRemoved(storage->getStorageID());
+ // Destroy the storage item, free up all the memory, kill
+ // the inotify thread.
+ mDatabase->destroyDB(storageID);
+ // Tell the host OS that the storage item is gone.
+ sendStoreRemoved(storageID);
+ // Unlock any remaining mutexes on other storage devices.
+ // If no storage devices exist anymore this will do nothing.
+ mDatabase->unlockMutex();
break;
}
}
+ MTPD("MtpServer::removeStorage DONE\n");
}
MtpStorage* MtpServer::getStorage(MtpStorageID id) {
@@ -275,6 +299,7 @@ void MtpServer::sendStoreAdded(MtpStorageID id) {
void MtpServer::sendStoreRemoved(MtpStorageID id) {
MTPD("sendStoreRemoved %08X\n", id);
sendEvent(MTP_EVENT_STORE_REMOVED, id);
+ MTPD("MtpServer::sendStoreRemoved done\n");
}
void MtpServer::sendEvent(MtpEventCode code, uint32_t param1) {