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

Commit 495c8e53 authored by Tom Natan's avatar Tom Natan Committed by Automerger Merge Worker
Browse files

Merge "Add an API method for clearing compat overrides on release builds" am:...

Merge "Add an API method for clearing compat overrides on release builds" am: b9680bac am: 9e9e1c4a am: 65654644 am: 43bf4624

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

Change-Id: Ibbe1593b751e63a8e9554cef813fe3354378cec2
parents ecf5b945 43bf4624
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -1242,10 +1242,11 @@ package android.app.backup {
package android.app.compat {
package android.app.compat {
  public final class CompatChanges {
  public final class CompatChanges {
    method @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public static void addPackageOverrides(@NonNull String, @NonNull java.util.Map<java.lang.Long,android.app.compat.PackageOverride>);
    method public static boolean isChangeEnabled(long);
    method public static boolean isChangeEnabled(long);
    method @RequiresPermission(allOf={"android.permission.READ_COMPAT_CHANGE_CONFIG", "android.permission.LOG_COMPAT_CHANGE"}) public static boolean isChangeEnabled(long, @NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission(allOf={"android.permission.READ_COMPAT_CHANGE_CONFIG", "android.permission.LOG_COMPAT_CHANGE"}) public static boolean isChangeEnabled(long, @NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission(allOf={"android.permission.READ_COMPAT_CHANGE_CONFIG", "android.permission.LOG_COMPAT_CHANGE"}) public static boolean isChangeEnabled(long, int);
    method @RequiresPermission(allOf={"android.permission.READ_COMPAT_CHANGE_CONFIG", "android.permission.LOG_COMPAT_CHANGE"}) public static boolean isChangeEnabled(long, int);
    method @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public static void setPackageOverride(@NonNull String, @NonNull java.util.Map<java.lang.Long,android.app.compat.PackageOverride>);
    method @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public static void removePackageOverrides(@NonNull String, @NonNull java.util.Set<java.lang.Long>);
  }
  }
  public final class PackageOverride {
  public final class PackageOverride {
+34 −3
Original line number Original line Diff line number Diff line
@@ -26,9 +26,11 @@ import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserHandle;


import com.android.internal.compat.CompatibilityOverrideConfig;
import com.android.internal.compat.CompatibilityOverrideConfig;
import com.android.internal.compat.CompatibilityOverridesToRemoveConfig;
import com.android.internal.compat.IPlatformCompat;
import com.android.internal.compat.IPlatformCompat;


import java.util.Map;
import java.util.Map;
import java.util.Set;


/**
/**
 * CompatChanges APIs - to be used by platform code only (including mainline
 * CompatChanges APIs - to be used by platform code only (including mainline
@@ -98,15 +100,19 @@ public final class CompatChanges {
    }
    }


    /**
    /**
     * Set an app compat override for a given package. This will check whether the caller is allowed
     * Adds app compat overrides for a given package. This will check whether the caller is allowed
     * to perform this operation on the given apk and build. Only the installer package is allowed
     * to perform this operation on the given apk and build. Only the installer package is allowed
     * to set overrides on a non-debuggable final build and a non-test apk.
     * to set overrides on a non-debuggable final build and a non-test apk.
     *
     *
     * <p>Note that calling this method doesn't remove previously added overrides for the given
     * package if their change ID isn't in the given map, only replaces those that have the same
     * change ID.
     *
     * @param packageName The package name of the app in question.
     * @param packageName The package name of the app in question.
     * @param overrides A map from changeId to the override applied for this change id.
     * @param overrides A map from change ID to the override applied for this change ID.
     */
     */
    @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD)
    @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD)
    public static void setPackageOverride(@NonNull String packageName,
    public static void addPackageOverrides(@NonNull String packageName,
            @NonNull Map<Long, PackageOverride> overrides) {
            @NonNull Map<Long, PackageOverride> overrides) {
        IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface(
        IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface(
                ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
                ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
@@ -117,4 +123,29 @@ public final class CompatChanges {
            e.rethrowFromSystemServer();
            e.rethrowFromSystemServer();
        }
        }
    }
    }

    /**
     * Removes app compat overrides for a given package. This will check whether the caller is
     * allowed to perform this operation on the given apk and build. Only the installer package is
     * allowed to clear overrides on a non-debuggable final build and a non-test apk.
     *
     * <p>Note that calling this method with an empty set is a no-op and no overrides will be
     * removed for the given package.
     *
     * @param packageName The package name of the app in question.
     * @param overridesToRemove A set of change IDs for which to remove overrides.
     */
    @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD)
    public static void removePackageOverrides(@NonNull String packageName,
            @NonNull Set<Long> overridesToRemove) {
        IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface(
                ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
        CompatibilityOverridesToRemoveConfig config = new CompatibilityOverridesToRemoveConfig(
                overridesToRemove);
        try {
            platformCompat.removeOverridesOnReleaseBuilds(config, packageName);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }
}
}
+19 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.compat;

parcelable CompatibilityOverridesToRemoveConfig;
+72 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.compat;


import android.os.Parcel;
import android.os.Parcelable;

import java.util.HashSet;
import java.util.Set;

/**
 * Parcelable containing compat config change IDs for which to remove overrides for a given
 * application.
 * @hide
 */
public final class CompatibilityOverridesToRemoveConfig implements Parcelable {
    public final Set<Long> changeIds;

    public CompatibilityOverridesToRemoveConfig(Set<Long> changeIds) {
        this.changeIds = changeIds;
    }

    private CompatibilityOverridesToRemoveConfig(Parcel in) {
        int keyCount = in.readInt();
        changeIds = new HashSet<>();
        for (int i = 0; i < keyCount; i++) {
            changeIds.add(in.readLong());
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(changeIds.size());
        for (Long changeId : changeIds) {
            dest.writeLong(changeId);
        }
    }

    public static final Creator<CompatibilityOverridesToRemoveConfig> CREATOR =
            new Creator<CompatibilityOverridesToRemoveConfig>() {

                @Override
                public CompatibilityOverridesToRemoveConfig createFromParcel(Parcel in) {
                    return new CompatibilityOverridesToRemoveConfig(in);
                }

                @Override
                public CompatibilityOverridesToRemoveConfig[] newArray(int size) {
                    return new CompatibilityOverridesToRemoveConfig[size];
                }
            };
}
+22 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import java.util.Map;


parcelable CompatibilityChangeConfig;
parcelable CompatibilityChangeConfig;
parcelable CompatibilityOverrideConfig;
parcelable CompatibilityOverrideConfig;
parcelable CompatibilityOverridesToRemoveConfig;
parcelable CompatibilityChangeInfo;
parcelable CompatibilityChangeInfo;
/**
/**
 * Platform private API for talking with the PlatformCompat service.
 * Platform private API for talking with the PlatformCompat service.
@@ -204,6 +205,27 @@ interface IPlatformCompat {
     */
     */
    boolean clearOverrideForTest(long changeId, String packageName);
    boolean clearOverrideForTest(long changeId, String packageName);


    /**
     * Restores the default behaviour for compatibility changes on release builds.
     *
     * <p>The caller to this API needs to hold
     * {@code android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD} and all change ids
     * in {@code overridesToRemove} need to annotated with
     * {@link android.compat.annotation.Overridable}.
     *
     * A release build in this definition means that {@link android.os.Build#IS_DEBUGGABLE} needs to
     * be {@code false}.
     *
     * <p>Note that this does not kill the app, and therefore overrides read from the app process
     * will not be updated. Overrides read from the system process do take effect.
     *
     * @param overridesToRemove   parcelable containing the compat change overrides to be removed
     * @param packageName         the package name of the app whose changes will be restored to the
     *                            default behaviour
     * @throws SecurityException if overriding changes is not permitted
     */
    void removeOverridesOnReleaseBuilds(in CompatibilityOverridesToRemoveConfig overridesToRemove, in String packageName);

    /**
    /**
     * Enables all compatibility changes that have enabledSinceTargetSdk ==
     * Enables all compatibility changes that have enabledSinceTargetSdk ==
     * {@param targetSdkVersion} for an app, subject to the policy.
     * {@param targetSdkVersion} for an app, subject to the policy.
Loading