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

Commit 5c8ba793 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Query overlays using package and name

Fabricated RROs identifiers are made using package name and overlay name
combinations. In the future, packages with multiple <overlay> tags will
use overlay name to distinguish between the tags.

This changes the OMS to manage overlays through OverlayIdentifiers.
The identifier is a overlay package and name combination. The name field
is optional so overlays without an overlay name can be managed.

This change simplifies the logic required to update the set of target
packages affected by overlay changes.

Bug: 172471315
Test: OverlayDeviceTests
Test: OverlayImpl tests
Change-Id: Iac679828d7480e5c7a2c1fe4ea8b73401d8d487f
parent a1baf11e
Loading
Loading
Loading
Loading
+60 −0
Original line number 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 android.content.om;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;

/**
 * A subset of {@link OverlayInfo} fields that when changed cause the overlay's settings to be
 * completely reinitialized.
 *
 * @hide
 */
public interface CriticalOverlayInfo {

    /**
     * @return the package name of the overlay.
     */
    @NonNull
    String getPackageName();

    /**
     * @return the unique name of the overlay within its containing package.
     */
    @Nullable
    String getOverlayName();

    /**
     * @return the target package name of the overlay.
     */
    @NonNull
    String getTargetPackageName();

    /**
     * @return the name of the target overlayable declaration.
     */
    @Nullable
    String getTargetOverlayableName();

    /**
     * @return an identifier representing the current overlay.
     */
    @NonNull
    OverlayIdentifier getOverlayIdentifier();
}
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content.om;

import android.content.om.OverlayIdentifier;
import android.content.om.OverlayInfo;
import android.content.om.OverlayManagerTransaction;

@@ -65,6 +66,17 @@ interface IOverlayManager {
    @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
    OverlayInfo getOverlayInfo(in String packageName, in int userId);

    /**
     * Returns information about the overlay with the given package name for the
     * specified user.
     *
     * @param packageName The name of the overlay package.
     * @param userId The user to get the OverlayInfo for.
     * @return The OverlayInfo for the overlay package; or null if no such
     *         overlay package exists.
     */
    OverlayInfo getOverlayInfoByIdentifier(in OverlayIdentifier packageName, in int userId);

    /**
     * Request that an overlay package be enabled or disabled when possible to
     * do so.
+19 −0
Original line number 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 android.content.om;

parcelable OverlayIdentifier;
+208 −0
Original line number 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 android.content.om;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.DataClass;

import java.util.Objects;

/**
 * A key used to uniquely identify a Runtime Resource Overlay (RRO).
 *
 * An overlay always belongs to a package and may optionally have a name associated with it.
 * The name helps uniquely identify a particular overlay within a package.
 * @hide
 */
/** @hide */
@DataClass(genConstructor = false, genBuilder = false, genHiddenBuilder = false,
        genEqualsHashCode = true, genToString = false)
public class OverlayIdentifier implements Parcelable  {
    /**
     * The package name containing or owning the overlay.
     */
    @Nullable
    private final String mPackageName;

    /**
     * The unique name within the package of the overlay.
     */
    @Nullable
    private final String mOverlayName;

    /**
     * Creates an identifier from a package and unique name within the package.
     *
     * @param packageName the package containing or owning the overlay
     * @param overlayName the unique name of the overlay within the package
     */
    public OverlayIdentifier(@NonNull String packageName, @Nullable String overlayName) {
        mPackageName = packageName;
        mOverlayName = overlayName;
    }

    /**
     * Creates an identifier for an overlay without a name.
     *
     * @param packageName the package containing or owning the overlay
     */
    public OverlayIdentifier(@NonNull String packageName) {
        mPackageName = packageName;
        mOverlayName = null;
    }

    @Override
    public String toString() {
        return mOverlayName == null ? mPackageName : mPackageName + ":" + mOverlayName;
    }

    /** @hide */
    public static OverlayIdentifier fromString(@NonNull String text) {
        final String[] parts = text.split(":", 2);
        if (parts.length == 2) {
            return new OverlayIdentifier(parts[0], parts[1]);
        } else {
            return new OverlayIdentifier(parts[0]);
        }
    }



    // Code below generated by codegen v1.0.22.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/om/OverlayIdentifier.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    /**
     * Retrieves the package name containing or owning the overlay.
     */
    @DataClass.Generated.Member
    public @Nullable String getPackageName() {
        return mPackageName;
    }

    /**
     * Retrieves the unique name within the package of the overlay.
     */
    @DataClass.Generated.Member
    public @Nullable String getOverlayName() {
        return mOverlayName;
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@Nullable Object o) {
        // You can override field equality logic by defining either of the methods like:
        // boolean fieldNameEquals(OverlayIdentifier other) { ... }
        // boolean fieldNameEquals(FieldType otherValue) { ... }

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        @SuppressWarnings("unchecked")
        OverlayIdentifier that = (OverlayIdentifier) o;
        //noinspection PointlessBooleanExpression
        return true
                && Objects.equals(mPackageName, that.mPackageName)
                && Objects.equals(mOverlayName, that.mOverlayName);
    }

    @Override
    @DataClass.Generated.Member
    public int hashCode() {
        // You can override field hashCode logic by defining methods like:
        // int fieldNameHashCode() { ... }

        int _hash = 1;
        _hash = 31 * _hash + Objects.hashCode(mPackageName);
        _hash = 31 * _hash + Objects.hashCode(mOverlayName);
        return _hash;
    }

    @Override
    @DataClass.Generated.Member
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }

        byte flg = 0;
        if (mPackageName != null) flg |= 0x1;
        if (mOverlayName != null) flg |= 0x2;
        dest.writeByte(flg);
        if (mPackageName != null) dest.writeString(mPackageName);
        if (mOverlayName != null) dest.writeString(mOverlayName);
    }

    @Override
    @DataClass.Generated.Member
    public int describeContents() { return 0; }

    /** @hide */
    @SuppressWarnings({"unchecked", "RedundantCast"})
    @DataClass.Generated.Member
    protected OverlayIdentifier(@NonNull Parcel in) {
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }

        byte flg = in.readByte();
        String packageName = (flg & 0x1) == 0 ? null : in.readString();
        String overlayName = (flg & 0x2) == 0 ? null : in.readString();

        this.mPackageName = packageName;
        this.mOverlayName = overlayName;

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public static final @NonNull Parcelable.Creator<OverlayIdentifier> CREATOR
            = new Parcelable.Creator<OverlayIdentifier>() {
        @Override
        public OverlayIdentifier[] newArray(int size) {
            return new OverlayIdentifier[size];
        }

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

    @DataClass.Generated(
            time = 1612482438728L,
            codegenVersion = "1.0.22",
            sourceFile = "frameworks/base/core/java/android/content/om/OverlayIdentifier.java",
            inputSignatures = "private final @android.annotation.Nullable java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mOverlayName\npublic @java.lang.Override java.lang.String toString()\npublic static  android.content.om.OverlayIdentifier fromString(java.lang.String)\nclass OverlayIdentifier extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=false, genHiddenBuilder=false, genEqualsHashCode=true, genToString=false)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}
+73 −13
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.annotations.VisibleForTesting;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
@@ -37,7 +39,7 @@ import java.util.Objects;
 * @hide
 */
@SystemApi
public final class OverlayInfo implements Parcelable {
public final class OverlayInfo implements CriticalOverlayInfo, Parcelable {

    /** @hide */
    @IntDef(prefix = "STATE_", value = {
@@ -142,6 +144,14 @@ public final class OverlayInfo implements Parcelable {
    @NonNull
    public final String packageName;

    /**
     * The unique name within the package of the overlay.
     *
     * @hide
     */
    @Nullable
    public final String overlayName;

    /**
     * Package name of the target package
     *
@@ -201,6 +211,8 @@ public final class OverlayInfo implements Parcelable {
     */
    public final boolean isMutable;

    private OverlayIdentifier mIdentifierCached;

    /**
     * Create a new OverlayInfo based on source with an updated state.
     *
@@ -210,17 +222,27 @@ public final class OverlayInfo implements Parcelable {
     * @hide
     */
    public OverlayInfo(@NonNull OverlayInfo source, @State int state) {
        this(source.packageName, source.targetPackageName, source.targetOverlayableName,
                source.category, source.baseCodePath, state, source.userId, source.priority,
                source.isMutable);
        this(source.packageName, source.overlayName, source.targetPackageName,
                source.targetOverlayableName, source.category, source.baseCodePath, state,
                source.userId, source.priority, source.isMutable);
    }

    /** @hide */
    @VisibleForTesting
    public OverlayInfo(@NonNull String packageName, @NonNull String targetPackageName,
            @Nullable String targetOverlayableName, @Nullable String category,
            @NonNull String baseCodePath, int state, int userId,
            @NonNull String baseCodePath, int state, int userId, int priority, boolean isMutable) {
        this(packageName, null /* overlayName */, targetPackageName, targetOverlayableName,
                category, baseCodePath, state, userId, priority, isMutable);
    }

    /** @hide */
    public OverlayInfo(@NonNull String packageName, @Nullable String overlayName,
            @NonNull String targetPackageName, @Nullable String targetOverlayableName,
            @Nullable String category, @NonNull String baseCodePath, int state, int userId,
            int priority, boolean isMutable) {
        this.packageName = packageName;
        this.overlayName = overlayName;
        this.targetPackageName = targetPackageName;
        this.targetOverlayableName = targetOverlayableName;
        this.category = category;
@@ -235,6 +257,7 @@ public final class OverlayInfo implements Parcelable {
    /** @hide */
    public OverlayInfo(Parcel source) {
        packageName = source.readString();
        overlayName = source.readString();
        targetPackageName = source.readString();
        targetOverlayableName = source.readString();
        category = source.readString();
@@ -247,9 +270,10 @@ public final class OverlayInfo implements Parcelable {
    }

    /**
     * Returns package name of the current overlay.
     * {@inheritDoc}
     * @hide
     */
    @Override
    @SystemApi
    @NonNull
    public String getPackageName() {
@@ -257,9 +281,20 @@ public final class OverlayInfo implements Parcelable {
    }

    /**
     * Returns the target package name of the current overlay.
     * {@inheritDoc}
     * @hide
     */
    @Override
    @Nullable
    public String getOverlayName() {
        return overlayName;
    }

    /**
     * {@inheritDoc}
     * @hide
     */
    @Override
    @SystemApi
    @NonNull
    public String getTargetPackageName() {
@@ -268,7 +303,8 @@ public final class OverlayInfo implements Parcelable {

    /**
     * Returns the category of the current overlay.
     * @hide\
     *
     * @hide
     */
    @SystemApi
    @Nullable
@@ -278,6 +314,7 @@ public final class OverlayInfo implements Parcelable {

    /**
     * Returns user handle for which this overlay applies to.
     *
     * @hide
     */
    @SystemApi
@@ -287,15 +324,29 @@ public final class OverlayInfo implements Parcelable {
    }

    /**
     * Returns name of the target overlayable declaration.
     * {@inheritDoc}
     * @hide
     */
    @Override
    @SystemApi
    @Nullable
    public String getTargetOverlayableName() {
        return targetOverlayableName;
    }

    /**
     * {@inheritDoc}
     * @hide
     */
    @Override
    @NonNull
    public OverlayIdentifier getOverlayIdentifier() {
        if (mIdentifierCached == null) {
            mIdentifierCached = new OverlayIdentifier(packageName, overlayName);
        }
        return mIdentifierCached;
    }

    @SuppressWarnings("ConstantConditions")
    private void ensureValidState() {
        if (packageName == null) {
@@ -330,6 +381,7 @@ public final class OverlayInfo implements Parcelable {
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(packageName);
        dest.writeString(overlayName);
        dest.writeString(targetPackageName);
        dest.writeString(targetOverlayableName);
        dest.writeString(category);
@@ -410,6 +462,7 @@ public final class OverlayInfo implements Parcelable {
        result = prime * result + userId;
        result = prime * result + state;
        result = prime * result + ((packageName == null) ? 0 : packageName.hashCode());
        result = prime * result + ((overlayName == null) ? 0 : overlayName.hashCode());
        result = prime * result + ((targetPackageName == null) ? 0 : targetPackageName.hashCode());
        result = prime * result + ((targetOverlayableName == null) ? 0
                : targetOverlayableName.hashCode());
@@ -439,6 +492,9 @@ public final class OverlayInfo implements Parcelable {
        if (!packageName.equals(other.packageName)) {
            return false;
        }
        if (!Objects.equals(overlayName, other.overlayName)) {
            return false;
        }
        if (!targetPackageName.equals(other.targetPackageName)) {
            return false;
        }
@@ -457,9 +513,13 @@ public final class OverlayInfo implements Parcelable {
    @NonNull
    @Override
    public String toString() {
        return "OverlayInfo { overlay=" + packageName + ", targetPackage=" + targetPackageName
                + ((targetOverlayableName == null) ? ""
                : ", targetOverlayable=" + targetOverlayableName)
                + ", state=" + state + " (" + stateToString(state) + "), userId=" + userId + " }";
        return "OverlayInfo {"
                + "packageName=" + packageName
                + ", overlayName=" + overlayName
                + ", targetPackage=" + targetPackageName
                + ", targetOverlayable=" + targetOverlayableName
                + ", state=" + state + " (" + stateToString(state) + "),"
                + ", userId=" + userId
                + " }";
    }
}
Loading