diff options
9 files changed, 117 insertions, 74 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java b/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java index 3cbc1bc74..d0f9ff30c 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +++ b/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java @@ -121,8 +121,7 @@ public class BluetoothOppLauncherActivity extends Activity { if (V) Log.v(TAG, "BT already enabled!! "); Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); in1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - //TODO modify to false after SDP query is ok - in1.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, true); + in1.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false); in1.putExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE, BluetoothDevicePicker.FILTER_TYPE_TRANSFER); in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE, diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index 3003cfea2..c83e2f0e4 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -36,6 +36,7 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import android.content.ContentValues; import android.content.Context; @@ -280,7 +281,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen } if (V) Log.v(TAG, "insert contentUri: " + contentUri); - Log.v(TAG, "mLocalShareInfoId = " + mLocalShareInfoId); + if (V) Log.v(TAG, "mLocalShareInfoId = " + mLocalShareInfoId); if (V) Log.v(TAG, "acquire partial WakeLock"); if (mWakeLock.isHeld()) { @@ -308,8 +309,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen } } if (D) Log.d(TAG, "Server unblocked "); - if (mCallback != null && mTimeoutMsgSent) { - mCallback.removeMessages(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT); + synchronized (this) { + if (mCallback != null && mTimeoutMsgSent) { + mCallback.removeMessages(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT); + } } /* we should have mInfo now */ @@ -513,24 +516,24 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen if (D) Log.d(TAG, "onConnect"); if (V) Constants.logHeader(request); - + try { + byte[] uuid = (byte[])request.getHeader(HeaderSet.TARGET); + if (V) Log.v(TAG, "onConnect(): uuid =" + Arrays.toString(uuid)); + if(uuid != null) { + reply.setHeader(HeaderSet.WHO, uuid); + } + } catch (IOException e) { + Log.e(TAG, e.toString()); + return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; + } mTimestamp = System.currentTimeMillis(); return ResponseCodes.OBEX_HTTP_OK; } @Override public void onDisconnect(HeaderSet req, HeaderSet resp) { - if (D) Log.d(TAG, "onDisconnect"); resp.responseCode = ResponseCodes.OBEX_HTTP_OK; - - /* onDisconnect could happen even before start() where mCallback is set */ - if (mCallback != null) { - Message msg = Message.obtain(mCallback); - msg.what = BluetoothOppObexSession.MSG_SESSION_COMPLETE; - msg.obj = mInfo; - msg.sendToTarget(); - } } @Override @@ -542,5 +545,12 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen if (mPartialWakeLock.isHeld()) { mPartialWakeLock.release(); } + /* onClose could happen even before start() where mCallback is set */ + if (mCallback != null) { + Message msg = Message.obtain(mCallback); + msg.what = BluetoothOppObexSession.MSG_SESSION_COMPLETE; + msg.obj = mInfo; + msg.sendToTarget(); + } } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java b/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java index 8b566d84b..69842e40b 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java +++ b/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java @@ -33,7 +33,6 @@ package com.android.bluetooth.opp; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Random; diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java index 91826c164..516947f05 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java +++ b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java @@ -124,7 +124,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver { .getSystemService(Context.NOTIFICATION_SERVICE); if (notMgr != null) { notMgr.cancel((int)ContentUris.parseId(intent.getData())); - Log.v(TAG, "notMgr.cancel called"); + if (V) Log.v(TAG, "notMgr.cancel called"); } } else if (action.equals(BluetoothShare.INCOMING_FILE_CONFIRMATION_REQUEST_ACTION)) { if (V) Log.v(TAG, "Receiver INCOMING_FILE_NOTIFICATION"); @@ -145,7 +145,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver { Uri uri = intent.getData(); transInfo = BluetoothOppUtility.queryRecord(context, uri); if (transInfo == null) { - if (V) Log.e(TAG, "Error: Can not get data from db"); + Log.e(TAG, "Error: Can not get data from db"); return; } @@ -198,7 +198,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver { BluetoothOppTransferInfo transInfo = new BluetoothOppTransferInfo(); transInfo = BluetoothOppUtility.queryRecord(context, intent.getData()); if (transInfo == null) { - if (V) Log.e(TAG, "Error: Can not get data from db"); + Log.e(TAG, "Error: Can not get data from db"); return; } diff --git a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java index a02441fc1..c33cb66dc 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java +++ b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java @@ -35,7 +35,6 @@ package com.android.bluetooth.opp; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; -import java.net.SocketException; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothServerSocket; diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index a8e6575d2..e846be931 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -687,10 +687,12 @@ public class BluetoothOppService extends Service { if (V) Log.v(TAG, "Service handle info " + info.mId + " confirmed"); /* Inbounds transfer get user confirmation, so we start it */ int i = findBatchWithTimeStamp(info.mTimestamp); - BluetoothOppBatch batch = mBatchs.get(i); - if (batch.mId == mServerTransfer.getBatchId()) { - mServerTransfer.setConfirmed(); - } //TODO need to think about else + if (i != -1) { + BluetoothOppBatch batch = mBatchs.get(i); + if (mServerTransfer != null && batch.mId == mServerTransfer.getBatchId()) { + mServerTransfer.setConfirmed(); + } //TODO need to think about else + } } int i = findBatchWithTimeStamp(info.mTimestamp); if (i != -1) { @@ -707,6 +709,7 @@ public class BluetoothOppService extends Service { Log.e(TAG, "Unexpected error! batch id " + batch.mId + " doesn't match mTransfer id " + mTransfer.getBatchId()); } + mTransfer = null; } else { if (mServerTransfer == null) { Log.e(TAG, "Unexpected error! mServerTransfer is null"); @@ -717,6 +720,7 @@ public class BluetoothOppService extends Service { + " doesn't match mServerTransfer id " + mServerTransfer.getBatchId()); } + mServerTransfer = null; } removeBatch(batch); } @@ -789,22 +793,33 @@ public class BluetoothOppService extends Service { private void removeBatch(BluetoothOppBatch batch) { if (V) Log.v(TAG, "Remove batch " + batch.mId); mBatchs.remove(batch); + BluetoothOppBatch nextBatch; if (mBatchs.size() > 0) { for (int i = 0; i < mBatchs.size(); i++) { // we have a running batch - if (mBatchs.get(i).mStatus == Constants.BATCH_STATUS_RUNNING) { + nextBatch = mBatchs.get(i); + if (nextBatch.mStatus == Constants.BATCH_STATUS_RUNNING) { return; } else { - // Pending batch for inbound transfer is not supported // just finish a transfer, start pending outbound transfer - if (mBatchs.get(i).mDirection == BluetoothShare.DIRECTION_OUTBOUND) { - if (V) Log.v(TAG, "Start pending outbound batch " + mBatchs.get(i).mId); - mTransfer = new BluetoothOppTransfer(this, mPowerManager, mBatchs.get(i)); + if (nextBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) { + if (V) Log.v(TAG, "Start pending outbound batch " + nextBatch.mId); + mTransfer = new BluetoothOppTransfer(this, mPowerManager, nextBatch); mTransfer.start(); return; - } else { - // have pending inbound transfer, should not happen - Log.e(TAG, "Should not happen"); + } else if (nextBatch.mDirection == BluetoothShare.DIRECTION_INBOUND + && mServerSession != null) { + // have to support pending inbound transfer + // if an outbound transfer and incoming socket happens together + if (V) Log.v(TAG, "Start pending inbound batch " + nextBatch.mId); + mServerTransfer = new BluetoothOppTransfer(this, mPowerManager, nextBatch, + mServerSession); + mServerTransfer.start(); + if (nextBatch.getPendingShare().mConfirm == + BluetoothShare.USER_CONFIRMATION_CONFIRMED) { + mServerTransfer.setConfirmed(); + } + return; } } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppShareInfo.java b/src/com/android/bluetooth/opp/BluetoothOppShareInfo.java index 63d3e8db1..da57bd20e 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppShareInfo.java +++ b/src/com/android/bluetooth/opp/BluetoothOppShareInfo.java @@ -32,8 +32,6 @@ package com.android.bluetooth.opp; -import android.bluetooth.BluetoothDevice; - /** * This class stores information about a single OBEX share, e.g. one object * send/receive to a destination address. diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index 9f01f67e0..c0db1209a 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -39,13 +39,17 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.bluetooth.BluetoothUuid; import android.bluetooth.ParcelUuid; +import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.net.Uri; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.Message; +import android.os.Parcelable; import android.os.PowerManager; import android.os.Process; import android.util.Log; @@ -140,7 +144,11 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch 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); mConnectThread.start(); @@ -238,14 +246,14 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch Log.e(TAG, "failed to close mTransport"); } if (V) Log.v(TAG, "mTransport closed "); + mBatch.mStatus = Constants.BATCH_STATUS_FAILED; + if (info3 != null) { + markBatchFailed(info3.mStatus); + } else { + markBatchFailed(); + } + tickShareStatus(mCurrentShare); } - mBatch.mStatus = Constants.BATCH_STATUS_FAILED; - if (info3 != null) { - markBatchFailed(info3.mStatus); - } else { - markBatchFailed(); - } - tickShareStatus(mCurrentShare); break; case BluetoothOppObexSession.MSG_CONNECT_TIMEOUT: @@ -499,49 +507,65 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } } - //TODO this commented code is necessary after bluez4 has good SDP API - /* - IBluetoothCallback.Stub mDeviceCallback = new IBluetoothCallback.Stub() { - public void onGetRemoteServiceChannelResult(String address, int channel) { - mSessionHandler.obtainMessage(SDP_RESULT, channel, -1, address).sendToTarget(); - } - }; - */ private void doOpushSdp() { if (V) Log.v(TAG, "Do Opush SDP request for address " + mBatch.mDestination); mTimestamp = System.currentTimeMillis(); - //TODO this commented code is necessary after bluez4 has good SDP API - /* - if (!mAdapter.getRemoteServiceChannel(mBatch.mDestination, OPUSH_UUID16, mDeviceCallback)) { - Log.e(TAG, "Could not start OPUSH SDP query"); - markBatchFailed(); - mBatch.mStatus = Constants.BATCH_STATUS_FAILED; - } - */ - ParcelUuid[] uuids = mBatch.mDestination.getUuids(); - if (V) Log.v(TAG, "After call getRemoteUuids for address " + mBatch.mDestination); - int channel = -1; - if (uuids != null) { - if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.ObexObjectPush)) { - channel = mBatch.mDestination.getServiceChannel(BluetoothUuid.ObexObjectPush); - if (D) Log.d(TAG, "Get OPUSH channel " + channel + " from SDP for " + - mBatch.mDestination); - if (channel != -1) { - mConnectThread = new SocketConnectThread(mBatch.mDestination, channel); - mConnectThread.start(); - return; - } + 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 { - if (D) Log.d(TAG, "Remote device doesn't support OPP"); + // 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; } } - 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 { diff --git a/src/com/android/bluetooth/opp/Constants.java b/src/com/android/bluetooth/opp/Constants.java index 601293ff7..fe286a343 100644 --- a/src/com/android/bluetooth/opp/Constants.java +++ b/src/com/android/bluetooth/opp/Constants.java @@ -41,7 +41,6 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.util.Config; import android.util.Log; /** |