From a3f8514492cb4bc8fa7c36e2c0f720342796ada7 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Thu, 17 Mar 2011 09:43:50 -0400 Subject: [PATCH] MtpServer: Do not attempt to stop MTP if it has not been started Fixes an ANR that occurred if we got a USB disconnected event before the MTP service had started. Bug: 4118033 Change-Id: I6cad4281a5911a9926cae923f34d3a6bf98346c5 Signed-off-by: Mike Lockwood --- media/java/android/mtp/MtpServer.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/media/java/android/mtp/MtpServer.java b/media/java/android/mtp/MtpServer.java index fe734e141cbce..006fa6d22aa28 100644 --- a/media/java/android/mtp/MtpServer.java +++ b/media/java/android/mtp/MtpServer.java @@ -24,6 +24,9 @@ import android.util.Log; */ public class MtpServer { + private final Object mLock = new Object(); + private boolean mStarted; + private static final String TAG = "MtpServer"; static { @@ -35,11 +38,19 @@ public class MtpServer { } public void start() { - native_start(); + synchronized (mLock) { + native_start(); + mStarted = true; + } } public void stop() { - native_stop(); + synchronized (mLock) { + if (mStarted) { + native_stop(); + mStarted = false; + } + } } public void sendObjectAdded(int handle) {