summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorJerry Zhang <zhangjerry@google.com>2017-03-07 15:56:07 -0800
committerJerry Zhang <zhangjerry@google.com>2017-03-08 22:02:28 +0000
commitb5bb058f1b32c598743234689db407a57fa12fc5 (patch)
treed2544e5ba7b6c5c0d2697d866f4e045d73f963b4 /src/com
parent792f244db4fb8da6ba24c9d930114ca90c0a2305 (diff)
downloadMediaProvider-b5bb058f1b32c598743234689db407a57fa12fc5.tar.gz
Only unbind Mtp service during disconnect or disable
This preserves MediaProvider's reference to MtpService. Bug: 35108939 Test: MtpHostTest in Cts verifier Change-Id: Ibef4a2445f16d76aab0d67d5341a906942c8a0bd
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/providers/media/MtpReceiver.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/com/android/providers/media/MtpReceiver.java b/src/com/android/providers/media/MtpReceiver.java
index 0e8990240..00f460c9b 100644
--- a/src/com/android/providers/media/MtpReceiver.java
+++ b/src/com/android/providers/media/MtpReceiver.java
@@ -49,6 +49,7 @@ public class MtpReceiver extends BroadcastReceiver {
private void handleUsbState(Context context, Intent intent) {
Bundle extras = intent.getExtras();
boolean configured = extras.getBoolean(UsbManager.USB_CONFIGURED);
+ boolean connected = extras.getBoolean(UsbManager.USB_CONNECTED);
boolean mtpEnabled = extras.getBoolean(UsbManager.USB_FUNCTION_MTP);
boolean ptpEnabled = extras.getBoolean(UsbManager.USB_FUNCTION_PTP);
boolean unlocked = extras.getBoolean(UsbManager.USB_DATA_UNLOCKED);
@@ -70,7 +71,8 @@ public class MtpReceiver extends BroadcastReceiver {
}
if (DEBUG) { Log.d(TAG, "handleUsbState startService"); }
context.startService(intent);
- } else {
+ } else if (!connected || !(mtpEnabled || ptpEnabled)) {
+ // Only unbind if disconnected or disabled.
boolean status = context.stopService(new Intent(context, MtpService.class));
if (DEBUG) { Log.d(TAG, "handleUsbState stopService status=" + status); }
// tell MediaProvider MTP is disconnected so it can unbind from the service