Merge "Don't check OverrideAllowedState" into rvc-dev

This commit is contained in:
Anna Trostanetski
2020-03-13 19:47:30 +00:00
committed by Android (Google) Code Review
3 changed files with 46 additions and 11 deletions

View File

@@ -151,6 +151,15 @@ public final class CompatChange extends CompatibilityChangeInfo {
return true; return true;
} }
/**
* Checks whether a change has an override for a package.
* @param packageName name of the package
* @return true if there is such override
*/
boolean hasOverride(String packageName) {
return mPackageOverrides != null && mPackageOverrides.containsKey(packageName);
}
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("ChangeId(") StringBuilder sb = new StringBuilder("ChangeId(")

View File

@@ -247,11 +247,13 @@ final class CompatConfig {
CompatChange c = mChanges.get(changeId); CompatChange c = mChanges.get(changeId);
try { try {
if (c != null) { if (c != null) {
OverrideAllowedState allowedState = overrideExists = c.hasOverride(packageName);
mOverrideValidator.getOverrideAllowedState(changeId, packageName); if (overrideExists) {
allowedState.enforce(changeId, packageName); OverrideAllowedState allowedState =
overrideExists = true; mOverrideValidator.getOverrideAllowedState(changeId, packageName);
c.removePackageOverride(packageName); allowedState.enforce(changeId, packageName);
c.removePackageOverride(packageName);
}
} }
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never occur, since validator is in the same process. // Should never occur, since validator is in the same process.
@@ -298,12 +300,14 @@ final class CompatConfig {
for (int i = 0; i < mChanges.size(); ++i) { for (int i = 0; i < mChanges.size(); ++i) {
try { try {
CompatChange change = mChanges.valueAt(i); CompatChange change = mChanges.valueAt(i);
OverrideAllowedState allowedState = if (change.hasOverride(packageName)) {
mOverrideValidator.getOverrideAllowedState(change.getId(), OverrideAllowedState allowedState =
packageName); mOverrideValidator.getOverrideAllowedState(change.getId(),
allowedState.enforce(change.getId(), packageName); packageName);
if (change != null) { allowedState.enforce(change.getId(), packageName);
mChanges.valueAt(i).removePackageOverride(packageName); if (change != null) {
mChanges.valueAt(i).removePackageOverride(packageName);
}
} }
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never occur, since validator is in the same process. // Should never occur, since validator is in the same process.

View File

@@ -250,6 +250,28 @@ public class CompatConfigTest {
assertThat(compatConfig.isChangeEnabled(1234L, applicationInfo)).isTrue(); assertThat(compatConfig.isChangeEnabled(1234L, applicationInfo)).isTrue();
} }
@Test
public void testAllowRemoveOverrideNoOverride() throws Exception {
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
.addDisabledChangeWithId(1234L)
.addLoggingOnlyChangeWithId(2L)
.build();
ApplicationInfo applicationInfo = ApplicationInfoBuilder.create()
.withPackageName("com.some.package")
.build();
when(mPackageManager.getApplicationInfo(eq("com.some.package"), anyInt()))
.thenReturn(applicationInfo);
// 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 remove a non existing override, and it doesn't fail.
assertThat(compatConfig.removeOverride(1234L, "com.some.package")).isFalse();
assertThat(compatConfig.removeOverride(2L, "com.some.package")).isFalse();
compatConfig.removePackageOverrides("com.some.package");
}
@Test @Test
public void testRemovePackageOverride() throws Exception { public void testRemovePackageOverride() throws Exception {
CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext) CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)