From b044d6b538f8b769e7038f5bdae184585d6e2fd1 Mon Sep 17 00:00:00 2001 From: yyalan Date: Wed, 4 Jan 2023 16:50:52 +0000 Subject: [PATCH] [Partial Screensharing] Hide app selector from Recent Tasks and move the caller to the tail Remove app selector from the Recent Task. Pass the caller app's packageName to MediaProjectionAppSelectorController and move it to the tail. Bug: 255340264 Test: MediaProjectionAppSelectorControllerTest Change-Id: I5b7ed51b3e74c0ba70cdf845b3f50cac2b548c1b --- .../MediaProjectionAppSelectorComponent.kt | 10 +- .../MediaProjectionAppSelectorController.kt | 15 +- ...ediaProjectionAppSelectorControllerTest.kt | 190 ++++++++++-------- 3 files changed, 126 insertions(+), 89 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorComponent.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorComponent.kt index 1678c6e6b7a9e..3088d8b580239 100644 --- a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorComponent.kt +++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorComponent.kt @@ -46,10 +46,10 @@ import dagger.Provides import dagger.Subcomponent import dagger.multibindings.ClassKey import dagger.multibindings.IntoMap -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.SupervisorJob import javax.inject.Qualifier import javax.inject.Scope +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob @Qualifier @Retention(AnnotationRetention.BINARY) annotation class MediaProjectionAppSelector @@ -107,6 +107,12 @@ interface MediaProjectionAppSelectorModule { fun provideAppSelectorComponentName(context: Context): ComponentName = ComponentName(context, MediaProjectionAppSelectorActivity::class.java) + @Provides + @MediaProjectionAppSelector + @MediaProjectionAppSelectorScope + fun provideCallerPackageName(activity: MediaProjectionAppSelectorActivity): String? = + activity.callingPackage + @Provides @MediaProjectionAppSelector @MediaProjectionAppSelectorScope diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorController.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorController.kt index 52c7ca3bb3d48..219629b44c5da 100644 --- a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorController.kt +++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorController.kt @@ -36,16 +36,16 @@ constructor( private val flags: FeatureFlags, @HostUserHandle private val hostUserHandle: UserHandle, @MediaProjectionAppSelector private val scope: CoroutineScope, - @MediaProjectionAppSelector private val appSelectorComponentName: ComponentName + @MediaProjectionAppSelector private val appSelectorComponentName: ComponentName, + @MediaProjectionAppSelector private val callerPackageName: String? ) { fun init() { scope.launch { val recentTasks = recentTaskListProvider.loadRecentTasks() - val tasks = recentTasks - .filterDevicePolicyRestrictedTasks() - .sortedTasks() + val tasks = + recentTasks.filterDevicePolicyRestrictedTasks().filterAppSelector().sortedTasks() view.bind(tasks) } @@ -67,8 +67,13 @@ constructor( filter { UserHandle.of(it.userId) == hostUserHandle } } + private fun List.filterAppSelector(): List = filter { + // Only take tasks that is not the app selector + it.topActivityComponent != appSelectorComponentName + } + private fun List.sortedTasks(): List = sortedBy { // Show normal tasks first and only then tasks with opened app selector - it.topActivityComponent == appSelectorComponentName + it.topActivityComponent?.packageName == callerPackageName } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorControllerTest.kt index 1042ea7149363..497777545c70a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorControllerTest.kt @@ -24,6 +24,8 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() { private val taskListProvider = TestRecentTaskListProvider() private val scope = CoroutineScope(Dispatchers.Unconfined) private val appSelectorComponentName = ComponentName("com.test", "AppSelector") + private val callerPackageName = "com.test.caller" + private val callerComponentName = ComponentName(callerPackageName, "Caller") private val hostUserHandle = UserHandle.of(123) private val otherUserHandle = UserHandle.of(456) @@ -31,14 +33,16 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() { private val view: MediaProjectionAppSelectorView = mock() private val featureFlags: FeatureFlags = mock() - private val controller = MediaProjectionAppSelectorController( - taskListProvider, - view, - featureFlags, - hostUserHandle, - scope, - appSelectorComponentName - ) + private val controller = + MediaProjectionAppSelectorController( + taskListProvider, + view, + featureFlags, + hostUserHandle, + scope, + appSelectorComponentName, + callerPackageName + ) @Test fun initNoRecentTasks_bindsEmptyList() { @@ -51,104 +55,87 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() { @Test fun initOneRecentTask_bindsList() { - taskListProvider.tasks = listOf( - createRecentTask(taskId = 1) - ) + taskListProvider.tasks = listOf(createRecentTask(taskId = 1)) controller.init() - verify(view).bind( - listOf( - createRecentTask(taskId = 1) - ) - ) + verify(view).bind(listOf(createRecentTask(taskId = 1))) } @Test fun initMultipleRecentTasksWithoutAppSelectorTask_bindsListInTheSameOrder() { - val tasks = listOf( - createRecentTask(taskId = 1), - createRecentTask(taskId = 2), - createRecentTask(taskId = 3), - ) - taskListProvider.tasks = tasks - - controller.init() - - verify(view).bind( + val tasks = listOf( createRecentTask(taskId = 1), createRecentTask(taskId = 2), createRecentTask(taskId = 3), ) - ) - } - - @Test - fun initRecentTasksWithAppSelectorTasks_bindsAppSelectorTasksAtTheEnd() { - val tasks = listOf( - createRecentTask(taskId = 1), - createRecentTask(taskId = 2, topActivityComponent = appSelectorComponentName), - createRecentTask(taskId = 3), - createRecentTask(taskId = 4, topActivityComponent = appSelectorComponentName), - createRecentTask(taskId = 5), - ) taskListProvider.tasks = tasks controller.init() - verify(view).bind( + verify(view) + .bind( + listOf( + createRecentTask(taskId = 1), + createRecentTask(taskId = 2), + createRecentTask(taskId = 3), + ) + ) + } + + @Test + fun initRecentTasksWithAppSelectorTasks_removeAppSelector() { + val tasks = listOf( createRecentTask(taskId = 1), - createRecentTask(taskId = 3), - createRecentTask(taskId = 5), createRecentTask(taskId = 2, topActivityComponent = appSelectorComponentName), - createRecentTask(taskId = 4, topActivityComponent = appSelectorComponentName), + createRecentTask(taskId = 3), + createRecentTask(taskId = 4), + ) + taskListProvider.tasks = tasks + + controller.init() + + verify(view) + .bind( + listOf( + createRecentTask(taskId = 1), + createRecentTask(taskId = 3), + createRecentTask(taskId = 4), + ) + ) + } + + @Test + fun initRecentTasksWithAppSelectorTasks_bindsCallerTasksAtTheEnd() { + val tasks = + listOf( + createRecentTask(taskId = 1), + createRecentTask(taskId = 2, topActivityComponent = callerComponentName), + createRecentTask(taskId = 3), + createRecentTask(taskId = 4), + ) + taskListProvider.tasks = tasks + + controller.init() + + verify(view) + .bind( + listOf( + createRecentTask(taskId = 1), + createRecentTask(taskId = 3), + createRecentTask(taskId = 4), + createRecentTask(taskId = 2, topActivityComponent = callerComponentName), + ) ) - ) } @Test fun initRecentTasksWithAppSelectorTasks_enterprisePoliciesDisabled_bindsOnlyTasksWithHostProfile() { givenEnterprisePoliciesFeatureFlag(enabled = false) - val tasks = listOf( - createRecentTask(taskId = 1, userId = hostUserHandle.identifier), - createRecentTask(taskId = 2, userId = otherUserHandle.identifier), - createRecentTask(taskId = 3, userId = hostUserHandle.identifier), - createRecentTask(taskId = 4, userId = otherUserHandle.identifier), - createRecentTask(taskId = 5, userId = hostUserHandle.identifier), - ) - taskListProvider.tasks = tasks - - controller.init() - - verify(view).bind( - listOf( - createRecentTask(taskId = 1, userId = hostUserHandle.identifier), - createRecentTask(taskId = 3, userId = hostUserHandle.identifier), - createRecentTask(taskId = 5, userId = hostUserHandle.identifier), - ) - ) - } - - @Test - fun initRecentTasksWithAppSelectorTasks_enterprisePoliciesEnabled_bindsAllTasks() { - givenEnterprisePoliciesFeatureFlag(enabled = true) - - val tasks = listOf( - createRecentTask(taskId = 1, userId = hostUserHandle.identifier), - createRecentTask(taskId = 2, userId = otherUserHandle.identifier), - createRecentTask(taskId = 3, userId = hostUserHandle.identifier), - createRecentTask(taskId = 4, userId = otherUserHandle.identifier), - createRecentTask(taskId = 5, userId = hostUserHandle.identifier), - ) - taskListProvider.tasks = tasks - - controller.init() - - // TODO(b/233348916) should filter depending on the policies - verify(view).bind( + val tasks = listOf( createRecentTask(taskId = 1, userId = hostUserHandle.identifier), createRecentTask(taskId = 2, userId = otherUserHandle.identifier), @@ -156,7 +143,47 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() { createRecentTask(taskId = 4, userId = otherUserHandle.identifier), createRecentTask(taskId = 5, userId = hostUserHandle.identifier), ) - ) + taskListProvider.tasks = tasks + + controller.init() + + verify(view) + .bind( + listOf( + createRecentTask(taskId = 1, userId = hostUserHandle.identifier), + createRecentTask(taskId = 3, userId = hostUserHandle.identifier), + createRecentTask(taskId = 5, userId = hostUserHandle.identifier), + ) + ) + } + + @Test + fun initRecentTasksWithAppSelectorTasks_enterprisePoliciesEnabled_bindsAllTasks() { + givenEnterprisePoliciesFeatureFlag(enabled = true) + + val tasks = + listOf( + createRecentTask(taskId = 1, userId = hostUserHandle.identifier), + createRecentTask(taskId = 2, userId = otherUserHandle.identifier), + createRecentTask(taskId = 3, userId = hostUserHandle.identifier), + createRecentTask(taskId = 4, userId = otherUserHandle.identifier), + createRecentTask(taskId = 5, userId = hostUserHandle.identifier), + ) + taskListProvider.tasks = tasks + + controller.init() + + // TODO(b/233348916) should filter depending on the policies + verify(view) + .bind( + listOf( + createRecentTask(taskId = 1, userId = hostUserHandle.identifier), + createRecentTask(taskId = 2, userId = otherUserHandle.identifier), + createRecentTask(taskId = 3, userId = hostUserHandle.identifier), + createRecentTask(taskId = 4, userId = otherUserHandle.identifier), + createRecentTask(taskId = 5, userId = hostUserHandle.identifier), + ) + ) } private fun givenEnterprisePoliciesFeatureFlag(enabled: Boolean) { @@ -183,6 +210,5 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() { var tasks: List = emptyList() override suspend fun loadRecentTasks(): List = tasks - } }