Merge "AVRCP: Prevent multithread issues in cleanup"
diff --git a/src/com/android/bluetooth/avrcp/AddressedMediaPlayer.java b/src/com/android/bluetooth/avrcp/AddressedMediaPlayer.java
index f67165d..d857228 100644
--- a/src/com/android/bluetooth/avrcp/AddressedMediaPlayer.java
+++ b/src/com/android/bluetooth/avrcp/AddressedMediaPlayer.java
@@ -133,7 +133,9 @@
         }
         mNowPlayingList = items;
         // TODO (jamuraa): test to see if the single-item queue is the same and don't send
-        mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
+        if (mMediaInterface != null) {
+            mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
+        }
         return items;
     }
 
diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java
index 6b3fc10..8d7d488 100644
--- a/src/com/android/bluetooth/avrcp/Avrcp.java
+++ b/src/com/android/bluetooth/avrcp/Avrcp.java
@@ -292,7 +292,7 @@
         context.registerReceiver(mBootReceiver, bootFilter);
     }
 
-    private void start() {
+    private synchronized void start() {
         HandlerThread thread = new HandlerThread("BluetoothAvrcpHandler");
         thread.start();
         Looper looper = thread.getLooper();
@@ -334,11 +334,9 @@
         return ar;
     }
 
-    public void doQuit() {
+    public synchronized void doQuit() {
         if (DEBUG) Log.d(TAG, "doQuit");
-        synchronized (this) {
-            if (mMediaController != null) mMediaController.unregisterCallback(mMediaControllerCb);
-        }
+        if (mMediaController != null) mMediaController.unregisterCallback(mMediaControllerCb);
         if (mMediaSessionManager != null) {
             mMediaSessionManager.setCallback(null, null);
             mMediaSessionManager.removeOnActiveSessionsChangedListener(mActiveSessionListener);