From 82ea198caf763489052ead6d497a3193688f120d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Go=CC=88llner?= Date: Tue, 23 May 2023 15:28:53 +0100 Subject: [PATCH] Fix media projection permission dialog too wide when in split screen When in split screen and large screen, the dialog was using almost the entire width of the screen. SysUIDialog defines the dialog width based on a resource dimension. For small screens, it is MATCH_PARENT, and for larger screens a specific value. For the media projection permission dialog, the context passed to the dialog was of the activity that was on one of the sides of the split screen, which has the same width as a small screen. The fix is to pass the application context instead to the dialog. Test: MediaProjectionPermissionTest Test: Manually - Put the device in split screen while on a large screen and start screen sharing. Fixes: 263801365 Change-Id: Ifd600b7ec54deeabe28f4762ce87975d97dbc89d --- .../media/MediaProjectionPermissionActivity.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java index c9c2ea27e5f41..f6a2f37042837 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java @@ -29,6 +29,7 @@ import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -203,14 +204,17 @@ public class MediaProjectionPermissionActivity extends Activity dialogTitle = getString(R.string.media_projection_dialog_title, appName); } + // Using application context for the dialog, instead of the activity context, so we get + // the correct screen width when in split screen. + Context dialogContext = getApplicationContext(); if (isPartialScreenSharingEnabled()) { - mDialog = new MediaProjectionPermissionDialog(this, () -> { + mDialog = new MediaProjectionPermissionDialog(dialogContext, () -> { ScreenShareOption selectedOption = ((MediaProjectionPermissionDialog) mDialog).getSelectedScreenShareOption(); grantMediaProjectionPermission(selectedOption.getMode()); }, () -> finish(RECORD_CANCEL, /* projection= */ null), appName); } else { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this, + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(dialogContext, R.style.Theme_SystemUI_Dialog) .setTitle(dialogTitle) .setIcon(R.drawable.ic_media_projection_permission) @@ -263,7 +267,10 @@ public class MediaProjectionPermissionActivity extends Activity final UserHandle hostUserHandle = getHostUserHandle(); if (mScreenCaptureDevicePolicyResolver.get() .isScreenCaptureCompletelyDisabled(hostUserHandle)) { - AlertDialog dialog = new ScreenCaptureDisabledDialog(this); + // Using application context for the dialog, instead of the activity context, so we get + // the correct screen width when in split screen. + Context dialogContext = getApplicationContext(); + AlertDialog dialog = new ScreenCaptureDisabledDialog(dialogContext); setUpDialog(dialog); dialog.show(); return true;