Only apply flag when it has been changed

The properies object provided in onPropertiesChanged only contains
flag(s) that have been added/deleted/updated.

Test: atest WmTests:HighRefreshRateBlacklistTest
Bug: 144693310
Change-Id: Ieb5a494c01103141ee97fc1f6507437cb1d9b6b6
This commit is contained in:
Linus Tufvesson
2019-11-18 18:14:00 +00:00
parent d04028ce6f
commit 6167bf230f
2 changed files with 21 additions and 2 deletions

View File

@@ -105,8 +105,10 @@ class HighRefreshRateBlacklist {
private class OnPropertiesChangedListener implements DeviceConfig.OnPropertiesChangedListener {
public void onPropertiesChanged(@NonNull DeviceConfig.Properties properties) {
updateBlacklist(
properties.getString(KEY_HIGH_REFRESH_RATE_BLACKLIST, null /*default*/));
if (properties.getKeyset().contains(KEY_HIGH_REFRESH_RATE_BLACKLIST)) {
updateBlacklist(
properties.getString(KEY_HIGH_REFRESH_RATE_BLACKLIST, null /*default*/));
}
}
}
}

View File

@@ -120,6 +120,23 @@ public class HighRefreshRateBlacklistTest {
assertFalse(mBlacklist.isBlacklisted(APP3));
}
@Test
public void testOverriddenByDeviceConfigUnrelatedFlagChanged() {
final Resources r = createResources(APP1);
final FakeDeviceConfig config = new FakeDeviceConfig();
mBlacklist = new HighRefreshRateBlacklist(r, config);
config.setBlacklist(APP2 + "," + APP3);
assertFalse(mBlacklist.isBlacklisted(APP1));
assertTrue(mBlacklist.isBlacklisted(APP2));
assertTrue(mBlacklist.isBlacklisted(APP3));
// Change an unrelated flag in our namespace and verify that the blacklist is intact
config.putPropertyAndNotify(DeviceConfig.NAMESPACE_DISPLAY_MANAGER, "someKey", "someValue");
assertFalse(mBlacklist.isBlacklisted(APP1));
assertTrue(mBlacklist.isBlacklisted(APP2));
assertTrue(mBlacklist.isBlacklisted(APP3));
}
private Resources createResources(String... defaultBlacklist) {
Resources r = mock(Resources.class);
when(r.getStringArray(R.array.config_highRefreshRateBlacklist))