diff --git a/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java b/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java index f600b038ddc..31d069afaee 100644 --- a/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java +++ b/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java @@ -27,7 +27,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; */ public class AvailableHearingDeviceUpdater extends AvailableMediaBluetoothDeviceUpdater { - private static final String PREF_KEY = "connected_hearing_device"; + private static final String PREF_KEY_PREFIX = "connected_hearing_device_"; public AvailableHearingDeviceUpdater(Context context, DevicePreferenceCallback devicePreferenceCallback, int metricsCategory) { @@ -42,7 +42,7 @@ public class AvailableHearingDeviceUpdater extends AvailableMediaBluetoothDevice } @Override - protected String getPreferenceKey() { - return PREF_KEY; + protected String getPreferenceKeyPrefix() { + return PREF_KEY_PREFIX; } } diff --git a/src/com/android/settings/accessibility/SavedHearingDeviceUpdater.java b/src/com/android/settings/accessibility/SavedHearingDeviceUpdater.java index 645d09143a7..1de9c727235 100644 --- a/src/com/android/settings/accessibility/SavedHearingDeviceUpdater.java +++ b/src/com/android/settings/accessibility/SavedHearingDeviceUpdater.java @@ -29,7 +29,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; */ public class SavedHearingDeviceUpdater extends SavedBluetoothDeviceUpdater { - private static final String PREF_KEY = "saved_hearing_device"; + private static final String PREF_KEY_PREFIX = "saved_hearing_device_"; public SavedHearingDeviceUpdater(Context context, DevicePreferenceCallback devicePreferenceCallback, int metricsCategory) { @@ -47,7 +47,7 @@ public class SavedHearingDeviceUpdater extends SavedBluetoothDeviceUpdater { } @Override - protected String getPreferenceKey() { - return PREF_KEY; + protected String getPreferenceKeyPrefix() { + return PREF_KEY_PREFIX; } } diff --git a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java index b361bd2560e..183de7f64c8 100644 --- a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java @@ -35,7 +35,7 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater private static final String TAG = "AvailableMediaBluetoothDeviceUpdater"; private static final boolean DBG = Log.isLoggable(BluetoothDeviceUpdater.TAG, Log.DEBUG); - private static final String PREF_KEY = "available_media_bt"; + private static final String PREF_KEY_PREFIX = "available_media_bt_"; private final AudioManager mAudioManager; private final LocalBluetoothManager mLocalBtManager; @@ -141,8 +141,8 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater } @Override - protected String getPreferenceKey() { - return PREF_KEY; + protected String getPreferenceKeyPrefix() { + return PREF_KEY_PREFIX; } @Override diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java index 4b21b2ecfb0..965bb94f255 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java @@ -213,9 +213,9 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice); /** - * Return a preference key for logging + * Return a preference key prefix for logging */ - protected abstract String getPreferenceKey(); + protected abstract String getPreferenceKeyPrefix(); /** * Update whether to show {@link CachedBluetoothDevice} in the list. @@ -248,7 +248,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, new BluetoothDevicePreference(mPrefContext, cachedDevice, true /* showDeviceWithoutNames */, type); - btPreference.setKey(getPreferenceKey()); + btPreference.setKey(getPreferenceKeyPrefix() + cachedDevice.hashCode()); btPreference.setOnGearClickListener(mDeviceProfilesListener); if (this instanceof Preference.OnPreferenceClickListener) { btPreference.setOnPreferenceClickListener( diff --git a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java index d15696b5d07..2107569d86b 100644 --- a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java @@ -36,7 +36,7 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater { private static final String TAG = "ConnBluetoothDeviceUpdater"; private static final boolean DBG = Log.isLoggable(BluetoothDeviceUpdater.TAG, Log.DEBUG); - private static final String PREF_KEY = "connected_bt"; + private static final String PREF_KEY_PREFIX = "connected_bt_"; private final AudioManager mAudioManager; @@ -126,8 +126,8 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater { } @Override - protected String getPreferenceKey() { - return PREF_KEY; + protected String getPreferenceKeyPrefix() { + return PREF_KEY_PREFIX; } @Override diff --git a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java index ed1be7a5c5f..d7c0366accd 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java @@ -41,7 +41,7 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater private static final String TAG = "SavedBluetoothDeviceUpdater"; - private static final String PREF_KEY = "saved_bt"; + private static final String PREF_KEY_PREFIX = "saved_bt_"; private final boolean mShowConnectedDevice; @@ -134,8 +134,8 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater } @Override - protected String getPreferenceKey() { - return PREF_KEY; + protected String getPreferenceKeyPrefix() { + return PREF_KEY_PREFIX; } @Override diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java index 4d7e6991589..21eb4d13d0a 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java @@ -21,6 +21,7 @@ import android.content.Context; import android.util.Log; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import com.android.settings.bluetooth.BluetoothDeviceUpdater; @@ -35,7 +36,8 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater private static final String TAG = "AudioSharingBluetoothDeviceUpdater"; - private static final String PREF_KEY = "audio_sharing_bt"; + @VisibleForTesting + static final String PREF_KEY_PREFIX = "audio_sharing_bt_"; @Nullable private LocalBluetoothManager mLocalBtManager; @@ -76,8 +78,8 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater } @Override - protected String getPreferenceKey() { - return PREF_KEY; + protected String getPreferenceKeyPrefix() { + return PREF_KEY_PREFIX; } @Override diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java index 660229d55b8..0fbb8924e19 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java @@ -25,6 +25,7 @@ import android.util.Log; import android.widget.SeekBar; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import com.android.settings.bluetooth.BluetoothDevicePreference; @@ -41,7 +42,8 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat private static final String TAG = "AudioSharingDeviceVolumeControlUpdater"; - private static final String PREF_KEY = "audio_sharing_volume_control"; + @VisibleForTesting + static final String PREF_KEY_PREFIX = "audio_sharing_volume_control_"; @Nullable private final LocalBluetoothManager mBtManager; @Nullable private final VolumeControlProfile mVolumeControl; @@ -119,7 +121,7 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat new AudioSharingDeviceVolumePreference(mPrefContext, cachedDevice); vPreference.initialize(); vPreference.setOnSeekBarChangeListener(listener); - vPreference.setKey(getPreferenceKey()); + vPreference.setKey(getPreferenceKeyPrefix() + cachedDevice.hashCode()); vPreference.setIcon(com.android.settingslib.R.drawable.ic_bt_untethered_earbuds); vPreference.setTitle(cachedDevice.getName()); mPreferenceMap.put(device, vPreference); @@ -128,8 +130,8 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat } @Override - protected String getPreferenceKey() { - return PREF_KEY; + protected String getPreferenceKeyPrefix() { + return PREF_KEY_PREFIX; } @Override diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java index d165aa5f6a4..4bfe3359255 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java @@ -275,7 +275,7 @@ public class BluetoothDeviceUpdaterTest { } @Override - protected String getPreferenceKey() { + protected String getPreferenceKeyPrefix() { return "test_bt"; } } diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java index 785b1dc9f9e..879c6a4d0ab 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java @@ -16,6 +16,8 @@ package com.android.settings.connecteddevice.audiosharing; +import static com.android.settings.connecteddevice.audiosharing.AudioSharingBluetoothDeviceUpdater.PREF_KEY_PREFIX; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -85,7 +87,6 @@ import java.util.List; public class AudioSharingBluetoothDeviceUpdaterTest { private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C"; private static final String TEST_DEVICE_NAME = "test"; - private static final String PREF_KEY = "audio_sharing_bt"; private static final String TAG = "AudioSharingBluetoothDeviceUpdater"; @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @@ -263,7 +264,7 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void getPreferenceKey_returnsCorrectKey() { - assertThat(mDeviceUpdater.getPreferenceKey()).isEqualTo(PREF_KEY); + assertThat(mDeviceUpdater.getPreferenceKeyPrefix()).isEqualTo(PREF_KEY_PREFIX); } @Test diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java index e7cfb859e74..3c12946b7e2 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java @@ -16,6 +16,8 @@ package com.android.settings.connecteddevice.audiosharing; +import static com.android.settings.connecteddevice.audiosharing.AudioSharingDeviceVolumeControlUpdater.PREF_KEY_PREFIX; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -79,7 +81,6 @@ import java.util.List; public class AudioSharingDeviceVolumeControlUpdaterTest { private static final String TEST_DEVICE_NAME = "test"; private static final String TAG = "AudioSharingDeviceVolumeControlUpdater"; - private static final String PREF_KEY = "audio_sharing_volume_control"; private static final String TEST_SETTINGS_KEY = "bluetooth_le_broadcast_fallback_active_group_id"; private static final int TEST_DEVICE_GROUP_ID = 1; @@ -326,7 +327,7 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { @Test public void getPreferenceKey_returnsCorrectKey() { - assertThat(mDeviceUpdater.getPreferenceKey()).isEqualTo(PREF_KEY); + assertThat(mDeviceUpdater.getPreferenceKeyPrefix()).isEqualTo(PREF_KEY_PREFIX); } @Test