diff options
| author | Chloe Dai <chloedai@google.com> | 2022-01-26 02:58:10 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-01-26 02:58:10 +0000 |
| commit | dda723993a345d6028fab6547808724ab4a997fa (patch) | |
| tree | 4ec704ee432fafefdc3a45f198643c5e3ce30931 /core/java | |
| parent | c016778d1e1ee88126eaa783ac850c464236eb99 (diff) | |
| parent | 49f7afe68b9637c1164d8592e8cb05c03bec229f (diff) | |
Merge "Add tag availability checking mechanism"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/nfc/INfcTag.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/nfc/Tag.java | 21 |
2 files changed, 24 insertions, 0 deletions
diff --git a/core/java/android/nfc/INfcTag.aidl b/core/java/android/nfc/INfcTag.aidl index 539fd4adb0a0..e1ccc4fb740b 100644 --- a/core/java/android/nfc/INfcTag.aidl +++ b/core/java/android/nfc/INfcTag.aidl @@ -45,4 +45,7 @@ interface INfcTag boolean canMakeReadOnly(int ndefType); 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 398ec63a931b..0ce9c70569b5 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -34,6 +34,7 @@ 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; @@ -121,6 +122,7 @@ public final class Tag implements Parcelable { 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. @@ -140,6 +142,13 @@ public final class Tag implements Parcelable { mTagService = tagService; mConnectedTechnology = -1; + + try { + mCookie = SystemClock.elapsedRealtime(); + tagService.setTagUpToDate(mCookie); + } catch (RemoteException e) { + throw e.rethrowAsRuntimeException(); + } } /** @@ -361,6 +370,18 @@ public final class Tag implements Parcelable { /** @hide */ @UnsupportedAppUsage public INfcTag getTagService() { + try { + if (!mTagService.isTagUpToDate(mCookie)) { + String id_str = ""; + for (int i = 0; i < mId.length; i++) { + id_str = id_str + String.format("%02X ", mId[i]); + } + String msg = "Permission Denial: Tag ( ID: " + id_str + ") is out of date"; + throw new SecurityException(msg); + } + } catch (RemoteException e) { + throw e.rethrowAsRuntimeException(); + } return mTagService; } |
