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

Commit fc716eb7 authored by Andrei-Valentin Onea's avatar Andrei-Valentin Onea Committed by Automerger Merge Worker
Browse files

Merge changes from topic "default-value-query" am: 17f8ae5f

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1529307

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I33f2c1591b2ae42c18aa55a4e2ef43acdb88bf91
parents f4fd7c70 17f8ae5f
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;