Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9968908 authored by atrost's avatar atrost
Browse files

Don't check OverrideAllowedState

Don't check OverrideAllowedState when calling remove overrides and there
are no overrides.
This fixes failure in CompatChangesTest (tried to clear non existing
overrides for a logging only change).
Also fixed return value of removeOverride to return the correct thing.

Test: atest  com.android.server.compat.CompatConfigTest
Test: atest  android.app.compat.CompatChangesTest
Bug: 151421544
Change-Id: I9c63f332337bc465115556fbc6f0b40fb7e102da
parent 8fa645a2
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -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(")
+15 −11
Original line number Original line Diff line number Diff line
@@ -247,12 +247,14 @@ final class CompatConfig {
            CompatChange c = mChanges.get(changeId);
            CompatChange c = mChanges.get(changeId);
            try {
            try {
                if (c != null) {
                if (c != null) {
                    overrideExists = c.hasOverride(packageName);
                    if (overrideExists) {
                        OverrideAllowedState allowedState =
                        OverrideAllowedState allowedState =
                                mOverrideValidator.getOverrideAllowedState(changeId, packageName);
                                mOverrideValidator.getOverrideAllowedState(changeId, packageName);
                        allowedState.enforce(changeId, packageName);
                        allowedState.enforce(changeId, packageName);
                    overrideExists = true;
                        c.removePackageOverride(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.
                throw new RuntimeException("Unable to call override validator!", e);
                throw new RuntimeException("Unable to call override validator!", e);
@@ -298,6 +300,7 @@ 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);
                    if (change.hasOverride(packageName)) {
                        OverrideAllowedState allowedState =
                        OverrideAllowedState allowedState =
                                mOverrideValidator.getOverrideAllowedState(change.getId(),
                                mOverrideValidator.getOverrideAllowedState(change.getId(),
                                        packageName);
                                        packageName);
@@ -305,6 +308,7 @@ final class CompatConfig {
                        if (change != null) {
                        if (change != null) {
                            mChanges.valueAt(i).removePackageOverride(packageName);
                            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.
                    throw new RuntimeException("Unable to call override validator!", e);
                    throw new RuntimeException("Unable to call override validator!", e);
+22 −0
Original line number Original line Diff line number Diff line
@@ -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)