Rename getGain() to getVendorSpecificGain()

Bug: 315131060
Test: Tested with CTS
Merged-In: I9b0d592fc12912ae8da29472de148206e3eb6324
Change-Id: I9b0d592fc12912ae8da29472de148206e3eb6324
diff --git a/nfc/api/current.txt b/nfc/api/current.txt
index d300e94..54f1421 100644
--- a/nfc/api/current.txt
+++ b/nfc/api/current.txt
@@ -268,9 +268,9 @@
     ctor public PollingFrame(int, @Nullable byte[], int, int);
     method public int describeContents();
     method @NonNull public byte[] getData();
-    method public int getGain();
     method public int getTimestamp();
     method public int getType();
+    method public int getVendorSpecificGain();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.nfc.cardemulation.PollingFrame> CREATOR;
     field @FlaggedApi("android.nfc.nfc_read_polling_loop") public static final int POLLING_LOOP_TYPE_A = 65; // 0x41
diff --git a/nfc/java/android/nfc/cardemulation/PollingFrame.java b/nfc/java/android/nfc/cardemulation/PollingFrame.java
index 994f4ae..ccd06cf 100644
--- a/nfc/java/android/nfc/cardemulation/PollingFrame.java
+++ b/nfc/java/android/nfc/cardemulation/PollingFrame.java
@@ -157,7 +157,11 @@
         mType = frame.getInt(KEY_POLLING_LOOP_TYPE);
         byte[] data = frame.getByteArray(KEY_POLLING_LOOP_DATA);
         mData = (data == null) ? new byte[0] : data;
-        mGain = frame.getByte(KEY_POLLING_LOOP_GAIN);
+        if (frame.containsKey(KEY_POLLING_LOOP_GAIN)) {
+            mGain = frame.getByte(KEY_POLLING_LOOP_GAIN);
+        } else {
+            mGain = -1;
+        }
         mTimestamp = frame.getInt(KEY_POLLING_LOOP_TIMESTAMP);
     }
 
@@ -194,8 +198,9 @@
     /**
      * Returns the gain representing the field strength of the NFC field when this polling loop
      * frame was observed.
+     * @return the gain or -1 if there is no gain measurement associated with this frame.
      */
-    public int getGain() {
+    public int getVendorSpecificGain() {
         return mGain;
     }
 
@@ -227,7 +232,9 @@
     public Bundle toBundle() {
         Bundle frame = new Bundle();
         frame.putInt(KEY_POLLING_LOOP_TYPE, getType());
-        frame.putByte(KEY_POLLING_LOOP_GAIN, (byte) getGain());
+        if (getVendorSpecificGain() != -1) {
+            frame.putByte(KEY_POLLING_LOOP_GAIN, (byte) getVendorSpecificGain());
+        }
         frame.putByteArray(KEY_POLLING_LOOP_DATA, getData());
         frame.putInt(KEY_POLLING_LOOP_TIMESTAMP, getTimestamp());
         return frame;
@@ -236,7 +243,7 @@
     @Override
     public String toString() {
         return "PollingFrame { Type: " + (char) getType()
-                + ", gain: " + getGain()
+                + ", gain: " + getVendorSpecificGain()
                 + ", timestamp: " + Integer.toUnsignedString(getTimestamp())
                 + ", data: [" + HexFormat.ofDelimiter(" ").formatHex(getData()) + "] }";
     }