diff options
author | Juffin Alex Varghese <jalex@codeaurora.org> | 2014-12-03 09:58:03 +0530 |
---|---|---|
committer | Juffin Alex Varghese <jalex@codeaurora.org> | 2014-12-04 17:02:31 +0530 |
commit | 7ba5b5c222f68871f9d398360159397c69657aa8 (patch) | |
tree | ce6ec4f1726882708d31e311d7bfb2a4465b4468 | |
parent | a04b0ed57e9019606864a2c26393313b28578bc7 (diff) | |
download | android_packages_apps_Bluetooth-7ba5b5c222f68871f9d398360159397c69657aa8.tar.gz android_packages_apps_Bluetooth-7ba5b5c222f68871f9d398360159397c69657aa8.tar.bz2 android_packages_apps_Bluetooth-7ba5b5c222f68871f9d398360159397c69657aa8.zip |
Bluetooth-OPP: Clean up OPP threads during user turned OFF BT
Cleanup OPP threads during Bluetooth is turing OFF. Otherwise,
if threads are in sleep during turn off and try to resend the failed
transfer immediately after Bluetooth is turned ON transfer won't
start and there are no status update in UI.
CRs-Fixed: 766506
Change-Id: Ibf06bf25af587df0982845d3300fced3c56bbd46
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppNotification.java | 12 | ||||
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppService.java | 30 |
2 files changed, 32 insertions, 10 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/src/com/android/bluetooth/opp/BluetoothOppNotification.java index ec180e844..161cd576f 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppNotification.java +++ b/src/com/android/bluetooth/opp/BluetoothOppNotification.java @@ -170,6 +170,16 @@ class BluetoothOppNotification { public void btOffNotification() { if (V) Log.v(TAG, "Update Notification while BT is Turning OFF"); synchronized (BluetoothOppNotification.this) { + if (mUpdateNotificationThread != null) { + try { + mUpdateNotificationThread.interrupt(); + mUpdateNotificationThread.join(); + mUpdateNotificationThread = null; + } catch (InterruptedException ie) { + Log.e(TAG, "Notification thread join interrupted"); + } + } + updateActiveNotification(); mInboundUpdateCompleteNotification = true; mOutboundUpdateCompleteNotification = true; @@ -205,7 +215,7 @@ class BluetoothOppNotification { Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } } catch (InterruptedException e) { - if (V) Log.v(TAG, "NotificationThread was interrupted (1), exiting"); + if (V) Log.v(TAG, "NotificationThread sleep is interrupted (1), exiting"); return; } diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 5d1846f62..319ee8de0 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -416,6 +416,17 @@ public class BluetoothOppService extends Service { break; case BluetoothAdapter.STATE_TURNING_OFF: if (V) Log.v(TAG, "Receiver DISABLED_ACTION "); + + if (mUpdateThread != null) { + try { + mUpdateThread.interrupt(); + mUpdateThread.join(); + mUpdateThread = null; + } catch (InterruptedException ie) { + Log.e(TAG, "OPPService Thread join interrupted"); + } + } + mNotifier.btOffNotification(); //FIX: Don't block main thread /* @@ -600,15 +611,6 @@ public class BluetoothOppService extends Service { cursor.close(); cursor = null; - try { - if (mPowerManager.isScreenOn()) { - Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); - } - } catch (InterruptedException e) { - if (V) Log.v(TAG, "OppService UpdateThread was interrupted (1), exiting"); - return; - } - if (V) { if (mServerSession != null) { Log.v(TAG, "Server Session is active"); @@ -622,6 +624,16 @@ public class BluetoothOppService extends Service { Log.v(TAG, "No active Client Session"); } } + + try { + if (((mServerSession != null) || (mTransfer != null)) + && 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))); synchronized (BluetoothOppService.this) { |