From d143df294c672f25601567fb970736c4ae7e96c5 Mon Sep 17 00:00:00 2001
From: CLOUDERHEM <cloudac@qq.com>
Date: Sat, 9 Dec 2023 16:52:04 +0800
Subject: [PATCH] Support on Android 14

---
 .../java/de/syss/MifareClassicTool/MCReader.java  | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java
index c083a6fb..0f17e17f 100644
--- a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java	
+++ b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java	
@@ -23,6 +23,7 @@
 import android.nfc.TagLostException;
 import android.nfc.tech.MifareClassic;
 import android.nfc.tech.NfcA;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Parcel;
@@ -131,6 +132,11 @@ public static Tag patchTag(Tag tag) {
         oldParcel.readIntArray(oldTechList);
         Bundle[] oldTechExtras = oldParcel.createTypedArray(Bundle.CREATOR);
         int serviceHandle = oldParcel.readInt();
+        // Android 14
+        long mCookie = 0;
+        if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
+            mCookie = oldParcel.readLong();
+        }
         int isMock = oldParcel.readInt();
         IBinder tagService;
         if (isMock == 0) {
@@ -151,9 +157,9 @@ public static Tag patchTag(Tag tag) {
                     nfcaIdx = i;
                 }
                 if (oldTechExtras[i] != null
-                        && oldTechExtras[i].containsKey("sak")) {
+                    && oldTechExtras[i].containsKey("sak")) {
                     sak = (short) (sak
-                            | oldTechExtras[i].getShort("sak"));
+                        | oldTechExtras[i].getShort("sak"));
                     isFirstSak = nfcaIdx == i;
                 }
             } else if (techList[i].equals(MifareClassic.class.getName())) {
@@ -189,6 +195,11 @@ public static Tag patchTag(Tag tag) {
         newParcel.writeIntArray(oldTechList);
         newParcel.writeTypedArray(oldTechExtras, 0);
         newParcel.writeInt(serviceHandle);
+        // Android 14
+        if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
+            newParcel.writeLong(mCookie);
+        }
+
         newParcel.writeInt(isMock);
         if (isMock == 0) {
             newParcel.writeStrongBinder(tagService);