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

Commit ef2ba721 authored by Nate Myren's avatar Nate Myren
Browse files

Flush binders in Async LiveData

Ensure binders are released by liveDatas that use coroutines. Also
changes thread pool size from 16 to 8, in order to help avoid binder
exhaustion.

Fixes: 153603849
Fixes: 158207248
Test: I wish. Everything still works, and "adb shell cat
/d/binder/proc/$pid" shows fewer completed but not released binder
allocations.

Change-Id: If4561fd304adace419e27e871980322b3ccb8c04
parent 26f2ff20
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.permissioncontroller.permission.data

import android.os.Binder
import com.android.permissioncontroller.permission.utils.IPC
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.GlobalScope
@@ -55,6 +56,8 @@ abstract class SmartAsyncMediatorLiveData<T> : SmartUpdateMediatorLiveData<T>()
        GlobalScope.launch(IPC) {
            currentJob = coroutineContext[Job]
            loadDataAndPostValue(currentJob!!)
            // TODO ntmyren: generalize this command to the IPC dispatcher
            Binder.flushPendingCommands()
            jobRunning = false
            if (jobQueued) {
                jobQueued = false
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ val Context.application: Application get() = when (this) {
 * The number of threads in the IPC thread pool. Set to the maximum number of binder threads allowed
 * to an app by the Android System.
 */
const val IPC_THREAD_POOL_COUNT = 16
const val IPC_THREAD_POOL_COUNT = 8

/**
 * A coroutine dispatcher with a fixed thread pool size, to be used for background tasks