Fix dup preference key on Connected devices page

Use different key (prefix + CacheBluetooothDevice hash) for
each BluetoothDevicePreference to avoid Java crash due to "Two different
ViewHolders have the same change ID".

Test: atest
Fix: 325831741
Flag: EXEMPT safe fix only change preference key string
Change-Id: Ic993f3cab206b794045c2f46e6b4b376bfa3adea
This commit is contained in:
Yiyi Shen
2024-07-01 14:28:50 +08:00
parent 1d838f62ea
commit 07a346fcf5
11 changed files with 36 additions and 30 deletions

View File

@@ -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(