Merge "Bluetooth: Fix to avoid BluetoothPan ServiceConnection leak"
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 1c9959e..1f19031 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -131,7 +131,8 @@
@Override
public void onCreate(Bundle savedInstanceState) {
- if (mBluetoothAdapter != null) {
+ if (mBluetoothAdapter != null &&
+ mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
BluetoothProfile.PAN);
}
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index b8a6d28..da90e49 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -78,10 +78,21 @@
@Test
public void lifeCycle_onCreate_shouldInitBluetoothPan() {
+ when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
mController.onCreate(null);
- verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
- BluetoothProfile.PAN);
+ verify(mBluetoothAdapter).getState();
+ verify(mBluetoothAdapter)
+ .getProfileProxy(mContext, mController.mBtProfileServiceListener, BluetoothProfile.PAN);
+ }
+
+ @Test
+ public void lifeCycle_onCreate_shouldNotInitBluetoothPanWhenBluetoothOff() {
+ when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
+ mController.onCreate(null);
+
+ verify(mBluetoothAdapter).getState();
+ verifyNoMoreInteractions(mBluetoothAdapter);
}
@Test