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

Commit 18041f78 authored by Andrei Onea's avatar Andrei Onea
Browse files

Add apis for listing all compat changes

These apis are required for adding UI in the Developer options for
modifying compatibility change overrides.

Bug: 138280620
Test: atest CompatConfigTest
Change-Id: If55aa68f9bdd6bed0765324e972de3683bacb553
parent 1b908876
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -49,6 +49,18 @@ public final class CompatibilityChangeConfig implements Parcelable {
        return mChangeConfig.forceDisabledSet();
    }

    /**
     * Returns if a change is enabled or disabled in this config.
     */
    public boolean isChangeEnabled(long changeId) {
        if (mChangeConfig.isForceEnabled(changeId)) {
            return true;
        } else if (mChangeConfig.isForceDisabled(changeId)) {
            return false;
        }
        throw new IllegalStateException("Change " + changeId + " is not defined.");
    }

    private CompatibilityChangeConfig(Parcel in) {
        long[] enabledArray = in.createLongArray();
        long[] disabledArray = in.createLongArray();
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 CompatibilityChangeInfo;
+92 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * This class is a parcelable version of {@link com.android.server.compat.Change}.
 *
 * @hide
 */
public class CompatibilityChangeInfo implements Parcelable {
    private final long mChangeId;
    private final @Nullable String mName;
    private final int mEnableAfterTargetSdk;
    private final boolean mDisabled;

    public long getId() {
        return mChangeId;
    }

    @Nullable
    public String getName() {
        return mName;
    }

    public int getEnableAfterTargetSdk() {
        return mEnableAfterTargetSdk;
    }

    public boolean getDisabled() {
        return mDisabled;
    }

    public CompatibilityChangeInfo(
            Long changeId, String name, int enableAfterTargetSdk, boolean disabled) {
        this.mChangeId = changeId;
        this.mName = name;
        this.mEnableAfterTargetSdk = enableAfterTargetSdk;
        this.mDisabled = disabled;
    }

    private CompatibilityChangeInfo(Parcel in) {
        mChangeId = in.readLong();
        mName = in.readString();
        mEnableAfterTargetSdk = in.readInt();
        mDisabled = in.readBoolean();
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mChangeId);
        dest.writeString(mName);
        dest.writeInt(mEnableAfterTargetSdk);
        dest.writeBoolean(mDisabled);
    }

    public static final Parcelable.Creator<CompatibilityChangeInfo> CREATOR =
            new Parcelable.Creator<CompatibilityChangeInfo>() {

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

                @Override
                public CompatibilityChangeInfo[] newArray(int size) {
                    return new CompatibilityChangeInfo[size];
                }
            };
}
+19 −0
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.internal.compat;

import android.content.pm.ApplicationInfo;
import java.util.Map;

parcelable CompatibilityChangeConfig;
parcelable CompatibilityChangeInfo;

/**
 * Platform private API for talking with the PlatformCompat service.
@@ -146,4 +148,21 @@ interface IPlatformCompat
     *
     */
    void clearOverrides(in String packageName);

    /**
     * Get configs for an application.
     *
     * @param appInfo The application whose config will be returned.
     *
     * @return A {@link CompatibilityChangeConfig}, representing whether a change is enabled for
     *         the given app or not.
     */
    CompatibilityChangeConfig getAppConfig(in ApplicationInfo appInfo);

    /**
     * List all compatibility changes.
     *
     * @return An array of {@link CompatChangeInfo} known to the service.
     */
    CompatibilityChangeInfo[] listAllChanges();
}
+14 −31
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.compat.annotation.EnabledAfter;
import android.content.pm.ApplicationInfo;

import com.android.internal.compat.CompatibilityChangeInfo;
import com.android.server.compat.config.Change;

import java.util.HashMap;
@@ -35,12 +36,8 @@ import java.util.Map;
 *
 * <p>Note, this class is not thread safe so callers must ensure thread safety.
 */
public final class CompatChange {
public final class CompatChange extends CompatibilityChangeInfo {

    private final long mChangeId;
    @Nullable private final String mName;
    private final int mEnableAfterTargetSdk;
    private final boolean mDisabled;
    private Map<String, Boolean> mPackageOverrides;

    public CompatChange(long changeId) {
@@ -56,29 +53,15 @@ public final class CompatChange {
     */
    public CompatChange(long changeId, @Nullable String name, int enableAfterTargetSdk,
            boolean disabled) {
        mChangeId = changeId;
        mName = name;
        mEnableAfterTargetSdk = enableAfterTargetSdk;
        mDisabled = disabled;
        super(changeId, name, enableAfterTargetSdk, disabled);
    }

    /**
     * @param change an object generated by services/core/xsd/platform-compat-config.xsd
     */
    public CompatChange(Change change) {
        mChangeId = change.getId();
        mName = change.getName();
        mEnableAfterTargetSdk = change.getEnableAfterTargetSdk();
        mDisabled = change.getDisabled();
    }

    long getId() {
        return mChangeId;
    }

    @Nullable
    String getName() {
        return mName;
        super(change.getId(), change.getName(), change.getEnableAfterTargetSdk(),
                change.getDisabled());
    }

    /**
@@ -121,11 +104,11 @@ public final class CompatChange {
        if (mPackageOverrides != null && mPackageOverrides.containsKey(app.packageName)) {
            return mPackageOverrides.get(app.packageName);
        }
        if (mDisabled) {
        if (getDisabled()) {
            return false;
        }
        if (mEnableAfterTargetSdk != -1) {
            return app.targetSdkVersion > mEnableAfterTargetSdk;
        if (getEnableAfterTargetSdk() != -1) {
            return app.targetSdkVersion > getEnableAfterTargetSdk();
        }
        return true;
    }
@@ -133,14 +116,14 @@ public final class CompatChange {
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("ChangeId(")
                .append(mChangeId);
        if (mName != null) {
            sb.append("; name=").append(mName);
                .append(getId());
        if (getName() != null) {
            sb.append("; name=").append(getName());
        }
        if (mEnableAfterTargetSdk != -1) {
            sb.append("; enableAfterTargetSdk=").append(mEnableAfterTargetSdk);
        if (getEnableAfterTargetSdk() != -1) {
            sb.append("; enableAfterTargetSdk=").append(getEnableAfterTargetSdk());
        }
        if (mDisabled) {
        if (getDisabled()) {
            sb.append("; disabled");
        }
        if (mPackageOverrides != null && mPackageOverrides.size() > 0) {
Loading