Bluetooth: Fix to avoid BluetoothPan ServiceConnection leak
Usecase:
1.) Make sure BT is turned off.
2.) Go to Settings -> Network & Internet
3.) Press back from Network & Internet.
4.) Repeat above step 2000 times
Expected Result:
No ANR/Crashed should be seen.
Observed Result:
ServiceConnection leak is happening & android setting app get crashed.
Root cause: TetherPreferenceController tries to get
pan Proxy object, when BT is oFF, which is leaking one
service connection each time
Fix: getProfileProxy for Pan must only be called, when BT is
turned on.
Test: lifeCycle_onCreate_shouldNotInitBluetoothPanWhenBluetoothOff
Bug: 79561076
Change-Id: I85208f48ce4dded94020cb156fcdb98b2cc873f9
Merged-In: I85208f48ce4dded94020cb156fcdb98b2cc873f9
This commit is contained in:
committed by
Myles Watson
parent
ea74edc9c5
commit
5ba33d1fd3
@@ -131,7 +131,8 @@ public class TetherPreferenceController extends AbstractPreferenceController imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
if (mBluetoothAdapter != null) {
|
if (mBluetoothAdapter != null &&
|
||||||
|
mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
|
||||||
mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
|
mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
|
||||||
BluetoothProfile.PAN);
|
BluetoothProfile.PAN);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,10 +78,21 @@ public class TetherPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lifeCycle_onCreate_shouldInitBluetoothPan() {
|
public void lifeCycle_onCreate_shouldInitBluetoothPan() {
|
||||||
|
when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
|
||||||
mController.onCreate(null);
|
mController.onCreate(null);
|
||||||
|
|
||||||
verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
|
verify(mBluetoothAdapter).getState();
|
||||||
BluetoothProfile.PAN);
|
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
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user