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

Commit 4e656938 authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Android (Google) Code Review
Browse files

Merge "Launching AppSelector from PermissionDialog without using AnimationController" into main

parents 8667ec11 0fbd524c
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -150,19 +150,6 @@
                    android:layout_height="match_parent"
                    android:layout_weight="1"/>

                <!-- Temporary entrypoint for the partial screensharing used for teamfooding -->
                <!-- TODO(b/236838395) remove this and use redesigned dialog -->
                <TextView
                    android:id="@+id/button_app"
                    android:visibility="gone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:layout_gravity="end"
                    android:layout_marginEnd="8dp"
                    android:text="App"
                    style="@style/Widget.Dialog.Button.BorderButton" />

                <TextView
                    android:id="@+id/button_start"
                    android:layout_width="wrap_content"
+3 −4
Original line number Diff line number Diff line
@@ -151,10 +151,9 @@ public class RecordingController

        return flags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)
                ? new ScreenRecordPermissionDialog(context,  getHostUserHandle(), this,
                    activityStarter, dialogLaunchAnimator, mUserContextProvider,
                    onStartRecordingClicked)
                : new ScreenRecordDialog(context, this, activityStarter,
                mUserContextProvider, flags, dialogLaunchAnimator, onStartRecordingClicked);
                    activityStarter, mUserContextProvider, onStartRecordingClicked)
                : new ScreenRecordDialog(context, this, mUserContextProvider,
                        onStartRecordingClicked);
    }

    /**
+1 −43
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.screenrecord;

import static android.app.Activity.RESULT_OK;

import static com.android.systemui.media.MediaProjectionAppSelectorActivity.EXTRA_CAPTURE_REGION_RESULT_RECEIVER;
import static com.android.systemui.media.MediaProjectionAppSelectorActivity.KEY_CAPTURE_TARGET;
import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.INTERNAL;
import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC;
@@ -28,13 +27,11 @@ import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.NONE;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.ResultReceiver;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
@@ -45,13 +42,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable;

import com.android.systemui.R;
import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.animation.DialogLaunchAnimator;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.media.MediaProjectionAppSelectorActivity;
import com.android.systemui.media.MediaProjectionCaptureTarget;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.statusbar.phone.SystemUIDialog;

@@ -71,23 +62,15 @@ public class ScreenRecordDialog extends SystemUIDialog {
    private final UserContextProvider mUserContextProvider;
    @Nullable
    private final Runnable mOnStartRecordingClicked;
    private final ActivityStarter mActivityStarter;
    private final FeatureFlags mFlags;
    private final DialogLaunchAnimator mDialogLaunchAnimator;
    private Switch mTapsSwitch;
    private Switch mAudioSwitch;
    private Spinner mOptions;

    public ScreenRecordDialog(Context context, RecordingController controller,
            ActivityStarter activityStarter, UserContextProvider userContextProvider,
            FeatureFlags flags, DialogLaunchAnimator dialogLaunchAnimator,
            @Nullable Runnable onStartRecordingClicked) {
            UserContextProvider userContextProvider, @Nullable Runnable onStartRecordingClicked) {
        super(context);
        mController = controller;
        mUserContextProvider = userContextProvider;
        mActivityStarter = activityStarter;
        mDialogLaunchAnimator = dialogLaunchAnimator;
        mFlags = flags;
        mOnStartRecordingClicked = onStartRecordingClicked;
    }

@@ -120,31 +103,6 @@ public class ScreenRecordDialog extends SystemUIDialog {
            dismiss();
        });

        if (mFlags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)) {
            TextView appBtn = findViewById(R.id.button_app);

            appBtn.setVisibility(View.VISIBLE);
            appBtn.setOnClickListener(v -> {
                Intent intent = new Intent(getContext(), MediaProjectionAppSelectorActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                // We can't start activity for result here so we use result receiver to get
                // the selected target to capture
                intent.putExtra(EXTRA_CAPTURE_REGION_RESULT_RECEIVER,
                        new CaptureTargetResultReceiver());

                ActivityLaunchAnimator.Controller animationController =
                        mDialogLaunchAnimator.createActivityLaunchController(appBtn);

                if (animationController == null) {
                    dismiss();
                }

                mActivityStarter.startActivity(intent, /* dismissShade= */ true,
                        animationController);
            });
        }

        mAudioSwitch = findViewById(R.id.screenrecord_audio_switch);
        mTapsSwitch = findViewById(R.id.screenrecord_taps_switch);
        mOptions = findViewById(R.id.screen_recording_options);
+1 −8
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.widget.Spinner
import android.widget.Switch
import androidx.annotation.LayoutRes
import com.android.systemui.R
import com.android.systemui.animation.DialogLaunchAnimator
import com.android.systemui.media.MediaProjectionAppSelectorActivity
import com.android.systemui.media.MediaProjectionCaptureTarget
import com.android.systemui.plugins.ActivityStarter
@@ -45,7 +44,6 @@ class ScreenRecordPermissionDialog(
    private val hostUserHandle: UserHandle,
    private val controller: RecordingController,
    private val activityStarter: ActivityStarter,
    private val dialogLaunchAnimator: DialogLaunchAnimator,
    private val userContextProvider: UserContextProvider,
    private val onStartRecordingClicked: Runnable?
) :
@@ -85,12 +83,7 @@ class ScreenRecordPermissionDialog(
                    MediaProjectionAppSelectorActivity.EXTRA_HOST_APP_USER_HANDLE,
                    hostUserHandle
                )

                val animationController = dialogLaunchAnimator.createActivityLaunchController(v!!)
                if (animationController == null) {
                    dismiss()
                }
                activityStarter.startActivity(intent, /* dismissShade= */ true, animationController)
                activityStarter.startActivity(intent, /* dismissShade= */ true)
            }
            dismiss()
        }
+0 −111
Original line number 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.
 */

/*
 * 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 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.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.MockitoAnnotations
import org.mockito.Mockito.`when` as whenever

@SmallTest
@RunWith(AndroidTestingRunner::class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class ScreenRecordDialogTest : 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: ScreenRecordDialog

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

        dialog = ScreenRecordDialog(
            context, controller, starter, userContextProvider, flags, dialogLaunchAnimator,
            onStartRecordingClicked
        )
    }

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

    @Test
    fun testShowDialog_partialScreenSharingDisabled_appButtonIsNotVisible() {
        whenever(flags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)).thenReturn(false)

        dialog.show()

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

    @Test
    fun testShowDialog_partialScreenSharingEnabled_appButtonIsVisible() {
        whenever(flags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)).thenReturn(true)

        dialog.show()

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