Merge changes from topic "fix-policy"
am: e7194bfdfc
Change-Id: Ib736976b6290e6b03b2f50a13fffcdb95491e7bc
This commit is contained in:
@@ -40,52 +40,52 @@ class CompatConfigBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addTargetSdkChangeWithId(int sdk, long id) {
|
CompatConfigBuilder addTargetSdkChangeWithId(int sdk, long id) {
|
||||||
mChanges.add(new CompatChange(id, null, sdk, false, null));
|
mChanges.add(new CompatChange(id, "", sdk, false, ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addTargetSdkDisabledChangeWithId(int sdk, long id) {
|
CompatConfigBuilder addTargetSdkDisabledChangeWithId(int sdk, long id) {
|
||||||
mChanges.add(new CompatChange(id, null, sdk, true, null));
|
mChanges.add(new CompatChange(id, "", sdk, true, ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addTargetSdkChangeWithIdAndName(int sdk, long id, String name) {
|
CompatConfigBuilder addTargetSdkChangeWithIdAndName(int sdk, long id, String name) {
|
||||||
mChanges.add(new CompatChange(id, name, sdk, false, null));
|
mChanges.add(new CompatChange(id, name, sdk, false, ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addTargetSdkChangeWithIdAndDescription(int sdk, long id,
|
CompatConfigBuilder addTargetSdkChangeWithIdAndDescription(int sdk, long id,
|
||||||
String description) {
|
String description) {
|
||||||
mChanges.add(new CompatChange(id, null, sdk, false, description));
|
mChanges.add(new CompatChange(id, "", sdk, false, description));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addEnabledChangeWithId(long id) {
|
CompatConfigBuilder addEnabledChangeWithId(long id) {
|
||||||
mChanges.add(new CompatChange(id, null, -1, false, null));
|
mChanges.add(new CompatChange(id, "", -1, false, ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addEnabledChangeWithIdAndName(long id, String name) {
|
CompatConfigBuilder addEnabledChangeWithIdAndName(long id, String name) {
|
||||||
mChanges.add(new CompatChange(id, name, -1, false, null));
|
mChanges.add(new CompatChange(id, name, -1, false, ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
CompatConfigBuilder addEnabledChangeWithIdAndDescription(long id, String description) {
|
CompatConfigBuilder addEnabledChangeWithIdAndDescription(long id, String description) {
|
||||||
mChanges.add(new CompatChange(id, null, -1, false, description));
|
mChanges.add(new CompatChange(id, "", -1, false, description));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addDisabledChangeWithId(long id) {
|
CompatConfigBuilder addDisabledChangeWithId(long id) {
|
||||||
mChanges.add(new CompatChange(id, null, -1, true, null));
|
mChanges.add(new CompatChange(id, "", -1, true, ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addDisabledChangeWithIdAndName(long id, String name) {
|
CompatConfigBuilder addDisabledChangeWithIdAndName(long id, String name) {
|
||||||
mChanges.add(new CompatChange(id, name, -1, true, null));
|
mChanges.add(new CompatChange(id, name, -1, true, ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatConfigBuilder addDisabledChangeWithIdAndDescription(long id, String description) {
|
CompatConfigBuilder addDisabledChangeWithIdAndDescription(long id, String description) {
|
||||||
mChanges.add(new CompatChange(id, null, -1, true, description));
|
mChanges.add(new CompatChange(id, "", -1, true, description));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,15 @@ package com.android.server.compat;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.anyInt;
|
||||||
|
import static org.mockito.Mockito.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.testng.Assert.assertThrows;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
@@ -45,15 +50,10 @@ public class CompatConfigTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
|
PackageManager mPackageManager;
|
||||||
|
@Mock
|
||||||
private AndroidBuildClassifier mBuildClassifier;
|
private AndroidBuildClassifier mBuildClassifier;
|
||||||
|
|
||||||
private ApplicationInfo makeAppInfo(String pName, int targetSdkVersion) {
|
|
||||||
ApplicationInfo ai = new ApplicationInfo();
|
|
||||||
ai.packageName = pName;
|
|
||||||
ai.targetSdkVersion = targetSdkVersion;
|
|
||||||
return ai;
|
|
||||||
}
|
|
||||||
|
|
||||||
private File createTempDir() {
|
private File createTempDir() {
|
||||||
String base = System.getProperty("java.io.tmpdir");
|
String base = System.getProperty("java.io.tmpdir");
|
||||||
File dir = new File(base, UUID.randomUUID().toString());
|
File dir = new File(base, UUID.randomUUID().toString());
|
||||||
@@ -70,6 +70,7 @@ public class CompatConfigTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
// Assume userdebug/eng non-final build
|
// Assume userdebug/eng non-final build
|
||||||
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
||||||
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
||||||
@@ -77,110 +78,195 @@ public class CompatConfigTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnknownChangeEnabled() throws Exception {
|
public void testUnknownChangeEnabled() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 1))).isTrue();
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create().build()))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisabledChangeDisabled() throws Exception {
|
public void testDisabledChangeDisabled() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true, ""));
|
.addDisabledChangeWithId(1234L)
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 1))).isFalse();
|
.build();
|
||||||
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create().build()))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetSdkChangeDisabled() throws Exception {
|
public void testTargetSdkChangeDisabled() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, false, null));
|
.addTargetSdkChangeWithId(2, 1234L)
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isFalse();
|
.build();
|
||||||
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(2).build()))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetSdkChangeEnabled() throws Exception {
|
public void testTargetSdkChangeEnabled() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, false, ""));
|
.addTargetSdkChangeWithId(2, 1234L)
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 3))).isTrue();
|
.build();
|
||||||
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(3).build())).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisabledOverrideTargetSdkChange() throws Exception {
|
public void testDisabledOverrideTargetSdkChange() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, true, null));
|
.addTargetSdkDisabledChangeWithId(2, 1234L)
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 3))).isFalse();
|
.build();
|
||||||
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(3).build())).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDisabledChanges() throws Exception {
|
public void testGetDisabledChanges() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true, null));
|
.addDisabledChangeWithId(1234L)
|
||||||
pc.addChange(new CompatChange(2345L, "OTHER_CHANGE", -1, false, null));
|
.addEnabledChangeWithId(2345L)
|
||||||
assertThat(pc.getDisabledChanges(
|
.build();
|
||||||
makeAppInfo("com.some.package", 2))).asList().containsExactly(1234L);
|
|
||||||
|
assertThat(compatConfig.getDisabledChanges(
|
||||||
|
ApplicationInfoBuilder.create().build())).asList().containsExactly(1234L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDisabledChangesSorted() throws Exception {
|
public void testGetDisabledChangesSorted() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, true, null));
|
.addDisabledChangeWithId(1234L)
|
||||||
pc.addChange(new CompatChange(123L, "OTHER_CHANGE", 2, true, null));
|
.addDisabledChangeWithId(123L)
|
||||||
pc.addChange(new CompatChange(12L, "THIRD_CHANGE", 2, true, null));
|
.addDisabledChangeWithId(12L)
|
||||||
assertThat(pc.getDisabledChanges(
|
.build();
|
||||||
makeAppInfo("com.some.package", 2))).asList().containsExactly(12L, 123L, 1234L);
|
|
||||||
|
assertThat(compatConfig.getDisabledChanges(ApplicationInfoBuilder.create().build()))
|
||||||
|
.asList().containsExactly(12L, 123L, 1234L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPackageOverrideEnabled() throws Exception {
|
public void testPackageOverrideEnabled() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true, null)); // disabled
|
.addDisabledChangeWithId(1234L)
|
||||||
pc.addOverride(1234L, "com.some.package", true);
|
.build();
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isTrue();
|
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.other.package", 2))).isFalse();
|
compatConfig.addOverride(1234L, "com.some.package", true);
|
||||||
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.some.package").build())).isTrue();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.other.package").build())).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPackageOverrideDisabled() throws Exception {
|
public void testPackageOverrideDisabled() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false, null));
|
.addEnabledChangeWithId(1234L)
|
||||||
pc.addOverride(1234L, "com.some.package", false);
|
.build();
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isFalse();
|
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.other.package", 2))).isTrue();
|
compatConfig.addOverride(1234L, "com.some.package", false);
|
||||||
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.some.package").build())).isFalse();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.other.package").build())).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPackageOverrideUnknownPackage() throws Exception {
|
public void testPackageOverrideUnknownPackage() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
pc.addOverride(1234L, "com.some.package", false);
|
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isFalse();
|
compatConfig.addOverride(1234L, "com.some.package", false);
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.other.package", 2))).isTrue();
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.some.package").build())).isFalse();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.other.package").build())).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPackageOverrideUnknownChange() throws Exception {
|
public void testPreventAddOverride() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
final long changeId = 1234L;
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 1))).isTrue();
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
|
.addDisabledChangeWithId(1234L)
|
||||||
|
.build();
|
||||||
|
ApplicationInfo applicationInfo = ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.some.package")
|
||||||
|
.build();
|
||||||
|
PackageManager packageManager = mock(PackageManager.class);
|
||||||
|
when(mContext.getPackageManager()).thenReturn(packageManager);
|
||||||
|
when(packageManager.getApplicationInfo(eq("com.some.package"), anyInt()))
|
||||||
|
.thenReturn(applicationInfo);
|
||||||
|
|
||||||
|
// Force the validator to prevent overriding the change by using a user build.
|
||||||
|
when(mBuildClassifier.isDebuggableBuild()).thenReturn(false);
|
||||||
|
when(mBuildClassifier.isFinalBuild()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThrows(SecurityException.class,
|
||||||
|
() -> compatConfig.addOverride(1234L, "com.some.package", true)
|
||||||
|
);
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, applicationInfo)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPreventRemoveOverride() throws Exception {
|
||||||
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
|
.addDisabledChangeWithId(1234L)
|
||||||
|
.build();
|
||||||
|
ApplicationInfo applicationInfo = ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName("com.some.package")
|
||||||
|
.build();
|
||||||
|
when(mPackageManager.getApplicationInfo(eq("com.some.package"), anyInt()))
|
||||||
|
.thenReturn(applicationInfo);
|
||||||
|
// Assume the override was allowed to be added.
|
||||||
|
compatConfig.addOverride(1234L, "com.some.package", true);
|
||||||
|
|
||||||
|
// Validator allows turning on the change.
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, applicationInfo)).isTrue();
|
||||||
|
|
||||||
|
// Reject all override attempts.
|
||||||
|
// Force the validator to prevent overriding the change by using a user build.
|
||||||
|
when(mBuildClassifier.isDebuggableBuild()).thenReturn(false);
|
||||||
|
when(mBuildClassifier.isFinalBuild()).thenReturn(true);
|
||||||
|
// Try to turn off change, but validator prevents it.
|
||||||
|
assertThrows(SecurityException.class,
|
||||||
|
() -> compatConfig.removeOverride(1234L, "com.some.package"));
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, applicationInfo)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemovePackageOverride() throws Exception {
|
public void testRemovePackageOverride() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false, null));
|
.addEnabledChangeWithId(1234L)
|
||||||
pc.addOverride(1234L, "com.some.package", false);
|
.build();
|
||||||
pc.removeOverride(1234L, "com.some.package");
|
ApplicationInfo applicationInfo = ApplicationInfoBuilder.create()
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isTrue();
|
.withPackageName("com.some.package")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertThat(compatConfig.addOverride(1234L, "com.some.package", false)).isTrue();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, applicationInfo)).isFalse();
|
||||||
|
|
||||||
|
compatConfig.removeOverride(1234L, "com.some.package");
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L, applicationInfo)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupChangeId() throws Exception {
|
public void testLookupChangeId() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
|
||||||
pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false, null));
|
.addEnabledChangeWithIdAndName(1234L, "MY_CHANGE")
|
||||||
pc.addChange(new CompatChange(2345L, "ANOTHER_CHANGE", -1, false, null));
|
.addEnabledChangeWithIdAndName(2345L, "MY_OTHER_CHANGE")
|
||||||
assertThat(pc.lookupChangeId("MY_CHANGE")).isEqualTo(1234L);
|
.build();
|
||||||
|
|
||||||
|
assertThat(compatConfig.lookupChangeId("MY_CHANGE")).isEqualTo(1234L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupChangeIdNotPresent() throws Exception {
|
public void testLookupChangeIdNotPresent() throws Exception {
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig compatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
assertThat(pc.lookupChangeId("MY_CHANGE")).isEqualTo(-1L);
|
assertThat(compatConfig.lookupChangeId("MY_CHANGE")).isEqualTo(-1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -193,14 +279,17 @@ public class CompatConfigTest {
|
|||||||
|
|
||||||
File dir = createTempDir();
|
File dir = createTempDir();
|
||||||
writeToFile(dir, "platform_compat_config.xml", configXml);
|
writeToFile(dir, "platform_compat_config.xml", configXml);
|
||||||
|
CompatConfig compatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
|
compatConfig.initConfigFromLib(dir);
|
||||||
|
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
pc.initConfigFromLib(dir);
|
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isFalse();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 1))).isFalse();
|
ApplicationInfoBuilder.create().withTargetSdk(3).build())).isTrue();
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 3))).isTrue();
|
assertThat(compatConfig.isChangeEnabled(1235L,
|
||||||
assertThat(pc.isChangeEnabled(1235L, makeAppInfo("com.some.package", 5))).isFalse();
|
ApplicationInfoBuilder.create().withTargetSdk(5).build())).isFalse();
|
||||||
assertThat(pc.isChangeEnabled(1236L, makeAppInfo("com.some.package", 1))).isTrue();
|
assertThat(compatConfig.isChangeEnabled(1236L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -216,15 +305,16 @@ public class CompatConfigTest {
|
|||||||
File dir = createTempDir();
|
File dir = createTempDir();
|
||||||
writeToFile(dir, "libcore_platform_compat_config.xml", configXml1);
|
writeToFile(dir, "libcore_platform_compat_config.xml", configXml1);
|
||||||
writeToFile(dir, "frameworks_platform_compat_config.xml", configXml2);
|
writeToFile(dir, "frameworks_platform_compat_config.xml", configXml2);
|
||||||
|
CompatConfig compatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
|
compatConfig.initConfigFromLib(dir);
|
||||||
|
|
||||||
CompatConfig pc = new CompatConfig(mBuildClassifier, mContext);
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
pc.initConfigFromLib(dir);
|
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isFalse();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 1))).isFalse();
|
ApplicationInfoBuilder.create().withTargetSdk(3).build())).isTrue();
|
||||||
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 3))).isTrue();
|
assertThat(compatConfig.isChangeEnabled(1235L,
|
||||||
assertThat(pc.isChangeEnabled(1235L, makeAppInfo("com.some.package", 5))).isFalse();
|
ApplicationInfoBuilder.create().withTargetSdk(5).build())).isFalse();
|
||||||
assertThat(pc.isChangeEnabled(1236L, makeAppInfo("com.some.package", 1))).isTrue();
|
assertThat(compatConfig.isChangeEnabled(1236L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,55 +17,36 @@
|
|||||||
package com.android.server.compat;
|
package com.android.server.compat;
|
||||||
|
|
||||||
import android.compat.Compatibility;
|
import android.compat.Compatibility;
|
||||||
import android.os.RemoteException;
|
|
||||||
|
|
||||||
import com.android.internal.compat.CompatibilityChangeConfig;
|
import com.android.internal.compat.CompatibilityChangeConfig;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class OverridesBuilder {
|
class CompatibilityChangeConfigBuilder {
|
||||||
private Set<Long> mEnabled;
|
private Set<Long> mEnabled;
|
||||||
private Set<Long> mDisabled;
|
private Set<Long> mDisabled;
|
||||||
private String mPackageName;
|
|
||||||
|
|
||||||
private OverridesBuilder() {
|
private CompatibilityChangeConfigBuilder() {
|
||||||
mEnabled = new HashSet<>();
|
mEnabled = new HashSet<>();
|
||||||
mDisabled = new HashSet<>();
|
mDisabled = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static OverridesBuilder create() {
|
static CompatibilityChangeConfigBuilder create() {
|
||||||
return new OverridesBuilder();
|
return new CompatibilityChangeConfigBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
OverridesBuilder enable(Long id) {
|
CompatibilityChangeConfigBuilder enable(Long id) {
|
||||||
mEnabled.add(id);
|
mEnabled.add(id);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OverridesBuilder disable(Long id) {
|
CompatibilityChangeConfigBuilder disable(Long id) {
|
||||||
mDisabled.add(id);
|
mDisabled.add(id);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OverridesBuilder toPackage(String packageName) {
|
CompatibilityChangeConfig build() {
|
||||||
mPackageName = packageName;
|
return new CompatibilityChangeConfig(new Compatibility.ChangeConfig(mEnabled, mDisabled));
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void override(CompatConfig config) throws RemoteException {
|
|
||||||
config.addOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(mEnabled, mDisabled)), mPackageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void override(PlatformCompat platformCompat) throws RemoteException {
|
|
||||||
platformCompat.setOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(mEnabled, mDisabled)), mPackageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear(PlatformCompat platformCompat) throws RemoteException {
|
|
||||||
platformCompat.clearOverrides(mPackageName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,22 +26,20 @@ import static org.mockito.Mockito.when;
|
|||||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||||
import static org.testng.Assert.assertThrows;
|
import static org.testng.Assert.assertThrows;
|
||||||
|
|
||||||
import android.compat.Compatibility;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import com.android.internal.compat.AndroidBuildClassifier;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
import com.android.internal.compat.CompatibilityChangeConfig;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.android.internal.compat.AndroidBuildClassifier;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class PlatformCompatTest {
|
public class PlatformCompatTest {
|
||||||
private static final String PACKAGE_NAME = "my.package";
|
private static final String PACKAGE_NAME = "my.package";
|
||||||
|
|
||||||
@@ -51,18 +49,19 @@ public class PlatformCompatTest {
|
|||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
@Mock
|
@Mock
|
||||||
CompatChange.ChangeListener mListener1, mListener2;
|
CompatChange.ChangeListener mListener1, mListener2;
|
||||||
|
PlatformCompat mPlatformCompat;
|
||||||
CompatConfig mCompatConfig;
|
CompatConfig mCompatConfig;
|
||||||
@Mock
|
@Mock
|
||||||
AndroidBuildClassifier mBuildClassifier;
|
private AndroidBuildClassifier mBuildClassifier;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
when(mPackageManager.getPackageUid(eq(PACKAGE_NAME), eq(0))).thenThrow(
|
when(mPackageManager.getPackageUid(eq(PACKAGE_NAME), eq(0))).thenThrow(
|
||||||
new PackageManager.NameNotFoundException());
|
new PackageManager.NameNotFoundException());
|
||||||
mCompatConfig = new CompatConfig(mBuildClassifier, mContext);
|
mCompatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
|
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig);
|
||||||
// Assume userdebug/eng non-final build
|
// Assume userdebug/eng non-final build
|
||||||
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
||||||
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
||||||
@@ -70,41 +69,34 @@ public class PlatformCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegisterListenerToSameIdThrows() throws Exception {
|
public void testRegisterListenerToSameIdThrows() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
|
||||||
|
|
||||||
// Registering a listener to change 1 is successful.
|
// Registering a listener to change 1 is successful.
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
// Registering a listener to change 2 is successful.
|
// Registering a listener to change 2 is successful.
|
||||||
pc.registerListener(2, mListener1);
|
mPlatformCompat.registerListener(2, mListener1);
|
||||||
// Trying to register another listener to change id 1 fails.
|
// Trying to register another listener to change id 1 fails.
|
||||||
assertThrows(IllegalStateException.class, () -> pc.registerListener(1, mListener1));
|
assertThrows(IllegalStateException.class,
|
||||||
|
() -> mPlatformCompat.registerListener(1, mListener1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegisterListenerReturn() throws Exception {
|
public void testRegisterListenerReturn() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.setOverrides(
|
||||||
|
CompatibilityChangeConfigBuilder.create().enable(1L).build(),
|
||||||
pc.setOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(ImmutableSet.of(1L), ImmutableSet.of())),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
// Change id 1 is known (added in setOverrides).
|
// Change id 1 is known (added in setOverrides).
|
||||||
assertThat(pc.registerListener(1, mListener1)).isTrue();
|
assertThat(mPlatformCompat.registerListener(1, mListener1)).isTrue();
|
||||||
// Change 2 is unknown.
|
// Change 2 is unknown.
|
||||||
assertThat(pc.registerListener(2, mListener1)).isFalse();
|
assertThat(mPlatformCompat.registerListener(2, mListener1)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnSetOverrides() throws Exception {
|
public void testListenerCalledOnSetOverrides() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
|
mPlatformCompat.registerListener(2, mListener1);
|
||||||
|
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.setOverrides(
|
||||||
pc.registerListener(2, mListener1);
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
|
|
||||||
pc.setOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(ImmutableSet.of(1L), ImmutableSet.of(2L))),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
verify(mListener1, times(2)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(2)).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -112,14 +104,11 @@ public class PlatformCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerNotCalledOnWrongPackage() throws Exception {
|
public void testListenerNotCalledOnWrongPackage() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
|
mPlatformCompat.registerListener(2, mListener1);
|
||||||
|
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.setOverrides(
|
||||||
pc.registerListener(2, mListener1);
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
|
|
||||||
pc.setOverridesForTest(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(ImmutableSet.of(1L), ImmutableSet.of(2L))),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
verify(mListener1, never()).onCompatChange("other.package");
|
verify(mListener1, never()).onCompatChange("other.package");
|
||||||
@@ -127,15 +116,10 @@ public class PlatformCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnSetOverridesTwoListeners() throws Exception {
|
public void testListenerCalledOnSetOverridesTwoListeners() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
pc.registerListener(1, mListener1);
|
|
||||||
|
|
||||||
final ImmutableSet<Long> enabled = ImmutableSet.of(1L);
|
mPlatformCompat.setOverrides(
|
||||||
final ImmutableSet<Long> disabled = ImmutableSet.of(2L);
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
|
|
||||||
pc.setOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(enabled, disabled)),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -144,11 +128,10 @@ public class PlatformCompatTest {
|
|||||||
reset(mListener1);
|
reset(mListener1);
|
||||||
reset(mListener2);
|
reset(mListener2);
|
||||||
|
|
||||||
pc.registerListener(2, mListener2);
|
mPlatformCompat.registerListener(2, mListener2);
|
||||||
|
|
||||||
pc.setOverrides(
|
mPlatformCompat.setOverrides(
|
||||||
new CompatibilityChangeConfig(
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
new Compatibility.ChangeConfig(enabled, disabled)),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -157,14 +140,11 @@ public class PlatformCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnSetOverridesForTest() throws Exception {
|
public void testListenerCalledOnSetOverridesForTest() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
|
mPlatformCompat.registerListener(2, mListener1);
|
||||||
|
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.setOverrides(
|
||||||
pc.registerListener(2, mListener1);
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
|
|
||||||
pc.setOverridesForTest(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(ImmutableSet.of(1L), ImmutableSet.of(2L))),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
verify(mListener1, times(2)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(2)).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -172,15 +152,10 @@ public class PlatformCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnSetOverridesTwoListenersForTest() throws Exception {
|
public void testListenerCalledOnSetOverridesTwoListenersForTest() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
pc.registerListener(1, mListener1);
|
|
||||||
|
|
||||||
final ImmutableSet<Long> enabled = ImmutableSet.of(1L);
|
mPlatformCompat.setOverrides(
|
||||||
final ImmutableSet<Long> disabled = ImmutableSet.of(2L);
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
|
|
||||||
pc.setOverridesForTest(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(enabled, disabled)),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -189,10 +164,10 @@ public class PlatformCompatTest {
|
|||||||
reset(mListener1);
|
reset(mListener1);
|
||||||
reset(mListener2);
|
reset(mListener2);
|
||||||
|
|
||||||
pc.registerListener(2, mListener2);
|
mPlatformCompat.registerListener(2, mListener2);
|
||||||
pc.setOverridesForTest(
|
|
||||||
new CompatibilityChangeConfig(
|
mPlatformCompat.setOverrides(
|
||||||
new Compatibility.ChangeConfig(enabled, disabled)),
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
|
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -201,14 +176,11 @@ public class PlatformCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnClearOverrides() throws Exception {
|
public void testListenerCalledOnClearOverrides() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
|
mPlatformCompat.registerListener(2, mListener2);
|
||||||
|
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.setOverrides(
|
||||||
pc.registerListener(2, mListener2);
|
CompatibilityChangeConfigBuilder.create().enable(1L).build(),
|
||||||
|
|
||||||
pc.setOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(ImmutableSet.of(1L), ImmutableSet.of())),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -216,21 +188,18 @@ public class PlatformCompatTest {
|
|||||||
reset(mListener1);
|
reset(mListener1);
|
||||||
reset(mListener2);
|
reset(mListener2);
|
||||||
|
|
||||||
pc.clearOverrides(PACKAGE_NAME);
|
mPlatformCompat.clearOverrides(PACKAGE_NAME);
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnClearOverridesMultipleOverrides() throws Exception {
|
public void testListenerCalledOnClearOverridesMultipleOverrides() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
|
mPlatformCompat.registerListener(2, mListener2);
|
||||||
|
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.setOverrides(
|
||||||
pc.registerListener(2, mListener2);
|
CompatibilityChangeConfigBuilder.create().enable(1L).disable(2L).build(),
|
||||||
|
|
||||||
pc.setOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(ImmutableSet.of(1L), ImmutableSet.of(2L))),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
verify(mListener2, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener2, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -238,21 +207,18 @@ public class PlatformCompatTest {
|
|||||||
reset(mListener1);
|
reset(mListener1);
|
||||||
reset(mListener2);
|
reset(mListener2);
|
||||||
|
|
||||||
pc.clearOverrides(PACKAGE_NAME);
|
mPlatformCompat.clearOverrides(PACKAGE_NAME);
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
verify(mListener2, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener2, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnClearOverrideExists() throws Exception {
|
public void testListenerCalledOnClearOverrideExists() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
|
mPlatformCompat.registerListener(2, mListener2);
|
||||||
|
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.setOverrides(
|
||||||
pc.registerListener(2, mListener2);
|
CompatibilityChangeConfigBuilder.create().enable(1L).build(),
|
||||||
|
|
||||||
pc.setOverrides(
|
|
||||||
new CompatibilityChangeConfig(
|
|
||||||
new Compatibility.ChangeConfig(ImmutableSet.of(1L), ImmutableSet.of())),
|
|
||||||
PACKAGE_NAME);
|
PACKAGE_NAME);
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
||||||
@@ -260,21 +226,17 @@ public class PlatformCompatTest {
|
|||||||
reset(mListener1);
|
reset(mListener1);
|
||||||
reset(mListener2);
|
reset(mListener2);
|
||||||
|
|
||||||
pc.clearOverride(1, PACKAGE_NAME);
|
mPlatformCompat.clearOverride(1, PACKAGE_NAME);
|
||||||
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, times(1)).onCompatChange(PACKAGE_NAME);
|
||||||
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
verify(mListener2, never()).onCompatChange(PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerCalledOnClearOverrideDoesntExist() throws Exception {
|
public void testListenerCalledOnClearOverrideDoesntExist() throws Exception {
|
||||||
PlatformCompat pc = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat.registerListener(1, mListener1);
|
||||||
|
|
||||||
pc.registerListener(1, mListener1);
|
mPlatformCompat.clearOverride(1, PACKAGE_NAME);
|
||||||
|
|
||||||
pc.clearOverride(1, PACKAGE_NAME);
|
|
||||||
// Listener not called when a non existing override is removed.
|
// Listener not called when a non existing override is removed.
|
||||||
verify(mListener1, never()).onCompatChange(PACKAGE_NAME);
|
verify(mListener1, never()).onCompatChange(PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user