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

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

Fix issue where unlock handlers are not properly updated

If an unlock handler already exists, we need to try
to update the tech mask for it. Don't permit unlock
handlers with no tech mask.

Bug: 17054331
Change-Id: I54a885d28bdd8ce41d8646d968621c7d6abc9387
parent 9fde9a25
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -59,5 +59,5 @@ interface INfcAdapter

    void registerLockscreenDispatch(INfcLockscreenDispatch lockscreenDispatch, in int[] techList);
    void addNfcUnlockHandler(INfcUnlockHandler unlockHandler, in int[] techList);
    void removeNfcUnlockHandler(IBinder b);
    void removeNfcUnlockHandler(INfcUnlockHandler unlockHandler);
}
+24 −15
Original line number Diff line number Diff line
@@ -311,7 +311,7 @@ public final class NfcAdapter {

    final NfcActivityManager mNfcActivityManager;
    final Context mContext;
    final HashMap<NfcUnlockHandler, IBinder> mNfcUnlockHandlers;
    final HashMap<NfcUnlockHandler, INfcUnlockHandler> mNfcUnlockHandlers;
    final Object mLock;

    /**
@@ -542,7 +542,7 @@ public final class NfcAdapter {
    NfcAdapter(Context context) {
        mContext = context;
        mNfcActivityManager = new NfcActivityManager(this);
        mNfcUnlockHandlers = new HashMap<NfcUnlockHandler, IBinder>();
        mNfcUnlockHandlers = new HashMap<NfcUnlockHandler, INfcUnlockHandler>();
        mLock = new Object();
    }

@@ -1498,14 +1498,27 @@ public final class NfcAdapter {
     * <p /> The parameter {@code tagTechnologies} determines which Tag technologies will be polled for
     * at the lockscreen. Polling for less tag technologies reduces latency, and so it is
     * strongly recommended to only provide the Tag technologies that the handler is expected to
     * receive.
     * receive. There must be at least one tag technology provided, otherwise the unlock handler
     * is ignored.
     *
     * @hide
     */
    @SystemApi
    public boolean addNfcUnlockHandler(final NfcUnlockHandler unlockHandler,
                                       String[] tagTechnologies) {
        // If there are no tag technologies, don't bother adding unlock handler
        if (tagTechnologies.length == 0) {
            return false;
        }

        try {
            synchronized (mLock) {
                if (mNfcUnlockHandlers.containsKey(unlockHandler)) {
                    // update the tag technologies
                    sService.removeNfcUnlockHandler(mNfcUnlockHandlers.get(unlockHandler));
                    mNfcUnlockHandlers.remove(unlockHandler);
                }

                INfcUnlockHandler.Stub iHandler = new INfcUnlockHandler.Stub() {
                    @Override
                    public boolean onUnlockAttempted(Tag tag) throws RemoteException {
@@ -1513,12 +1526,9 @@ public final class NfcAdapter {
                    }
                };

            synchronized (mLock) {
                if (mNfcUnlockHandlers.containsKey(unlockHandler)) {
                    return true;
                }
                sService.addNfcUnlockHandler(iHandler, Tag.getTechCodesFromStrings(tagTechnologies));
                mNfcUnlockHandlers.put(unlockHandler, iHandler.asBinder());
                sService.addNfcUnlockHandler(iHandler,
                        Tag.getTechCodesFromStrings(tagTechnologies));
                mNfcUnlockHandlers.put(unlockHandler, iHandler);
            }
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
@@ -1542,8 +1552,7 @@ public final class NfcAdapter {
        try {
            synchronized (mLock) {
                if (mNfcUnlockHandlers.containsKey(unlockHandler)) {
                    sService.removeNfcUnlockHandler(mNfcUnlockHandlers.get(unlockHandler));
                    mNfcUnlockHandlers.remove(unlockHandler);
                    sService.removeNfcUnlockHandler(mNfcUnlockHandlers.remove(unlockHandler));
                }

                return true;