From 233b5d2188c1f55ece7ad6882d0b0e9d5062a496 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Mon, 7 Nov 2022 18:54:57 +0000 Subject: [PATCH] Don't dismiss the keyguard from the binder thread It doesn't work when called from the binder thread (see bug). Bug: 257974574 Test: Launch a screenshot action from the lockscreen, verify that bouncer appears before action is completed. Change-Id: I2eb974fc82d8434e9f0df57aea123ae62f18260e --- .../screenshot/ScreenshotProxyService.kt | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt index c41e2bc14afc4..4cb91e1340031 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt @@ -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, -) : Service() { + @Main private val mMainDispatcher: CoroutineDispatcher, +) : LifecycleService() { private val mBinder: IBinder = object : IScreenshotProxy.Stub() { /** @@ -43,20 +49,28 @@ internal class ScreenshotProxyService @Inject constructor( } override fun dismissKeyguard(callback: IOnDoneCallback) { - if (mCentralSurfacesOptional.isPresent) { - mCentralSurfacesOptional.get().executeRunnableDismissingKeyguard( - Runnable { - callback.onDone(true) - }, null, - true /* dismissShade */, true /* afterKeyguardGone */, - true /* deferred */ - ) - } else { - callback.onDone(false) + 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 */ + ) + }, + { callback.onDone(false) } + ) + } + override fun onBind(intent: Intent): IBinder? { Log.d(TAG, "onBind: $intent") return mBinder