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

Commit fceb7ecc authored by Mark Renouf's avatar Mark Renouf Committed by Android (Google) Code Review
Browse files

Merge "Update screenshot action system window dismiss fix" into main

parents 057d218e d30667a5
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -469,6 +469,17 @@ flag {
    bug: "309933761"
}

flag {
    name: "fix_screenshot_action_dismiss_system_windows"
    namespace: "systemui"
    description: "Dismiss existing system windows when starting action from screenshot UI"
    bug: "309933761"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}


flag {
    name: "screenshot_private_profile_behavior_fix"
    namespace: "systemui"
+5 −27
Original line number Diff line number Diff line
@@ -33,10 +33,11 @@ import android.view.WindowManager
import android.view.WindowManagerGlobal
import com.android.app.tracing.coroutines.launch
import com.android.internal.infra.ServiceConnector
import com.android.systemui.Flags.screenshotActionDismissSystemWindows
import com.android.systemui.Flags
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.screenshot.proxy.SystemUiProxy
import com.android.systemui.settings.DisplayTracker
import com.android.systemui.shared.system.ActivityManagerWrapper
import com.android.systemui.statusbar.phone.CentralSurfaces
@@ -54,8 +55,8 @@ constructor(
    private val activityManagerWrapper: ActivityManagerWrapper,
    @Application private val applicationScope: CoroutineScope,
    @Main private val mainDispatcher: CoroutineDispatcher,
    private val systemUiProxy: SystemUiProxy,
    private val displayTracker: DisplayTracker,
    private val keyguardController: ScreenshotKeyguardController,
) {
    /**
     * Execute the given intent with startActivity while performing operations for screenshot action
@@ -83,14 +84,12 @@ constructor(
        options: ActivityOptions?,
        transitionCoordinator: ExitTransitionCoordinator?,
    ) {
        if (screenshotActionDismissSystemWindows()) {
            keyguardController.dismiss()
        if (Flags.fixScreenshotActionDismissSystemWindows()) {
            activityManagerWrapper.closeSystemWindows(
                CentralSurfaces.SYSTEM_DIALOG_REASON_SCREENSHOT
            )
        } else {
            dismissKeyguard()
        }
        systemUiProxy.dismissKeyguard()
        transitionCoordinator?.startExit()

        if (user == myUserHandle()) {
@@ -110,27 +109,6 @@ constructor(
        }
    }

    private val proxyConnector: ServiceConnector<IScreenshotProxy> =
        ServiceConnector.Impl(
            context,
            Intent(context, ScreenshotProxyService::class.java),
            Context.BIND_AUTO_CREATE or Context.BIND_WAIVE_PRIORITY or Context.BIND_NOT_VISIBLE,
            context.userId,
            IScreenshotProxy.Stub::asInterface,
        )

    private suspend fun dismissKeyguard() {
        val completion = CompletableDeferred<Unit>()
        val onDoneBinder =
            object : IOnDoneCallback.Stub() {
                override fun onDone(success: Boolean) {
                    completion.complete(Unit)
                }
            }
        proxyConnector.post { it.dismissKeyguard(onDoneBinder) }
        completion.await()
    }

    private fun getCrossProfileConnector(user: UserHandle): ServiceConnector<ICrossProfileService> =
        ServiceConnector.Impl<ICrossProfileService>(
            context,
+0 −46
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.screenshot

import android.content.Context
import android.content.Intent
import com.android.internal.infra.ServiceConnector
import javax.inject.Inject
import kotlinx.coroutines.CompletableDeferred

open class ScreenshotKeyguardController @Inject constructor(context: Context) {
    private val proxyConnector: ServiceConnector<IScreenshotProxy> =
        ServiceConnector.Impl(
            context,
            Intent(context, ScreenshotProxyService::class.java),
            Context.BIND_AUTO_CREATE or Context.BIND_WAIVE_PRIORITY or Context.BIND_NOT_VISIBLE,
            context.userId,
            IScreenshotProxy.Stub::asInterface
        )

    suspend fun dismiss() {
        val completion = CompletableDeferred<Unit>()
        val onDoneBinder =
            object : IOnDoneCallback.Stub() {
                override fun onDone(success: Boolean) {
                    completion.complete(Unit)
                }
            }
        proxyConnector.post { it.dismissKeyguard(onDoneBinder) }
        completion.await()
    }
}
+7 −5
Original line number Diff line number Diff line
@@ -23,17 +23,18 @@ import android.testing.AndroidTestingRunner
import android.testing.TestableContext
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.screenshot.proxy.SystemUiProxy
import com.android.systemui.settings.DisplayTracker
import com.android.systemui.shared.system.ActivityManagerWrapper
import com.android.systemui.statusbar.phone.CentralSurfaces
import com.android.systemui.util.mockito.mock
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestCoroutineScheduler
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.verify
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

@RunWith(AndroidTestingRunner::class)
class ActionIntentExecutorTest : SysuiTestCase() {
@@ -44,8 +45,9 @@ class ActionIntentExecutorTest : SysuiTestCase() {
    private val testableContext = TestableContext(mContext)

    private val activityManagerWrapper = mock<ActivityManagerWrapper>()
    private val systemUiProxy = mock<SystemUiProxy>()

    private val displayTracker = mock<DisplayTracker>()
    private val keyguardController = mock<ScreenshotKeyguardController>()

    private val actionIntentExecutor =
        ActionIntentExecutor(
@@ -53,12 +55,12 @@ class ActionIntentExecutorTest : SysuiTestCase() {
            activityManagerWrapper,
            testScope,
            mainDispatcher,
            systemUiProxy,
            displayTracker,
            keyguardController,
        )

    @Test
    @EnableFlags(Flags.FLAG_SCREENSHOT_ACTION_DISMISS_SYSTEM_WINDOWS)
    @EnableFlags(Flags.FLAG_FIX_SCREENSHOT_ACTION_DISMISS_SYSTEM_WINDOWS)
    fun launchIntent_callsCloseSystemWindows() =
        testScope.runTest {
            val intent = Intent(Intent.ACTION_EDIT).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK }