diff options
Diffstat (limited to 'src/com/android/bluetooth')
-rw-r--r-- | src/com/android/bluetooth/avrcp/Avrcp.java | 58 | ||||
-rw-r--r-- | src/com/android/bluetooth/btservice/AdapterService.java | 9 | ||||
-rw-r--r-- | src/com/android/bluetooth/gatt/ScanManager.java | 2 |
3 files changed, 48 insertions, 21 deletions
diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java index 3f9c35f4a..50c7ece8c 100644 --- a/src/com/android/bluetooth/avrcp/Avrcp.java +++ b/src/com/android/bluetooth/avrcp/Avrcp.java @@ -153,6 +153,10 @@ public final class Avrcp { private static final int MESSAGE_CHANGE_PLAY_POS = 12; private static final int MESSAGE_SET_A2DP_AUDIO_STATE = 13; private static final int MESSAGE_SET_ADDR_PLAYER_REQ_TIMEOUT = 14; + private static final int MESSAGE_DEVICE_RC_CLEANUP = 15; + + private static final int STACK_CLEANUP = 0; + private static final int APP_CLEANUP = 1; private static final int AVRCP_BR_RSP_TIMEOUT = 2000; private static final int MESSAGE_SEND_PASS_THROUGH_CMD = 2001; @@ -749,16 +753,10 @@ public final class Avrcp { public void doQuit() { if (DEBUG) Log.v(TAG, "doQuit"); - mHandler.removeCallbacksAndMessages(null); - Looper looper = mHandler.getLooper(); - if (looper != null) { - looper.quit(); - } - mMediaSessionManager.removeOnActiveSessionsChangedListener(mSessionChangeListener); - clearDeviceDependentFeature(); - for (int i = 0; i < maxAvrcpConnections; i++) { - cleanupDeviceFeaturesIndex(i); - } + Message msg = mHandler.obtainMessage(MESSAGE_DEVICE_RC_CLEANUP, APP_CLEANUP, + 0, null); + mHandler.sendMessage(msg); + mAvrcpBipRsp.stop(); try { mContext.unregisterReceiver(mIntentReceiver); @@ -771,6 +769,13 @@ public final class Avrcp { if (DEBUG) Log.v(TAG, "Addressed player message cleanup as part of doQuit"); } + + mHandler.removeCallbacksAndMessages(null); + Looper looper = mHandler.getLooper(); + if (looper != null) { + looper.quit(); + } + mMediaSessionManager.removeOnActiveSessionsChangedListener(mSessionChangeListener); } public void clearDeviceDependentFeature() { @@ -1539,6 +1544,31 @@ public final class Avrcp { updateA2dpAudioState(msg.arg1, (BluetoothDevice)msg.obj); break; + case MESSAGE_DEVICE_RC_CLEANUP: + if (DEBUG) + Log.v(TAG,"MESSAGE_DEVICE_RC_CLEANUP: " + msg.arg1); + if (msg.arg1 == STACK_CLEANUP) { + deviceIndex = getIndexForDevice((BluetoothDevice) msg.obj); + if (deviceIndex == INVALID_DEVICE_INDEX) { + Log.e(TAG,"invalid device index for cleanup"); + break; + } + cleanupDeviceFeaturesIndex(deviceIndex); + } else if (msg.arg1 == APP_CLEANUP) { + if (msg.obj == null) { + clearDeviceDependentFeature(); + for (int i = 0; i < maxAvrcpConnections; i++) { + cleanupDeviceFeaturesIndex(i); + } + } else { + Log.v(TAG, "Invalid message params"); + break; + } + } else { + Log.v(TAG, "Invalid Arguments to MESSAGE_DEVICE_RC_CLEANUP"); + } + break; + case MSG_UPDATE_RCC_CHANGE: Log.v(TAG, "MSG_UPDATE_RCC_CHANGE"); String callingPackageName = (String)msg.obj; @@ -1729,7 +1759,7 @@ public final class Avrcp { deviceFeatures[deviceIndex].mCurrentPlayState = state; if ((deviceFeatures[deviceIndex].mPlayStatusChangedNT == NOTIFICATION_TYPE_INTERIM) && - (oldPlayStatus != newPlayStatus)) { + (oldPlayStatus != newPlayStatus) && deviceFeatures[deviceIndex].mCurrentDevice != null) { deviceFeatures[deviceIndex].mPlayStatusChangedNT = NOTIFICATION_TYPE_CHANGED; registerNotificationRspPlayStatusNative( deviceFeatures[deviceIndex].mPlayStatusChangedNT, @@ -5353,11 +5383,11 @@ public final class Avrcp { if (deviceFeatures[i].mCurrentDevice !=null && deviceFeatures[i].mCurrentDevice.equals(device)) { // initiate cleanup for all variables; - + Message msg = mHandler.obtainMessage(MESSAGE_DEVICE_RC_CLEANUP, STACK_CLEANUP, + 0, device); + mHandler.sendMessage(msg); Log.i(TAG,"Device removed is " + device); Log.i(TAG,"removed at " + i); - deviceFeatures[i].mCurrentDevice = null; - cleanupDeviceFeaturesIndex(i); /* device is disconnect and some response form music app was * pending for this device clear it.*/ if (mBrowserDevice != null && diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index 9d26c0d67..09f03808f 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -547,12 +547,9 @@ public class AdapterService extends Service { return mBinder; } public boolean onUnbind(Intent intent) { - if (getState() == BluetoothAdapter.STATE_OFF) { - Log.w(TAG, "onUnbind, calling cleanup"); - cleanup(); - return super.onUnbind(intent); - } - return false; + Log.w(TAG, "onUnbind, calling cleanup"); + cleanup(); + return super.onUnbind(intent); } public void onDestroy() { diff --git a/src/com/android/bluetooth/gatt/ScanManager.java b/src/com/android/bluetooth/gatt/ScanManager.java index b20a54f3f..7712997db 100644 --- a/src/com/android/bluetooth/gatt/ScanManager.java +++ b/src/com/android/bluetooth/gatt/ScanManager.java @@ -268,7 +268,7 @@ public class ScanManager { mScanNative.stopRegularScan(client); - if (mScanNative.numRegularScanClients() == 0) { + if (mScanNative.numRegularScanClients() == 0 && mHandler != null) { mHandler.removeMessages(MSG_SCAN_TIMEOUT); } |