summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHemant Gupta <hemantg@codeaurora.org>2016-01-19 15:00:24 +0530
committerSravan Kumar V <sravankumar@codeaurora.org>2016-03-21 15:59:50 +0530
commit84a10777b6a072f4328befc9a9bcccbe00f0c9c1 (patch)
tree0fad35f6552e89278bbeb98bb031bda67f6be877
parent5ef39577be3c0188651413415182a95a849c9ee3 (diff)
downloadandroid_packages_apps_Bluetooth-84a10777b6a072f4328befc9a9bcccbe00f0c9c1.tar.gz
android_packages_apps_Bluetooth-84a10777b6a072f4328befc9a9bcccbe00f0c9c1.tar.bz2
android_packages_apps_Bluetooth-84a10777b6a072f4328befc9a9bcccbe00f0c9c1.zip
OPP: Add checks to initiate rfcomm connection in case sdp fails
This patch initiates rfcomm connection directly when sdp fails to start for Obex over l2cap. This would prevent usecases when in CTS test multiple user are creted, and sdp is initiated by profile user which is different from active user, resulting in unecessary wait for 10 seconds for SDP, leading to test case failure. Change-Id: I2d307b48a9a835e3cec17dc5ca66ddda9c13446e CRs-Fixed: 992642
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppTransfer.java62
1 files changed, 53 insertions, 9 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
index e1b720c5a..c4960d4f1 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
@@ -567,10 +567,17 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
mConnectThread = new SocketConnectThread("localhost", Constants.TCP_DEBUG_PORT, 0);
mConnectThread.start();
} else {
- OolConnManager.setSdpInitiatedAddress(mBatch.mDestination);
- mBatch.mDestination.sdpSearch(BluetoothUuid.ObexObjectPush);
- mConnectThread = new SocketConnectThread(mBatch.mDestination,false);
- mConnectThread.start();
+ OolConnManager.setSdpInitiatedAddress(mBatch.mDestination);
+ if (!mBatch.mDestination.sdpSearch(BluetoothUuid.ObexObjectPush)) {
+ /* SDP failed, start rfcomm connect directly */
+ mConnectThread = new SocketConnectThread(mBatch.mDestination, false, false);
+ /* update bd address as sdp could not be started */
+ OolConnManager.setSdpInitiatedAddress(null);
+ } else {
+ /* SDP sucessfully started, start l2cap connect after sdp completes */
+ mConnectThread = new SocketConnectThread(mBatch.mDestination, false, true);
+ }
+ mConnectThread.start();
}
}
@@ -593,6 +600,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
private boolean mRetry = false;
+ private boolean mSdpInitiated = false;
+
/* create a TCP socket */
public SocketConnectThread(String host, int port, int dummy) {
super("Socket Connect Thread");
@@ -600,9 +609,10 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
this.channel = port;
this.device = null;
isConnected = false;
+ mSdpInitiated = false;
}
- /* create a Rfcomm Socket */
+ /* create a Rfcomm/L2CAP Socket */
public SocketConnectThread(BluetoothDevice device, int channel, boolean
retry) {
super("Socket Connect Thread");
@@ -611,17 +621,30 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
this.channel = channel;
isConnected = false;
mRetry = retry;
+ mSdpInitiated = false;
}
- /* create a Rfcomm Socket */
- public SocketConnectThread(BluetoothDevice device, boolean
- retry) {
+ /* create a Rfcomm/L2CAP Socket */
+ public SocketConnectThread(BluetoothDevice device, boolean retry) {
+ super("Socket Connect Thread");
+ this.device = device;
+ this.host = null;
+ this.channel = -1;
+ isConnected = false;
+ mRetry = retry;
+ mSdpInitiated = false;
+ }
+
+ /* create a Rfcomm/L2CAP Socket */
+ public SocketConnectThread(BluetoothDevice device, boolean retry,
+ boolean sdpInitiated) {
super("Socket Connect Thread");
this.device = device;
this.host = null;
this.channel = -1;
isConnected = false;
mRetry = retry;
+ mSdpInitiated = sdpInitiated;
}
public void interrupt() {
@@ -745,11 +768,32 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
return ;
}
+ Log.d(TAG, "sdp initiated = " + mSdpInitiated);
+
+ // check if sdp initiated successfully for l2cap or not. If not connect
+ // directly to rfcomm
+ if (!mSdpInitiated) {
+ /* sdp failed for some reason, connect on rfcomm */
+ Log.d(TAG, "sdp not initiated, connecting on rfcomm");
+ connectRfcommSocket();
+ return;
+ }
+
+ /* Reset the flag */
+ mSdpInitiated = false;
+
/* Use BluetoothSocket to connect */
l2cChannel = 0;
try {
l2cChannel = OolConnManager.getL2cPSM(device);
- btSocket = device.createInsecureL2capSocket(l2cChannel);
+ if (l2cChannel > 0) {
+ Log.d(TAG, "Connecting to l2cap psm = " + l2cChannel);
+ btSocket = device.createInsecureL2capSocket(l2cChannel);
+ } else {
+ Log.d(TAG, "L2cap psm not found, connecting on rfcomm");
+ connectRfcommSocket();
+ return;
+ }
} catch (IOException e1) {
Log.e(TAG, "L2cap socket create error",e1);
connectRfcommSocket();