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

Commit 013400fa authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

`PackageManager` info objects under Ravenwood.

Many tests across the OS are already writing tests where they "mock"
their own responses from `PackageManager`, primarily by filling in
the "info" objects that it returns.

Since these are simple data structures that primarily hold static
data, let's opt-in under Ravenwood, so that other tests can
construct for their own internal uses.  Complex dynamic operations,
such as loading drawables, remain opted-out.

This change brings along relevant CTS, but ignores several tests that
currently depend on a fully-running PackageManager service.  To
ensure we have solid coverage, new `testSimple` is added.

Bug: 292141694
Test: atest CtsContentTestCasesRavenwood
Change-Id: Ie9682184cb5250f649426947bcf353802918ce50
parent 7812cce9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import java.util.Set;
 * from the AndroidManifest.xml's <activity> and
 * <receiver> tags.
 */
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class ActivityInfo extends ComponentInfo implements Parcelable {

    private static final Parcelling.BuiltIn.ForStringSet sForStringSet =
+6 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import java.util.UUID;
 * corresponds to information collected from the AndroidManifest.xml's
 * <application> tag.
 */
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class ApplicationInfo extends PackageItemInfo implements Parcelable {
    private static final ForBoolean sForBoolean = Parcelling.Cache.getOrCreate(ForBoolean.class);
    private static final Parcelling.BuiltIn.ForStringSet sForStringSet =
@@ -1386,6 +1387,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     *
     * @see #category
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public static CharSequence getCategoryTitle(Context context, @Category int category) {
        switch (category) {
            case ApplicationInfo.CATEGORY_GAME:
@@ -2187,6 +2189,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     * @return Returns a CharSequence containing the application's description.
     * If there is no description, null is returned.
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public CharSequence loadDescription(PackageManager pm) {
        if (descriptionRes != 0) {
            CharSequence label = pm.getText(packageName, descriptionRes, this);
@@ -2222,6 +2225,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
    }

    /** {@hide} */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Environment.class)
    public void initForUser(int userId) {
        uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));

@@ -2414,6 +2418,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     * @hide
     */
    @Override
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public Drawable loadDefaultIcon(PackageManager pm) {
        if ((flags & FLAG_EXTERNAL_STORAGE) != 0
                && isPackageUnavailable(pm)) {
@@ -2424,6 +2429,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = PackageManager.class)
    private boolean isPackageUnavailable(PackageManager pm) {
        try {
            return pm.getPackageInfo(packageName, 0) == null;
+4 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.util.Printer;
 * implement Parcelable, but does provide convenience methods to assist
 * in the implementation of Parcelable in subclasses.
 */
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class ComponentInfo extends PackageItemInfo {
    /**
     * Global information about the application/package this component is a
@@ -258,6 +259,7 @@ public class ComponentInfo extends PackageItemInfo {
     * @hide
     */
    @Override
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public Drawable loadDefaultIcon(PackageManager pm) {
        return applicationInfo.loadIcon(pm);
    }
@@ -265,6 +267,7 @@ public class ComponentInfo extends PackageItemInfo {
    /**
     * @hide
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    @Override protected Drawable loadDefaultBanner(PackageManager pm) {
        return applicationInfo.loadBanner(pm);
    }
@@ -273,6 +276,7 @@ public class ComponentInfo extends PackageItemInfo {
     * @hide
     */
    @Override
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    protected Drawable loadDefaultLogo(PackageManager pm) {
        return applicationInfo.loadLogo(pm);
    }
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.Parcelable;
 * Overall information about the contents of a package.  This corresponds
 * to all of the information collected from AndroidManifest.xml.
 */
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class PackageInfo implements Parcelable {
    /**
     * The name of this package.  From the <manifest> tag's "name"
+13 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import java.util.Objects;
 * itself implement Parcelable, but does provide convenience methods to assist
 * in the implementation of Parcelable in subclasses.
 */
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class PackageItemInfo {

    /**
@@ -214,6 +215,7 @@ public class PackageItemInfo {
     * @return Returns a CharSequence containing the item's label.  If the
     * item does not have a label, its name is returned.
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public @NonNull CharSequence loadLabel(@NonNull PackageManager pm) {
        if (sForceSafeLabels && !Objects.equals(packageName, ActivityThread.currentPackageName())) {
            return loadSafeLabel(pm, DEFAULT_MAX_LABEL_SIZE_PX, SAFE_STRING_FLAG_TRIM
@@ -226,6 +228,7 @@ public class PackageItemInfo {
    }

    /** {@hide} */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public CharSequence loadUnsafeLabel(PackageManager pm) {
        if (nonLocalizedLabel != null) {
            return nonLocalizedLabel;
@@ -248,6 +251,7 @@ public class PackageItemInfo {
     */
    @SystemApi
    @Deprecated
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public @NonNull CharSequence loadSafeLabel(@NonNull PackageManager pm) {
        return loadSafeLabel(pm, DEFAULT_MAX_LABEL_SIZE_PX, SAFE_STRING_FLAG_TRIM
                | SAFE_STRING_FLAG_FIRST_LINE);
@@ -261,6 +265,7 @@ public class PackageItemInfo {
     * @hide
    */
    @SystemApi
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public @NonNull CharSequence loadSafeLabel(@NonNull PackageManager pm,
            @FloatRange(from = 0) float ellipsizeDip, @TextUtils.SafeStringFlags int flags) {
        Objects.requireNonNull(pm);
@@ -281,6 +286,7 @@ public class PackageItemInfo {
     * item does not have an icon, the item's default icon is returned
     * such as the default activity icon.
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public Drawable loadIcon(PackageManager pm) {
        return pm.loadItemIcon(this, getApplicationInfo());
    }
@@ -298,6 +304,7 @@ public class PackageItemInfo {
     * item does not have an icon, the item's default icon is returned
     * such as the default activity icon.
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public Drawable loadUnbadgedIcon(PackageManager pm) {
        return pm.loadUnbadgedItemIcon(this, getApplicationInfo());
    }
@@ -313,6 +320,7 @@ public class PackageItemInfo {
     * @return Returns a Drawable containing the item's banner.  If the item
     * does not have a banner, this method will return null.
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public Drawable loadBanner(PackageManager pm) {
        if (banner != 0) {
            Drawable dr = pm.getDrawable(packageName, banner, getApplicationInfo());
@@ -334,6 +342,7 @@ public class PackageItemInfo {
     *
     * @hide
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public Drawable loadDefaultIcon(PackageManager pm) {
        return pm.getDefaultActivityIcon();
    }
@@ -349,6 +358,7 @@ public class PackageItemInfo {
     *
     * @hide
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    protected Drawable loadDefaultBanner(PackageManager pm) {
        return null;
    }
@@ -364,6 +374,7 @@ public class PackageItemInfo {
     * @return Returns a Drawable containing the item's logo. If the item
     * does not have a logo, this method will return null.
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public Drawable loadLogo(PackageManager pm) {
        if (logo != 0) {
            Drawable d = pm.getDrawable(packageName, logo, getApplicationInfo());
@@ -385,6 +396,7 @@ public class PackageItemInfo {
     *
     * @hide
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    protected Drawable loadDefaultLogo(PackageManager pm) {
        return null;
    }
@@ -402,6 +414,7 @@ public class PackageItemInfo {
     * assigned as the given meta-data.  If the meta-data name is not defined
     * or the XML resource could not be found, null is returned.
     */
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = android.content.res.Resources.class)
    public XmlResourceParser loadXmlMetaData(PackageManager pm, String name) {
        if (metaData != null) {
            int resid = metaData.getInt(name);
Loading