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

Commit 86d1a3ec authored by Anna Trostanetski's avatar Anna Trostanetski Committed by Gerrit Code Review
Browse files

Merge "Don't check OverrideAllowedState"

parents c118981c 2faac55a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -151,6 +151,15 @@ public final class CompatChange extends CompatibilityChangeInfo {
        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
    public String toString() {
        StringBuilder sb = new StringBuilder("ChangeId(")
+15 −11
Original line number Diff line number Diff line
@@ -242,12 +242,14 @@ final class CompatConfig {
            CompatChange c = mChanges.get(changeId);
            try {
                if (c != null) {
                    overrideExists = c.hasOverride(packageName);
                    if (overrideExists) {
                        OverrideAllowedState allowedState =
                                mOverrideValidator.getOverrideAllowedState(changeId, packageName);
                        allowedState.enforce(changeId, packageName);
                    overrideExists = true;
                        c.removePackageOverride(packageName);
                    }
                }
            } catch (RemoteException e) {
                // Should never occur, since validator is in the same process.
                throw new RuntimeException("Unable to call override validator!", e);
@@ -291,6 +293,7 @@ final class CompatConfig {
            for (int i = 0; i < mChanges.size(); ++i) {
                try {
                    CompatChange change = mChanges.valueAt(i);
                    if (change.hasOverride(packageName)) {
                        OverrideAllowedState allowedState =
                                mOverrideValidator.getOverrideAllowedState(change.getId(),
                                        packageName);
@@ -298,6 +301,7 @@ final class CompatConfig {
                        if (change != null) {
                            mChanges.valueAt(i).removePackageOverride(packageName);
                        }
                    }
                } catch (RemoteException e) {
                    // Should never occur, since validator is in the same process.
                    throw new RuntimeException("Unable to call override validator!", e);
+22 −0
Original line number Diff line number Diff line
@@ -248,6 +248,28 @@ public class CompatConfigTest {
        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
    public void testRemovePackageOverride() throws Exception {
        CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)