From e25b96fd4a5c1d5ff461d4d121ea51edea62b2ec Mon Sep 17 00:00:00 2001 From: pramod kotreshappa Date: Wed, 28 Jan 2015 19:42:55 -0800 Subject: Bluetooth: Fix to respond to Browse command when not supported Send error response for GetFolderItem with NowPlaying scope AVRCP browse command sent by remote prior to SetBrowsedPlayer command. Change-Id: I878e71d5534e055a0d498317200ee13cbba878dd --- src/com/android/bluetooth/avrcp/Avrcp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java index de31eef45..2363d8067 100644 --- a/src/com/android/bluetooth/avrcp/Avrcp.java +++ b/src/com/android/bluetooth/avrcp/Avrcp.java @@ -2961,7 +2961,7 @@ public final class Avrcp { while (rccIterator.hasNext()) { final MediaPlayerInfo di = rccIterator.next(); if (di.GetPlayerFocus()) { - if (!di.IsRemoteAddressable()) { + if (!di.IsRemoteAddressable() || mCurrentPath.equals(PATH_INVALID)) { getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType, uid, type, playable, displayName, numAtt, attValues, attIds); Log.e(TAG, "GetFolderItems fails: addressed player is not browsable"); -- cgit v1.2.3 From d595be9b728f2f9157619cffd7aa3a2ab7a1ab1b Mon Sep 17 00:00:00 2001 From: Juffin Alex Varghese Date: Tue, 13 Jan 2015 15:39:02 +0530 Subject: Bluetooth-OPP: Read share count from OPP manager before transfer starts This change will ensure that all the selected files in the batch will be transfered properly. Otherwise, if actual file count is not used before transfer start then client session will be disconnected after reaching the count value that is send during session start and remaining files will be ignored. Also added pending update flags for any contentresolver changes so that transfer status can be properly updated. CRs-Fixed: 785276 Change-Id: Ia9f9d8a953614b2e0945ca9cfbd2ce026dd40e26 --- .../android/bluetooth/opp/BluetoothOppManager.java | 2 +- .../bluetooth/opp/BluetoothOppNotification.java | 21 ++++++++++++++------- .../android/bluetooth/opp/BluetoothOppService.java | 12 +++++++++--- .../android/bluetooth/opp/BluetoothOppTransfer.java | 7 ++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/com/android/bluetooth/opp/BluetoothOppManager.java b/src/com/android/bluetooth/opp/BluetoothOppManager.java index 44ea6a93f..29c4500f9 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppManager.java +++ b/src/com/android/bluetooth/opp/BluetoothOppManager.java @@ -109,7 +109,7 @@ public class BluetoothOppManager { public boolean mMultipleFlag; - private int mfileNumInBatch; + private int mfileNumInBatch = 1; private int mInsertShareThreadNum = 0; diff --git a/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/src/com/android/bluetooth/opp/BluetoothOppNotification.java index 161cd576f..adfeeb68a 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppNotification.java +++ b/src/com/android/bluetooth/opp/BluetoothOppNotification.java @@ -109,10 +109,11 @@ class BluetoothOppNotification { private static final int NOTIFICATION_ID_INBOUND = -1000006; + private boolean mPendingUpdate = true; private boolean mOutboundUpdateCompleteNotification = true; private boolean mInboundUpdateCompleteNotification = true; - private int confirmation = 0; + private int mConfirmation = 0; private int mInboundActiveNotificationId = 0; private int mOutboundActiveNotificationId = 0; private int mRunning = 0; @@ -158,7 +159,9 @@ class BluetoothOppNotification { * Update the notification ui. */ public void updateNotification() { + if (V) Log.v(TAG, "Updating the notification"); synchronized (BluetoothOppNotification.this) { + mPendingUpdate = true; if (mUpdateNotificationThread == null) { if (V) Log.v(TAG, "new notify thread!!!"); mUpdateNotificationThread = new NotificationUpdateThread(); @@ -203,6 +206,7 @@ class BluetoothOppNotification { throw new IllegalStateException( "multiple UpdateThreads in BluetoothOppNotification"); } + mPendingUpdate = false; } updateActiveNotification(); @@ -210,7 +214,7 @@ class BluetoothOppNotification { updateIncomingFileConfirmNotification(); try { - if ((confirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED) + if ((mConfirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED) || mPowerManager.isScreenOn()) { Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } @@ -219,9 +223,12 @@ class BluetoothOppNotification { return; } - if (V) Log.v(TAG, "Running = " + mRunning); - } while ((mRunning > 0) && (mPowerManager.isScreenOn() - || (confirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED))); + if (V) { + Log.v(TAG, "Running = " + mRunning + " Pending notification is " + + mPendingUpdate); + } + } while ((mPendingUpdate || (mRunning > 0)) && (mPowerManager.isScreenOn() + || (mConfirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED))); synchronized (BluetoothOppNotification.this) { mUpdateNotificationThread = null; @@ -314,7 +321,7 @@ class BluetoothOppNotification { int id = cursor.getInt(idIndex); long total = cursor.getLong(totalBytesIndex); long current = cursor.getLong(currentBytesIndex); - confirmation = cursor.getInt(confirmIndex); + mConfirmation = cursor.getInt(confirmIndex); String destination = cursor.getString(destinationIndex); String fileName = cursor.getString(dataIndex); @@ -347,7 +354,7 @@ class BluetoothOppNotification { item.totalCurrent = current; item.totalTotal = total; item.handoverInitiated = - confirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED; + mConfirmation == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED; item.destination = destination; mNotifications.put(batchID, item); diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index c6fb79ad2..7306f9ca0 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -96,6 +96,8 @@ public class BluetoothOppService extends Service { /** Class to handle Notification Manager updates */ private BluetoothOppNotification mNotifier; + private boolean mPendingUpdate = true; + private UpdateThread mUpdateThread; private ArrayList mShares; @@ -448,7 +450,9 @@ public class BluetoothOppService extends Service { }; private void updateFromProvider() { + if (V) Log.v(TAG, "Updating the provider"); synchronized (BluetoothOppService.this) { + mPendingUpdate = true; if ((mUpdateThread == null) && (mAdapter != null) && mAdapter.isEnabled()) { if (V) Log.v(TAG, "Starting a new thread"); @@ -477,6 +481,7 @@ public class BluetoothOppService extends Service { } if (V) Log.v(TAG, "keepUpdateThread is " + keepService + " sListenStarted is " + mListenStarted); + mPendingUpdate = false; } Cursor cursor; try { @@ -627,15 +632,16 @@ public class BluetoothOppService extends Service { } try { - if (((mServerSession != null) || (mTransfer != null)) - && mPowerManager.isScreenOn()) { + if (mPowerManager.isScreenOn()) { Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } } catch (InterruptedException e) { if (V) Log.v(TAG, "OppService Thread sleep is interrupted (1), exiting"); return; } - } while (mPowerManager.isScreenOn() && ((mServerSession != null) || (mTransfer != null))); + + if(V) Log.v(TAG, "PendingUpdate is " + mPendingUpdate); + } while (mPendingUpdate); synchronized (BluetoothOppService.this) { mUpdateThread = null; diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index acdd188de..9f8a71d86 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -475,6 +475,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch private void startObexSession() { mBatch.mStatus = Constants.BATCH_STATUS_RUNNING; + BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(mContext); mCurrentShare = mBatch.getPendingShare(); if (mCurrentShare == null) { @@ -507,7 +508,11 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } if (mSession != null) { - mSession.start(mSessionHandler, mBatch.getNumShares()); + /* Read the number of files are sharing from OPP Manager instead of getting + * the number of files from Batch before OBEX session start. + */ + if (V) Log.v(TAG, "Sharing files = " + mOppManager.getBatchSize()); + mSession.start(mSessionHandler, mOppManager.getBatchSize()); processCurrentShare(); } -- cgit v1.2.3 From 4a8aae4b75901fb03409233d06d74efa29976e80 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Tue, 17 Feb 2015 17:32:33 +0530 Subject: Bluetooth: Stopping all services in case of enable Timeout We are not stopping services in case of enable timeout while all profile services will stop only when we explicitly stop services. This will enable all services to cleanup properly and allocate resources for the fresh retrial. Change-Id: I6a2e4ba87bdbbcc6864f1e26964f6e55bfefc03b CRs-Fixed: 779057 --- src/com/android/bluetooth/btservice/AdapterState.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/android/bluetooth/btservice/AdapterState.java b/src/com/android/bluetooth/btservice/AdapterState.java index 419300ac3..3469068c4 100644 --- a/src/com/android/bluetooth/btservice/AdapterState.java +++ b/src/com/android/bluetooth/btservice/AdapterState.java @@ -333,6 +333,7 @@ final class AdapterState extends StateMachine { adapterService.ssrcleanupNative(false); mPendingCommandState.setTurningOn(false); transitionTo(mOffState); + adapterService.stopProfileServices(); notifyAdapterStateChange(BluetoothAdapter.STATE_OFF); break; case STOP_TIMEOUT: -- cgit v1.2.3 From 6e0b6a99ebb0e2392654570ab5426de9e15dbc0e Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Thu, 23 Oct 2014 12:53:40 -0700 Subject: updateshare confirm logic missed cases like CONFIRMATION_DENIED, TIMEOUT. fix it bug 17770561 Change-Id: I34fb018d9787b4deef8592c71f5539778e76e325 --- src/com/android/bluetooth/opp/BluetoothOppService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 7306f9ca0..6f88d7362 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -840,7 +840,9 @@ public class BluetoothOppService extends Service { info.mVisibility = newVisibility; if (info.mConfirm == BluetoothShare.USER_CONFIRMATION_PENDING - && newConfirm != BluetoothShare.USER_CONFIRMATION_PENDING) { + && (newConfirm == BluetoothShare.USER_CONFIRMATION_CONFIRMED || + newConfirm == BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED || + newConfirm == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED)) { confirmed = true; } info.mConfirm = newConfirm; -- cgit v1.2.3 From 39b40fa22cb25a9471d6ce51871338ee3df9499f Mon Sep 17 00:00:00 2001 From: Juffin Alex Varghese Date: Fri, 30 Jan 2015 18:57:11 +0530 Subject: Bluetooth-OPP: Check socket congestion status before writing the data This change will ensure that data will be send to socket only after congestion is cleared. Otherwise, if socket is already in congestion and send the data before clearing, will cause transfer failure. CRs-Fixed: 790313 Change-Id: I8847a9f3473d97cd6fadf24e293ac179418df457 --- .../bluetooth/opp/BluetoothOppObexClientSession.java | 14 ++++++++++++++ src/com/android/bluetooth/opp/BluetoothOppTransport.java | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 6684b1fd7..0b480e70b 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -587,6 +587,20 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } readLength = a.read(buffer, 0, outputBufferSize); + + while (true) { + int congStatus = ((BluetoothOppTransport)mTransport1).getSockCongStatus(); + if ((congStatus == 0) || (congStatus == -1)) { + break; + } + try { + Thread.sleep(5); + } catch (InterruptedException slpe) { + Log.v(TAG, "Interrupted while checking the socket congestion evt"); + break; + } + } + int writtenLength = 0; while (writtenLength != readLength) { //SET MTU SIZE BEFORE WRITE diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransport.java b/src/com/android/bluetooth/opp/BluetoothOppTransport.java index 25c66fc7e..0615c1899 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransport.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransport.java @@ -99,6 +99,21 @@ public class BluetoothOppTransport implements ObexTransport { return status; } + /** + * Returns the Congestion status of the Socket + */ + public int getSockCongStatus() { + ByteBuffer bb = ByteBuffer.allocate(4); + bb.order(ByteOrder.LITTLE_ENDIAN); + int status; + try { + status = mSocket.getSocketOpt(5, bb.array()); + } catch (IOException ex) { + return -1; + } + return bb.getInt(); + } + public void connect() throws IOException { } -- cgit v1.2.3 From 2c10e9a62501786ec6fa676decdd266285ef1405 Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Mon, 17 Nov 2014 09:50:54 -0800 Subject: Check previous user confirmation before auto-confirm put request Also correct a confirm status change check in updateShare. Bug: 17770561, 18343032 Conflicts: src/com/android/bluetooth/opp/BluetoothOppService.java Change-Id: I8e7d10e73604c0bf1c88801a1caef7d579fbd1eb --- .../bluetooth/opp/BluetoothOppObexServerSession.java | 2 +- src/com/android/bluetooth/opp/BluetoothOppService.java | 14 +++++++------- src/com/android/bluetooth/opp/BluetoothOppTransfer.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index c7876409e..5adad6994 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -395,7 +395,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen boolean needConfirm = true; /** It's not first put if !serverBlocking, so we auto accept it */ - if (!mServerBlocking) { + if (!mServerBlocking && mAccepted == BluetoothShare.USER_CONFIRMATION_CONFIRMED) { values.put(BluetoothShare.USER_CONFIRMATION, BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED); needConfirm = false; diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 6f88d7362..2cec3b1c4 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -827,7 +827,7 @@ public class BluetoothOppService extends Service { info.mDestination = stringFromCursor(info.mDestination, cursor, BluetoothShare.DESTINATION); int newVisibility = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.VISIBILITY)); - boolean confirmed = false; + boolean confirmUpdated = false; int newConfirm = cursor.getInt(cursor .getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION)); @@ -843,7 +843,7 @@ public class BluetoothOppService extends Service { && (newConfirm == BluetoothShare.USER_CONFIRMATION_CONFIRMED || newConfirm == BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED || newConfirm == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED)) { - confirmed = true; + confirmUpdated = true; } info.mConfirm = newConfirm; int newStatus = cursor.getInt(statusColumn); @@ -860,14 +860,14 @@ public class BluetoothOppService extends Service { info.mTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP)); info.mMediaScanned = (cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) != Constants.MEDIA_SCANNED_NOT_SCANNED); - if (confirmed) { - if (V) Log.v(TAG, "Service handle info " + info.mId + " confirmed"); - /* Inbounds transfer get user confirmation, so we start it */ + if (confirmUpdated) { + if (V) Log.v(TAG, "Service handle info " + info.mId + " confirmation updated"); + /* Inbounds transfer user confirmation status changed, update the session server */ int i = findBatchWithTimeStamp(info.mTimestamp); if (i != -1) { BluetoothOppBatch batch = mBatchs.get(i); if (mServerTransfer != null && batch.mId == mServerTransfer.getBatchId()) { - mServerTransfer.setConfirmed(); + mServerTransfer.confirmStatusChanged(); } //TODO need to think about else } } @@ -1012,7 +1012,7 @@ public class BluetoothOppService extends Service { BluetoothOppShareInfo mPendingShare = nextBatch.getPendingShare(); if ((mPendingShare != null) && (mPendingShare.mConfirm == BluetoothShare.USER_CONFIRMATION_CONFIRMED)) { - mServerTransfer.setConfirmed(); + mServerTransfer.confirmStatusChanged(); } return; } diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index 9f8a71d86..9c639c72f 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -566,7 +566,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch if (V) Log.v(TAG, "processCurrentShare" + mCurrentShare.mId); mSession.addShare(mCurrentShare); if (mCurrentShare.mConfirm == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED) { - setConfirmed(); + confirmStatusChanged(); } } @@ -574,7 +574,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch * Set transfer confirmed status. It should only be called for inbound * transfer */ - public void setConfirmed() { + public void confirmStatusChanged() { /* unblock server session */ final Thread notifyThread = new Thread("Server Unblock thread") { public void run() { @@ -584,7 +584,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } } }; - if (V) Log.v(TAG, "setConfirmed to unblock mSession" + mSession.toString()); + if (V) Log.v(TAG, "confirmStatusChanged to unblock mSession" + mSession.toString()); notifyThread.start(); } @@ -848,7 +848,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch if (V) Log.v(TAG, "Transfer continue session for info " + mCurrentShare.mId + " from batch " + mBatch.mId); processCurrentShare(); - setConfirmed(); + confirmStatusChanged(); } } } -- cgit v1.2.3 From e880022abeb16a0576495b6d5e0433de40573269 Mon Sep 17 00:00:00 2001 From: Andre Eisenbach Date: Sun, 14 Dec 2014 12:22:31 -0800 Subject: Prevent duplicate OPP permission request dialogs When multiple files are sent in a single OPP session, the user should be prompted to accept/reject only once. Bug: 17770561 Change-Id: I438116915883c5fdc2d743f13456006f66511c0f --- src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index 5adad6994..831ea811d 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -395,7 +395,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen boolean needConfirm = true; /** It's not first put if !serverBlocking, so we auto accept it */ - if (!mServerBlocking && mAccepted == BluetoothShare.USER_CONFIRMATION_CONFIRMED) { + if (!mServerBlocking && (mAccepted == BluetoothShare.USER_CONFIRMATION_CONFIRMED || + mAccepted == BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED)) { values.put(BluetoothShare.USER_CONFIRMATION, BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED); needConfirm = false; -- cgit v1.2.3 From 91428fc2175173fd586cd182a6b47a088e65bd6e Mon Sep 17 00:00:00 2001 From: Ashwini Munigala Date: Wed, 4 Mar 2015 14:48:38 +0530 Subject: MAP: Fix parsing special character issue in vcard email. Replace '<' for '<' and '>' for '>' while parsing email address in vcard pushed from some paticular carkits in MCE role. Change-Id: Id24d202a6a60b5edb2de11732527135a7542ecd2 CRs-fixed: 802930 --- src/com/android/bluetooth/map/BluetoothMapbMessage.java | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 src/com/android/bluetooth/map/BluetoothMapbMessage.java diff --git a/src/com/android/bluetooth/map/BluetoothMapbMessage.java b/src/com/android/bluetooth/map/BluetoothMapbMessage.java old mode 100644 new mode 100755 index 21d96f13d..7d4d586c4 --- a/src/com/android/bluetooth/map/BluetoothMapbMessage.java +++ b/src/com/android/bluetooth/map/BluetoothMapbMessage.java @@ -225,6 +225,7 @@ public abstract class BluetoothMapbMessage { // Empty phone number - ignore } else if(line.startsWith("EMAIL:")){ + line = line.replace("<", "<").replace(">", ">"); parts = line.split("[^\\\\]:"); // Split on "un-escaped" : if(parts.length == 2) { String[] subParts = parts[1].split("[^\\\\];"); -- cgit v1.2.3 From ea6eec14f2fe78d5eb09ee39a4a9e896b2fca61d Mon Sep 17 00:00:00 2001 From: Srinu Jella Date: Mon, 9 Mar 2015 17:44:04 +0530 Subject: Bluetooth: Avoid cleanup the scan manager if already cleaned up - Avoid cleanup the scan manager if already cleaned up, scan manager can be cleared on receiving the stop request or when the service is destroyed. - There is a case, where destroy and stop called one after the other, it will try to cleanup twice, that leads to crash. CRs-Fixed: 797597 Change-Id: I0adc5cb683bbf47f12598e6c54eae7df87cdbbc4 --- src/com/android/bluetooth/gatt/GattService.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java index 654df69b9..05ff17a7d 100644 --- a/src/com/android/bluetooth/gatt/GattService.java +++ b/src/com/android/bluetooth/gatt/GattService.java @@ -198,16 +198,28 @@ public class GattService extends ProfileService { mServiceDeclarations.clear(); mActiveServiceDeclarations.clear(); mReliableQueue.clear(); - if (mAdvertiseManager != null) mAdvertiseManager.cleanup(); - if (mScanManager != null) mScanManager.cleanup(); + if (mAdvertiseManager != null) { + mAdvertiseManager.cleanup(); + mAdvertiseManager = null; + } + if (mScanManager != null) { + mScanManager.cleanup(); + mScanManager = null; + } return true; } protected boolean cleanup() { if (DBG) Log.d(TAG, "cleanup()"); cleanupNative(); - if (mAdvertiseManager != null) mAdvertiseManager.cleanup(); - if (mScanManager != null) mScanManager.cleanup(); + if (mAdvertiseManager != null) { + mAdvertiseManager.cleanup(); + mAdvertiseManager = null; + } + if (mScanManager != null) { + mScanManager.cleanup(); + mScanManager = null; + } return true; } -- cgit v1.2.3 From dc47b46719405b3fb49a748c8452e8984ceb0d66 Mon Sep 17 00:00:00 2001 From: Juffin Alex Varghese Date: Fri, 30 Jan 2015 18:57:11 +0530 Subject: Bluetooth-OPP: Check socket congestion status before writing the data This change will ensure that data will be send to socket only after congestion is cleared. Otherwise, if socket is already in congestion and send the data before clearing, will cause transfer failure. CRs-Fixed: 790313 Change-Id: I8847a9f3473d97cd6fadf24e293ac179418df457 --- .../bluetooth/opp/BluetoothOppObexClientSession.java | 14 ++++++++++++++ src/com/android/bluetooth/opp/BluetoothOppTransport.java | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 6684b1fd7..0b480e70b 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -587,6 +587,20 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } readLength = a.read(buffer, 0, outputBufferSize); + + while (true) { + int congStatus = ((BluetoothOppTransport)mTransport1).getSockCongStatus(); + if ((congStatus == 0) || (congStatus == -1)) { + break; + } + try { + Thread.sleep(5); + } catch (InterruptedException slpe) { + Log.v(TAG, "Interrupted while checking the socket congestion evt"); + break; + } + } + int writtenLength = 0; while (writtenLength != readLength) { //SET MTU SIZE BEFORE WRITE diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransport.java b/src/com/android/bluetooth/opp/BluetoothOppTransport.java index 25c66fc7e..0615c1899 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransport.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransport.java @@ -99,6 +99,21 @@ public class BluetoothOppTransport implements ObexTransport { return status; } + /** + * Returns the Congestion status of the Socket + */ + public int getSockCongStatus() { + ByteBuffer bb = ByteBuffer.allocate(4); + bb.order(ByteOrder.LITTLE_ENDIAN); + int status; + try { + status = mSocket.getSocketOpt(5, bb.array()); + } catch (IOException ex) { + return -1; + } + return bb.getInt(); + } + public void connect() throws IOException { } -- cgit v1.2.3