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

Commit 0180d5bf authored by burakov's avatar burakov Committed by Danny Burakov
Browse files

[flexiglass] Force garbage collection after successful authentication.

Fix: 308826153
Test: Unit tests updated and still pass.
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: Ib7612896983d6eefa7c8729fa51ecf1e21d27c0b
parent 9dda4cc1
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * Hosts application business logic related to user authentication.
@@ -227,6 +228,10 @@ constructor(
            // Since authentication succeeded, we should refresh throttling to make sure that our
            // state is completely reflecting the upstream source of truth.
            refreshThrottling()

            // Force a garbage collection in an attempt to erase any credentials left in memory.
            // Do it after a 5-sec delay to avoid making the bouncer dismiss animation janky.
            initiateGarbageCollection(delayMs = 5000)
        }

        return if (authenticationResult.isSuccessful) {
@@ -310,6 +315,15 @@ constructor(
        }
    }

    private suspend fun initiateGarbageCollection(delayMs: Long) {
        withContext(backgroundDispatcher) {
            delay(delayMs)
            System.gc()
            System.runFinalization()
            System.gc()
        }
    }

    companion object {
        const val TAG = "AuthenticationInteractor"
    }