Merge "Address API council feedback for setDiscoveryTechnology flags" into main am: 641ad04275
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2941248
Change-Id: I8d95c443c0246dc14d0916e54a84b1a61a5d9626
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/nfc/api/current.txt b/nfc/api/current.txt
index 91e4603..0ab2ef7 100644
--- a/nfc/api/current.txt
+++ b/nfc/api/current.txt
@@ -97,12 +97,12 @@
field public static final String EXTRA_SECURE_ELEMENT_NAME = "android.nfc.extra.SECURE_ELEMENT_NAME";
field public static final String EXTRA_TAG = "android.nfc.extra.TAG";
field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_LISTEN_DISABLE = 0; // 0x0
- field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_LISTEN_KEEP = -1; // 0xffffffff
+ field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_LISTEN_KEEP = -2147483648; // 0x80000000
field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_LISTEN_NFC_PASSIVE_A = 1; // 0x1
field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_LISTEN_NFC_PASSIVE_B = 2; // 0x2
field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_LISTEN_NFC_PASSIVE_F = 4; // 0x4
field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_READER_DISABLE = 0; // 0x0
- field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_READER_KEEP = -1; // 0xffffffff
+ field @FlaggedApi("android.nfc.enable_nfc_set_discovery_tech") public static final int FLAG_READER_KEEP = -2147483648; // 0x80000000
field public static final int FLAG_READER_NFC_A = 1; // 0x1
field public static final int FLAG_READER_NFC_B = 2; // 0x2
field public static final int FLAG_READER_NFC_BARCODE = 16; // 0x10
diff --git a/nfc/java/android/nfc/NfcAdapter.java b/nfc/java/android/nfc/NfcAdapter.java
index 979855e..0791721 100644
--- a/nfc/java/android/nfc/NfcAdapter.java
+++ b/nfc/java/android/nfc/NfcAdapter.java
@@ -414,18 +414,18 @@
/**
* Flags for use with {@link #setDiscoveryTechnology(Activity, int, int)}.
* <p>
- * Setting this flag makes listening to use current flags.
+ * Setting this flag makes listening to keep the current technology configuration.
*/
@FlaggedApi(Flags.FLAG_ENABLE_NFC_SET_DISCOVERY_TECH)
- public static final int FLAG_LISTEN_KEEP = -1;
+ public static final int FLAG_LISTEN_KEEP = 0x80000000;
/**
* Flags for use with {@link #setDiscoveryTechnology(Activity, int, int)}.
* <p>
- * Setting this flag makes polling to use current flags.
+ * Setting this flag makes polling to keep the current technology configuration.
*/
@FlaggedApi(Flags.FLAG_ENABLE_NFC_SET_DISCOVERY_TECH)
- public static final int FLAG_READER_KEEP = -1;
+ public static final int FLAG_READER_KEEP = 0x80000000;
/** @hide */
public static final int FLAG_USE_ALL_TECH = 0xff;
@@ -1793,6 +1793,8 @@
*
* Use {@link #FLAG_READER_KEEP} to keep current polling technology.
* Use {@link #FLAG_LISTEN_KEEP} to keep current listenig technology.
+ * (if the _KEEP flag is specified the other technology flags shouldn't be set
+ * and are quietly ignored otherwise).
* Use {@link #FLAG_READER_DISABLE} to disable polling.
* Use {@link #FLAG_LISTEN_DISABLE} to disable listening.
* Also refer to {@link #resetDiscoveryTechnology(Activity)} to restore these changes.
@@ -1824,6 +1826,15 @@
@FlaggedApi(Flags.FLAG_ENABLE_NFC_SET_DISCOVERY_TECH)
public void setDiscoveryTechnology(@NonNull Activity activity,
@PollTechnology int pollTechnology, @ListenTechnology int listenTechnology) {
+
+ // A special treatment of the _KEEP flags
+ if ((listenTechnology & FLAG_LISTEN_KEEP) != 0) {
+ listenTechnology = -1;
+ }
+ if ((pollTechnology & FLAG_READER_KEEP) != 0) {
+ pollTechnology = -1;
+ }
+
if (listenTechnology == FLAG_LISTEN_DISABLE) {
synchronized (sLock) {
if (!sHasNfcFeature) {
@@ -1850,10 +1861,10 @@
}
/**
- * Restore the poll/listen technologies of NFC controller,
+ * Restore the poll/listen technologies of NFC controller to its default state,
* which were changed by {@link #setDiscoveryTechnology(Activity , int , int)}
*
- * @param activity The Activity that requests to changed technologies.
+ * @param activity The Activity that requested to change technologies.
*/
@FlaggedApi(Flags.FLAG_ENABLE_NFC_SET_DISCOVERY_TECH)