diff options
author | Hemant Gupta <hemantg@codeaurora.org> | 2016-01-19 15:00:24 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2016-08-24 08:17:22 -0600 |
commit | f7b2a685b23469082994550381fb715c3a3d3a20 (patch) | |
tree | 72834232590ccdef15aab2cd451818ba907339c2 /src/com/android/bluetooth/opp/BluetoothOppTransfer.java | |
parent | 95054fcf658f1a6d6001097ba5550e35a9ee559a (diff) | |
download | android_packages_apps_Bluetooth-f7b2a685b23469082994550381fb715c3a3d3a20.tar.gz android_packages_apps_Bluetooth-f7b2a685b23469082994550381fb715c3a3d3a20.tar.bz2 android_packages_apps_Bluetooth-f7b2a685b23469082994550381fb715c3a3d3a20.zip |
OPP: Add checks to initiate rfcomm connection in case sdp fails
Initiate 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: 961190
Diffstat (limited to 'src/com/android/bluetooth/opp/BluetoothOppTransfer.java')
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppTransfer.java | 62 |
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 7a4710857..293cbfe5e 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -564,10 +564,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(); } } @@ -590,6 +597,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"); @@ -597,9 +606,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"); @@ -608,17 +618,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() { @@ -733,11 +756,32 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } } else { + 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(); |