diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2016-11-23 15:11:13 -0700 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2016-11-23 15:11:13 -0700 |
commit | c7ae94e96c0c7bb93ec80d548c024a968c411d32 (patch) | |
tree | 8d5c989d2c31f55122ba62c65aa40e83e0188bc9 | |
parent | 45073c8d3d3188c8c0ac8edc7cec0dd80ca61e75 (diff) | |
parent | eddf6db49910f6d679e85586e53985034f2eff52 (diff) | |
download | android_packages_apps_Bluetooth-c7ae94e96c0c7bb93ec80d548c024a968c411d32.tar.gz android_packages_apps_Bluetooth-c7ae94e96c0c7bb93ec80d548c024a968c411d32.tar.bz2 android_packages_apps_Bluetooth-c7ae94e96c0c7bb93ec80d548c024a968c411d32.zip |
Promotion of bt.lnx.2.1-00038.
CRs Change ID Subject
--------------------------------------------------------------------------------------------------------------
1088801 I0c13b1608286cf81463c7e8e5363c42bdef4e176 GAP: Check prev discovery state during discovery operati
1088247 I65d658da81fdb48ba40315d8cb176b9f3427bede A2DP: Fix NPE issue while BT turning off
1086579 I766538debaec330c5694844c4b7145bc9402dc6e Serialize the RC Cleanup events in BT-App context
736029 Ie1db73c8d0ad184b3920c3d8784a56ae8ad2d75d Cancel inquiry while auto-reconnect.
1089590 Ia12a26398f47c6bcfdf7346e5f8d00f77b56349e Modified playstatus mapping and disallow sending invalid
1084325 I40667a6e8c5a2cb047a1fd081d676e654e3ee858 Opp : Check interrupted state before create socket
Change-Id: I557b7ebfdad46c3e6a06574e825453937c425d23
CRs-Fixed: 1088801, 1084325, 1086579, 1088247, 736029, 1089590
-rw-r--r-- | src/com/android/bluetooth/OolConnManager.java | 4 | ||||
-rw-r--r-- | src/com/android/bluetooth/avrcp/Avrcp.java | 69 | ||||
-rw-r--r-- | src/com/android/bluetooth/btservice/AdapterService.java | 19 | ||||
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppTransfer.java | 23 |
4 files changed, 93 insertions, 22 deletions
diff --git a/src/com/android/bluetooth/OolConnManager.java b/src/com/android/bluetooth/OolConnManager.java index 44729180c..c0b56e143 100644 --- a/src/com/android/bluetooth/OolConnManager.java +++ b/src/com/android/bluetooth/OolConnManager.java @@ -40,6 +40,7 @@ public class OolConnManager { static int channel = 0; static boolean sdpDone = false; static String mAddress; + public static boolean interruptSdp = false; public static BluetoothSocket CreateL2capConnection(BluetoothDevice remBtDev,UUID uuid ) { @@ -66,7 +67,7 @@ public class OolConnManager { int waitCount = 0; int channelNo = -1; - while(!sdpDone && waitCount < 100) { + while(!sdpDone && waitCount < 100 && (!interruptSdp)) { try { Thread.sleep(100); @@ -77,6 +78,7 @@ public class OolConnManager { } waitCount = 0; sdpDone = false; + interruptSdp = false; Log.d(TAG,"returning l2c channel as "+channel); channelNo = channel; diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java index 9c59c9982..8d7a77dc7 100644 --- a/src/com/android/bluetooth/avrcp/Avrcp.java +++ b/src/com/android/bluetooth/avrcp/Avrcp.java @@ -154,6 +154,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; @@ -751,16 +755,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); @@ -773,6 +771,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() { @@ -1513,6 +1518,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; @@ -1703,7 +1733,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, @@ -5014,16 +5044,17 @@ public final class Avrcp { int playStatus = PLAYSTATUS_ERROR; switch (state.getState()) { case PlaybackState.STATE_PLAYING: - case PlaybackState.STATE_BUFFERING: playStatus = PLAYSTATUS_PLAYING; break; case PlaybackState.STATE_STOPPED: + case PlaybackState.STATE_CONNECTING: case PlaybackState.STATE_NONE: playStatus = PLAYSTATUS_STOPPED; break; case PlaybackState.STATE_PAUSED: + case PlaybackState.STATE_BUFFERING: playStatus = PLAYSTATUS_PAUSED; break; @@ -5063,6 +5094,14 @@ public final class Avrcp { return; } long playPositionMs = getPlayPosition(deviceFeatures[i].mCurrentDevice); + int currPlayStatus = convertPlayStateToPlayStatus(deviceFeatures[i].mCurrentPlayState); + + // Some remote devices are going to bad state when sending play position + // as ffff for non-playing state + if (playPositionMs == -1L && currPlayStatus != PLAYSTATUS_PLAYING) { + if (DEBUG) Log.d(TAG, " Don't send invalid play position notification for non-playing state"); + return; + } // mNextPosMs is set to -1 when the previous position was invalid // so this will be true if the new position is valid & old was invalid. @@ -5614,11 +5653,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 fb7d28226..4dcca00b0 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -1643,7 +1643,10 @@ public class AdapterService extends Service { Log.i(TAG,"A2dp Multicast is Ongoing, ignore discovery"); return false; } - + if (mAdapterProperties.isDiscovering()) { + Log.i(TAG,"discovery already active, ignore startDiscovery"); + return false; + } return startDiscoveryNative(); } @@ -1651,6 +1654,10 @@ public class AdapterService extends Service { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); + if (!mAdapterProperties.isDiscovering()) { + Log.i(TAG,"discovery not active, ignore cancelDiscovery"); + return false; + } return cancelDiscoveryNative(); } @@ -1800,9 +1807,10 @@ public class AdapterService extends Service { for (BluetoothDevice device : bondedDevices) { if (headsetClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT){ - debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " + - device.toString()); - headsetClientService.connect(device); + cancelDiscoveryforautoConnect(); + debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " + + device.toString()); + headsetClientService.connect(device); } } } @@ -1831,6 +1839,7 @@ public class AdapterService extends Service { } for (BluetoothDevice device : bondedDevices) { if (pbapClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) { + cancelDiscoveryforautoConnect(); debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString()); pbapClientService.connect(device); @@ -2110,9 +2119,9 @@ public class AdapterService extends Service { case BluetoothProfile.A2DP: A2dpService a2dpService = A2dpService.getA2dpService(); - deviceList = a2dpService.getConnectedDevices(); if ((a2dpService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != a2dpService.getPriority(device))){ + deviceList = a2dpService.getConnectedDevices(); adjustOtherSinkPriorities(a2dpService, deviceList); a2dpService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index d74cbd67b..bc2510faf 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -416,8 +416,9 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch if (mConnectThread != null) { try { mConnectThread.interrupt(); - if (V) Log.v(TAG, "waiting for connect thread to terminate"); + if (D) Log.v(TAG, "waiting for connect thread to terminate"); mConnectThread.join(); + if (D) Log.d(TAG, "connect thread to terminated"); } catch (InterruptedException e) { if (V) Log.v(TAG, "Interrupted waiting for connect thread to join"); } @@ -435,6 +436,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch mHandlerThread = null; } } + if (V) Log.v(TAG, "exit stop :"+mConnectThread); } private void startObexSession() { @@ -603,6 +605,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch private boolean mSdpInitiated = false; + private boolean isInterrupted = false; + /* create a TCP socket */ public SocketConnectThread(String host, int port, int dummy) { super("Socket Connect Thread"); @@ -611,6 +615,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch this.device = null; isConnected = false; mSdpInitiated = false; + isInterrupted = false; } /* create a Rfcomm/L2CAP Socket */ @@ -623,6 +628,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch isConnected = false; mRetry = retry; mSdpInitiated = false; + isInterrupted = false; } /* create a Rfcomm/L2CAP Socket */ @@ -649,7 +655,10 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } public void interrupt() { + Log.d(TAG, "start interrupt :" + btSocket); if (!Constants.USE_TCP_DEBUG) { + isInterrupted = true; + OolConnManager.interruptSdp= true; if (btSocket != null) { try { btSocket.close(); @@ -664,6 +673,11 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch if (V) Log.v(TAG, "connectRfcommSocket"); try { + if (isInterrupted) { + Log.d(TAG, "connectRfcommSocket interrupted"); + markConnectionFailed(btSocket); + return; + } btSocket = device.createInsecureRfcommSocketToServiceRecord(BluetoothUuid.ObexObjectPush.getUuid()); } catch (IOException e1) { Log.e(TAG, "Rfcomm socket create error",e1); @@ -786,6 +800,13 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch l2cChannel = 0; try { l2cChannel = OolConnManager.getL2cPSM(device); + if (isInterrupted) { + Log.e(TAG, "btSocket connect interrupted "); + markConnectionFailed(btSocket); + return; + } else { + btSocket = device.createInsecureL2capSocket(l2cChannel); + } if (l2cChannel > 0) { Log.d(TAG, "Connecting to l2cap psm = " + l2cChannel); btSocket = device.createInsecureL2capSocket(l2cChannel); |