summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/opp
diff options
context:
space:
mode:
authorfredc <fredc@broadcom.com>2012-03-30 23:27:24 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-07-16 21:55:24 -0700
commit9f0d856f41d443ec23d5aa2eecfc561d7a3c01d1 (patch)
tree7622b0325dde85bd125a8c6882619f14d815a4d8 /src/com/android/bluetooth/opp
parent0708fe3087b690439dd9745b2cf1a96f29f570b0 (diff)
downloadandroid_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')
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java31
-rwxr-xr-xsrc/com/android/bluetooth/opp/BluetoothOppTransfer.java124
2 files changed, 30 insertions, 125 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java
index 3f139840a..2e4f200a9 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java
@@ -39,6 +39,7 @@ import java.net.Socket;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
+import android.bluetooth.BluetoothUuid;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
@@ -61,10 +62,6 @@ public class BluetoothOppRfcommListener {
private static final int CREATE_RETRY_TIME = 10;
- private static final int DEFAULT_OPP_CHANNEL = 12;
-
- private final int mBtOppRfcommChannel;
-
private final BluetoothAdapter mAdapter;
private BluetoothServerSocket mBtServerSocket = null;
@@ -72,14 +69,10 @@ public class BluetoothOppRfcommListener {
private ServerSocket mTcpServerSocket = null;
public BluetoothOppRfcommListener(BluetoothAdapter adapter) {
- this(adapter, DEFAULT_OPP_CHANNEL);
- }
-
- public BluetoothOppRfcommListener(BluetoothAdapter adapter, int channel) {
- mBtOppRfcommChannel = channel;
mAdapter = adapter;
}
+
public synchronized boolean start(Handler callback) {
if (mSocketAcceptThread == null) {
mCallback = callback;
@@ -120,19 +113,18 @@ public class BluetoothOppRfcommListener {
* retry for 10 times
*/
for (int i = 0; i < CREATE_RETRY_TIME && !mInterrupted; i++) {
- //TODO(BT)
- /*
try {
- mBtServerSocket = mAdapter
- .listenUsingInsecureRfcommOn(mBtOppRfcommChannel);
+ if (V) Log.v(TAG, "Starting RFCOMM listener....");
+ mBtServerSocket = mAdapter.listenUsingInsecureRfcommWithServiceRecord("OBEX Object Push", BluetoothUuid.ObexObjectPush.getUuid());
+ if (V) Log.v(TAG, "Started RFCOMM listener....");
} catch (IOException e1) {
Log.e(TAG, "Error create RfcommServerSocket " + e1);
serverOK = false;
- }*/
+ }
if (!serverOK) {
synchronized (this) {
try {
- if (V) Log.v(TAG, "wait 3 seconds");
+ if (V) Log.v(TAG, "Wait 3 seconds");
Thread.sleep(3000);
} catch (InterruptedException e) {
Log.e(TAG, "socketAcceptThread thread was interrupted (3)");
@@ -148,15 +140,14 @@ public class BluetoothOppRfcommListener {
mInterrupted = true;
}
if (!mInterrupted) {
- Log.i(TAG, "Accept thread started on channel " + mBtOppRfcommChannel);
+ Log.i(TAG, "Accept thread started.");
}
BluetoothSocket clientSocket;
- //TODO(BT)
- /*
while (!mInterrupted) {
try {
+ if (V) Log.v(TAG, "Accepting connection...");
clientSocket = mBtServerSocket.accept();
- Log.i(TAG, "Accepted connectoin from "
+ if (V) Log.v(TAG, "Accepted connection from "
+ clientSocket.getRemoteDevice());
BluetoothOppRfcommTransport transport = new BluetoothOppRfcommTransport(
clientSocket);
@@ -168,7 +159,7 @@ public class BluetoothOppRfcommListener {
} catch (IOException e) {
Log.e(TAG, "Error accept connection " + e);
}
- }*/
+ }
Log.i(TAG, "BluetoothSocket listen thread finished");
}
}
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);
}
}