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

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

Merge "Don't dismiss the keyguard from the binder thread" into tm-qpr-dev am:...

Merge "Don't dismiss the keyguard from the binder thread" into tm-qpr-dev am: 2aea66b3 am: 0315de8d

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



Change-Id: I2b5ebb4df79a6f8187a1850c76e05cf9c5c1f741
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e56781a7 0315de8d
Loading
Loading
Loading
Loading
+26 −12
Original line number Diff line number Diff line
@@ -15,12 +15,17 @@
 */
package com.android.systemui.screenshot

import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.shade.ShadeExpansionStateManager
import com.android.systemui.statusbar.phone.CentralSurfaces
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Optional
import javax.inject.Inject

@@ -30,7 +35,8 @@ import javax.inject.Inject
internal class ScreenshotProxyService @Inject constructor(
    private val mExpansionMgr: ShadeExpansionStateManager,
    private val mCentralSurfacesOptional: Optional<CentralSurfaces>,
) : Service() {
    @Main private val mMainDispatcher: CoroutineDispatcher,
) : LifecycleService() {

    private val mBinder: IBinder = object : IScreenshotProxy.Stub() {
        /**
@@ -43,18 +49,26 @@ internal class ScreenshotProxyService @Inject constructor(
        }

        override fun dismissKeyguard(callback: IOnDoneCallback) {
            if (mCentralSurfacesOptional.isPresent) {
                mCentralSurfacesOptional.get().executeRunnableDismissingKeyguard(
            lifecycleScope.launch {
                executeAfterDismissing(callback)
            }
        }
    }

    private suspend fun executeAfterDismissing(callback: IOnDoneCallback) =
        withContext(mMainDispatcher) {
            mCentralSurfacesOptional.ifPresentOrElse(
                    {
                        it.executeRunnableDismissingKeyguard(
                                Runnable {
                                    callback.onDone(true)
                                }, null,
                                true /* dismissShade */, true /* afterKeyguardGone */,
                                true /* deferred */
                        )
            } else {
                callback.onDone(false)
            }
        }
                    },
                    { callback.onDone(false) }
            )
        }

    override fun onBind(intent: Intent): IBinder? {