From 886254005940c3ba469d49489ef086ff8fc8aaa1 Mon Sep 17 00:00:00 2001 From: Naomi Musgrave Date: Mon, 24 Apr 2023 18:51:23 +0000 Subject: [PATCH] (4/N)[MediaProjection] Don't send result to server until setup ends SysUI sends a result to MediaProjectionManagerService if the setup flow was launched by the service, to handle projection token reuse. If another activity is launched as part of the MediaProjection setup flow, do not send the result to the server when the permission dialog is dismissed; let the next activity handle sending the result. Bug: 253218374 Test: manual Change-Id: I92b27262a86f13c370f69fa14f427f4107c4df70 --- .../media/MediaProjectionPermissionActivity.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java index 28adfbba1103d..c9c2ea27e5f41 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java @@ -79,6 +79,9 @@ public class MediaProjectionPermissionActivity extends Activity // Indicates if user must review already-granted consent that the MediaProjection app is // attempting to re-use. private boolean mReviewGrantedConsentRequired = false; + // Indicates if the user has consented to record, but is continuing in another activity to + // select a particular task to capture. + private boolean mUserSelectingTask = false; @Inject public MediaProjectionPermissionActivity(FeatureFlags featureFlags, @@ -296,6 +299,7 @@ public class MediaProjectionPermissionActivity extends Activity // Start activity from the current foreground user to avoid creating a separate // SystemUI process without access to recent tasks because it won't have // WM Shell running inside. + mUserSelectingTask = true; startActivityAsUser(intent, UserHandle.of(ActivityManager.getCurrentUser())); } } catch (RemoteException e) { @@ -316,7 +320,10 @@ public class MediaProjectionPermissionActivity extends Activity @Override public void finish() { // Default to cancelling recording when user needs to review consent. - finish(RECORD_CANCEL, /* projection= */ null); + // Don't send cancel if the user has moved on to the next activity. + if (!mUserSelectingTask) { + finish(RECORD_CANCEL, /* projection= */ null); + } } private void finish(@ReviewGrantedConsentResult int consentResult, @@ -328,7 +335,7 @@ public class MediaProjectionPermissionActivity extends Activity private void onDialogDismissedOrCancelled(DialogInterface dialogInterface) { if (!isFinishing()) { - finish(RECORD_CANCEL, /* projection= */ null); + finish(); } }