nfc(api): Add return status for pause/resume Polling APIs
Bug: 375983875
Test: TH
Change-Id: Ie56ef44561cdcc617ba1aeeb8970ccad1b0c079d
diff --git a/nfc/api/system-current.txt b/nfc/api/system-current.txt
index 72447b1..c5b22ac 100644
--- a/nfc/api/system-current.txt
+++ b/nfc/api/system-current.txt
@@ -65,9 +65,9 @@
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean isTagPresent();
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void maybeTriggerFirmwareUpdate();
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void overwriteRoutingTable(int, int, int, int);
- method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void pausePolling(int);
+ method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public int pausePolling(int);
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcOemExtension.Callback);
- method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void resumePolling();
+ method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public int resumePolling();
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setAutoChangeEnabled(boolean);
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.NFC_SET_CONTROLLER_ALWAYS_ON) public void setControllerAlwaysOnMode(int);
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void synchronizeScreenState();
@@ -83,6 +83,8 @@
field public static final int HCE_ACTIVATE = 1; // 0x1
field public static final int HCE_DATA_TRANSFERRED = 2; // 0x2
field public static final int HCE_DEACTIVATE = 3; // 0x3
+ field public static final int POLLING_STATE_CHANGE_ALREADY_IN_REQUESTED_STATE = 2; // 0x2
+ field public static final int POLLING_STATE_CHANGE_SUCCEEDED = 1; // 0x1
field public static final int STATUS_OK = 0; // 0x0
field public static final int STATUS_UNKNOWN_ERROR = 1; // 0x1
}
diff --git a/nfc/java/android/nfc/INfcAdapter.aidl b/nfc/java/android/nfc/INfcAdapter.aidl
index a08b55f..7ed6019c 100644
--- a/nfc/java/android/nfc/INfcAdapter.aidl
+++ b/nfc/java/android/nfc/INfcAdapter.aidl
@@ -52,8 +52,8 @@
int getState();
boolean disable(boolean saveState, in String pkg);
boolean enable(in String pkg);
- void pausePolling(int timeoutInMs);
- void resumePolling();
+ int pausePolling(int timeoutInMs);
+ int resumePolling();
void setForegroundDispatch(in PendingIntent intent,
in IntentFilter[] filters, in TechListParcel techLists);
diff --git a/nfc/java/android/nfc/NfcOemExtension.java b/nfc/java/android/nfc/NfcOemExtension.java
index 326ca64..5be23fd 100644
--- a/nfc/java/android/nfc/NfcOemExtension.java
+++ b/nfc/java/android/nfc/NfcOemExtension.java
@@ -173,6 +173,31 @@
public @interface HostCardEmulationAction {}
/**
+ * Status code returned when the polling state change request succeeded.
+ * @see #pausePolling()
+ * @see #resumePolling()
+ */
+ public static final int POLLING_STATE_CHANGE_SUCCEEDED = 1;
+ /**
+ * Status code returned when the polling state change request is already in
+ * required state.
+ * @see #pausePolling()
+ * @see #resumePolling()
+ */
+ public static final int POLLING_STATE_CHANGE_ALREADY_IN_REQUESTED_STATE = 2;
+ /**
+ * Possible status codes for {@link #pausePolling()} and
+ * {@link #resumePolling()}.
+ * @hide
+ */
+ @IntDef(value = {
+ POLLING_STATE_CHANGE_SUCCEEDED,
+ POLLING_STATE_CHANGE_ALREADY_IN_REQUESTED_STATE,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface PollingStateChangeStatusCode {}
+
+ /**
* Status OK
*/
public static final int STATUS_OK = 0;
@@ -644,24 +669,32 @@
/**
* Pauses NFC tag reader mode polling for a {@code timeoutInMs} millisecond.
- * In case of {@code timeoutInMs} is zero or invalid polling will be stopped indefinitely
- * use {@link #resumePolling()} to resume the polling.
+ * In case of {@code timeoutInMs} is zero or invalid polling will be stopped indefinitely.
+ * Use {@link #resumePolling() to resume the polling.
* @param timeoutInMs the pause polling duration in millisecond, ranging from 0 to 40000.
+ * @return status of the operation
+ * @throws IllegalArgumentException if timeoutInMs value is invalid
+ * (0 < timeoutInMs < max).
*/
@FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
@RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
- public void pausePolling(@DurationMillisLong int timeoutInMs) {
- NfcAdapter.callService(() -> NfcAdapter.sService.pausePolling(timeoutInMs));
+ public @PollingStateChangeStatusCode int pausePolling(@DurationMillisLong int timeoutInMs) {
+ return NfcAdapter.callServiceReturn(() ->
+ NfcAdapter.sService.pausePolling(timeoutInMs),
+ POLLING_STATE_CHANGE_ALREADY_IN_REQUESTED_STATE);
}
/**
* Resumes default NFC tag reader mode polling for the current device state if polling is
* paused. Calling this while already in polling is a no-op.
+ * @return status of the operation
*/
@FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
@RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
- public void resumePolling() {
- NfcAdapter.callService(() -> NfcAdapter.sService.resumePolling());
+ public @PollingStateChangeStatusCode int resumePolling() {
+ return NfcAdapter.callServiceReturn(() ->
+ NfcAdapter.sService.resumePolling(),
+ POLLING_STATE_CHANGE_ALREADY_IN_REQUESTED_STATE);
}
/**