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

Commit d5860a21 authored by Chris Göllner's avatar Chris Göllner Committed by Chris Göllner
Browse files

[Media Projection] Use plain AlertDialog for 3rd party hosts instead of SystemUIDialog

This will fix a crash in Android Automotive CTS tests, where a sysui
dependency is being pulled in, and trying to create a window that
has already been created, and causing a crash.

We have done this change before (ag/25220221) for the main permission dialog, but not
for the ScreenCaptureDisabledDialog.

Test: Manual
Test: Unit tests in this CL
Fixes: 328847021
Fixes: 330661784
Flag: NONE
Change-Id: I297ef751c88909d1f351eac87c91c7bdff35ecf5
parent 5060389b
Loading
Loading
Loading
Loading
+24 −11
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.systemui.mediaprojection.devicepolicy

import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface.BUTTON_POSITIVE
import android.content.res.Resources
import com.android.systemui.dagger.qualifiers.Main
@@ -23,22 +25,33 @@ import com.android.systemui.statusbar.phone.SystemUIDialog
import javax.inject.Inject

/** Dialog that shows that screen capture is disabled on this device. */
class ScreenCaptureDisabledDialogDelegate @Inject constructor(
class ScreenCaptureDisabledDialogDelegate
@Inject
constructor(
    private val context: Context,
    @Main private val resources: Resources,
        private val systemUIDialogFactory: SystemUIDialog.Factory
) : SystemUIDialog.Delegate {
) {

    override fun createDialog(): SystemUIDialog {
        val dialog = systemUIDialogFactory.create(this)
        dialog.setTitle(resources.getString(R.string.screen_capturing_disabled_by_policy_dialog_title))
    fun createPlainDialog(): AlertDialog {
        return AlertDialog.Builder(context, R.style.Theme_SystemUI_Dialog).create().also {
            initDialog(it)
        }
    }

    fun createSysUIDialog(): AlertDialog {
        return SystemUIDialog(context).also { initDialog(it) }
    }

    private fun initDialog(dialog: AlertDialog) {
        dialog.setTitle(
            resources.getString(R.string.screen_capturing_disabled_by_policy_dialog_title)
        )
        dialog.setMessage(
            resources.getString(R.string.screen_capturing_disabled_by_policy_dialog_description)
        )
        dialog.setIcon(R.drawable.ic_cast)
        dialog.setButton(BUTTON_POSITIVE, resources.getString(android.R.string.ok)) {
            _, _ -> dialog.cancel()
        dialog.setButton(BUTTON_POSITIVE, resources.getString(android.R.string.ok)) { _, _ ->
            dialog.cancel()
        }

        return dialog
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -319,7 +319,7 @@ public class MediaProjectionPermissionActivity extends Activity
        final UserHandle hostUserHandle = getHostUserHandle();
        if (mScreenCaptureDevicePolicyResolver.get()
                .isScreenCaptureCompletelyDisabled(hostUserHandle)) {
            AlertDialog dialog = mScreenCaptureDisabledDialogDelegate.createDialog();
            AlertDialog dialog = mScreenCaptureDisabledDialogDelegate.createPlainDialog();
            setUpDialog(dialog);
            dialog.show();
            return true;
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ constructor(
                    .isScreenCaptureCompletelyDisabled(UserHandle.of(userTracker.userId))
        ) {
            mainExecutor.execute {
                screenCaptureDisabledDialogDelegate.createDialog().show()
                screenCaptureDisabledDialogDelegate.createSysUIDialog().show()
                screenRecordSwitch.isChecked = false
            }
            return
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ public class RecordingController
        if (mFlags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING_ENTERPRISE_POLICIES)
                && mDevicePolicyResolver.get()
                        .isScreenCaptureCompletelyDisabled(getHostUserHandle())) {
            return mScreenCaptureDisabledDialogDelegate.createDialog();
            return mScreenCaptureDisabledDialogDelegate.createSysUIDialog();
        }

        mMediaProjectionMetricsLogger.notifyProjectionInitiated(
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ class RecordIssueDialogDelegateTest : SysuiTestCase() {
        MockitoAnnotations.initMocks(this)
        whenever(dprLazy.get()).thenReturn(devicePolicyResolver)
        whenever(sysuiState.setFlag(anyInt(), anyBoolean())).thenReturn(sysuiState)
        whenever(screenCaptureDisabledDialogDelegate.createDialog())
        whenever(screenCaptureDisabledDialogDelegate.createSysUIDialog())
            .thenReturn(screenCaptureDisabledDialog)
        whenever(
                userFileManager.getSharedPreferences(
Loading