Add support for NFC associated role services
This allows NFC APDU services to opt-in to sharing the same priority as
the role owner if the containing package and the role owner have the
same package signature. The is useful for apps that have these types of
services spread amongst multiple packages.
Bug: 366243361
Test: atest RegisteredAidCacheTest
Flag: android.nfc.nfc_associated_role_services
Change-Id: Id1ff0a7dbef12283a135508d43f66148c08fbba3
diff --git a/core/api/current.txt b/core/api/current.txt
index 8b17908..8022baa 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -1502,6 +1502,7 @@
field public static final int shadowRadius = 16843108; // 0x1010164
field public static final int shape = 16843162; // 0x101019a
field public static final int shareInterpolator = 16843195; // 0x10101bb
+ field @FlaggedApi("android.nfc.nfc_associated_role_services") public static final int shareRolePriority;
field @Deprecated public static final int sharedUserId = 16842763; // 0x101000b
field @Deprecated public static final int sharedUserLabel = 16843361; // 0x1010261
field public static final int sharedUserMaxSdkVersion = 16844365; // 0x101064d
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 9c5eb3e..b0e0237 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -11110,6 +11110,7 @@
method @FlaggedApi("android.nfc.enable_nfc_mainline") public void setDynamicAidGroup(@NonNull android.nfc.cardemulation.AidGroup);
method @FlaggedApi("android.nfc.enable_nfc_mainline") public void setOffHostSecureElement(@NonNull String);
method @FlaggedApi("android.nfc.nfc_observe_mode") public void setShouldDefaultToObserveMode(boolean);
+ method @FlaggedApi("android.nfc.nfc_associated_role_services") public boolean shareRolePriority();
method @FlaggedApi("android.nfc.nfc_observe_mode") public boolean shouldDefaultToObserveMode();
method @FlaggedApi("android.nfc.enable_nfc_mainline") public void writeToParcel(@NonNull android.os.Parcel, int);
field @FlaggedApi("android.nfc.enable_nfc_mainline") @NonNull public static final android.os.Parcelable.Creator<android.nfc.cardemulation.ApduServiceInfo> CREATOR;
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index f6590b1..8c46ccc 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -4808,6 +4808,12 @@
<!-- Whether the device should default to observe mode when this service is
default or in the foreground. -->
<attr name="shouldDefaultToObserveMode" format="boolean"/>
+ <!-- Whether this service should share the same AID routing priority as the role
+ owner. This package and the role owner must have the same signature, and the
+ role owner must opt into this behavior by using the property named by
+ {@link android.nfc.cardemulation.CardEmulation.PROPERTY_ALLOW_SHARED_ROLE_PRIORITY }
+ in the <code><application&rt;</code> tag. -->
+ <attr name="shareRolePriority" format="boolean"/>
</declare-styleable>
<!-- Use <code>offhost-apdu-service</code> as the root tag of the XML resource that
@@ -4835,6 +4841,7 @@
<!-- Whether the device should default to observe mode when this service is
default or in the foreground. -->
<attr name="shouldDefaultToObserveMode"/>
+ <attr name="shareRolePriority"/>
</declare-styleable>
<!-- Specify one or more <code>aid-group</code> elements inside a
diff --git a/core/res/res/values/public-staging.xml b/core/res/res/values/public-staging.xml
index b0b87d1d..4c3fa4b 100644
--- a/core/res/res/values/public-staging.xml
+++ b/core/res/res/values/public-staging.xml
@@ -133,6 +133,8 @@
<public name="alternateLauncherLabels"/>
<!-- @FlaggedApi(android.content.pm.Flags.FLAG_APP_COMPAT_OPTION_16KB) -->
<public name="pageSizeCompat" />
+ <!-- @FlaggedApi(android.nfc.Flags.FLAG_NFC_ASSOCIATED_ROLE_SERVICES) -->
+ <public name="shareRolePriority"/>
</staging-public-group>
<staging-public-group type="id" first-id="0x01b60000">
diff --git a/nfc/api/current.txt b/nfc/api/current.txt
index 7ae2eafa..fa6df42 100644
--- a/nfc/api/current.txt
+++ b/nfc/api/current.txt
@@ -232,6 +232,7 @@
field @FlaggedApi("android.nfc.nfc_event_listener") public static final int NFC_INTERNAL_ERROR_NFC_CRASH_RESTART = 1; // 0x1
field @FlaggedApi("android.nfc.nfc_event_listener") public static final int NFC_INTERNAL_ERROR_NFC_HARDWARE_ERROR = 2; // 0x2
field @FlaggedApi("android.nfc.nfc_event_listener") public static final int NFC_INTERNAL_ERROR_UNKNOWN = 0; // 0x0
+ field @FlaggedApi("android.nfc.nfc_associated_role_services") public static final String PROPERTY_ALLOW_SHARED_ROLE_PRIORITY = "android.nfc.cardemulation.PROPERTY_ALLOW_SHARED_ROLE_PRIORITY";
field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_DEFAULT = 3; // 0x3
field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_DH = 0; // 0x0
field @FlaggedApi("android.nfc.nfc_override_recover_routing_table") public static final int PROTOCOL_AND_TECHNOLOGY_ROUTE_ESE = 1; // 0x1
diff --git a/nfc/java/android/nfc/cardemulation/ApduServiceInfo.java b/nfc/java/android/nfc/cardemulation/ApduServiceInfo.java
index 9ff83fe..308b5d1 100644
--- a/nfc/java/android/nfc/cardemulation/ApduServiceInfo.java
+++ b/nfc/java/android/nfc/cardemulation/ApduServiceInfo.java
@@ -171,6 +171,12 @@
private boolean mShouldDefaultToObserveMode;
/**
+ * Whether or not this service wants to share the same routing priority as the
+ * Wallet role owner.
+ */
+ private boolean mShareRolePriority;
+
+ /**
* @hide
*/
@UnsupportedAppUsage
@@ -307,6 +313,12 @@
mShouldDefaultToObserveMode = sa.getBoolean(
R.styleable.HostApduService_shouldDefaultToObserveMode,
false);
+ if (Flags.nfcAssociatedRoleServices()) {
+ mShareRolePriority = sa.getBoolean(
+ R.styleable.HostApduService_shareRolePriority,
+ false
+ );
+ }
sa.recycle();
} else {
TypedArray sa = res.obtainAttributes(attrs,
@@ -337,6 +349,12 @@
}
}
mStaticOffHostName = mOffHostName;
+ if (Flags.nfcAssociatedRoleServices()) {
+ mShareRolePriority = sa.getBoolean(
+ R.styleable.OffHostApduService_shareRolePriority,
+ false
+ );
+ }
sa.recycle();
}
@@ -728,6 +746,17 @@
}
/**
+ * Returns whether or not this service wants to share the Wallet role holder priority
+ * with other packages/services with the same signature.
+ *
+ * @return whether or not this service wants to share priority
+ */
+ @FlaggedApi(Flags.FLAG_NFC_ASSOCIATED_ROLE_SERVICES)
+ public boolean shareRolePriority() {
+ return mShareRolePriority;
+ }
+
+ /**
* Returns description of service.
* @return user readable description of service
*/
diff --git a/nfc/java/android/nfc/cardemulation/CardEmulation.java b/nfc/java/android/nfc/cardemulation/CardEmulation.java
index 24ff7ab..753964d 100644
--- a/nfc/java/android/nfc/cardemulation/CardEmulation.java
+++ b/nfc/java/android/nfc/cardemulation/CardEmulation.java
@@ -244,6 +244,25 @@
@Retention(RetentionPolicy.SOURCE)
public @interface SetServiceEnabledStatusCode {}
+ /**
+ * Property name used to indicate that an application wants to allow associated services
+ * to share the same AID routing priority when this application is the role holder.
+ * <p>
+ * Example:
+ * <pre>
+ * {@code
+ * <application>
+ * ...
+ * <property android:name="android.nfc.cardemulation.PROPERTY_ALLOW_SHARED_ROLE_PRIORITY"
+ * android:value="true"/>
+ * </application>
+ * }
+ * </pre>
+ */
+ @FlaggedApi(Flags.FLAG_NFC_ASSOCIATED_ROLE_SERVICES)
+ public static final String PROPERTY_ALLOW_SHARED_ROLE_PRIORITY =
+ "android.nfc.cardemulation.PROPERTY_ALLOW_SHARED_ROLE_PRIORITY";
+
static boolean sIsInitialized = false;
static HashMap<Context, CardEmulation> sCardEmus = new HashMap<Context, CardEmulation>();
static INfcCardEmulation sService;