Snap for 6852881 from ca04ccd911
to rvc-qpr1-release
Change-Id: I913fc331aa054600c9321aabdb71eba2964631dd
This commit is contained in:
@@ -52,8 +52,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
* BluetoothDevicePreference is the preference type used to display each remote
|
* BluetoothDevicePreference is the preference type used to display each remote
|
||||||
* Bluetooth device in the Bluetooth Settings screen.
|
* Bluetooth device in the Bluetooth Settings screen.
|
||||||
*/
|
*/
|
||||||
public final class BluetoothDevicePreference extends GearPreference implements
|
public final class BluetoothDevicePreference extends GearPreference {
|
||||||
CachedBluetoothDevice.Callback {
|
|
||||||
private static final String TAG = "BluetoothDevicePref";
|
private static final String TAG = "BluetoothDevicePref";
|
||||||
|
|
||||||
private static int sDimAlpha = Integer.MIN_VALUE;
|
private static int sDimAlpha = Integer.MIN_VALUE;
|
||||||
@@ -77,10 +76,20 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
private AlertDialog mDisconnectDialog;
|
private AlertDialog mDisconnectDialog;
|
||||||
private String contentDescription = null;
|
private String contentDescription = null;
|
||||||
private boolean mHideSecondTarget = false;
|
private boolean mHideSecondTarget = false;
|
||||||
|
private boolean mIsCallbackRemoved = false;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mNeedNotifyHierarchyChanged = false;
|
boolean mNeedNotifyHierarchyChanged = false;
|
||||||
/* Talk-back descriptions for various BT icons */
|
/* Talk-back descriptions for various BT icons */
|
||||||
Resources mResources;
|
Resources mResources;
|
||||||
|
final BluetoothDevicePreferenceCallback mCallback;
|
||||||
|
|
||||||
|
private class BluetoothDevicePreferenceCallback implements CachedBluetoothDevice.Callback {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeviceAttributesChanged() {
|
||||||
|
onPreferenceAttributesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice,
|
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice,
|
||||||
boolean showDeviceWithoutNames, @SortType int type) {
|
boolean showDeviceWithoutNames, @SortType int type) {
|
||||||
@@ -96,10 +105,12 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCachedDevice = cachedDevice;
|
mCachedDevice = cachedDevice;
|
||||||
|
mCallback = new BluetoothDevicePreferenceCallback();
|
||||||
|
mCachedDevice.registerCallback(mCallback);
|
||||||
mCurrentTime = System.currentTimeMillis();
|
mCurrentTime = System.currentTimeMillis();
|
||||||
mType = type;
|
mType = type;
|
||||||
|
|
||||||
onDeviceAttributesChanged();
|
onPreferenceAttributesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNeedNotifyHierarchyChanged(boolean needNotifyHierarchyChanged) {
|
public void setNeedNotifyHierarchyChanged(boolean needNotifyHierarchyChanged) {
|
||||||
@@ -126,6 +137,10 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
@Override
|
@Override
|
||||||
protected void onPrepareForRemoval() {
|
protected void onPrepareForRemoval() {
|
||||||
super.onPrepareForRemoval();
|
super.onPrepareForRemoval();
|
||||||
|
if (!mIsCallbackRemoved) {
|
||||||
|
mCachedDevice.unregisterCallback(mCallback);
|
||||||
|
mIsCallbackRemoved = true;
|
||||||
|
}
|
||||||
if (mDisconnectDialog != null) {
|
if (mDisconnectDialog != null) {
|
||||||
mDisconnectDialog.dismiss();
|
mDisconnectDialog.dismiss();
|
||||||
mDisconnectDialog = null;
|
mDisconnectDialog = null;
|
||||||
@@ -135,13 +150,20 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
@Override
|
@Override
|
||||||
public void onAttached() {
|
public void onAttached() {
|
||||||
super.onAttached();
|
super.onAttached();
|
||||||
mCachedDevice.registerCallback(this);
|
if (mIsCallbackRemoved) {
|
||||||
|
mCachedDevice.registerCallback(mCallback);
|
||||||
|
mIsCallbackRemoved = false;
|
||||||
|
}
|
||||||
|
onPreferenceAttributesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetached() {
|
public void onDetached() {
|
||||||
super.onDetached();
|
super.onDetached();
|
||||||
mCachedDevice.unregisterCallback(this);
|
if (!mIsCallbackRemoved) {
|
||||||
|
mCachedDevice.unregisterCallback(mCallback);
|
||||||
|
mIsCallbackRemoved = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedBluetoothDevice getBluetoothDevice() {
|
public CachedBluetoothDevice getBluetoothDevice() {
|
||||||
@@ -152,7 +174,7 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
mHideSecondTarget = hideSecondTarget;
|
mHideSecondTarget = hideSecondTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDeviceAttributesChanged() {
|
private void onPreferenceAttributesChanged() {
|
||||||
/*
|
/*
|
||||||
* The preference framework takes care of making sure the value has
|
* The preference framework takes care of making sure the value has
|
||||||
* changed before proceeding. It will also call notifyChanged() if
|
* changed before proceeding. It will also call notifyChanged() if
|
||||||
|
@@ -91,7 +91,6 @@ public class RemoteMediaSlice implements CustomSliceable {
|
|||||||
R.drawable.ic_volume_remote);
|
R.drawable.ic_volume_remote);
|
||||||
// To create an empty icon to indent the row
|
// To create an empty icon to indent the row
|
||||||
final IconCompat emptyIcon = createEmptyIcon();
|
final IconCompat emptyIcon = createEmptyIcon();
|
||||||
int requestCode = 0;
|
|
||||||
for (RoutingSessionInfo info : infos) {
|
for (RoutingSessionInfo info : infos) {
|
||||||
final int maxVolume = info.getVolumeMax();
|
final int maxVolume = info.getVolumeMax();
|
||||||
if (maxVolume <= 0) {
|
if (maxVolume <= 0) {
|
||||||
@@ -104,7 +103,7 @@ public class RemoteMediaSlice implements CustomSliceable {
|
|||||||
listBuilder.addInputRange(new InputRangeBuilder()
|
listBuilder.addInputRange(new InputRangeBuilder()
|
||||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||||
.setTitle(castVolume)
|
.setTitle(castVolume)
|
||||||
.setInputAction(getSliderInputAction(requestCode++, info.getId()))
|
.setInputAction(getSliderInputAction(info.getId().hashCode(), info.getId()))
|
||||||
.setPrimaryAction(getSoundSettingAction(castVolume, icon, info.getId()))
|
.setPrimaryAction(getSoundSettingAction(castVolume, icon, info.getId()))
|
||||||
.setMax(maxVolume)
|
.setMax(maxVolume)
|
||||||
.setValue(info.getVolume()));
|
.setValue(info.getVolume()));
|
||||||
|
@@ -17,10 +17,12 @@ package com.android.settings.bluetooth;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -35,7 +37,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
|||||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settingslib.testutils.DrawableTestHelper;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -261,4 +262,19 @@ public class BluetoothDevicePreferenceTest {
|
|||||||
assertThat(mPreferenceList.get(2).getCachedDevice().getAddress())
|
assertThat(mPreferenceList.get(2).getCachedDevice().getAddress())
|
||||||
.isEqualTo(preference3.getCachedDevice().getAddress());
|
.isEqualTo(preference3.getCachedDevice().getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onAttached_callbackNotRemoved_doNotRegisterCallback() {
|
||||||
|
mPreference.onAttached();
|
||||||
|
|
||||||
|
verify(mCachedBluetoothDevice, never()).unregisterCallback(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onAttached_callbackRemoved_registerCallback() {
|
||||||
|
mPreference.onPrepareForRemoval();
|
||||||
|
mPreference.onAttached();
|
||||||
|
|
||||||
|
verify(mCachedBluetoothDevice, times(2)).registerCallback(any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user