Merge "Use flag to confirm whether callback should unregister"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5900c5a6ac
@@ -73,6 +73,8 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Handler mHandler = new Handler(Looper.getMainLooper());
|
Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
boolean mIsRegisterCallback = false;
|
||||||
|
@VisibleForTesting
|
||||||
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
|
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
|
||||||
new BluetoothAdapter.OnMetadataChangedListener() {
|
new BluetoothAdapter.OnMetadataChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -96,6 +98,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
final boolean untetheredHeadset = mCachedDevice != null
|
final boolean untetheredHeadset = mCachedDevice != null
|
||||||
&& BluetoothUtils.getBooleanMetaData(
|
&& BluetoothUtils.getBooleanMetaData(
|
||||||
mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
|
mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
|
||||||
|
Log.d(TAG, "getAvailabilityStatus() is untethered : " + untetheredHeadset);
|
||||||
return advancedEnabled && untetheredHeadset ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
return advancedEnabled && untetheredHeadset ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +116,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
if (!isAvailable()) {
|
if (!isAvailable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mIsRegisterCallback = true;
|
||||||
mCachedDevice.registerCallback(this);
|
mCachedDevice.registerCallback(this);
|
||||||
mBluetoothAdapter.addOnMetadataChangedListener(mCachedDevice.getDevice(),
|
mBluetoothAdapter.addOnMetadataChangedListener(mCachedDevice.getDevice(),
|
||||||
mContext.getMainExecutor(), mMetadataListener);
|
mContext.getMainExecutor(), mMetadataListener);
|
||||||
@@ -120,19 +124,17 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
if (!isAvailable()) {
|
if (!mIsRegisterCallback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mCachedDevice.unregisterCallback(this);
|
mCachedDevice.unregisterCallback(this);
|
||||||
mBluetoothAdapter.removeOnMetadataChangedListener(mCachedDevice.getDevice(),
|
mBluetoothAdapter.removeOnMetadataChangedListener(mCachedDevice.getDevice(),
|
||||||
mMetadataListener);
|
mMetadataListener);
|
||||||
|
mIsRegisterCallback = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (!isAvailable()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Destroy icon bitmap associated with this header
|
// Destroy icon bitmap associated with this header
|
||||||
for (Bitmap bitmap : mIconCache.values()) {
|
for (Bitmap bitmap : mIconCache.values()) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
|
@@ -210,11 +210,8 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onStop_isAvailable_unregisterCallback() {
|
public void onStop_isRegisterCallback_unregisterCallback() {
|
||||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
mController.mIsRegisterCallback = true;
|
||||||
SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true);
|
|
||||||
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
|
|
||||||
.thenReturn("true".getBytes());
|
|
||||||
|
|
||||||
mController.onStop();
|
mController.onStop();
|
||||||
|
|
||||||
@@ -234,9 +231,8 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onStop_notAvailable_unregisterCallback() {
|
public void onStop_notRegisterCallback_unregisterCallback() {
|
||||||
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
|
mController.mIsRegisterCallback = false;
|
||||||
.thenReturn("false".getBytes());
|
|
||||||
|
|
||||||
mController.onStop();
|
mController.onStop();
|
||||||
|
|
||||||
@@ -245,11 +241,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onDestroy_isAvailable_recycleBitmap() {
|
public void onDestroy_recycleBitmap() {
|
||||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
|
||||||
SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true);
|
|
||||||
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
|
|
||||||
.thenReturn("true".getBytes());
|
|
||||||
mController.mIconCache.put(ICON_URI, mBitmap);
|
mController.mIconCache.put(ICON_URI, mBitmap);
|
||||||
|
|
||||||
mController.onDestroy();
|
mController.onDestroy();
|
||||||
|
Reference in New Issue
Block a user