Allow any app to show panel, based on flag

Eventually, we'll add a flow for the user to opt in to these extra apps.
For now, just allow all of them.

These flag should not be released without the flow in place.

Test: atest ControlsListingControllerImplTest
Bug: 261990872
Change-Id: I6b52305106d5b0f6a56ac72827a93e7fcde5a7fb
This commit is contained in:
Fabian Kozynski
2022-12-09 12:56:53 -05:00
parent ec093cc3d1
commit 76b7967725
3 changed files with 41 additions and 3 deletions

View File

@@ -69,12 +69,14 @@ class ControlsServiceInfo(
private var resolved: Boolean = false
@WorkerThread
fun resolvePanelActivity() {
fun resolvePanelActivity(
allowAllApps: Boolean = false
) {
if (resolved) return
resolved = true
val validPackages = context.resources
.getStringArray(R.array.config_controlsPreferredPackages)
if (componentName.packageName !in validPackages) return
if (componentName.packageName !in validPackages && !allowAllApps) return
panelActivity = _panelActivity?.let {
val resolveInfos = mPm.queryIntentActivitiesAsUser(
Intent().setComponent(it),

View File

@@ -98,7 +98,9 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
backgroundExecutor.execute {
if (userChangeInProgress.get() > 0) return@execute
if (featureFlags.isEnabled(Flags.USE_APP_PANELS)) {
newServices.forEach(ControlsServiceInfo::resolvePanelActivity)
val allowAllApps = featureFlags.isEnabled(Flags.APP_PANELS_ALL_APPS_ALLOWED)
newServices.forEach {
it.resolvePanelActivity(allowAllApps) }
}
if (newServices != availableServices) {

View File

@@ -36,6 +36,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.controls.ControlsServiceInfo
import com.android.systemui.dump.DumpManager
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags.APP_PANELS_ALL_APPS_ALLOWED
import com.android.systemui.flags.Flags.USE_APP_PANELS
import com.android.systemui.settings.UserTracker
import com.android.systemui.util.concurrency.FakeExecutor
@@ -119,6 +120,8 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
// Return true by default, we'll test the false path
`when`(featureFlags.isEnabled(USE_APP_PANELS)).thenReturn(true)
// Return false by default, we'll test the true path
`when`(featureFlags.isEnabled(APP_PANELS_ALL_APPS_ALLOWED)).thenReturn(false)
val wrapper = object : ContextWrapper(mContext) {
override fun createContextAsUser(user: UserHandle, flags: Int): Context {
@@ -517,6 +520,37 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
assertNull(controller.getCurrentServices()[0].panelActivity)
}
@Test
fun testPackageNotPreferred_allowAllApps_correctPanel() {
`when`(featureFlags.isEnabled(APP_PANELS_ALL_APPS_ALLOWED)).thenReturn(true)
mContext.orCreateTestableResources
.addOverride(R.array.config_controlsPreferredPackages, arrayOf<String>())
val serviceInfo = ServiceInfo(
componentName,
activityName
)
`when`(packageManager.getComponentEnabledSetting(eq(activityName)))
.thenReturn(PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
setUpQueryResult(listOf(
ActivityInfo(
activityName,
exported = true,
permission = Manifest.permission.BIND_CONTROLS
)
))
val list = listOf(serviceInfo)
serviceListingCallbackCaptor.value.onServicesReloaded(list)
executor.runAllReady()
assertEquals(activityName, controller.getCurrentServices()[0].panelActivity)
}
@Test
fun testListingsNotModifiedByCallback() {
// This test checks that if the list passed to the callback is modified, it has no effect