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

Commit e6b63e6c authored by Andres Morales's avatar Andres Morales Committed by Android (Google) Code Review
Browse files

Merge "Fix issue where unlock handlers are not properly updated" into lmp-dev

parents 89147ed8 f9a97942
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;