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

Commit e9c57ef7 authored by Daniel Akinola's avatar Daniel Akinola
Browse files

Hide desktop option from connecion dialog in kiosk mode

When connecting an external display to a device in kiosk mode, we want
to hide the "desktop" option and only allow the device to go into
mirroring.

Bug: 429288575
Flag: com.android.window.flags.enable_updated_display_connection_dialog
Test: ExternalDisplayDialogDelegateScreenshotTest
Change-Id: I3c5eb55d8ef93d2d8a72b685e7ef2a47ceaba2a9
parent 2a22330b
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ class ExternalDisplayConnectionDialogDelegate
@AssistedInject
constructor(
    @Application private val context: Context,
    @Assisted private val showConcurrentDisplayInfo: Boolean = false,
    @Assisted("showConcurrentDisplayInfo") private val showConcurrentDisplayInfo: Boolean = false,
    @Assisted("isInKioskMode") private val isInKioskMode: Boolean = false,
    @Assisted private val rememberChoiceCheckBoxListener: CompoundButton.OnCheckedChangeListener,
    @Assisted("onStartDesktop") private val onStartDesktopClickListener: View.OnClickListener,
    @Assisted("onStartMirroring") private val onStartMirroringClickListener: View.OnClickListener,
@@ -79,15 +80,25 @@ constructor(

        desktopButton =
            dialog.requireViewById<Button>(R.id.start_desktop_mode).apply {
                setOnClickListener(onStartDesktopClickListener)
                if (isInKioskMode) {
                    visibility = View.GONE
                } else {
                    visibility = View.VISIBLE
                    setOnClickListener {
                        optionSelected = true
                        onStartDesktopClickListener.onClick(this)
                    }
                }
            }

        mirrorButton =
            dialog.requireViewById<Button>(R.id.start_mirroring).apply {
                setOnClickListener(onStartMirroringClickListener)
                setOnClickListener {
                    optionSelected = true
                    onStartMirroringClickListener.onClick(this)
                }
            }

        dismissButton =
            dialog.requireViewById<Button>(R.id.cancel).apply {
                setOnClickListener(onCancelClickListener)
@@ -159,7 +170,8 @@ constructor(
    @AssistedFactory
    interface Factory {
        fun create(
            showConcurrentDisplayInfo: Boolean,
            @Assisted("showConcurrentDisplayInfo") showConcurrentDisplayInfo: Boolean,
            @Assisted("isInKioskMode") isInKioskMode: Boolean,
            rememberChoiceCheckBoxListener: CompoundButton.OnCheckedChangeListener,
            @Assisted("onStartDesktop") onStartDesktopClickListener: View.OnClickListener,
            @Assisted("onStartMirroring") onStartMirroringClickListener: View.OnClickListener,
+16 −5
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.systemui.display.ui.viewmodel

import android.app.ActivityManager
import android.app.ActivityManager.LOCK_TASK_MODE_LOCKED
import android.app.Dialog
import android.content.Context
import android.provider.Settings.Secure.MIRROR_BUILT_IN_DISPLAY
@@ -73,6 +75,7 @@ constructor(
    private val context: Context,
    private val desktopState: DesktopState,
    private val secureSettings: SecureSettings,
    private val activityManager: ActivityManager,
    private val connectedDisplayInteractor: ConnectedDisplayInteractor,
    @Application private val scope: CoroutineScope,
    @Background private val bgDispatcher: CoroutineDispatcher,
@@ -137,7 +140,10 @@ constructor(
                .apply { show() }
    }

    private fun PendingDisplay.showNewDialog(showConcurrentDisplayInfo: Boolean) {
    private fun PendingDisplay.showNewDialog(
        showConcurrentDisplayInfo: Boolean,
        isInKioskMode: Boolean,
    ) {
        var saveChoice = false
        dismissDialog()

@@ -152,6 +158,7 @@ constructor(
                },
                insetsProvider = { getInsetsOf(context, displayCutout() or navigationBars()) },
                showConcurrentDisplayInfo = showConcurrentDisplayInfo,
                isInKioskMode = isInKioskMode,
            )

        dialog =
@@ -173,14 +180,20 @@ constructor(
            return
        }

        if (isInExtendedMode()) {
        val isInKioskMode = activityManager.lockTaskModeState == LOCK_TASK_MODE_LOCKED
        val isInExtendedMode = desktopState.isDesktopModeSupportedOnDisplay(DEFAULT_DISPLAY)

        if (isInKioskMode) {
            pendingDisplay.showNewDialog(concurrentDisplaysInProgress, isInKioskMode)
        } else if (isInExtendedMode) {
            pendingDisplay.enableForDesktop()
            showExtendedDisplayConnectionToast()
        } else {
            when (pendingDisplay.connectionType) {
                DESKTOP -> pendingDisplay.enableForDesktop()
                MIRROR -> pendingDisplay.enableForMirroring()
                NOT_SPECIFIED -> pendingDisplay.showNewDialog(concurrentDisplaysInProgress)
                NOT_SPECIFIED ->
                    pendingDisplay.showNewDialog(concurrentDisplaysInProgress, isInKioskMode)
            }
        }
    }
@@ -231,8 +244,6 @@ constructor(
        dialog = null
    }

    private fun isInExtendedMode() = desktopState.isDesktopModeSupportedOnDisplay(DEFAULT_DISPLAY)

    private fun showExtendedDisplayConnectionToast() =
        Toast.makeText(context, R.string.connected_display_extended_mode_text, LENGTH_LONG).show()