Skip lifecycle if controller is not available

Fixes: 129076378
Test: RunSettingsRoboTests
Change-Id: If1e49785c2378ec2cf0f7d2837bc7d4c0ff915a0
This commit is contained in:
jackqdyulei
2019-03-22 14:43:19 -07:00
parent 8edea74eda
commit 281cf17d89
2 changed files with 39 additions and 2 deletions

View File

@@ -62,6 +62,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
@VisibleForTesting
final Map<String, Bitmap> mIconCache;
private CachedBluetoothDevice mCachedDevice;
private BluetoothDevice mBluetoothDevice;
@VisibleForTesting
BluetoothAdapter mBluetoothAdapter;
@VisibleForTesting
@@ -102,6 +103,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
@Override
public void onStart() {
if (!isAvailable()) {
return;
}
mCachedDevice.registerCallback(this::onDeviceAttributesChanged);
mBluetoothAdapter.registerMetadataListener(mCachedDevice.getDevice(), mMetadataListener,
mHandler);
@@ -109,6 +113,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
@Override
public void onStop() {
if (!isAvailable()) {
return;
}
mCachedDevice.unregisterCallback(this::onDeviceAttributesChanged);
mBluetoothAdapter.unregisterMetadataListener(mCachedDevice.getDevice());
@@ -123,6 +130,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
public void init(CachedBluetoothDevice cachedBluetoothDevice) {
mCachedDevice = cachedBluetoothDevice;
mBluetoothDevice = mCachedDevice.getDevice();
}
@VisibleForTesting