Clean up transceive().

BasicTagTechnology.transceive(byte[] raw) should work for most child classes,
except those that want to disable (raw) transceive.

Current plan is not to add transceiveMifare() etc - use explicit methods
instead.

Add package scoped BasicTagTechnology.transceive(byte[] rata, boolean raw)
as a helper to remove code duplication.

Change-Id: Iaea161022751c99058d291e2ed0f8c475d1c7282
diff --git a/core/java/android/nfc/technology/BasicTagTechnology.java b/core/java/android/nfc/technology/BasicTagTechnology.java
index 553f6ec..bd0bc1e 100644
--- a/core/java/android/nfc/technology/BasicTagTechnology.java
+++ b/core/java/android/nfc/technology/BasicTagTechnology.java
@@ -226,6 +226,22 @@
         }
     }
 
+    /** internal transceive */
+    /*package*/ byte[] transceive(byte[] data, boolean raw) throws IOException {
+        checkConnected();
+
+        try {
+            byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, raw);
+            if (response == null) {
+                throw new IOException("transceive failed");
+            }
+            return response;
+        } catch (RemoteException e) {
+            attemptDeadServiceRecovery(e);
+            throw new IOException("NFC service died");
+        }
+    }
+
     /**
      * Send data to a tag and receive the response.
      * <p>
@@ -238,17 +254,6 @@
      * @throws IOException if the target is lost or connection closed
      */
     public byte[] transceive(byte[] data) throws IOException {
-        checkConnected();
-
-        try {
-            byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, true);
-            if (response == null) {
-                throw new IOException("transceive failed");
-            }
-            return response;
-        } catch (RemoteException e) {
-            attemptDeadServiceRecovery(e);
-            throw new IOException("NFC service died");
-        }
+        return transceive(data, true);
     }
 }
diff --git a/core/java/android/nfc/technology/MifareClassic.java b/core/java/android/nfc/technology/MifareClassic.java
index 6874f67..c5fb361 100644
--- a/core/java/android/nfc/technology/MifareClassic.java
+++ b/core/java/android/nfc/technology/MifareClassic.java
@@ -263,7 +263,7 @@
         System.arraycopy(key, 0, cmd, 6, 6);
 
         try {
-            if ((transceive(cmd) != null)) {
+            if ((transceive(cmd, false) != null)) {
                 return true;
             }
         } catch (IOException e) {
@@ -308,7 +308,7 @@
         byte addr = (byte) block;
         byte[] blockread_cmd = { 0x30, addr };
 
-        return transceive(blockread_cmd);
+        return transceive(blockread_cmd, false);
     }
 
     /**
@@ -324,7 +324,7 @@
         blockwrite_cmd[1] = addr;
         System.arraycopy(data, 0, blockwrite_cmd, 2, data.length);
 
-        transceive(blockwrite_cmd);
+        transceive(blockwrite_cmd, false);
     }
 
     /**
@@ -345,7 +345,7 @@
         byte addr = (byte) block;
         byte[] incr_cmd = { (byte) 0xC1, (byte) block };
 
-        transceive(incr_cmd);
+        transceive(incr_cmd, false);
     }
 
     public void decrement(int block) throws IOException {
@@ -354,7 +354,7 @@
         byte addr = (byte) block;
         byte[] decr_cmd = { (byte) 0xC0, (byte) block };
 
-        transceive(decr_cmd);
+        transceive(decr_cmd, false);
     }
 
     public void transfer(int block) throws IOException {
@@ -363,7 +363,7 @@
         byte addr = (byte) block;
         byte[] trans_cmd = { (byte) 0xB0, (byte) block };
 
-        transceive(trans_cmd);
+        transceive(trans_cmd, false);
     }
 
     public void restore(int block) throws IOException {
@@ -372,33 +372,6 @@
         byte addr = (byte) block;
         byte[] rest_cmd = { (byte) 0xC2, (byte) block };
 
-        transceive(rest_cmd);
-    }
-
-    /**
-     * Send data to a tag and receive the response.
-     * <p>
-     * This method will block until the response is received. It can be canceled
-     * with {@link #close}.
-     * <p>Requires {@link android.Manifest.permission#NFC} permission.
-     *
-     * @param data bytes to send
-     * @return bytes received in response
-     * @throws IOException if the target is lost or connection closed
-     */
-    @Override
-    public byte[] transceive(byte[] data) throws IOException {
-        checkConnected();
-
-        try {
-            byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, false);
-            if (response == null) {
-                throw new IOException("transceive failed");
-            }
-            return response;
-        } catch (RemoteException e) {
-            attemptDeadServiceRecovery(e);
-            throw new IOException("NFC service died");
-        }
+        transceive(rest_cmd, false);
     }
 }
diff --git a/core/java/android/nfc/technology/MifareUltralight.java b/core/java/android/nfc/technology/MifareUltralight.java
index 3104943..e53061f 100644
--- a/core/java/android/nfc/technology/MifareUltralight.java
+++ b/core/java/android/nfc/technology/MifareUltralight.java
@@ -69,7 +69,7 @@
         checkConnected();
 
         byte[] blockread_cmd = { 0x30, (byte)block }; // phHal_eMifareRead
-        return transceive(blockread_cmd);
+        return transceive(blockread_cmd, false);
     }
 
     /**
@@ -89,7 +89,7 @@
         pagewrite_cmd[1] = (byte) block;
         System.arraycopy(data, 0, pagewrite_cmd, 2, data.length);
 
-        transceive(pagewrite_cmd);
+        transceive(pagewrite_cmd, false);
     }
 
     public void writeBlock(int block, byte[] data) throws IOException {
@@ -100,34 +100,6 @@
         blockwrite_cmd[1] = (byte) block;
         System.arraycopy(data, 0, blockwrite_cmd, 2, data.length);
 
-        transceive(blockwrite_cmd);
+        transceive(blockwrite_cmd, false);
     }
-
-    /**
-     * Send data to a tag and receive the response.
-     * <p>
-     * This method will block until the response is received. It can be canceled
-     * with {@link #close}.
-     * <p>Requires {@link android.Manifest.permission#NFC} permission.
-     *
-     * @param data bytes to send
-     * @return bytes received in response
-     * @throws IOException if the target is lost or connection closed
-     */
-    @Override
-    public byte[] transceive(byte[] data) throws IOException {
-        checkConnected();
-
-        try {
-            byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, false);
-            if (response == null) {
-                throw new IOException("transceive failed");
-            }
-            return response;
-        } catch (RemoteException e) {
-            attemptDeadServiceRecovery(e);
-            throw new IOException("NFC service died");
-        }
-    }
-
 }