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

Commit 345b1d53 authored by Mathew Inwood's avatar Mathew Inwood
Browse files

Always apply compat changes to system apps.

System apps should always get the "latest" behaviour from the platform
since they are updated with the platform.

Bug: 135010838
Test: atest CompatConfigTest
Change-Id: Ieacac20dc0eb02e4687dfe0b7b4800b3fce3db83
parent 929cb5fc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -106,6 +106,12 @@ public final class CompatChange {
     * @return {@code true} if the change should be enabled for the package.
     */
    boolean isEnabled(ApplicationInfo app) {
        if (app.isSystemApp()) {
            // All changes are enabled for system apps, and we do not support overrides.
            // Compatibility issues for system apps should be addressed in the app itself when
            // the compatibility change is made.
            return true;
        }
        if (mPackageOverrides != null && mPackageOverrides.containsKey(app.packageName)) {
            return mPackageOverrides.get(app.packageName);
        }
+28 −0
Original line number Diff line number Diff line
@@ -142,4 +142,32 @@ public class CompatConfigTest {
        CompatConfig pc = new CompatConfig();
        assertThat(pc.lookupChangeId("MY_CHANGE")).isEqualTo(-1L);
    }

    @Test
    public void testSystemAppDisabledChangeEnabled() {
        CompatConfig pc = new CompatConfig();
        pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true)); // disabled
        ApplicationInfo sysApp = makeAppInfo("system.app", 1);
        sysApp.flags |= ApplicationInfo.FLAG_SYSTEM;
        assertThat(pc.isChangeEnabled(1234L, sysApp)).isTrue();
    }

    @Test
    public void testSystemAppOverrideIgnored() {
        CompatConfig pc = new CompatConfig();
        pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false));
        pc.addOverride(1234L, "system.app", false);
        ApplicationInfo sysApp = makeAppInfo("system.app", 1);
        sysApp.flags |= ApplicationInfo.FLAG_SYSTEM;
        assertThat(pc.isChangeEnabled(1234L, sysApp)).isTrue();
    }

    @Test
    public void testSystemAppTargetSdkIgnored() {
        CompatConfig pc = new CompatConfig();
        pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, false));
        ApplicationInfo sysApp = makeAppInfo("system.app", 1);
        sysApp.flags |= ApplicationInfo.FLAG_SYSTEM;
        assertThat(pc.isChangeEnabled(1234L, sysApp)).isTrue();
    }
}