summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author dakinola <dakinola@google.com> 2024-09-25 11:34:27 +0000
committer Daniel Akinola <dakinola@google.com> 2024-09-25 21:51:47 +0000
commit1648937d800c7102ef51a80ee6450c1532fd268d (patch)
treed759ce0102f6fd5e40c3efac480b3da70f4e6e9b
parente8c0fd8f96fab06b556ed1c04f7fff6c3d18e1e1 (diff)
Fix Launching Foreground Recording App with MediaProjection App Selector
Partner found a bug relating to when we attempt to partial screenshare the app that is requesting MediaProjection. We always attempt to find the selected app by launch cookie provided, but if we select the currently open app that is requesting a MediaProjection, the launch cookie won't match. It only works now by accident because the launch cookie is attributed to the app selector activity instead of the base recording activity, but if the app selector activity is closed by the time virtual display set up starts then it won't find an activity with the new launch cookie. To remedy this, for the case of starting a mediaprojection for the active activity, then we'll provide the task id as a backup Bug: 365498349 Test: atest ShellRecentTaskListProviderTest Flag: EXEMPT bugfix Change-Id: I7f5e4139dd72f7f7795adab00a52dc82b14e4ac9
-rw-r--r--packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt35
1 files changed, 22 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt
index 228b57603bed..d413474fde90 100644
--- a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt
@@ -54,6 +54,7 @@ import com.android.systemui.mediaprojection.MediaProjectionServiceHelper
import com.android.systemui.mediaprojection.appselector.data.RecentTask
import com.android.systemui.mediaprojection.appselector.view.MediaProjectionRecentsViewController
import com.android.systemui.res.R
+import com.android.systemui.shared.system.ActivityManagerWrapper
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.AsyncActivityLauncher
import java.lang.IllegalArgumentException
@@ -62,9 +63,10 @@ import javax.inject.Inject
class MediaProjectionAppSelectorActivity(
private val componentFactory: MediaProjectionAppSelectorComponent.Factory,
private val activityLauncher: AsyncActivityLauncher,
+ private val activityManager: ActivityManagerWrapper,
/** This is used to override the dependency in a screenshot test */
@VisibleForTesting
- private val listControllerFactory: ((userHandle: UserHandle) -> ResolverListController)?
+ private val listControllerFactory: ((userHandle: UserHandle) -> ResolverListController)?,
) :
ChooserActivity(),
MediaProjectionAppSelectorView,
@@ -74,8 +76,9 @@ class MediaProjectionAppSelectorActivity(
@Inject
constructor(
componentFactory: MediaProjectionAppSelectorComponent.Factory,
- activityLauncher: AsyncActivityLauncher
- ) : this(componentFactory, activityLauncher, listControllerFactory = null)
+ activityLauncher: AsyncActivityLauncher,
+ activityManager: ActivityManagerWrapper,
+ ) : this(componentFactory, activityLauncher, activityManager, listControllerFactory = null)
private val lifecycleRegistry = LifecycleRegistry(this)
override val lifecycle = lifecycleRegistry
@@ -100,7 +103,7 @@ class MediaProjectionAppSelectorActivity(
callingPackage = callingPackage,
view = this,
resultHandler = this,
- isFirstStart = savedInstanceState == null
+ isFirstStart = savedInstanceState == null,
)
component.lifecycleObservers.forEach { lifecycle.addObserver(it) }
@@ -113,7 +116,7 @@ class MediaProjectionAppSelectorActivity(
intent.configureChooserIntent(
resources,
component.hostUserHandle,
- component.personalProfileUserHandle
+ component.personalProfileUserHandle,
)
reviewGrantedConsentRequired =
@@ -180,7 +183,13 @@ class MediaProjectionAppSelectorActivity(
// is created and ready to be captured.
val activityStarted =
activityLauncher.startActivityAsUser(intent, userHandle, activityOptions.toBundle()) {
- returnSelectedApp(launchCookie, taskId = -1)
+ if (targetInfo.resolvedComponentName == callingActivity) {
+ // If attempting to launch the app used to launch the MediaProjection, then
+ // provide the task id since the launch cookie won't match the existing task
+ returnSelectedApp(launchCookie, taskId = activityManager.runningTask.taskId)
+ } else {
+ returnSelectedApp(launchCookie, taskId = -1)
+ }
}
// Rely on the ActivityManager to pop up a dialog regarding app suspension
@@ -213,7 +222,7 @@ class MediaProjectionAppSelectorActivity(
MediaProjectionServiceHelper.setReviewedConsentIfNeeded(
RECORD_CANCEL,
reviewGrantedConsentRequired,
- /* projection= */ null
+ /* projection= */ null,
)
if (isFinishing) {
// Only log dismissed when actually finishing, and not when changing configuration.
@@ -246,7 +255,7 @@ class MediaProjectionAppSelectorActivity(
val resultReceiver =
intent.getParcelableExtra(
EXTRA_CAPTURE_REGION_RESULT_RECEIVER,
- ResultReceiver::class.java
+ ResultReceiver::class.java,
) as ResultReceiver
val captureRegion = MediaProjectionCaptureTarget(launchCookie, taskId)
val data = Bundle().apply { putParcelable(KEY_CAPTURE_TARGET, captureRegion) }
@@ -260,8 +269,8 @@ class MediaProjectionAppSelectorActivity(
val mediaProjectionBinder = intent.getIBinderExtra(EXTRA_MEDIA_PROJECTION)
val projection = IMediaProjection.Stub.asInterface(mediaProjectionBinder)
- projection.setLaunchCookie(launchCookie)
- projection.setTaskId(taskId)
+ projection.launchCookie = launchCookie
+ projection.taskId = taskId
val intent = Intent()
intent.putExtra(EXTRA_MEDIA_PROJECTION, projection.asBinder())
@@ -270,7 +279,7 @@ class MediaProjectionAppSelectorActivity(
MediaProjectionServiceHelper.setReviewedConsentIfNeeded(
RECORD_CONTENT_TASK,
reviewGrantedConsentRequired,
- projection
+ projection,
)
}
@@ -457,7 +466,7 @@ class MediaProjectionAppSelectorActivity(
*/
private class RecyclerViewExpandingAccessibilityDelegate(
rdl: ResolverDrawerLayout,
- view: RecyclerView
+ view: RecyclerView,
) : RecyclerViewAccessibilityDelegate(view) {
private val delegate = AppListAccessibilityDelegate(rdl)
@@ -465,7 +474,7 @@ class MediaProjectionAppSelectorActivity(
override fun onRequestSendAccessibilityEvent(
host: ViewGroup,
child: View,
- event: AccessibilityEvent
+ event: AccessibilityEvent,
): Boolean {
super.onRequestSendAccessibilityEvent(host, child, event)
return delegate.onRequestSendAccessibilityEvent(host, child, event)