summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Brad Lassey <lassey@google.com> 2024-04-10 17:35:50 -0400
committer Brad Lassey <lassey@google.com> 2024-04-11 09:31:31 -0400
commitd65fbe17ef043bfb0e1d05f32c5e4f8b5ada3f91 (patch)
tree59c00cc21165cadfa1e4e29060e33fe25b356ce9
parentf67a900615d9cfbb535ca571066afa38c1bba929 (diff)
Use PollingFrame class instead of Bundles to represent polling frames in NFC stack
Bug: 333768122 Test: Tested by CTS Change-Id: I86ebecd530126d477cae1e7066a4908ccb02744e
-rw-r--r--nfc/java/android/nfc/INfcAdapter.aidl3
-rw-r--r--nfc/java/android/nfc/NfcAdapter.java5
-rw-r--r--nfc/java/android/nfc/cardemulation/HostApduService.java13
-rw-r--r--nfc/java/android/nfc/cardemulation/PollingFrame.aidl19
-rw-r--r--nfc/java/android/nfc/cardemulation/PollingFrame.java41
5 files changed, 46 insertions, 35 deletions
diff --git a/nfc/java/android/nfc/INfcAdapter.aidl b/nfc/java/android/nfc/INfcAdapter.aidl
index b57d54821b75..7cd7e7ab49a9 100644
--- a/nfc/java/android/nfc/INfcAdapter.aidl
+++ b/nfc/java/android/nfc/INfcAdapter.aidl
@@ -35,6 +35,7 @@ import android.nfc.INfcDta;
import android.nfc.INfcWlcStateListener;
import android.nfc.NfcAntennaInfo;
import android.nfc.WlcListenerDeviceInfo;
+import android.nfc.cardemulation.PollingFrame;
import android.os.Bundle;
/**
@@ -101,7 +102,7 @@ interface INfcAdapter
void updateDiscoveryTechnology(IBinder b, int pollFlags, int listenFlags);
- void notifyPollingLoop(in Bundle frame);
+ void notifyPollingLoop(in PollingFrame frame);
void notifyHceDeactivated();
int sendVendorNciMessage(int mt, int gid, int oid, in byte[] payload);
void registerVendorExtensionCallback(in INfcVendorNciCallback callbacks);
diff --git a/nfc/java/android/nfc/NfcAdapter.java b/nfc/java/android/nfc/NfcAdapter.java
index b44a71bf9be0..29867d924c78 100644
--- a/nfc/java/android/nfc/NfcAdapter.java
+++ b/nfc/java/android/nfc/NfcAdapter.java
@@ -2803,12 +2803,11 @@ public final class NfcAdapter {
@TestApi
@FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP)
public void notifyPollingLoop(@NonNull PollingFrame pollingFrame) {
- Bundle frame = pollingFrame.toBundle();
try {
if (sService == null) {
attemptDeadServiceRecovery(null);
}
- sService.notifyPollingLoop(frame);
+ sService.notifyPollingLoop(pollingFrame);
} catch (RemoteException e) {
attemptDeadServiceRecovery(e);
// Try one more time
@@ -2817,7 +2816,7 @@ public final class NfcAdapter {
return;
}
try {
- sService.notifyPollingLoop(frame);
+ sService.notifyPollingLoop(pollingFrame);
} catch (RemoteException ee) {
Log.e(TAG, "Failed to recover NFC Service.");
}
diff --git a/nfc/java/android/nfc/cardemulation/HostApduService.java b/nfc/java/android/nfc/cardemulation/HostApduService.java
index 61037a2e7e9e..f674b06ad33d 100644
--- a/nfc/java/android/nfc/cardemulation/HostApduService.java
+++ b/nfc/java/android/nfc/cardemulation/HostApduService.java
@@ -325,15 +325,12 @@ public abstract class HostApduService extends Service {
}
break;
case MSG_POLLING_LOOP:
- ArrayList<Bundle> frames =
- msg.getData().getParcelableArrayList(KEY_POLLING_LOOP_FRAMES_BUNDLE,
- Bundle.class);
- ArrayList<PollingFrame> pollingFrames =
- new ArrayList<PollingFrame>(frames.size());
- for (Bundle frame : frames) {
- pollingFrames.add(new PollingFrame(frame));
+ if (android.nfc.Flags.nfcReadPollingLoop()) {
+ ArrayList<PollingFrame> pollingFrames =
+ msg.getData().getParcelableArrayList(
+ KEY_POLLING_LOOP_FRAMES_BUNDLE, PollingFrame.class);
+ processPollingFrames(pollingFrames);
}
- processPollingFrames(pollingFrames);
break;
default:
super.handleMessage(msg);
diff --git a/nfc/java/android/nfc/cardemulation/PollingFrame.aidl b/nfc/java/android/nfc/cardemulation/PollingFrame.aidl
new file mode 100644
index 000000000000..8e09f8baaff2
--- /dev/null
+++ b/nfc/java/android/nfc/cardemulation/PollingFrame.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.nfc.cardemulation;
+
+parcelable PollingFrame; \ No newline at end of file
diff --git a/nfc/java/android/nfc/cardemulation/PollingFrame.java b/nfc/java/android/nfc/cardemulation/PollingFrame.java
index c6861bf97443..b52faba79ed7 100644
--- a/nfc/java/android/nfc/cardemulation/PollingFrame.java
+++ b/nfc/java/android/nfc/cardemulation/PollingFrame.java
@@ -101,47 +101,37 @@ public final class PollingFrame implements Parcelable{
/**
* KEY_POLLING_LOOP_TYPE is the Bundle key for the type of
* polling loop frame in the Bundle included in MSG_POLLING_LOOP.
- *
- * @hide
*/
@FlaggedApi(android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP)
- public static final String KEY_POLLING_LOOP_TYPE = "android.nfc.cardemulation.TYPE";
+ private static final String KEY_POLLING_LOOP_TYPE = "android.nfc.cardemulation.TYPE";
/**
* KEY_POLLING_LOOP_DATA is the Bundle key for the raw data of captured from
* the polling loop frame in the Bundle included in MSG_POLLING_LOOP.
- *
- * @hide
*/
@FlaggedApi(android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP)
- public static final String KEY_POLLING_LOOP_DATA = "android.nfc.cardemulation.DATA";
+ private static final String KEY_POLLING_LOOP_DATA = "android.nfc.cardemulation.DATA";
/**
* KEY_POLLING_LOOP_GAIN is the Bundle key for the field strength of
* the polling loop frame in the Bundle included in MSG_POLLING_LOOP.
- *
- * @hide
- */
+ */
@FlaggedApi(android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP)
- public static final String KEY_POLLING_LOOP_GAIN = "android.nfc.cardemulation.GAIN";
+ private static final String KEY_POLLING_LOOP_GAIN = "android.nfc.cardemulation.GAIN";
/**
* KEY_POLLING_LOOP_TIMESTAMP is the Bundle key for the timestamp of
* the polling loop frame in the Bundle included in MSG_POLLING_LOOP.
- *
- * @hide
- */
+ */
@FlaggedApi(android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP)
- public static final String KEY_POLLING_LOOP_TIMESTAMP = "android.nfc.cardemulation.TIMESTAMP";
+ private static final String KEY_POLLING_LOOP_TIMESTAMP = "android.nfc.cardemulation.TIMESTAMP";
/**
* KEY_POLLING_LOOP_TIMESTAMP is the Bundle key for whether this polling frame triggered
* autoTransact in the Bundle included in MSG_POLLING_LOOP.
- *
- * @hide
- */
+ */
@FlaggedApi(android.nfc.Flags.FLAG_NFC_READ_POLLING_LOOP)
- public static final String KEY_POLLING_LOOP_TRIGGERED_AUTOTRANSACT =
+ private static final String KEY_POLLING_LOOP_TRIGGERED_AUTOTRANSACT =
"android.nfc.cardemulation.TRIGGERED_AUTOTRANSACT";
@@ -151,7 +141,7 @@ public final class PollingFrame implements Parcelable{
private final int mGain;
@DurationMillisLong
private final long mTimestamp;
- private final boolean mTriggeredAutoTransact;
+ private boolean mTriggeredAutoTransact;
public static final @NonNull Parcelable.Creator<PollingFrame> CREATOR =
new Parcelable.Creator<>() {
@@ -166,7 +156,7 @@ public final class PollingFrame implements Parcelable{
}
};
- PollingFrame(Bundle frame) {
+ private PollingFrame(Bundle frame) {
mType = frame.getInt(KEY_POLLING_LOOP_TYPE);
byte[] data = frame.getByteArray(KEY_POLLING_LOOP_DATA);
mData = (data == null) ? new byte[0] : data;
@@ -239,6 +229,13 @@ public final class PollingFrame implements Parcelable{
}
/**
+ * @hide
+ */
+ public void setTriggeredAutoTransact(boolean triggeredAutoTransact) {
+ mTriggeredAutoTransact = triggeredAutoTransact;
+ }
+
+ /**
* Returns whether this frame triggered the device to automatically disable observe mode and
* allow one transaction.
*/
@@ -257,11 +254,9 @@ public final class PollingFrame implements Parcelable{
}
/**
- *
- * @hide
* @return a Bundle representing this frame
*/
- public Bundle toBundle() {
+ private Bundle toBundle() {
Bundle frame = new Bundle();
frame.putInt(KEY_POLLING_LOOP_TYPE, getType());
if (getVendorSpecificGain() != -1) {