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

Commit 17f8ae5f authored by Andrei-Valentin Onea's avatar Andrei-Valentin Onea Committed by Gerrit Code Review
Browse files

Merge changes from topic "default-value-query"

* changes:
  Assume default values when querying compat fw
  Add non-logging method to PlatformCompat
parents 96db3dad 35f8e5e7
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) {
+16 −11
Original line number Diff line number Diff line
@@ -107,17 +107,25 @@ public class PlatformCompat extends IPlatformCompat.Stub {
    }

    /**
     * Internal version of the above method. Does not perform costly permission check.
     * Internal version of the above method, without logging. Does not perform costly permission
     * check.
     * TODO(b/167551701): Remove this method and add 'loggability' as a changeid property.
     */
    public boolean isChangeEnabledInternalNoLogging(long changeId, ApplicationInfo appInfo) {
        return mCompatConfig.isChangeEnabled(changeId, appInfo);
    }

    /**
     * Internal version of {@link #isChangeEnabled(long, ApplicationInfo)}. Does not perform costly
     * permission check.
     */
    public boolean isChangeEnabledInternal(long changeId, ApplicationInfo appInfo) {
        if (mCompatConfig.isChangeEnabled(changeId, appInfo)) {
        boolean enabled = isChangeEnabledInternalNoLogging(changeId, appInfo);
        if (appInfo != null) {
            reportChange(changeId, appInfo.uid,
                    ChangeReporter.STATE_ENABLED);
            return true;
                    enabled ? ChangeReporter.STATE_ENABLED : ChangeReporter.STATE_DISABLED);
        }
        reportChange(changeId, appInfo.uid,
                ChangeReporter.STATE_DISABLED);
        return false;
        return enabled;
    }

    @Override
@@ -125,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);
    }

@@ -136,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) {
+2 −1
Original line number Diff line number Diff line
@@ -290,7 +290,8 @@ public class AppsFilter {

        private void updateEnabledState(@NonNull AndroidPackage pkg) {
            // TODO(b/135203078): Do not use toAppInfo
            final boolean enabled = mInjector.getCompatibility().isChangeEnabledInternal(
            // TODO(b/167551701): Make changeId non-logging
            final boolean enabled = mInjector.getCompatibility().isChangeEnabledInternalNoLogging(
                    PackageManager.FILTER_APPLICATION_QUERY, pkg.toAppInfoWithoutState());
            if (enabled) {
                mDisabledPackages.remove(pkg.getPackageName());
+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;