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
|
||||
* Bluetooth device in the Bluetooth Settings screen.
|
||||
*/
|
||||
public final class BluetoothDevicePreference extends GearPreference implements
|
||||
CachedBluetoothDevice.Callback {
|
||||
public final class BluetoothDevicePreference extends GearPreference {
|
||||
private static final String TAG = "BluetoothDevicePref";
|
||||
|
||||
private static int sDimAlpha = Integer.MIN_VALUE;
|
||||
@@ -77,10 +76,20 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
private AlertDialog mDisconnectDialog;
|
||||
private String contentDescription = null;
|
||||
private boolean mHideSecondTarget = false;
|
||||
private boolean mIsCallbackRemoved = false;
|
||||
@VisibleForTesting
|
||||
boolean mNeedNotifyHierarchyChanged = false;
|
||||
/* Talk-back descriptions for various BT icons */
|
||||
Resources mResources;
|
||||
final BluetoothDevicePreferenceCallback mCallback;
|
||||
|
||||
private class BluetoothDevicePreferenceCallback implements CachedBluetoothDevice.Callback {
|
||||
|
||||
@Override
|
||||
public void onDeviceAttributesChanged() {
|
||||
onPreferenceAttributesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice,
|
||||
boolean showDeviceWithoutNames, @SortType int type) {
|
||||
@@ -96,10 +105,12 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
}
|
||||
|
||||
mCachedDevice = cachedDevice;
|
||||
mCallback = new BluetoothDevicePreferenceCallback();
|
||||
mCachedDevice.registerCallback(mCallback);
|
||||
mCurrentTime = System.currentTimeMillis();
|
||||
mType = type;
|
||||
|
||||
onDeviceAttributesChanged();
|
||||
onPreferenceAttributesChanged();
|
||||
}
|
||||
|
||||
public void setNeedNotifyHierarchyChanged(boolean needNotifyHierarchyChanged) {
|
||||
@@ -126,6 +137,10 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
@Override
|
||||
protected void onPrepareForRemoval() {
|
||||
super.onPrepareForRemoval();
|
||||
if (!mIsCallbackRemoved) {
|
||||
mCachedDevice.unregisterCallback(mCallback);
|
||||
mIsCallbackRemoved = true;
|
||||
}
|
||||
if (mDisconnectDialog != null) {
|
||||
mDisconnectDialog.dismiss();
|
||||
mDisconnectDialog = null;
|
||||
@@ -135,13 +150,20 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
mCachedDevice.registerCallback(this);
|
||||
if (mIsCallbackRemoved) {
|
||||
mCachedDevice.registerCallback(mCallback);
|
||||
mIsCallbackRemoved = false;
|
||||
}
|
||||
onPreferenceAttributesChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetached() {
|
||||
super.onDetached();
|
||||
mCachedDevice.unregisterCallback(this);
|
||||
if (!mIsCallbackRemoved) {
|
||||
mCachedDevice.unregisterCallback(mCallback);
|
||||
mIsCallbackRemoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
public CachedBluetoothDevice getBluetoothDevice() {
|
||||
@@ -152,7 +174,7 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
mHideSecondTarget = hideSecondTarget;
|
||||
}
|
||||
|
||||
public void onDeviceAttributesChanged() {
|
||||
private void onPreferenceAttributesChanged() {
|
||||
/*
|
||||
* The preference framework takes care of making sure the value has
|
||||
* changed before proceeding. It will also call notifyChanged() if
|
||||
|
@@ -91,7 +91,6 @@ public class RemoteMediaSlice implements CustomSliceable {
|
||||
R.drawable.ic_volume_remote);
|
||||
// To create an empty icon to indent the row
|
||||
final IconCompat emptyIcon = createEmptyIcon();
|
||||
int requestCode = 0;
|
||||
for (RoutingSessionInfo info : infos) {
|
||||
final int maxVolume = info.getVolumeMax();
|
||||
if (maxVolume <= 0) {
|
||||
@@ -104,7 +103,7 @@ public class RemoteMediaSlice implements CustomSliceable {
|
||||
listBuilder.addInputRange(new InputRangeBuilder()
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(castVolume)
|
||||
.setInputAction(getSliderInputAction(requestCode++, info.getId()))
|
||||
.setInputAction(getSliderInputAction(info.getId().hashCode(), info.getId()))
|
||||
.setPrimaryAction(getSoundSettingAction(castVolume, icon, info.getId()))
|
||||
.setMax(maxVolume)
|
||||
.setValue(info.getVolume()));
|
||||
|
@@ -17,10 +17,12 @@ package com.android.settings.bluetooth;
|
||||
|
||||
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.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
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.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.testutils.DrawableTestHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -261,4 +262,19 @@ public class BluetoothDevicePreferenceTest {
|
||||
assertThat(mPreferenceList.get(2).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