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

Commit d11fe3b4 authored by felkachang's avatar felkachang
Browse files

Public self targeting API

Apps can maintains overlays by using these public APIs.
1. Create a FabricatedOverlay instance and set the overlay content.
2. Get a OverlayManager by calling context.getSystemService(...)
3. Create an OverlayManagerTransaction.
4. Register/unregister the overlays via the OverlayManagerTransaction
5. Commit the OverlayManagerTransaction.

Apps can use the registered overlay to overlay itself resources.
1. Get the overlay information by calling
    overlayManager.getOverlayInfosByTarget(...)
2. Create a ResourcesProvider by calling
    ResourcesProvider.loadOverlay(overlayInfo)
3. Create a ResourcesLoader to adding the ResourcesProvider in
    steps 2.
4. Overlay a Resources instance by calling
    Resources.addLoader(...)

This patch removes @hide to public the above APIs.

Bug: 205919743
CTS-Coverage-Bug: 262232910
API-Coverage-Bug: 262232910

Test: make update-api ; make
Test: make online-sdk-docs offline-sdk-docs
Test: atest \
        OverlayHostTests \
        OverlayDeviceTests \
        SelfTargetingOverlayDeviceTests \
        OverlayRemountedTest \
        FrameworksServicesTests:com.android.server.om \
        CtsContentTestCases:android.content.om.cts \
        CtsContentTestCases:android.content.res.loader.cts \
        idmap2_tests

Change-Id: I34fee52f55cd2ce63613dfb43e8ab235eca47772
parent eaa0ad10
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -10010,6 +10010,7 @@ package android.content {
    field public static final String NFC_SERVICE = "nfc";
    field public static final String NOTIFICATION_SERVICE = "notification";
    field public static final String NSD_SERVICE = "servicediscovery";
    field public static final String OVERLAY_SERVICE = "overlay";
    field public static final String PEOPLE_SERVICE = "people";
    field public static final String PERFORMANCE_HINT_SERVICE = "performance_hint";
    field public static final String POWER_SERVICE = "power";
@@ -11178,6 +11179,49 @@ package android.content {
}
package android.content.om {
  public class FabricatedOverlay {
    ctor public FabricatedOverlay(@NonNull String, @NonNull String);
    method @NonNull public android.content.om.OverlayIdentifier getIdentifier();
    method @NonNull public void setResourceValue(@NonNull String, @IntRange(from=android.util.TypedValue.TYPE_FIRST_INT, to=android.util.TypedValue.TYPE_LAST_INT) int, int, @Nullable String);
    method @NonNull public void setResourceValue(@NonNull String, int, @NonNull String, @Nullable String);
    method @NonNull public void setResourceValue(@NonNull String, @NonNull android.os.ParcelFileDescriptor, @Nullable String);
    method public void setTargetOverlayable(@Nullable String);
  }
  public final class OverlayIdentifier implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.om.OverlayIdentifier> CREATOR;
  }
  public final class OverlayInfo implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.content.om.OverlayIdentifier getOverlayIdentifier();
    method @Nullable public String getOverlayName();
    method @Nullable public String getTargetOverlayableName();
    method @NonNull public String getTargetPackageName();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.om.OverlayInfo> CREATOR;
  }
  public class OverlayManager {
    method @NonNull @NonUiContext public java.util.List<android.content.om.OverlayInfo> getOverlayInfosForTarget(@NonNull String);
  }
  public final class OverlayManagerTransaction implements android.os.Parcelable {
    ctor public OverlayManagerTransaction(@NonNull android.content.om.OverlayManager);
    method @NonUiContext public void commit() throws java.io.IOException, android.content.pm.PackageManager.NameNotFoundException;
    method public int describeContents();
    method @NonNull public void registerFabricatedOverlay(@NonNull android.content.om.FabricatedOverlay);
    method @NonNull public void unregisterFabricatedOverlay(@NonNull android.content.om.OverlayIdentifier);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.om.OverlayManagerTransaction> CREATOR;
  }
}
package android.content.pm {
  public class ActivityInfo extends android.content.pm.ComponentInfo implements android.os.Parcelable {
@@ -13082,6 +13126,7 @@ package android.content.res.loader {
    method @NonNull public static android.content.res.loader.ResourcesProvider loadFromDirectory(@NonNull String, @Nullable android.content.res.loader.AssetsProvider) throws java.io.IOException;
    method @NonNull public static android.content.res.loader.ResourcesProvider loadFromSplit(@NonNull android.content.Context, @NonNull String) throws java.io.IOException;
    method @NonNull public static android.content.res.loader.ResourcesProvider loadFromTable(@NonNull android.os.ParcelFileDescriptor, @Nullable android.content.res.loader.AssetsProvider) throws java.io.IOException;
    method @NonNull public static android.content.res.loader.ResourcesProvider loadOverlay(@NonNull android.content.om.OverlayInfo) throws java.io.IOException;
  }
}
+0 −5
Original line number Diff line number Diff line
@@ -3420,15 +3420,10 @@ package android.content.integrity {
package android.content.om {
  public final class OverlayInfo implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getCategory();
    method @NonNull public String getPackageName();
    method @Nullable public String getTargetOverlayableName();
    method @NonNull public String getTargetPackageName();
    method public int getUserId();
    method public boolean isEnabled();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.om.OverlayInfo> CREATOR;
  }
  public class OverlayManager {
+0 −1
Original line number Diff line number Diff line
@@ -5766,7 +5766,6 @@ public abstract class Context {
     *
     * @see #getSystemService(String)
     * @see android.content.om.OverlayManager
     * @hide
     */
    public static final String OVERLAY_SERVICE = "overlay";

+1 −8
Original line number Diff line number Diff line
@@ -78,16 +78,14 @@ import java.util.Objects;
 *
 * @see OverlayManager
 * @see OverlayManagerTransaction
 * @hide
 */
public class FabricatedOverlay {

    /**
     * Retrieves the identifier for this fabricated overlay.
     * @return the overlay identifier
     *
     * @hide
     */
    @NonNull
    public OverlayIdentifier getIdentifier() {
        return new OverlayIdentifier(
                mOverlay.packageName, TextUtils.nullIfEmpty(mOverlay.overlayName));
@@ -325,7 +323,6 @@ public class FabricatedOverlay {
     * @param overlayName a name used to uniquely identify the fabricated overlay owned by the
     *                   caller itself.
     * @param targetPackage the name of the package to be overlaid
     * @hide
     */
    public FabricatedOverlay(@NonNull String overlayName, @NonNull String targetPackage) {
        this(generateFabricatedOverlayInternal(
@@ -344,7 +341,6 @@ public class FabricatedOverlay {
     * should specify which overlayable to be overlaid.
     *
     * @param targetOverlayable the overlayable name defined in target package.
     * @hide
     */
    public void setTargetOverlayable(@Nullable String targetOverlayable) {
        mOverlay.targetOverlayable = TextUtils.emptyIfNull(targetOverlayable);
@@ -438,7 +434,6 @@ public class FabricatedOverlay {
     * @param value the integer representing the new value
     * @param configuration The string representation of the config this overlay is enabled for
     * @see android.util.TypedValue#TYPE_INT_COLOR_ARGB8 android.util.TypedValue#type
     * @hide
     */
    @NonNull
    public void setResourceValue(
@@ -470,7 +465,6 @@ public class FabricatedOverlay {
     * @param value the string representing the new value
     * @param configuration The string representation of the config this overlay is enabled for
     * @see android.util.TypedValue#TYPE_STRING android.util.TypedValue#type
     * @hide
     */
    @NonNull
    public void setResourceValue(
@@ -491,7 +485,6 @@ public class FabricatedOverlay {
     *     [package]:type/entry)
     * @param value the file descriptor whose contents are the value of the frro
     * @param configuration The string representation of the config this overlay is enabled for
     * @hide
     */
    @NonNull
    public void setResourceValue(
+0 −3
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import java.util.Objects;
 * @see OverlayInfo#getOverlayIdentifier()
 * @see OverlayManagerTransaction.Builder#unregisterFabricatedOverlay(OverlayIdentifier)
 */
/** @hide */
@DataClass(genConstructor = false, genBuilder = false, genHiddenBuilder = false,
        genEqualsHashCode = true, genToString = false)
public final class OverlayIdentifier implements Parcelable {
@@ -176,7 +175,6 @@ public final class OverlayIdentifier implements Parcelable {

    /**
     * {@inheritDoc}
     * @hide
     */
    @Override
    @DataClass.Generated.Member
@@ -194,7 +192,6 @@ public final class OverlayIdentifier implements Parcelable {

    /**
     * {@inheritDoc}
     * @hide
     */
    @Override
    @DataClass.Generated.Member
Loading