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

Commit e1bde69d authored by Aaron Liu's avatar Aaron Liu
Browse files

Do not pass in anon callback.

The anon callback gets deferenced after the first few calls. Make sure
that it is a class field. Also update the documentation to reflect this.

There are no known bugs due to this, but proactively fixing this to
avoid unintended behavior.

Bug: 267821080
Test: add logs to see if the callbacks are called continuously.
onBiometricRunningStateChanged is called pretty much every time we go to
LS and leave LS.

Change-Id: If7fb2450f9025b85a30a10612966561c020ec865
parent 65247012
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -3620,7 +3620,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
     * Register to receive notifications about general keyguard information
     * (see {@link KeyguardUpdateMonitorCallback}.
     *
     * @param callback The callback to register
     * @param callback The callback to register. Stay away from passing anonymous instances
     *                 as they will likely be dereferenced. Ensure that the callback is a class
     *                 field to persist it.
     */
    public void registerCallback(KeyguardUpdateMonitorCallback callback) {
        Assert.isMainThread();
+17 −14
Original line number Diff line number Diff line
@@ -122,9 +122,10 @@ constructor(
    val isInteractable: Flow<Boolean> = bouncerExpansion.map { it > 0.9 }
    val sideFpsShowing: Flow<Boolean> = repository.sideFpsShowing

    init {
        keyguardUpdateMonitor.registerCallback(
            object : KeyguardUpdateMonitorCallback() {
    /**
     * This callback needs to be a class field so it does not get garbage collected.
     */
    val keyguardUpdateMonitorCallback = object : KeyguardUpdateMonitorCallback() {
        override fun onBiometricRunningStateChanged(
            running: Boolean,
            biometricSourceType: BiometricSourceType?
@@ -136,7 +137,9 @@ constructor(
            updateSideFpsVisibility()
        }
    }
        )

    init {
        keyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback)
    }

    // TODO(b/243685699): Move isScrimmed logic to data layer.