From e32b3b57731dbf53b3e7b00fc28490e9d3b82f9f Mon Sep 17 00:00:00 2001 From: Ruslan Tkhakokhov Date: Sun, 7 Feb 2021 21:00:10 +0000 Subject: [PATCH] Introduce 'dataExtractionRules' manifest attribute Introduce the attribute apps targeting Android S+ can use to point to an XML file that contains rules for copying app data during backup and transfer operations. If this attribute is specified, the config pointed to by the existing 'fullBackupContent' will be ignored. Bug: 174216309 Test: m -j Change-Id: I6ad57a24b40cf5b80b312c719747e8ba89aa0a93 --- core/api/current.txt | 1 + .../android/content/pm/ApplicationInfo.java | 18 ++++++++++++++++++ .../content/pm/parsing/ParsingPackage.java | 2 ++ .../content/pm/parsing/ParsingPackageImpl.java | 15 +++++++++++++++ .../content/pm/parsing/ParsingPackageRead.java | 5 +++++ .../pm/parsing/ParsingPackageUtils.java | 2 ++ core/res/res/values/attrs_manifest.xml | 5 +++++ core/res/res/values/public.xml | 1 + 8 files changed, 49 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index 160ad7a4d5553..8a543de40b183 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -507,6 +507,7 @@ package android { field public static final int dashGap = 16843175; // 0x10101a7 field public static final int dashWidth = 16843174; // 0x10101a6 field public static final int data = 16842798; // 0x101002e + field public static final int dataExtractionRules = 16844350; // 0x101063e field public static final int datePickerDialogTheme = 16843948; // 0x10104ac field public static final int datePickerMode = 16843955; // 0x10104b3 field public static final int datePickerStyle = 16843612; // 0x101035c diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index dec2c3d7fe487..0aa1be94d279d 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -135,6 +135,18 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public int fullBackupContent = 0; + /** + * Applications can set this attribute to an xml resource within their app where they specified + * the rules determining which files and directories can be copied from the device as part of + * backup or transfer operations. + *

+ * Set from the {@link android.R.styleable#AndroidManifestApplication_dataExtractionRules} + * attribute in the manifest. + * + * @hide + */ + public int dataExtractionRulesRes = 0; + /** * true if the package is capable of presenting a unified interface representing * multiple profiles. @@ -1520,6 +1532,9 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { pw.println(prefix + "fullBackupContent=" + (fullBackupContent < 0 ? "false" : "true")); } + if (dataExtractionRulesRes != 0) { + pw.println(prefix + "dataExtractionRules=@xml/" + dataExtractionRulesRes); + } pw.println(prefix + "crossProfile=" + (crossProfile ? "true" : "false")); if (networkSecurityConfigRes != 0) { pw.println(prefix + "networkSecurityConfigRes=0x" @@ -1749,6 +1764,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { uiOptions = orig.uiOptions; backupAgentName = orig.backupAgentName; fullBackupContent = orig.fullBackupContent; + dataExtractionRulesRes = orig.dataExtractionRulesRes; crossProfile = orig.crossProfile; networkSecurityConfigRes = orig.networkSecurityConfigRes; category = orig.category; @@ -1836,6 +1852,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { dest.writeInt(descriptionRes); dest.writeInt(uiOptions); dest.writeInt(fullBackupContent); + dest.writeInt(dataExtractionRulesRes); dest.writeBoolean(crossProfile); dest.writeInt(networkSecurityConfigRes); dest.writeInt(category); @@ -1920,6 +1937,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { descriptionRes = source.readInt(); uiOptions = source.readInt(); fullBackupContent = source.readInt(); + dataExtractionRulesRes = source.readInt(); crossProfile = source.readBoolean(); networkSecurityConfigRes = source.readInt(); category = source.readInt(); diff --git a/core/java/android/content/pm/parsing/ParsingPackage.java b/core/java/android/content/pm/parsing/ParsingPackage.java index 7a01392a24e8f..29edd405be6b9 100644 --- a/core/java/android/content/pm/parsing/ParsingPackage.java +++ b/core/java/android/content/pm/parsing/ParsingPackage.java @@ -260,6 +260,8 @@ public interface ParsingPackage extends ParsingPackageRead { ParsingPackage setFullBackupContent(int fullBackupContent); + ParsingPackage setDataExtractionRules(int dataExtractionRules); + ParsingPackage setHasDomainUrls(boolean hasDomainUrls); ParsingPackage setIconRes(int iconRes); diff --git a/core/java/android/content/pm/parsing/ParsingPackageImpl.java b/core/java/android/content/pm/parsing/ParsingPackageImpl.java index c1a93d8c24285..067787d725d9b 100644 --- a/core/java/android/content/pm/parsing/ParsingPackageImpl.java +++ b/core/java/android/content/pm/parsing/ParsingPackageImpl.java @@ -334,6 +334,7 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { private int descriptionRes; private int fullBackupContent; + private int dataExtractionRules; private int iconRes; private int installLocation = ParsingPackageUtils.PARSE_DEFAULT_INSTALL_LOCATION; private int labelRes; @@ -1015,6 +1016,7 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { appInfo.enabled = getBoolean(Booleans.ENABLED); // appInfo.enabledSetting appInfo.fullBackupContent = fullBackupContent; + appInfo.dataExtractionRulesRes = dataExtractionRules; // TODO(b/135203078): See ParsingPackageImpl#getHiddenApiEnforcementPolicy // appInfo.mHiddenApiPolicy // appInfo.hiddenUntilInstalled @@ -1163,6 +1165,7 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { dest.writeInt(this.compatibleWidthLimitDp); dest.writeInt(this.descriptionRes); dest.writeInt(this.fullBackupContent); + dest.writeInt(this.dataExtractionRules); dest.writeInt(this.iconRes); dest.writeInt(this.installLocation); dest.writeInt(this.labelRes); @@ -1284,6 +1287,7 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { this.compatibleWidthLimitDp = in.readInt(); this.descriptionRes = in.readInt(); this.fullBackupContent = in.readInt(); + this.dataExtractionRules = in.readInt(); this.iconRes = in.readInt(); this.installLocation = in.readInt(); this.labelRes = in.readInt(); @@ -1807,6 +1811,11 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { return fullBackupContent; } + @Override + public int getDataExtractionRules() { + return dataExtractionRules; + } + @Override public int getIconRes() { return iconRes; @@ -2263,6 +2272,12 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { return this; } + @Override + public ParsingPackageImpl setDataExtractionRules(int value) { + dataExtractionRules = value; + return this; + } + @Override public ParsingPackageImpl setIconRes(int value) { iconRes = value; diff --git a/core/java/android/content/pm/parsing/ParsingPackageRead.java b/core/java/android/content/pm/parsing/ParsingPackageRead.java index ff4cebdd15335..f7f3e19efdf39 100644 --- a/core/java/android/content/pm/parsing/ParsingPackageRead.java +++ b/core/java/android/content/pm/parsing/ParsingPackageRead.java @@ -587,6 +587,11 @@ public interface ParsingPackageRead extends Parcelable { */ int getFullBackupContent(); + /** + * @see R.styleable#AndroidManifestApplication_dataExtractionRules + */ + int getDataExtractionRules(); + /** @see ApplicationInfo#PRIVATE_FLAG_HAS_DOMAIN_URLS */ boolean isHasDomainUrls(); diff --git a/core/java/android/content/pm/parsing/ParsingPackageUtils.java b/core/java/android/content/pm/parsing/ParsingPackageUtils.java index b7aa30f00691f..0c033fddf0692 100644 --- a/core/java/android/content/pm/parsing/ParsingPackageUtils.java +++ b/core/java/android/content/pm/parsing/ParsingPackageUtils.java @@ -2168,6 +2168,8 @@ public class ParsingPackageUtils { .setNetworkSecurityConfigRes(resId(R.styleable.AndroidManifestApplication_networkSecurityConfig, sa)) .setRoundIconRes(resId(R.styleable.AndroidManifestApplication_roundIcon, sa)) .setTheme(resId(R.styleable.AndroidManifestApplication_theme, sa)) + .setDataExtractionRules( + resId(R.styleable.AndroidManifestApplication_dataExtractionRules, sa)) // Strings .setClassLoaderName(string(R.styleable.AndroidManifestApplication_classLoader, sa)) .setRequiredAccountType(string(R.styleable.AndroidManifestApplication_requiredAccountType, sa)) diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index 0ae6a76e2a606..45e11ba9820ed 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -1893,6 +1893,11 @@ + + +