From 90d2c04d988ea90138042d85f861a40afb76f705 Mon Sep 17 00:00:00 2001 From: chloedai Date: Wed, 11 May 2022 14:19:19 +0000 Subject: [PATCH] Assign the nonce from NfcService while contructing a Tag object 1. Remove nonce setting method from AIDL, only NfcService could generate nonce 2. NfcService directily assign a nonce to Tag object while contructing Bug: 199291025 Test: test with some reader apps, test pass Change-Id: I0cf3d22a785b463589f1ba9bd3ca49825839b9ce Merged-In: I0cf3d22a785b463589f1ba9bd3ca49825839b9ce --- core/java/android/nfc/INfcTag.aidl | 1 - core/java/android/nfc/Tag.java | 23 +++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/core/java/android/nfc/INfcTag.aidl b/core/java/android/nfc/INfcTag.aidl index e1ccc4fb740be..170df71385bbe 100644 --- a/core/java/android/nfc/INfcTag.aidl +++ b/core/java/android/nfc/INfcTag.aidl @@ -46,6 +46,5 @@ interface INfcTag int getMaxTransceiveLength(int technology); boolean getExtendedLengthApdusSupported(); - void setTagUpToDate(long cookie); boolean isTagUpToDate(long cookie); } diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index 731d1ba782997..500038f14d9d4 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -34,7 +34,6 @@ import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; -import android.os.SystemClock; import java.io.IOException; import java.util.Arrays; @@ -119,17 +118,17 @@ public final class Tag implements Parcelable { final String[] mTechStringList; final Bundle[] mTechExtras; final int mServiceHandle; // for use by NFC service, 0 indicates a mock + final long mCookie; // for accessibility checking final INfcTag mTagService; // interface to NFC service, will be null if mock tag int mConnectedTechnology; - long mCookie; /** * Hidden constructor to be used by NFC service and internal classes. * @hide */ public Tag(byte[] id, int[] techList, Bundle[] techListExtras, int serviceHandle, - INfcTag tagService) { + long cookie, INfcTag tagService) { if (techList == null) { throw new IllegalArgumentException("rawTargets cannot be null"); } @@ -139,20 +138,13 @@ public final class Tag implements Parcelable { // Ensure mTechExtras is as long as mTechList mTechExtras = Arrays.copyOf(techListExtras, techList.length); mServiceHandle = serviceHandle; + mCookie = cookie; mTagService = tagService; - mConnectedTechnology = -1; - mCookie = SystemClock.elapsedRealtime(); if (tagService == null) { return; } - - try { - tagService.setTagUpToDate(mCookie); - } catch (RemoteException e) { - throw e.rethrowAsRuntimeException(); - } } /** @@ -165,9 +157,10 @@ public final class Tag implements Parcelable { * @return freshly constructed tag * @hide */ - public static Tag createMockTag(byte[] id, int[] techList, Bundle[] techListExtras) { + public static Tag createMockTag(byte[] id, int[] techList, Bundle[] techListExtras, + long cookie) { // set serviceHandle to 0 and tagService to null to indicate mock tag - return new Tag(id, techList, techListExtras, 0, null); + return new Tag(id, techList, techListExtras, 0, cookie, null); } private String[] generateTechStringList(int[] techList) { @@ -445,6 +438,7 @@ public final class Tag implements Parcelable { dest.writeIntArray(mTechList); dest.writeTypedArray(mTechExtras, 0); dest.writeInt(mServiceHandle); + dest.writeLong(mCookie); dest.writeInt(isMock); if (isMock == 0) { dest.writeStrongBinder(mTagService.asBinder()); @@ -463,6 +457,7 @@ public final class Tag implements Parcelable { in.readIntArray(techList); Bundle[] techExtras = in.createTypedArray(Bundle.CREATOR); int serviceHandle = in.readInt(); + long cookie = in.readLong(); int isMock = in.readInt(); if (isMock == 0) { tagService = INfcTag.Stub.asInterface(in.readStrongBinder()); @@ -471,7 +466,7 @@ public final class Tag implements Parcelable { tagService = null; } - return new Tag(id, techList, techExtras, serviceHandle, tagService); + return new Tag(id, techList, techExtras, serviceHandle, cookie, tagService); } @Override