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

Commit e17b8794 authored by yyalan's avatar yyalan Committed by Yalan Yiue
Browse files

[Partial Screensharing] Hide 'show touches' in SysUI Recorder

Disable and hide 'Show Touches' Switch when Single App is selected as the screen share option.

Bug: 241366482
Test: com.android.systemui.screenrecord.ScreenRecordPermissionDialogTest
Change-Id: I7344669b0a08ea971c76950bac429152711f3fda
parent d8251475
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@
            android:importantForAccessibility="yes"/>
            android:importantForAccessibility="yes"/>
    </LinearLayout>
    </LinearLayout>
    <LinearLayout
    <LinearLayout
        android:id="@+id/show_taps"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:orientation="horizontal"
+18 −7
Original line number Original line Diff line number Diff line
@@ -24,8 +24,9 @@ import android.os.Handler
import android.os.Looper
import android.os.Looper
import android.os.ResultReceiver
import android.os.ResultReceiver
import android.view.View
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.AdapterView
import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.ArrayAdapter
import android.widget.ArrayAdapter
import android.widget.Spinner
import android.widget.Spinner
import android.widget.Switch
import android.widget.Switch
@@ -47,6 +48,7 @@ class ScreenRecordPermissionDialog(
    private val onStartRecordingClicked: Runnable?
    private val onStartRecordingClicked: Runnable?
) : BaseScreenSharePermissionDialog(context, createOptionList(), null) {
) : BaseScreenSharePermissionDialog(context, createOptionList(), null) {
    private lateinit var tapsSwitch: Switch
    private lateinit var tapsSwitch: Switch
    private lateinit var tapsView: View
    private lateinit var audioSwitch: Switch
    private lateinit var audioSwitch: Switch
    private lateinit var options: Spinner
    private lateinit var options: Spinner
    override fun onCreate(savedInstanceState: Bundle?) {
    override fun onCreate(savedInstanceState: Bundle?) {
@@ -84,16 +86,25 @@ class ScreenRecordPermissionDialog(
    private fun initRecordOptionsView() {
    private fun initRecordOptionsView() {
        audioSwitch = findViewById(R.id.screenrecord_audio_switch)
        audioSwitch = findViewById(R.id.screenrecord_audio_switch)
        tapsSwitch = findViewById(R.id.screenrecord_taps_switch)
        tapsSwitch = findViewById(R.id.screenrecord_taps_switch)
        tapsView = findViewById(R.id.show_taps)
        updateTapsViewVisibility()
        options = findViewById(R.id.screen_recording_options)
        options = findViewById(R.id.screen_recording_options)
        val a: ArrayAdapter<*> =
        val a: ArrayAdapter<*> =
            ScreenRecordingAdapter(context, android.R.layout.simple_spinner_dropdown_item, MODES)
            ScreenRecordingAdapter(context, android.R.layout.simple_spinner_dropdown_item, MODES)
        a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        options.adapter = a
        options.adapter = a
        options.setOnItemClickListenerInt(
        options.setOnItemClickListenerInt { _: AdapterView<*>?, _: View?, _: Int, _: Long ->
            OnItemClickListener { _: AdapterView<*>?, _: View?, _: Int, _: Long ->
            audioSwitch.isChecked = true
            audioSwitch.isChecked = true
        }
        }
        )
    }

    override fun onItemSelected(adapterView: AdapterView<*>?, view: View, pos: Int, id: Long) {
        super.onItemSelected(adapterView, view, pos, id)
        updateTapsViewVisibility()
    }

    private fun updateTapsViewVisibility() {
        tapsView.visibility = if (selectedScreenShareOption.mode == SINGLE_APP) GONE else VISIBLE
    }
    }


    /**
    /**
@@ -103,7 +114,7 @@ class ScreenRecordPermissionDialog(
     */
     */
    private fun requestScreenCapture(captureTarget: MediaProjectionCaptureTarget?) {
    private fun requestScreenCapture(captureTarget: MediaProjectionCaptureTarget?) {
        val userContext = userContextProvider.userContext
        val userContext = userContextProvider.userContext
        val showTaps = tapsSwitch.isChecked
        val showTaps = selectedScreenShareOption.mode != SINGLE_APP && tapsSwitch.isChecked
        val audioMode =
        val audioMode =
            if (audioSwitch.isChecked) options.selectedItem as ScreenRecordingAudioSource
            if (audioSwitch.isChecked) options.selectedItem as ScreenRecordingAudioSource
            else ScreenRecordingAudioSource.NONE
            else ScreenRecordingAudioSource.NONE
+109 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 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.screenrecord

import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.view.View
import android.widget.Spinner
import androidx.test.filters.SmallTest
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.DialogLaunchAnimator
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserContextProvider
import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations

@SmallTest
@RunWith(AndroidTestingRunner::class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class ScreenRecordPermissionDialogTest : SysuiTestCase() {

    @Mock private lateinit var starter: ActivityStarter
    @Mock private lateinit var controller: RecordingController
    @Mock private lateinit var userContextProvider: UserContextProvider
    @Mock private lateinit var flags: FeatureFlags
    @Mock private lateinit var dialogLaunchAnimator: DialogLaunchAnimator
    @Mock private lateinit var onStartRecordingClicked: Runnable

    private lateinit var dialog: ScreenRecordPermissionDialog

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)

        dialog =
            ScreenRecordPermissionDialog(
                context,
                controller,
                starter,
                dialogLaunchAnimator,
                userContextProvider,
                onStartRecordingClicked
            )
        dialog.onCreate(null)
        whenever(flags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)).thenReturn(true)
    }

    @After
    fun teardown() {
        if (::dialog.isInitialized) {
            dialog.dismiss()
        }
    }

    @Test
    fun testShowDialog_partialScreenSharingEnabled_optionsSpinnerIsVisible() {
        dialog.show()

        val visibility = dialog.requireViewById<Spinner>(R.id.screen_share_mode_spinner).visibility
        assertThat(visibility).isEqualTo(View.VISIBLE)
    }

    @Test
    fun testShowDialog_singleAppSelected_showTapsIsGone() {
        dialog.show()
        onSpinnerItemSelected(SINGLE_APP)

        val visibility = dialog.requireViewById<View>(R.id.show_taps).visibility
        assertThat(visibility).isEqualTo(View.GONE)
    }

    @Test
    fun testShowDialog_entireScreenSelected_showTapsIsVisible() {
        dialog.show()
        onSpinnerItemSelected(ENTIRE_SCREEN)

        val visibility = dialog.requireViewById<View>(R.id.show_taps).visibility
        assertThat(visibility).isEqualTo(View.VISIBLE)
    }

    private fun onSpinnerItemSelected(position: Int) {
        val spinner = dialog.requireViewById<Spinner>(R.id.screen_share_mode_spinner)
        spinner.onItemSelectedListener.onItemSelected(spinner, mock(), position, /* id= */ 0)
    }
}