Merge "Add timeout to lock in MtpServer configure" into oc-dev
diff --git a/media/mtp/MtpFfsHandle.cpp b/media/mtp/MtpFfsHandle.cpp
index 35dd10f..0ea70fa 100644
--- a/media/mtp/MtpFfsHandle.cpp
+++ b/media/mtp/MtpFfsHandle.cpp
@@ -490,7 +490,11 @@
int MtpFfsHandle::configure(bool usePtp) {
// Wait till previous server invocation has closed
- std::lock_guard<std::mutex> lk(mLock);
+ if (!mLock.try_lock_for(std::chrono::milliseconds(1000))) {
+ LOG(ERROR) << "MtpServer was unable to get configure lock";
+ return -1;
+ }
+ int ret = 0;
// If ptp is changed, the configuration must be rewritten
if (mPtp != usePtp) {
@@ -500,10 +504,10 @@
mPtp = usePtp;
if (!initFunctionfs()) {
- return -1;
+ ret = -1;
}
-
- return 0;
+ mLock.unlock();
+ return ret;
}
void MtpFfsHandle::close() {
diff --git a/media/mtp/MtpFfsHandle.h b/media/mtp/MtpFfsHandle.h
index b4d5a97..7491a1b 100644
--- a/media/mtp/MtpFfsHandle.h
+++ b/media/mtp/MtpFfsHandle.h
@@ -36,7 +36,7 @@
bool mPtp;
- std::mutex mLock;
+ std::timed_mutex mLock;
android::base::unique_fd mControl;
// "in" from the host's perspective => sink for mtp server