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

Commit 35f8e5e7 authored by Andrei Onea's avatar Andrei Onea
Browse files

Assume default values when querying compat fw

When querying the state of change ids for packages not yet installed,
assume the default value (i.e. false for default disabled changes, true
for anything else).

Test: atest CompatConfigTest
Bug: 175676478
Change-Id: I86169f683b72d1d13821a3197331b19aa5c8bf07
parent 5249ffc9
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -143,6 +143,9 @@ public final class CompatChange extends CompatibilityChangeInfo {
     * @return {@code true} if the change should be enabled for the package.
     */
    boolean isEnabled(ApplicationInfo app) {
        if (app == null) {
            return defaultValue();
        }
        if (mPackageOverrides != null && mPackageOverrides.containsKey(app.packageName)) {
            return mPackageOverrides.get(app.packageName);
        }
@@ -155,6 +158,15 @@ public final class CompatChange extends CompatibilityChangeInfo {
        return true;
    }

    /**
     * Returns the default value for the change id, assuming there are no overrides.
     *
     * @return {@code false} if it's a default disabled change, {@code true} otherwise.
     */
    boolean defaultValue() {
        return !getDisabled();
    }

    /**
     * Checks whether a change has an override for a package.
     * @param packageName name of the package
+8 −0
Original line number Diff line number Diff line
@@ -392,6 +392,14 @@ final class CompatConfig {
        return alreadyKnown;
    }

    boolean defaultChangeIdValue(long changeId) {
        CompatChange c = mChanges.get(changeId);
        if (c == null) {
            return true;
        }
        return c.defaultValue();
    }

    @VisibleForTesting
    void clearChanges() {
        synchronized (mChanges) {
+7 −8
Original line number Diff line number Diff line
@@ -120,10 +120,12 @@ public class PlatformCompat extends IPlatformCompat.Stub {
     * permission check.
     */
    public boolean isChangeEnabledInternal(long changeId, ApplicationInfo appInfo) {
        boolean value = isChangeEnabledInternalNoLogging(changeId, appInfo);
        boolean enabled = isChangeEnabledInternalNoLogging(changeId, appInfo);
        if (appInfo != null) {
            reportChange(changeId, appInfo.uid,
                value ? ChangeReporter.STATE_ENABLED : ChangeReporter.STATE_DISABLED);
        return value;
                    enabled ? ChangeReporter.STATE_ENABLED : ChangeReporter.STATE_DISABLED);
        }
        return enabled;
    }

    @Override
@@ -131,9 +133,6 @@ public class PlatformCompat extends IPlatformCompat.Stub {
            @UserIdInt int userId) {
        checkCompatChangeReadAndLogPermission();
        ApplicationInfo appInfo = getApplicationInfo(packageName, userId);
        if (appInfo == null) {
            return true;
        }
        return isChangeEnabled(changeId, appInfo);
    }

@@ -142,7 +141,7 @@ public class PlatformCompat extends IPlatformCompat.Stub {
        checkCompatChangeReadAndLogPermission();
        String[] packages = mContext.getPackageManager().getPackagesForUid(uid);
        if (packages == null || packages.length == 0) {
            return true;
            return mCompatConfig.defaultChangeIdValue(changeId);
        }
        boolean enabled = true;
        for (String packageName : packages) {
+16 −0
Original line number Diff line number Diff line
@@ -189,6 +189,22 @@ public class CompatConfigTest {
                .withPackageName("com.other.package").build())).isTrue();
    }

    @Test
    public void testIsChangeEnabledForInvalidApp() throws Exception {
        final long disabledChangeId = 1234L;
        final long enabledChangeId = 1235L;
        final long targetSdkChangeId = 1236L;
        CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
                .addEnabledChangeWithId(enabledChangeId)
                .addDisabledChangeWithId(disabledChangeId)
                .addEnableSinceSdkChangeWithId(42, targetSdkChangeId)
                .build();

        assertThat(compatConfig.isChangeEnabled(enabledChangeId, null)).isTrue();
        assertThat(compatConfig.isChangeEnabled(disabledChangeId, null)).isFalse();
        assertThat(compatConfig.isChangeEnabled(targetSdkChangeId, null)).isTrue();
    }

    @Test
    public void testPreventAddOverride() throws Exception {
        final long changeId = 1234L;