diff options
Diffstat (limited to 'src/com/android/bluetooth')
5 files changed, 145 insertions, 12 deletions
diff --git a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java index 7648acd90..dd70eb19b 100644 --- a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +++ b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java @@ -188,6 +188,8 @@ final class A2dpStateMachine extends StateMachine { @Override public void enter() { log("Enter Disconnected: " + getCurrentMessage().what); + // Remove Timeout msg when moved to stable state + removeMessages(CONNECT_TIMEOUT); } @Override @@ -320,6 +322,7 @@ final class A2dpStateMachine extends StateMachine { deferMessage(message); break; case CONNECT_TIMEOUT: + disconnectA2dpNative(getByteAddress(mTargetDevice)); onConnectionStateChanged(CONNECTION_STATE_DISCONNECTED, getByteAddress(mTargetDevice)); break; @@ -342,7 +345,6 @@ final class A2dpStateMachine extends StateMachine { log("Stack Event: " + event.type); switch (event.type) { case EVENT_TYPE_CONNECTION_STATE_CHANGED: - removeMessages(CONNECT_TIMEOUT); processConnectionEvent(event.valueInt, event.device); break; default: @@ -509,6 +511,7 @@ final class A2dpStateMachine extends StateMachine { @Override public void enter() { log("Enter Connected: " + getCurrentMessage().what); + removeMessages(CONNECT_TIMEOUT); // Upon connected, the audio starts out as stopped broadcastAudioState(mCurrentDevice, BluetoothA2dp.STATE_NOT_PLAYING, BluetoothA2dp.STATE_PLAYING); @@ -663,6 +666,7 @@ final class A2dpStateMachine extends StateMachine { } break; case AUDIO_STATE_STOPPED: + case AUDIO_STATE_REMOTE_SUSPEND: if (mPlayingA2dpDevice != null) { mPlayingA2dpDevice = null; mService.setAvrcpAudioState(BluetoothA2dp.STATE_NOT_PLAYING); @@ -722,7 +726,8 @@ final class A2dpStateMachine extends StateMachine { List<BluetoothDevice> getConnectedDevices() { List<BluetoothDevice> devices = new ArrayList<BluetoothDevice>(); synchronized(this) { - if (getCurrentState() == mConnected) { + /* If connected and mCurrentDevice is not null*/ + if ((getCurrentState() == mConnected) && (mCurrentDevice != null)) { devices.add(mCurrentDevice); } } diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index 2bb78bcf5..8e7decc2a 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -27,6 +27,7 @@ import android.app.Service; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; +import android.bluetooth.BluetoothUuid; import android.bluetooth.IBluetooth; import android.bluetooth.IBluetoothCallback; import android.bluetooth.IBluetoothManager; @@ -78,6 +79,7 @@ public class AdapterService extends Service { private static final String TAG = "BluetoothAdapterService"; private static final boolean DBG = true; private static final boolean TRACE_REF = true; + private static final String delayConnectTimeoutDevice[] = {"00:23:3D"}; // volkswagen carkit //For Debugging only private static int sRefCount=0; @@ -89,6 +91,10 @@ public class AdapterService extends Service { public static final int PROFILE_CONN_CONNECTED = 1; public static final int PROFILE_CONN_REJECTED = 2; + static final ParcelUuid[] A2DP_SOURCE_SINK_UUIDS = { + BluetoothUuid.AudioSource, + BluetoothUuid.AudioSink + }; static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; @@ -414,12 +420,13 @@ public class AdapterService extends Service { if (DBG)debugLog("cleanup() done"); } - private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED =1; - private static final int MESSAGE_PROFILE_CONNECTION_STATE_CHANGED=20; + private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED = 1; + private static final int MESSAGE_PROFILE_CONNECTION_STATE_CHANGED = 20; private static final int MESSAGE_CONNECT_OTHER_PROFILES = 30; - private static final int CONNECT_OTHER_PROFILES_TIMEOUT= 6000; + private static final int CONNECT_OTHER_PROFILES_TIMEOUT = 6000; + private static final int CONNECT_OTHER_PROFILES_TIMEOUT_DEYALED = 10000; private static final int MESSAGE_AUTO_CONNECT_PROFILES = 50; - private static final int AUTO_CONNECT_PROFILES_TIMEOUT= 500; + private static final int AUTO_CONNECT_PROFILES_TIMEOUT = 500; private final Handler mHandler = new Handler() { @Override @@ -488,6 +495,7 @@ public class AdapterService extends Service { Intent intent = new Intent(this,services[i]); intent.putExtra(EXTRA_ACTION,ACTION_SERVICE_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_STATE,state); + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); startService(intent); } } @@ -1218,12 +1226,31 @@ public class AdapterService extends Service { } public void connectOtherProfile(BluetoothDevice device, int firstProfileStatus){ - if ((mHandler.hasMessages(MESSAGE_CONNECT_OTHER_PROFILES) == false) && - (isQuietModeEnabled()== false)){ + String deviceAddress = device.getAddress(); + boolean isConnectionTimeoutDelayed = false; + + for (int i = 0; i < delayConnectTimeoutDevice.length;i++) { + if (deviceAddress.indexOf(delayConnectTimeoutDevice[i]) == 0) { + isConnectionTimeoutDelayed = true; + } + } + if (mHandler.hasMessages(MESSAGE_CONNECT_OTHER_PROFILES) == false) { + ParcelUuid[] featureUuids = device.getUuids(); + // Some Carkits disconnect just after pairing,Initiate SDP for missing UUID's support + if ((!(BluetoothUuid.containsAnyUuid(featureUuids, A2DP_SOURCE_SINK_UUIDS))) || + (!(BluetoothUuid.isUuidPresent(featureUuids, BluetoothUuid.Handsfree)))) { + Log.v(TAG,"Initiate SDP for Missing UUID's support in remote"); + device.fetchUuidsWithSdp(); + } Message m = mHandler.obtainMessage(MESSAGE_CONNECT_OTHER_PROFILES); m.obj = device; m.arg1 = (int)firstProfileStatus; - mHandler.sendMessageDelayed(m,CONNECT_OTHER_PROFILES_TIMEOUT); + if (isConnectionTimeoutDelayed) { + mHandler.sendMessageDelayed(m,CONNECT_OTHER_PROFILES_TIMEOUT_DEYALED); + } + else { + mHandler.sendMessageDelayed(m,CONNECT_OTHER_PROFILES_TIMEOUT); + } } } @@ -1556,6 +1583,7 @@ public class AdapterService extends Service { private native static void classInitNative(); private native boolean initNative(); private native void cleanupNative(); + /*package*/ native void ssrcleanupNative(); /*package*/ native boolean enableNative(); /*package*/ native boolean disableNative(); /*package*/ native boolean setAdapterPropertyNative(int type, byte[] val); diff --git a/src/com/android/bluetooth/btservice/AdapterState.java b/src/com/android/bluetooth/btservice/AdapterState.java index 585f5ae86..a0ec83865 100644 --- a/src/com/android/bluetooth/btservice/AdapterState.java +++ b/src/com/android/bluetooth/btservice/AdapterState.java @@ -342,11 +342,14 @@ final class AdapterState extends StateMachine { mPendingCommandState.setTurningOff(false); transitionTo(mOffState); notifyAdapterStateChange(BluetoothAdapter.STATE_OFF); + errorLog("STOP_TIMEOUT:Killing the process to force a restart as part cleanup"); + android.os.Process.killProcess(android.os.Process.myPid()); break; case DISABLE_TIMEOUT: if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE = DISABLE_TIMEOUT, isTurningOn=" + isTurningOn + ", isTurningOff=" + isTurningOff); errorLog("Error disabling Bluetooth"); mPendingCommandState.setTurningOff(false); + adapterService.ssrcleanupNative(); transitionTo(mOffState); notifyAdapterStateChange(BluetoothAdapter.STATE_OFF); errorLog("Killing the process to force a restart as part cleanup"); diff --git a/src/com/android/bluetooth/opp/BluetoothOppManager.java b/src/com/android/bluetooth/opp/BluetoothOppManager.java index 849abf36a..b9c0a8a60 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppManager.java +++ b/src/com/android/bluetooth/opp/BluetoothOppManager.java @@ -77,6 +77,8 @@ public class BluetoothOppManager { private String mUriOfSendingFile; + private String mNameOfSendingFile; + private String mMimeTypeOfSendingFiles; private ArrayList<Uri> mUrisOfSendingFiles; @@ -260,6 +262,7 @@ public class BluetoothOppManager { uri = BluetoothOppUtility.generateUri(uri, sendFileInfo); BluetoothOppUtility.putSendFileInfo(uri, sendFileInfo); mUriOfSendingFile = uri.toString(); + mNameOfSendingFile = sendFileInfo.mFileName; storeApplicationData(); } } @@ -357,7 +360,7 @@ public class BluetoothOppManager { return; } insertThread = new InsertShareInfoThread(device, mMultipleFlag, mMimeTypeOfSendingFile, - mUriOfSendingFile, mMimeTypeOfSendingFiles, mUrisOfSendingFiles, + mUriOfSendingFile, mNameOfSendingFile, mMimeTypeOfSendingFiles, mUrisOfSendingFiles, mIsHandoverInitiated); if (mMultipleFlag) { mfileNumInBatch = mUrisOfSendingFiles.size(); @@ -382,6 +385,8 @@ public class BluetoothOppManager { private final String mUri; + private final String mNameOfSingleFile; + private final String mTypeOfMultipleFiles; private final ArrayList<Uri> mUris; @@ -391,13 +396,15 @@ public class BluetoothOppManager { private final boolean mIsHandoverInitiated; public InsertShareInfoThread(BluetoothDevice device, boolean multiple, - String typeOfSingleFile, String uri, String typeOfMultipleFiles, - ArrayList<Uri> uris, boolean handoverInitiated) { + String typeOfSingleFile, String uri, String nameOfSingleFile, + String typeOfMultipleFiles, ArrayList<Uri> uris, + boolean handoverInitiated) { super("Insert ShareInfo Thread"); this.mRemoteDevice = device; this.mIsMultiple = multiple; this.mTypeOfSingleFile = typeOfSingleFile; this.mUri = uri; + this.mNameOfSingleFile = nameOfSingleFile; this.mTypeOfMultipleFiles = typeOfMultipleFiles; this.mUris = uris; this.mIsHandoverInitiated = handoverInitiated; @@ -467,6 +474,7 @@ public class BluetoothOppManager { private void insertSingleShare() { ContentValues values = new ContentValues(); values.put(BluetoothShare.URI, mUri); + values.put(BluetoothShare.FILENAME_HINT, mNameOfSingleFile); values.put(BluetoothShare.MIMETYPE, mTypeOfSingleFile); values.put(BluetoothShare.DESTINATION, mRemoteDevice.getAddress()); if (mIsHandoverInitiated) { diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 945d5475c..f38736513 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -393,6 +393,7 @@ public class BluetoothOppService extends Service { break; case BluetoothAdapter.STATE_TURNING_OFF: if (V) Log.v(TAG, "Receiver DISABLED_ACTION "); + removePendingTransfer(); mNotifier.updateNotifier(); //FIX: Don't block main thread /* @@ -867,6 +868,94 @@ public class BluetoothOppService extends Service { } } + private void removePendingTransfer() { + if (V) Log.v(TAG, "Remove pending share"); + Cursor cursor = null; + try { + cursor = getContentResolver().query(BluetoothShare.CONTENT_URI, null, null, + null, BluetoothShare._ID); + } catch (SQLiteException e) { + if (cursor != null){ + cursor.close(); + } + cursor = null; + Log.e(TAG, "UpdateThread: " + e); + } catch (CursorWindowAllocationException e) { + cursor = null; + Log.e(TAG, "UpdateThread: " + e); + } + + if (cursor == null) { + return; + } + + cursor.moveToFirst(); + int arrayPos = 0; + boolean isAfterLast = cursor.isAfterLast(); + + while (!isAfterLast || arrayPos < mShares.size()) { + String uriString = cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.URI)); + Uri uri; + if (uriString != null) { + uri = Uri.parse(uriString); + Log.d(TAG, "removeShare parsed URI: " + uri); + } else { + uri = null; + Log.e(TAG, "removeShare found null URI at cursor!"); + } + BluetoothOppShareInfo info = new BluetoothOppShareInfo( + cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID)), + uri, + cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT)), + cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare._DATA)), + cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.MIMETYPE)), + cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.DIRECTION)), + cursor.getString(cursor.getColumnIndexOrThrow(BluetoothShare.DESTINATION)), + cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.VISIBILITY)), + cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION)), + cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.STATUS)), + cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TOTAL_BYTES)), + cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.CURRENT_BYTES)), + cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP)), + cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) != Constants.MEDIA_SCANNED_NOT_SCANNED); + + if (V) { + Log.v(TAG, "Service remove entry"); + Log.v(TAG, "ID : " + info.mId); + // Log.v(TAG, "URI : " + ((info.mUri != null) ? "yes" : "no")); + Log.v(TAG, "URI : " + info.mUri); + Log.v(TAG, "HINT : " + info.mHint); + Log.v(TAG, "FILENAME: " + info.mFilename); + Log.v(TAG, "MIMETYPE: " + info.mMimetype); + Log.v(TAG, "DIRECTION: " + info.mDirection); + Log.v(TAG, "DESTINAT: " + info.mDestination); + Log.v(TAG, "VISIBILI: " + info.mVisibility); + Log.v(TAG, "CONFIRM : " + info.mConfirm); + Log.v(TAG, "STATUS : " + info.mStatus); + Log.v(TAG, "TOTAL : " + info.mTotalBytes); + Log.v(TAG, "CURRENT : " + info.mCurrentBytes); + Log.v(TAG, "TIMESTAMP : " + info.mTimestamp); + Log.v(TAG, "SCANNED : " + info.mMediaScanned); + } + + if (info.isReadyToStart()) { + if (info.mDirection == BluetoothShare.DIRECTION_OUTBOUND) { + BluetoothOppSendFileInfo sendFileInfo = BluetoothOppUtility.getSendFileInfo( + info.mUri); + Constants.updateShareStatus(this, info.mId, BluetoothShare.STATUS_BAD_REQUEST); + BluetoothOppUtility.closeSendFileInfo(info.mUri); + } + } + + ++arrayPos; + cursor.moveToNext(); + isAfterLast = cursor.isAfterLast(); + } + cursor.close(); + if (V) Log.v(TAG, "Freeing cursor: " + cursor); + cursor = null; + } + /** * Removes the local copy of the info about a share. */ |