Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8cf53f8 authored by Andres Morales's avatar Andres Morales
Browse files

Make unlock api take String instead of int codes

int code method not exposed to third parties

Change-Id: I18ad0703be9d06664db3fd00a6435f789979fe73
parent 07a9e2cb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17664,7 +17664,7 @@ package android.nfc {
    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...);
+5 −2
Original line number Diff line number Diff line
@@ -1428,17 +1428,20 @@ public final class NfcAdapter {
    }

    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;
+36 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.RemoteException;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;

/**
 * Represents an NFC tag that has been discovered.
@@ -195,6 +196,41 @@ public final class Tag implements Parcelable {
        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