diff options
author | fredc <fredc@broadcom.com> | 2012-03-30 23:27:24 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-07-16 21:55:24 -0700 |
commit | 9f0d856f41d443ec23d5aa2eecfc561d7a3c01d1 (patch) | |
tree | 7622b0325dde85bd125a8c6882619f14d815a4d8 /src/com/android/bluetooth/opp/BluetoothOppTransfer.java | |
parent | 0708fe3087b690439dd9745b2cf1a96f29f570b0 (diff) | |
download | android_packages_apps_Bluetooth-9f0d856f41d443ec23d5aa2eecfc561d7a3c01d1.tar.gz android_packages_apps_Bluetooth-9f0d856f41d443ec23d5aa2eecfc561d7a3c01d1.tar.bz2 android_packages_apps_Bluetooth-9f0d856f41d443ec23d5aa2eecfc561d7a3c01d1.zip |
Initial checkin of OPP and PBAP
Change-Id: Ie43a26874bd5f0c00d69c2ce02430f4a16da327a
Diffstat (limited to 'src/com/android/bluetooth/opp/BluetoothOppTransfer.java')
-rwxr-xr-x | src/com/android/bluetooth/opp/BluetoothOppTransfer.java | 124 |
1 files changed, 19 insertions, 105 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index ec9c7db46..1f8690b98 100755 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -76,8 +76,6 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch private static final int RFCOMM_CONNECTED = 11; - private static final int SDP_RESULT = 12; - private static final int SOCKET_ERROR_RETRY = 13; private static final int CONNECT_WAIT_TIMEOUT = 45000; @@ -137,32 +135,10 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch @Override public void handleMessage(Message msg) { switch (msg.what) { - case SDP_RESULT: - if (V) Log.v(TAG, "SDP request returned " + msg.arg1 + " (" + - (System.currentTimeMillis() - mTimestamp + " ms)")); - if (!((BluetoothDevice)msg.obj).equals(mBatch.mDestination)) { - return; - } - try { - mContext.unregisterReceiver(mReceiver); - } catch (IllegalArgumentException e) { - // ignore - } - if (msg.arg1 > 0) { - mConnectThread = new - SocketConnectThread(mBatch.mDestination, msg.arg1, false); - mConnectThread.start(); - } else { - /* SDP query fail case */ - Log.e(TAG, "SDP query failed!"); - markBatchFailed(BluetoothShare.STATUS_CONNECTION_ERROR); - mBatch.mStatus = Constants.BATCH_STATUS_FAILED; - } - - break; case SOCKET_ERROR_RETRY: mConnectThread = new - SocketConnectThread((BluetoothDevice)msg.obj, msg.arg1, true); + SocketConnectThread((BluetoothDevice)msg.obj, true); + mConnectThread.start(); break; case RFCOMM_ERROR: @@ -510,79 +486,11 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch mConnectThread = new SocketConnectThread("localhost", Constants.TCP_DEBUG_PORT, 0); mConnectThread.start(); } else { - int channel = BluetoothOppPreference.getInstance(mContext).getChannel( - mBatch.mDestination, OPUSH_UUID16); - if (channel != -1) { - if (D) Log.d(TAG, "Get OPUSH channel " + channel + " from cache for " + - mBatch.mDestination); - mTimestamp = System.currentTimeMillis(); - mSessionHandler.obtainMessage(SDP_RESULT, channel, -1, mBatch.mDestination) - .sendToTarget(); - } else { - doOpushSdp(); - } - } - } - - private void doOpushSdp() { - if (V) Log.v(TAG, "Do Opush SDP request for address " + mBatch.mDestination); - - mTimestamp = System.currentTimeMillis(); - - int channel; - channel = mBatch.mDestination.getServiceChannel(BluetoothUuid.ObexObjectPush); - if (channel != -1) { - if (D) Log.d(TAG, "Get OPUSH channel " + channel + " from SDP for " - + mBatch.mDestination); - - mSessionHandler.obtainMessage(SDP_RESULT, channel, -1, mBatch.mDestination) - .sendToTarget(); - return; - - } else { - if (V) Log.v(TAG, "Remote Service channel not in cache"); - - if (!mBatch.mDestination.fetchUuidsWithSdp()) { - Log.e(TAG, "Start SDP query failed"); - } else { - // we expect framework send us Intent ACTION_UUID. otherwise we will fail - if (V) Log.v(TAG, "Start new SDP, wait for result"); - IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_UUID); - mContext.registerReceiver(mReceiver, intentFilter); - return; - } + mConnectThread = new SocketConnectThread(mBatch.mDestination,false); + mConnectThread.start(); } - Message msg = mSessionHandler.obtainMessage(SDP_RESULT, channel, -1, mBatch.mDestination); - mSessionHandler.sendMessageDelayed(msg, 2000); } - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(BluetoothDevice.ACTION_UUID)) { - BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - if (V) Log.v(TAG, "ACTION_UUID for device " + device); - if (device.equals(mBatch.mDestination)) { - int channel = -1; - Parcelable[] uuid = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID); - if (uuid != null) { - ParcelUuid[] uuids = new ParcelUuid[uuid.length]; - for (int i = 0; i < uuid.length; i++) { - uuids[i] = (ParcelUuid)uuid[i]; - } - if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.ObexObjectPush)) { - if (V) Log.v(TAG, "SDP get OPP result for device " + device); - channel = mBatch.mDestination - .getServiceChannel(BluetoothUuid.ObexObjectPush); - } - } - mSessionHandler.obtainMessage(SDP_RESULT, channel, -1, mBatch.mDestination) - .sendToTarget(); - } - } - } - }; - private SocketConnectThread mConnectThread; private class SocketConnectThread extends Thread { @@ -620,6 +528,17 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch mRetry = retry; } + /* create a Rfcomm Socket */ + public SocketConnectThread(BluetoothDevice device, boolean + retry) { + super("Socket Connect Thread"); + this.device = device; + this.host = null; + this.channel = -1; + isConnected = false; + mRetry = retry; + } + public void interrupt() { if (!Constants.USE_TCP_DEBUG) { if (btSocket != null) { @@ -694,9 +613,9 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch /* Use BluetoothSocket to connect */ try { - btSocket = device.createInsecureRfcommSocket(channel); + btSocket = device.createInsecureRfcommSocketToServiceRecord(BluetoothUuid.ObexObjectPush.getUuid()); } catch (IOException e1) { - Log.e(TAG, "Rfcomm socket create error"); + Log.e(TAG, "Rfcomm socket create error",e1); markConnectionFailed(btSocket); return; } @@ -708,15 +627,13 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch BluetoothOppRfcommTransport transport; transport = new BluetoothOppRfcommTransport(btSocket); - BluetoothOppPreference.getInstance(mContext).setChannel(device, OPUSH_UUID16, - channel); BluetoothOppPreference.getInstance(mContext).setName(device, device.getName()); if (V) Log.v(TAG, "Send transport message " + transport.toString()); mSessionHandler.obtainMessage(RFCOMM_CONNECTED, transport).sendToTarget(); } catch (IOException e) { - Log.e(TAG, "Rfcomm socket connect exception"); + Log.e(TAG, "Rfcomm socket connect exception",e); // If the devices were paired before, but unpaired on the // remote end, it will return an error for the auth request // for the socket connection. Link keys will get exchanged @@ -724,12 +641,9 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch // inform this socket asking it to retry apart from a blind // delayed retry. if (!mRetry && e.getMessage().equals(SOCKET_LINK_KEY_ERROR)) { - Message msg = mSessionHandler.obtainMessage(SOCKET_ERROR_RETRY, - channel, -1, device); + Message msg = mSessionHandler.obtainMessage(SOCKET_ERROR_RETRY,-1,-1,device); mSessionHandler.sendMessageDelayed(msg, 1500); } else { - BluetoothOppPreference.getInstance(mContext) - .removeChannel(device, OPUSH_UUID16); markConnectionFailed(btSocket); } } |