diff options
author | Matthew Xie <mattx@google.com> | 2012-08-08 12:19:13 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-08-08 12:19:13 -0700 |
commit | 73d192095093759688cccc896714f71fcee218d8 (patch) | |
tree | f140691c0194201178c164999088c14a1dee1a63 /src/com | |
parent | 4f5430babbc5a8f870e5a578a4ea3452f41dd97a (diff) | |
parent | 15d36984a79d6e35c659edb0efdf929f0b526bd5 (diff) | |
download | android_packages_apps_Bluetooth-73d192095093759688cccc896714f71fcee218d8.tar.gz android_packages_apps_Bluetooth-73d192095093759688cccc896714f71fcee218d8.tar.bz2 android_packages_apps_Bluetooth-73d192095093759688cccc896714f71fcee218d8.zip |
Merge "Fix for BT turn on/off issues: NPE, FD/thread leaks, ANR." into jb-mr1-dev
Diffstat (limited to 'src/com')
17 files changed, 54 insertions, 116 deletions
diff --git a/src/com/android/bluetooth/a2dp/A2dpService.java b/src/com/android/bluetooth/a2dp/A2dpService.java index 4441f4b99..278023269 100755 --- a/src/com/android/bluetooth/a2dp/A2dpService.java +++ b/src/com/android/bluetooth/a2dp/A2dpService.java @@ -43,14 +43,13 @@ public class A2dpService extends ProfileService { } protected boolean stop() { - // TODO(BT) mStateMachine.quit(); + mStateMachine.doQuit(); return true; } protected boolean cleanup() { if (mStateMachine!= null) { mStateMachine.cleanup(); - mStateMachine=null; } clearA2dpService(); return true; diff --git a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java index c742fd483..3004b5a5a 100755 --- a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +++ b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java @@ -130,14 +130,12 @@ final class A2dpStateMachine extends StateMachine { } + public void doQuit() { + quitNow(); + } + public void cleanup() { cleanupNative(); - if(mService != null) - mService = null; - if (mContext != null) - mContext = null; - if(mAdapter != null) - mAdapter = null; } private class Disconnected extends State { diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index 7e0bbd160..7c2d1a381 100755 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -334,20 +334,17 @@ public class AdapterService extends Service { mCleaningUp = true; if (mAdapterStateMachine != null) { - // TODO(BT) mAdapterStateMachine.quit(); + mAdapterStateMachine.doQuit(); mAdapterStateMachine.cleanup(); - mAdapterStateMachine = null; } if (mBondStateMachine != null) { - // TODO(BT) mBondStateMachine.quit(); + mBondStateMachine.doQuit(); mBondStateMachine.cleanup(); - mBondStateMachine = null; } if (mRemoteDevices != null) { mRemoteDevices.cleanup(); - mRemoteDevices = null; } if (mNativeAvailable) { @@ -359,24 +356,21 @@ public class AdapterService extends Service { if (mAdapterProperties != null) { mAdapterProperties.cleanup(); - mAdapterProperties = null; } if (mJniCallbacks != null) { mJniCallbacks.cleanup(); - mJniCallbacks = null; } if (mProfileServicesState != null) { mProfileServicesState.clear(); - mProfileServicesState= null; } clearAdapterService(); if (mBinder != null) { mBinder.cleanup(); - mBinder = null; + mBinder = null; //Do not remove. Otherwise Binder leak! } if (mCallbacks !=null) { diff --git a/src/com/android/bluetooth/btservice/AdapterState.java b/src/com/android/bluetooth/btservice/AdapterState.java index 0f28b6b56..366674e96 100755 --- a/src/com/android/bluetooth/btservice/AdapterState.java +++ b/src/com/android/bluetooth/btservice/AdapterState.java @@ -80,6 +80,11 @@ final class AdapterState extends StateMachine { setInitialState(mOffState); } + + public void doQuit() { + quitNow(); + } + public void cleanup() { if(mAdapterProperties != null) mAdapterProperties = null; @@ -95,10 +100,6 @@ final class AdapterState extends StateMachine { @Override public boolean processMessage(Message msg) { - /* TODO(BT) if (msg.what == SM_QUIT_CMD) { - Log.d(TAG, "Received quit request..."); - return false; - } */ switch(msg.what) { case USER_TURN_ON: @@ -130,6 +131,7 @@ final class AdapterState extends StateMachine { @Override public boolean processMessage(Message msg) { + switch(msg.what) { case USER_TURN_OFF: if (DBG) Log.d(TAG,"CURRENT_STATE=ON, MESSAGE = USER_TURN_OFF"); @@ -182,8 +184,10 @@ final class AdapterState extends StateMachine { @Override public boolean processMessage(Message msg) { + boolean isTurningOn= isTurningOn(); boolean isTurningOff = isTurningOff(); + switch (msg.what) { case USER_TURN_ON: if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE = USER_TURN_ON" @@ -324,4 +328,5 @@ final class AdapterState extends StateMachine { private void errorLog(String msg) { Log.e(TAG, msg); } + } diff --git a/src/com/android/bluetooth/btservice/BondStateMachine.java b/src/com/android/bluetooth/btservice/BondStateMachine.java index c2b38f0a2..cdd93f2e6 100755 --- a/src/com/android/bluetooth/btservice/BondStateMachine.java +++ b/src/com/android/bluetooth/btservice/BondStateMachine.java @@ -63,6 +63,10 @@ final class BondStateMachine extends StateMachine { setInitialState(mStableState); } + public void doQuit() { + quitNow(); + } + public void cleanup() { mAdapterService = null; mRemoteDevices = null; @@ -77,12 +81,6 @@ final class BondStateMachine extends StateMachine { @Override public boolean processMessage(Message msg) { - // TODO(BT) - // if (msg.what == SM_QUIT_CMD) { - // Log.d(TAG, "Received quit request..."); - // return false; - // } - BluetoothDevice dev = (BluetoothDevice)msg.obj; @@ -130,11 +128,6 @@ final class BondStateMachine extends StateMachine { @Override public boolean processMessage(Message msg) { - // TODO(BT) - // if (msg.what == SM_QUIT_CMD) { - // Log.d(TAG, "PendingCommandState(): Received quit request..."); - // return false; - // } BluetoothDevice dev = (BluetoothDevice)msg.obj; boolean result = false; @@ -319,4 +312,5 @@ final class BondStateMachine extends StateMachine { private void errorLog(String msg) { Log.e(TAG, msg); } + } diff --git a/src/com/android/bluetooth/btservice/RemoteDevices.java b/src/com/android/bluetooth/btservice/RemoteDevices.java index e9f4792fd..08ba36b8c 100755 --- a/src/com/android/bluetooth/btservice/RemoteDevices.java +++ b/src/com/android/bluetooth/btservice/RemoteDevices.java @@ -47,12 +47,11 @@ final class RemoteDevices { void cleanup() { - mSdpTracker.clear(); - mSdpTracker = null; - mDevices.clear(); - mDevices = null; - mAdapterService = null; - mAdapter= null; + if (mSdpTracker !=null) + mSdpTracker.clear(); + + if (mDevices != null) + mDevices.clear(); } public Object Clone() throws CloneNotSupportedException { diff --git a/src/com/android/bluetooth/hdp/HealthService.java b/src/com/android/bluetooth/hdp/HealthService.java index b843bc657..f689cfcb1 100755 --- a/src/com/android/bluetooth/hdp/HealthService.java +++ b/src/com/android/bluetooth/hdp/HealthService.java @@ -114,15 +114,12 @@ public class HealthService extends ProfileService { } if(mHealthChannels != null) { mHealthChannels.clear(); - mHealthChannels = null; } if(mHealthDevices != null) { mHealthDevices.clear(); - mHealthDevices = null; } if(mApps != null) { mApps.clear(); - mApps = null; } return true; } diff --git a/src/com/android/bluetooth/hfp/AtPhonebook.java b/src/com/android/bluetooth/hfp/AtPhonebook.java index dea20100f..3f499bac8 100755 --- a/src/com/android/bluetooth/hfp/AtPhonebook.java +++ b/src/com/android/bluetooth/hfp/AtPhonebook.java @@ -113,9 +113,6 @@ public class AtPhonebook { public void cleanup() { mPhonebooks.clear(); - mContentResolver = null; - mContext = null; - mStateMachine = null; } /** Returns the last dialled number, or null if no numbers have been called */ @@ -220,6 +217,8 @@ public class AtPhonebook { } int size = pbr.cursor.getCount(); atCommandResponse = "+CPBS: \"" + mCurrentPhonebook + "\"," + size + "," + getMaxPhoneBookSize(size); + pbr.cursor.close(); + pbr.cursor = null; atCommandResult = HeadsetHalConstants.AT_RESPONSE_OK; break; case TYPE_TEST: // Test @@ -282,6 +281,8 @@ public class AtPhonebook { } size = pbr.cursor.getCount(); log("handleCpbrCommand - size = "+size); + pbr.cursor.close(); + pbr.cursor = null; } if (size == 0) { /* Sending "+CPBR: (1-0)" can confused some carkits, send "1-1" * instead */ @@ -547,6 +548,10 @@ public class AtPhonebook { break; } } + if(pbr != null && pbr.cursor != null) { + pbr.cursor.close(); + pbr.cursor = null; + } return atCommandResult; } diff --git a/src/com/android/bluetooth/hfp/HeadsetService.java b/src/com/android/bluetooth/hfp/HeadsetService.java index 9f6f6da0c..9e9d71b8f 100755 --- a/src/com/android/bluetooth/hfp/HeadsetService.java +++ b/src/com/android/bluetooth/hfp/HeadsetService.java @@ -65,14 +65,13 @@ public class HeadsetService extends ProfileService { } catch (Exception e) { Log.w(TAG,"Unable to unregister headset receiver",e); } - // TODO(BT) mStateMachine.quit(); + mStateMachine.doQuit(); return true; } protected boolean cleanup() { if (mStateMachine != null) { mStateMachine.cleanup(); - mStateMachine=null; } clearHeadsetService(); return true; diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java index 51af3ce90..e21921dd7 100755 --- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java @@ -192,6 +192,11 @@ final class HeadsetStateMachine extends StateMachine { setInitialState(mDisconnected); } + + public void doQuit() { + quitNow(); + } + public void cleanup() { if (mPhoneProxy != null) { if (DBG) Log.d(TAG,"Unbinding service..."); @@ -207,18 +212,14 @@ final class HeadsetStateMachine extends StateMachine { if (mPhoneState != null) { mPhoneState.listenForPhoneState(false); mPhoneState.cleanup(); - mPhoneState=null; } if (mPhonebook != null) { mPhonebook.cleanup(); - mPhonebook = null; } if (mNativeAvailable) { cleanupNative(); mNativeAvailable = false; } - mService = null; - mAdapter = null; } private class Disconnected extends State { diff --git a/src/com/android/bluetooth/hid/HidService.java b/src/com/android/bluetooth/hid/HidService.java index 2f3c6de2e..8bf9e1ff5 100755 --- a/src/com/android/bluetooth/hid/HidService.java +++ b/src/com/android/bluetooth/hid/HidService.java @@ -86,7 +86,6 @@ public class HidService extends ProfileService { if(mInputDevices != null) { mInputDevices.clear(); - mInputDevices = null; } clearHidService(); return true; diff --git a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java index b5506f07f..6109b5a61 100755 --- a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java +++ b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java @@ -53,10 +53,8 @@ public class BluetoothOppRfcommListener { private static final boolean V = Constants.VERBOSE; public static final int MSG_INCOMING_BTOPP_CONNECTION = 100; - private static final int JOIN_TIMEOUT_MS=2000; private volatile boolean mInterrupted; - private volatile boolean mFinish; private Thread mSocketAcceptThread; @@ -123,11 +121,12 @@ public class BluetoothOppRfcommListener { Log.e(TAG, "Error create RfcommServerSocket " + e1); serverOK = false; } + if (!serverOK) { synchronized (this) { try { - if (V) Log.v(TAG, "Wait 3 seconds"); - Thread.sleep(3000); + if (V) Log.v(TAG, "Wait 300 ms"); + Thread.sleep(300); } catch (InterruptedException e) { Log.e(TAG, "socketAcceptThread thread was interrupted (3)"); mInterrupted = true; @@ -169,6 +168,9 @@ public class BluetoothOppRfcommListener { } } catch (IOException e) { Log.e(TAG, "Error accept connection " + e); + try { + Thread.sleep(500); + } catch (InterruptedException ie) {} } } Log.i(TAG, "BluetoothSocket listen thread finished"); diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 750487bd9..5a304335c 100755 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -333,43 +333,16 @@ public class BluetoothOppService extends Service { getContentResolver().unregisterContentObserver(mObserver); unregisterReceiver(mBluetoothReceiver); mSocketListener.stop(); - _cleanup(); - } - /* Cleanup all local references. Called during onDestroy */ - private void _cleanup() { if(mBatchs != null) { mBatchs.clear(); - mBatchs = null; } if(mShares != null) { mShares.clear(); - mShares = null; } - if(mObserver != null) - mObserver = null; - if(mNotifier != null) - mNotifier = null; if(mHandler != null) { mHandler.removeCallbacksAndMessages(null); - mHandler = null; - } - if(mSocketListener != null) - mSocketListener = null; - if(mPowerManager != null) - mPowerManager = null; - if(mPendingConnection != null) - mPendingConnection = null; - if(mTransfer != null) { - mTransfer.cleanup(); - mTransfer = null; - } - if(mServerTransfer!= null) { - mServerTransfer.cleanup(); - mServerTransfer = null; } - if(mAdapter != null) - mAdapter = null; } /* suppose we auto accept an incoming OPUSH connection */ @@ -771,7 +744,6 @@ public class BluetoothOppService extends Service { Log.e(TAG, "Unexpected error! batch id " + batch.mId + " doesn't match mTransfer id " + mTransfer.getBatchId()); } - mTransfer.cleanup(); mTransfer = null; } else { if (mServerTransfer == null) { @@ -783,7 +755,6 @@ public class BluetoothOppService extends Service { + " doesn't match mServerTransfer id " + mServerTransfer.getBatchId()); } - mServerTransfer.cleanup(); mServerTransfer = null; } removeBatch(batch); diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index e345f4eed..44d9bb68e 100755 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -419,28 +419,6 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } } - /** - * Object cleanup - */ - public void cleanup() { - if(mContext != null) - mContext = null; - if(mAdapter != null) - mAdapter = null; - if(mBatch != null) { - mBatch = null; - } - if(mSession != null) - mSession = null; - if(mCurrentShare != null) - mCurrentShare = null; - if(mTransport != null) - mTransport = null; - if(mSessionHandler != null) { - mSessionHandler = null; - } - } - private void startObexSession() { mBatch.mStatus = Constants.BATCH_STATUS_RUNNING; diff --git a/src/com/android/bluetooth/pan/PanService.java b/src/com/android/bluetooth/pan/PanService.java index e851433d5..f5d5ff2fc 100755 --- a/src/com/android/bluetooth/pan/PanService.java +++ b/src/com/android/bluetooth/pan/PanService.java @@ -105,14 +105,10 @@ public class PanService extends ProfileService { BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE); } mPanDevices.clear(); - mPanDevices = null; } if(mBluetoothIfaceAddresses != null) { mBluetoothIfaceAddresses.clear(); - mBluetoothIfaceAddresses = null; } - if(mPanIfName != null) - mPanIfName = null; return true; } diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapReceiver.java b/src/com/android/bluetooth/pbap/BluetoothPbapReceiver.java index 6aa09dce8..2356e81f0 100644 --- a/src/com/android/bluetooth/pbap/BluetoothPbapReceiver.java +++ b/src/com/android/bluetooth/pbap/BluetoothPbapReceiver.java @@ -61,7 +61,9 @@ public class BluetoothPbapReceiver extends BroadcastReceiver { in.putExtra(BluetoothAdapter.EXTRA_STATE, state); if (V) Log.v(TAG,"***********state = " + state); if ((state == BluetoothAdapter.STATE_TURNING_ON) - || (state == BluetoothAdapter.STATE_TURNING_OFF)) { + || (state == BluetoothAdapter.STATE_OFF)) { + //FIX: We turn on PBAP after BluetoothAdapter.STATE_ON, + //but we turn off PBAP right after BluetoothAdapter.STATE_TURNING_OFF startService = false; } } else { diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapService.java b/src/com/android/bluetooth/pbap/BluetoothPbapService.java index 4c918e016..80cd8ee1b 100755 --- a/src/com/android/bluetooth/pbap/BluetoothPbapService.java +++ b/src/com/android/bluetooth/pbap/BluetoothPbapService.java @@ -236,7 +236,7 @@ public class BluetoothPbapService extends Service { boolean removeTimeoutMsg = true; if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { - if (state == BluetoothAdapter.STATE_OFF) { + if (state == BluetoothAdapter.STATE_TURNING_OFF) { // Send any pending timeout now, as this service will be destroyed. if (mSessionStatusHandler.hasMessages(USER_TIMEOUT)) { Intent timeoutIntent = @@ -340,8 +340,7 @@ public class BluetoothPbapService extends Service { try { // It is mandatory for PSE to support initiation of bonding and // encryption. - mServerSocket = mAdapter.listenUsingEncryptedRfcommWithServiceRecord( - "OBEX Phonebook Access Server", BluetoothUuid.PBAP_PSE.getUuid()); + mServerSocket = mAdapter.listenUsingEncryptedRfcommWithServiceRecord("OBEX Phonebook Access Server", BluetoothUuid.PBAP_PSE.getUuid()); } catch (IOException e) { Log.e(TAG, "Error create RfcommServerSocket " + e.toString()); @@ -350,8 +349,8 @@ public class BluetoothPbapService extends Service { if (!initSocketOK) { synchronized (this) { try { - if (VERBOSE) Log.v(TAG, "wait 3 seconds"); - Thread.sleep(3000); + if (VERBOSE) Log.v(TAG, "wait 300 ms"); + Thread.sleep(300); } catch (InterruptedException e) { Log.e(TAG, "socketAcceptThread thread was interrupted (3)"); mInterrupted = true; |