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

Commit dccb3586 authored by Yalan Yiue's avatar Yalan Yiue Committed by Android (Google) Code Review
Browse files

Merge "[Partial Screensharing] Permission Dialog initial version" into tm-qpr-dev

parents abee62b6 c3b0b684
Loading
Loading
Loading
Loading
+86 −0
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.
  -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="@dimen/screenrecord_option_icon_size"
            android:layout_height="@dimen/screenrecord_option_icon_size"
            android:src="@drawable/ic_mic_26dp"
            android:tint="?android:attr/textColorSecondary"
            android:layout_gravity="center_vertical"
            android:layout_weight="0"
            android:layout_marginRight="@dimen/screenrecord_option_padding"
            android:importantForAccessibility="no"/>
        <Spinner
            android:id="@+id/screen_recording_options"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:minHeight="48dp"
            android:layout_weight="1"
            android:popupBackground="@drawable/screenrecord_spinner_background"
            android:dropDownWidth="274dp"
            android:importantForAccessibility="yes"/>
        <Switch
            android:layout_width="wrap_content"
            android:minWidth="48dp"
            android:layout_height="48dp"
            android:layout_weight="0"
            android:layout_gravity="end"
            android:id="@+id/screenrecord_audio_switch"
            style="@style/ScreenRecord.Switch"
            android:importantForAccessibility="yes"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="@dimen/screenrecord_option_padding">
        <ImageView
            android:layout_width="@dimen/screenrecord_option_icon_size"
            android:layout_height="@dimen/screenrecord_option_icon_size"
            android:layout_weight="0"
            android:src="@drawable/ic_touch"
            android:tint="?android:attr/textColorSecondary"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="@dimen/screenrecord_option_padding"
            android:importantForAccessibility="no"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:minHeight="48dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="@string/screenrecord_taps_label"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:fontFamily="@*android:string/config_headlineFontFamily"
            android:textColor="?android:attr/textColorPrimary"
            android:contentDescription="@string/screenrecord_taps_label"/>
        <Switch
            android:layout_width="wrap_content"
            android:minWidth="48dp"
            android:layout_height="48dp"
            android:layout_weight="0"
            android:id="@+id/screenrecord_taps_switch"
            style="@style/ScreenRecord.Switch"
            android:importantForAccessibility="yes"/>
    </LinearLayout>
</LinearLayout>
 No newline at end of file
+94 −0
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.
  -->

<!-- Scrollview is necessary to fit everything in landscape layout -->
<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/screen_share_permission_dialog"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="@dimen/dialog_side_padding"
        android:paddingEnd="@dimen/dialog_side_padding"
        android:paddingTop="@dimen/dialog_top_padding"
        android:paddingBottom="@dimen/dialog_bottom_padding"
        android:orientation="vertical"
        android:gravity="center_horizontal">

        <ImageView
            android:layout_width="@dimen/screenrecord_logo_size"
            android:layout_height="@dimen/screenrecord_logo_size"
            android:src="@drawable/ic_screenrecord"
            android:tint="@color/screenrecord_icon_color"
            android:importantForAccessibility="no"/>
        <TextView
            android:id="@+id/screen_share_dialog_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:fontFamily="@*android:string/config_headlineFontFamily"
            android:layout_marginTop="22dp"
            android:layout_marginBottom="15dp"/>
        <Spinner
            android:id="@+id/screen_share_mode_spinner"
            android:layout_width="320dp"
            android:layout_height="72dp"
            android:layout_marginTop="24dp"
            android:layout_marginBottom="24dp" />
        <ViewStub
            android:id="@+id/options_stub"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <TextView
            android:id="@+id/text_warning"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/screenrecord_description"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:textColorSecondary"
            android:gravity="start"
            android:layout_marginBottom="20dp"/>

        <!-- Buttons -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="36dp">
            <TextView
                android:id="@+id/button_cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="@string/cancel"
                style="@style/Widget.Dialog.Button.BorderButton" />
            <Space
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"/>
            <TextView
                android:id="@+id/button_start"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="@string/screenrecord_start"
                style="@style/Widget.Dialog.Button" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>
 No newline at end of file
+31 −18
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package com.android.systemui.media;

import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;

import static com.android.systemui.screenrecord.ScreenShareOptionKt.ENTIRE_SCREEN;
import static com.android.systemui.screenrecord.ScreenShareOptionKt.SINGLE_APP;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
@@ -44,6 +47,8 @@ import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.screenrecord.MediaProjectionPermissionDialog;
import com.android.systemui.screenrecord.ScreenShareOption;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.util.Utils;

@@ -102,7 +107,9 @@ public class MediaProjectionPermissionActivity extends Activity

        CharSequence dialogText = null;
        CharSequence dialogTitle = null;
        String appName = null;
        if (Utils.isHeadlessRemoteDisplayProvider(packageManager, mPackageName)) {
            // TODO(b/253438807): handle special app name
            dialogText = getString(R.string.media_projection_dialog_service_text);
            dialogTitle = getString(R.string.media_projection_dialog_service_title);
        } else {
@@ -132,7 +139,7 @@ public class MediaProjectionPermissionActivity extends Activity

            String unsanitizedAppName = TextUtils.ellipsize(label,
                    paint, MAX_APP_NAME_SIZE_PX, TextUtils.TruncateAt.END).toString();
            String appName = BidiFormatter.getInstance().unicodeWrap(unsanitizedAppName);
            appName = BidiFormatter.getInstance().unicodeWrap(unsanitizedAppName);

            String actionText = getString(R.string.media_projection_dialog_text, appName);
            SpannableString message = new SpannableString(actionText);
@@ -146,27 +153,28 @@ public class MediaProjectionPermissionActivity extends Activity
            dialogTitle = getString(R.string.media_projection_dialog_title, appName);
        }

        if (isPartialScreenSharingEnabled()) {
            mDialog = new MediaProjectionPermissionDialog(this, () -> {
                ScreenShareOption selectedOption =
                        ((MediaProjectionPermissionDialog) mDialog).getSelectedScreenShareOption();
                grantMediaProjectionPermission(selectedOption.getMode());
            }, appName);
        } else {
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this,
                    R.style.Theme_SystemUI_Dialog)
                    .setTitle(dialogTitle)
                    .setIcon(R.drawable.ic_media_projection_permission)
                    .setMessage(dialogText)
                    .setPositiveButton(R.string.media_projection_action_text, this)
                .setNeutralButton(android.R.string.cancel, this)
                .setOnCancelListener(this);

        if (isPartialScreenSharingEnabled()) {
            // This is a temporary entry point before we have a new permission dialog
            // TODO(b/233183090): this activity should be redesigned to have a dropdown selector
            dialogBuilder.setNegativeButton("App", this);
        }

                    .setNeutralButton(android.R.string.cancel, this);
            mDialog = dialogBuilder.create();
        }

        SystemUIDialog.registerDismissListener(mDialog);
        SystemUIDialog.applyFlags(mDialog);
        SystemUIDialog.setDialogSize(mDialog);

        mDialog.setOnCancelListener(this);
        mDialog.create();
        mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setFilterTouchesWhenObscured(true);

@@ -186,12 +194,17 @@ public class MediaProjectionPermissionActivity extends Activity

    @Override
    public void onClick(DialogInterface dialog, int which) {
        try {
        if (which == AlertDialog.BUTTON_POSITIVE) {
                setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName));
            grantMediaProjectionPermission(ENTIRE_SCREEN);
        }
    }

            if (isPartialScreenSharingEnabled() && which == AlertDialog.BUTTON_NEGATIVE) {
    private void grantMediaProjectionPermission(int screenShareMode) {
        try {
            if (screenShareMode == ENTIRE_SCREEN) {
                setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName));
            }
            if (isPartialScreenSharingEnabled() && screenShareMode == SINGLE_APP) {
                IMediaProjection projection = createProjection(mUid, mPackageName);
                final Intent intent = new Intent(this, MediaProjectionAppSelectorActivity.class);
                intent.putExtra(MediaProjectionManager.EXTRA_MEDIA_PROJECTION,
+3 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs.tiles;

import android.app.Dialog;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
@@ -43,7 +44,6 @@ import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.screenrecord.RecordingController;
import com.android.systemui.screenrecord.ScreenRecordDialog;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
import com.android.systemui.statusbar.policy.KeyguardStateController;

@@ -170,9 +170,9 @@ public class ScreenRecordTile extends QSTileImpl<QSTile.BooleanState>
            mDialogLaunchAnimator.disableAllCurrentDialogsExitAnimations();
            getHost().collapsePanels();
        };
        ScreenRecordDialog dialog = mController.createScreenRecordDialog(mContext, mFlags,
                mDialogLaunchAnimator, mActivityStarter, onStartRecordingClicked);

        Dialog dialog = mController.createScreenRecordDialog(mContext, mFlags,
                mDialogLaunchAnimator, mActivityStarter, onStartRecordingClicked);
        ActivityStarter.OnDismissAction dismissAction = () -> {
            if (shouldAnimateFromView) {
                mDialogLaunchAnimator.showFromView(dialog, view, new DialogCuj(
+110 −0
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.
 */
package com.android.systemui.screenrecord

import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewStub
import android.view.WindowManager
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
import android.widget.TextView
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import com.android.systemui.R
import com.android.systemui.statusbar.phone.SystemUIDialog

/** Base permission dialog for screen share and recording */
open class BaseScreenSharePermissionDialog(
    context: Context?,
    private val screenShareOptions: List<ScreenShareOption>,
    private val appName: String?
) : SystemUIDialog(context), AdapterView.OnItemSelectedListener {
    private lateinit var dialogTitle: TextView
    private lateinit var startButton: TextView
    private lateinit var warning: TextView
    private lateinit var screenShareModeSpinner: Spinner
    var selectedScreenShareOption: ScreenShareOption = screenShareOptions.first()

    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.apply {
            addPrivateFlags(WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS)
            setGravity(Gravity.CENTER)
        }
        setContentView(R.layout.screen_share_dialog)
        dialogTitle = findViewById(R.id.screen_share_dialog_title)
        warning = findViewById(R.id.text_warning)
        startButton = findViewById(R.id.button_start)
        findViewById<TextView>(R.id.button_cancel).setOnClickListener { dismiss() }
        initScreenShareOptions()
        createOptionsView(getOptionsViewLayoutId())
    }

    protected fun initScreenShareOptions() {
        selectedScreenShareOption = screenShareOptions.first()
        warning.text = warningText
        initScreenShareSpinner()
    }

    private val warningText: String
        get() = context.getString(selectedScreenShareOption.warningText, appName)

    private fun initScreenShareSpinner() {
        val options = screenShareOptions.map { context.getString(it.spinnerText) }.toTypedArray()
        val adapter =
            ArrayAdapter(context.applicationContext, android.R.layout.simple_spinner_item, options)
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        screenShareModeSpinner = findViewById(R.id.screen_share_mode_spinner)
        screenShareModeSpinner.adapter = adapter
        screenShareModeSpinner.onItemSelectedListener = this
    }

    override fun onItemSelected(adapterView: AdapterView<*>?, view: View, pos: Int, id: Long) {
        selectedScreenShareOption = screenShareOptions[pos]
        warning.text = warningText
    }

    override fun onNothingSelected(parent: AdapterView<*>?) {}

    /** Protected methods for the text updates & functionality */
    protected fun setDialogTitle(@StringRes stringId: Int) {
        val title = context.getString(stringId, appName)
        dialogTitle.text = title
    }

    protected fun setStartButtonText(@StringRes stringId: Int) {
        startButton.setText(stringId)
    }

    protected fun setStartButtonOnClickListener(listener: View.OnClickListener?) {
        startButton.setOnClickListener(listener)
    }

    // Create additional options that is shown under the share mode spinner
    // Eg. the audio and tap toggles in SysUI Recorder
    @LayoutRes protected open fun getOptionsViewLayoutId(): Int? = null

    private fun createOptionsView(@LayoutRes layoutId: Int?) {
        if (layoutId == null) return
        val stub = findViewById<View>(R.id.options_stub) as ViewStub
        stub.layoutResource = layoutId
        stub.inflate()
    }
}
Loading