Make unlock api take String instead of int codes
int code method not exposed to third parties
Change-Id: I18ad0703be9d06664db3fd00a6435f789979fe73
diff --git a/api/current.txt b/api/current.txt
index a263946..f788098 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -17664,7 +17664,7 @@
method public boolean invokeBeam(android.app.Activity);
method public boolean isEnabled();
method public boolean isNdefPushEnabled();
- method public boolean registerLockscreenDispatch(android.nfc.NfcAdapter.NfcLockscreenDispatch, int[]);
+ method public boolean registerLockscreenDispatch(android.nfc.NfcAdapter.NfcLockscreenDispatch, java.lang.String[]);
method public void setBeamPushUris(android.net.Uri[], android.app.Activity);
method public void setBeamPushUrisCallback(android.nfc.NfcAdapter.CreateBeamUrisCallback, android.app.Activity);
method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, android.app.Activity...);
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index 8991066..be098a8 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -1428,17 +1428,20 @@
}
public boolean registerLockscreenDispatch(final NfcLockscreenDispatch lockscreenDispatch,
- int[] techList) {
+ String[] techList) {
try {
sService.registerLockscreenDispatch(new INfcLockscreenDispatch.Stub() {
@Override
public boolean onTagDetected(Tag tag) throws RemoteException {
return lockscreenDispatch.onTagDetected(tag);
}
- }, techList);
+ }, Tag.techListFromStrings(techList));
} catch (RemoteException e) {
attemptDeadServiceRecovery(e);
return false;
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Unable to register LockscreenDispatch", e);
+ return false;
}
return true;
diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java
index 0d261d1..43be702 100644
--- a/core/java/android/nfc/Tag.java
+++ b/core/java/android/nfc/Tag.java
@@ -35,6 +35,7 @@
import java.io.IOException;
import java.util.Arrays;
+import java.util.HashMap;
/**
* Represents an NFC tag that has been discovered.
@@ -195,6 +196,41 @@
return strings;
}
+ static int[] techListFromStrings(String[] techStringList) throws IllegalArgumentException {
+ if (techStringList == null) {
+ throw new IllegalArgumentException("List cannot be null");
+ }
+ int[] techIntList = new int[techStringList.length];
+ HashMap<String, Integer> stringToCodeMap = getTechStringToCodeMap();
+ for (int i = 0; i < techStringList.length; i++) {
+ Integer code = stringToCodeMap.get(techStringList[i]);
+
+ if (code == null) {
+ throw new IllegalArgumentException("Unknown tech type " + techStringList[i]);
+ }
+
+ techIntList[i] = code.intValue();
+ }
+ return techIntList;
+ }
+
+ private static HashMap<String, Integer> getTechStringToCodeMap() {
+ HashMap<String, Integer> techStringToCodeMap = new HashMap<String, Integer>();
+
+ techStringToCodeMap.put(IsoDep.class.getName(), TagTechnology.ISO_DEP);
+ techStringToCodeMap.put(MifareClassic.class.getName(), TagTechnology.MIFARE_CLASSIC);
+ techStringToCodeMap.put(MifareUltralight.class.getName(), TagTechnology.MIFARE_ULTRALIGHT);
+ techStringToCodeMap.put(Ndef.class.getName(), TagTechnology.NDEF);
+ techStringToCodeMap.put(NdefFormatable.class.getName(), TagTechnology.NDEF_FORMATABLE);
+ techStringToCodeMap.put(NfcA.class.getName(), TagTechnology.NFC_A);
+ techStringToCodeMap.put(NfcB.class.getName(), TagTechnology.NFC_B);
+ techStringToCodeMap.put(NfcF.class.getName(), TagTechnology.NFC_F);
+ techStringToCodeMap.put(NfcV.class.getName(), TagTechnology.NFC_V);
+ techStringToCodeMap.put(NfcBarcode.class.getName(), TagTechnology.NFC_BARCODE);
+
+ return techStringToCodeMap;
+ }
+
/**
* For use by NfcService only.
* @hide