From dc8eab403913ec4870818a878007baa7793a6f71 Mon Sep 17 00:00:00 2001 From: Mary Xia Date: Thu, 29 Sep 2022 13:16:16 +0000 Subject: [PATCH] Define a new manifest attribute targetDisplayCategory in tag and parse into ActivityInfo through string validation Test: atest PackageParserTest or atest ParsedActivityTest Bug:233910285 Change-Id: I8306b93e9479135f319837108f943192f93fe8de --- core/api/current.txt | 2 + .../java/android/content/pm/ActivityInfo.java | 23 ++++++++++ core/res/res/values/attrs_manifest.xml | 14 +++++++ core/res/res/values/public-staging.xml | 1 + .../server/pm/parsing/PackageInfoUtils.java | 1 + .../pm/pkg/component/ParsedActivity.java | 6 +++ .../pm/pkg/component/ParsedActivityImpl.java | 26 ++++++++++-- .../pm/pkg/component/ParsedActivityUtils.java | 13 ++++++ .../parsing/parcelling/ParsedActivityTest.kt | 3 +- services/tests/servicestests/Android.bp | 1 + .../android/server/pm/PackageParserTest.java | 42 +++++++++++++++++++ .../test-apps/PackageParserApp/Android.bp | 14 +++++++ .../PackageParserApp/AndroidManifestApp4.xml | 3 +- .../PackageParserApp/AndroidManifestApp6.xml | 27 ++++++++++++ 14 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 services/tests/servicestests/test-apps/PackageParserApp/AndroidManifestApp6.xml diff --git a/core/api/current.txt b/core/api/current.txt index e5cc625038ddf..555e518aa6260 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -1490,6 +1490,7 @@ package android { field public static final int targetCellWidth = 16844340; // 0x1010634 field public static final int targetClass = 16842799; // 0x101002f field @Deprecated public static final int targetDescriptions = 16843680; // 0x10103a0 + field public static final int targetDisplayCategory; field public static final int targetId = 16843740; // 0x10103dc field public static final int targetName = 16843853; // 0x101044d field public static final int targetPackage = 16842785; // 0x1010021 @@ -11114,6 +11115,7 @@ package android.content.pm { field public int screenOrientation; field public int softInputMode; field public String targetActivity; + field @Nullable public String targetDisplayCategory; field public String taskAffinity; field public int theme; field public int uiOptions; diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java index 26c947b5f916d..fda4119aff997 100644 --- a/core/java/android/content/pm/ActivityInfo.java +++ b/core/java/android/content/pm/ActivityInfo.java @@ -220,6 +220,23 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { */ public String launchToken; + /** + * Specifies the category of the target display the activity is expected to run on. Set from + * the {@link android.R.attr#targetDisplayCategory} attribute. Upon creation, a virtual display + * can specify which display categories it supports and one of the category must be present in + * the activity's manifest to allow this activity to run. The default value is {@code null}, + * which indicates the activity does not belong to a restricted display category and thus can + * only run on a display that didn't specify any display categories. Each activity can only + * specify one category it targets to but a virtual display can support multiple restricted + * categories. + * + * This field should be formatted as a Java-language-style free form string(for example, + * com.google.automotive_entertainment), which may contain uppercase or lowercase letters ('A' + * through 'Z'), numbers, and underscores ('_') but may only start with letters. + */ + @Nullable + public String targetDisplayCategory; + /** * Activity can not be resized and always occupies the fullscreen area with all windows fully * visible. @@ -1313,6 +1330,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { mMaxAspectRatio = orig.mMaxAspectRatio; mMinAspectRatio = orig.mMinAspectRatio; supportsSizeChanges = orig.supportsSizeChanges; + targetDisplayCategory = orig.targetDisplayCategory; } /** @@ -1651,6 +1669,9 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { if (mKnownActivityEmbeddingCerts != null) { pw.println(prefix + "knownActivityEmbeddingCerts=" + mKnownActivityEmbeddingCerts); } + if (targetDisplayCategory != null) { + pw.println(prefix + "targetDisplayCategory=" + targetDisplayCategory); + } super.dumpBack(pw, prefix, dumpFlags); } @@ -1697,6 +1718,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { dest.writeFloat(mMinAspectRatio); dest.writeBoolean(supportsSizeChanges); sForStringSet.parcel(mKnownActivityEmbeddingCerts, dest, flags); + dest.writeString8(targetDisplayCategory); } /** @@ -1822,6 +1844,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { if (mKnownActivityEmbeddingCerts.isEmpty()) { mKnownActivityEmbeddingCerts = null; } + targetDisplayCategory = source.readString8(); } /** diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index b5c7ea6bf4c55..eac2b94436319 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -3062,6 +3062,20 @@ + + + + + + + + +