Perform ACTION_USER_PRESENT processing in a thread
b/7561695
Change-Id: I9bce548caa2f6cc9a380495bfb0058bfc3122ebd
diff --git a/src/com/android/providers/media/MtpService.java b/src/com/android/providers/media/MtpService.java
index 04033e9..74fd747 100644
--- a/src/com/android/providers/media/MtpService.java
+++ b/src/com/android/providers/media/MtpService.java
@@ -71,13 +71,23 @@
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_USER_PRESENT.equals(action)) {
- synchronized (mBinder) {
- // Unhide the storage units when the user has unlocked the lockscreen
- if (mMtpDisabled) {
- addStorageDevicesLocked();
- mMtpDisabled = false;
- }
- }
+ // If the media scanner is running, it may currently be calling
+ // sendObjectAdded/Removed, which also synchronizes on mBinder
+ // (and in addition to that, all the native MtpServer methods
+ // lock the same Mutex). If it happens to be in an mtp device
+ // write(), it may block for some time, so process this broadcast
+ // in a thread.
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ synchronized (mBinder) {
+ // Unhide the storage units when the user has unlocked the lockscreen
+ if (mMtpDisabled) {
+ addStorageDevicesLocked();
+ mMtpDisabled = false;
+ }
+ }
+ }}, "addStorageDevices").start();
}
}
};