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

Commit 5b11cac4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Kill off callback reference as soon as credential is verified" into...

Merge "Kill off callback reference as soon as credential is verified" into rvc-dev am: 998df4f3 am: 13dbfb28

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11721688

Change-Id: Ia96be987943252256f1b0ad7d5cd889988ae0cbf
parents 2ae1cfc8 13dbfb28
Loading
Loading
Loading
Loading
+27 −7
Original line number Original line Diff line number Diff line
@@ -1430,6 +1430,32 @@ public class LockPatternUtils {
                == StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
                == StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
    }
    }


    private static class WrappedCallback extends ICheckCredentialProgressCallback.Stub {

        private Handler mHandler;
        private CheckCredentialProgressCallback mCallback;

        WrappedCallback(Handler handler, CheckCredentialProgressCallback callback) {
            mHandler = handler;
            mCallback = callback;
        }

        @Override
        public void onCredentialVerified() throws RemoteException {
            if (mHandler == null) {
                Log.e(TAG, "Handler is null during callback");
            }
            // Kill reference immediately to allow early GC at client side independent of
            // when system_server decides to lose its reference to the
            // ICheckCredentialProgressCallback binder object.
            mHandler.post(() -> {
                mCallback.onEarlyMatched();
                mCallback = null;
            });
            mHandler = null;
        }
    }

    private ICheckCredentialProgressCallback wrapCallback(
    private ICheckCredentialProgressCallback wrapCallback(
            final CheckCredentialProgressCallback callback) {
            final CheckCredentialProgressCallback callback) {
        if (callback == null) {
        if (callback == null) {
@@ -1439,13 +1465,7 @@ public class LockPatternUtils {
                throw new IllegalStateException("Must construct LockPatternUtils on a looper thread"
                throw new IllegalStateException("Must construct LockPatternUtils on a looper thread"
                        + " to use progress callbacks.");
                        + " to use progress callbacks.");
            }
            }
            return new ICheckCredentialProgressCallback.Stub() {
            return new WrappedCallback(mHandler, callback);

                @Override
                public void onCredentialVerified() throws RemoteException {
                    mHandler.post(callback::onEarlyMatched);
                }
            };
        }
        }
    }
    }