Merge "Restrict panels to preferred apps" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
04088cff0e
@@ -30,6 +30,7 @@ import android.os.UserHandle
|
|||||||
import android.service.controls.ControlsProviderService
|
import android.service.controls.ControlsProviderService
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import com.android.settingslib.applications.DefaultAppInfo
|
import com.android.settingslib.applications.DefaultAppInfo
|
||||||
|
import com.android.systemui.R
|
||||||
import java.util.Objects
|
import java.util.Objects
|
||||||
|
|
||||||
class ControlsServiceInfo(
|
class ControlsServiceInfo(
|
||||||
@@ -59,7 +60,8 @@ class ControlsServiceInfo(
|
|||||||
* instead of using the controls rendered by SystemUI.
|
* instead of using the controls rendered by SystemUI.
|
||||||
*
|
*
|
||||||
* The activity must be in the same package, exported, enabled and protected by the
|
* The activity must be in the same package, exported, enabled and protected by the
|
||||||
* [Manifest.permission.BIND_CONTROLS] permission.
|
* [Manifest.permission.BIND_CONTROLS] permission. Additionally, only packages declared in
|
||||||
|
* [R.array.config_controlsPreferredPackages] can declare activities for use as a panel.
|
||||||
*/
|
*/
|
||||||
var panelActivity: ComponentName? = null
|
var panelActivity: ComponentName? = null
|
||||||
private set
|
private set
|
||||||
@@ -70,6 +72,9 @@ class ControlsServiceInfo(
|
|||||||
fun resolvePanelActivity() {
|
fun resolvePanelActivity() {
|
||||||
if (resolved) return
|
if (resolved) return
|
||||||
resolved = true
|
resolved = true
|
||||||
|
val validPackages = context.resources
|
||||||
|
.getStringArray(R.array.config_controlsPreferredPackages)
|
||||||
|
if (componentName.packageName !in validPackages) return
|
||||||
panelActivity = _panelActivity?.let {
|
panelActivity = _panelActivity?.let {
|
||||||
val resolveInfos = mPm.queryIntentActivitiesAsUser(
|
val resolveInfos = mPm.queryIntentActivitiesAsUser(
|
||||||
Intent().setComponent(it),
|
Intent().setComponent(it),
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.service.controls.ControlsProviderService
|
|||||||
import android.testing.AndroidTestingRunner
|
import android.testing.AndroidTestingRunner
|
||||||
import androidx.test.filters.SmallTest
|
import androidx.test.filters.SmallTest
|
||||||
import com.android.settingslib.applications.ServiceListing
|
import com.android.settingslib.applications.ServiceListing
|
||||||
|
import com.android.systemui.R
|
||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.controls.ControlsServiceInfo
|
import com.android.systemui.controls.ControlsServiceInfo
|
||||||
import com.android.systemui.dump.DumpManager
|
import com.android.systemui.dump.DumpManager
|
||||||
@@ -110,6 +111,12 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
|
|||||||
.thenReturn(PackageManager.COMPONENT_ENABLED_STATE_DISABLED)
|
.thenReturn(PackageManager.COMPONENT_ENABLED_STATE_DISABLED)
|
||||||
mContext.setMockPackageManager(packageManager)
|
mContext.setMockPackageManager(packageManager)
|
||||||
|
|
||||||
|
mContext.orCreateTestableResources
|
||||||
|
.addOverride(
|
||||||
|
R.array.config_controlsPreferredPackages,
|
||||||
|
arrayOf(componentName.packageName)
|
||||||
|
)
|
||||||
|
|
||||||
// Return true by default, we'll test the false path
|
// Return true by default, we'll test the false path
|
||||||
`when`(featureFlags.isEnabled(USE_APP_PANELS)).thenReturn(true)
|
`when`(featureFlags.isEnabled(USE_APP_PANELS)).thenReturn(true)
|
||||||
|
|
||||||
@@ -481,6 +488,35 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
|
|||||||
assertNull(controller.getCurrentServices()[0].panelActivity)
|
assertNull(controller.getCurrentServices()[0].panelActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testPackageNotPreferred_nullPanel() {
|
||||||
|
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()
|
||||||
|
|
||||||
|
assertNull(controller.getCurrentServices()[0].panelActivity)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testListingsNotModifiedByCallback() {
|
fun testListingsNotModifiedByCallback() {
|
||||||
// This test checks that if the list passed to the callback is modified, it has no effect
|
// This test checks that if the list passed to the callback is modified, it has no effect
|
||||||
|
|||||||
Reference in New Issue
Block a user