diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt index ea1ade41dca8c..31fadb13db08e 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt @@ -184,6 +184,9 @@ interface ControlsController : UserAwareController { */ fun countFavoritesForComponent(componentName: ComponentName): Int + /** See [ControlsUiController.getPreferredStructure]. */ + fun getPreferredStructure(): StructureInfo + /** * Interface for structure to pass data to [ControlsFavoritingActivity]. */ diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt index 5d0127a714fbc..25985181364d4 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt @@ -556,6 +556,10 @@ class ControlsControllerImpl @Inject constructor ( ) } + override fun getPreferredStructure(): StructureInfo { + return uiController.getPreferredStructure(getFavorites()) + } + override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array) { pw.println("ControlsController state:") pw.println(" Changing users: $userChanging") diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt index 2bbd3cbbc220e..91e75f6436c2d 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt @@ -21,6 +21,7 @@ import android.content.Context import android.service.controls.Control import android.service.controls.actions.ControlAction import android.view.ViewGroup +import com.android.systemui.controls.controller.StructureInfo interface ControlsUiController { companion object { @@ -43,4 +44,11 @@ interface ControlsUiController { controlId: String, @ControlAction.ResponseResult response: Int ) + + /** + * Returns the structure that is currently preferred by the user. + * + * This structure will be the one that appears when the user first opens the controls activity. + */ + fun getPreferredStructure(structures: List): StructureInfo } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt index c322f4549aca6..821a171e883c3 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt @@ -165,7 +165,7 @@ class ControlsUiControllerImpl @Inject constructor ( controlActionCoordinator.activityContext = activityContext allStructures = controlsController.get().getFavorites() - selectedStructure = loadPreference(allStructures) + selectedStructure = getPreferredStructure(allStructures) if (controlsController.get().addSeedingFavoritesCallback(onSeedingComplete)) { listingCallback = createCallback(::showSeedingView) @@ -448,7 +448,7 @@ class ControlsUiControllerImpl @Inject constructor ( return maxColumns } - private fun loadPreference(structures: List): StructureInfo { + override fun getPreferredStructure(structures: List): StructureInfo { if (structures.isEmpty()) return EMPTY_STRUCTURE val component = sharedPreferences.getString(PREF_COMPONENT, null)?.let { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt index 11b0e010e7401..2ab5a3a15205b 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt @@ -124,7 +124,8 @@ class DeviceControlsTile @Inject constructor( if (controlsComponent.isEnabled() && hasControlsApps.get()) { if (controlsComponent.getVisibility() == AVAILABLE) { state.state = Tile.STATE_ACTIVE - state.secondaryLabel = "" + state.secondaryLabel = controlsComponent + .getControlsController().get().getPreferredStructure().structure } else { state.state = Tile.STATE_INACTIVE state.secondaryLabel = mContext.getText(R.string.controls_tile_locked) diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt index f17fe9aefbb90..580cd35459b9c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt @@ -16,6 +16,7 @@ package com.android.systemui.qs.tiles +import android.content.ComponentName import android.os.Handler import android.content.Context import android.content.Intent @@ -32,6 +33,7 @@ import com.android.systemui.animation.ActivityLaunchAnimator import com.android.systemui.classifier.FalsingManagerFake import com.android.systemui.controls.ControlsServiceInfo import com.android.systemui.controls.controller.ControlsController +import com.android.systemui.controls.controller.StructureInfo import com.android.systemui.controls.dagger.ControlsComponent import com.android.systemui.controls.management.ControlsListingController import com.android.systemui.controls.ui.ControlsUiController @@ -113,6 +115,8 @@ class DeviceControlsTileTest : SysuiTestCase() { `when`(qsHost.uiEventLogger).thenReturn(uiEventLogger) `when`(controlsComponent.isEnabled()).thenReturn(true) `when`(keyguardStateController.isUnlocked()).thenReturn(true) + `when`(controlsController.getPreferredStructure()) + .thenReturn(StructureInfo(ComponentName("pkg", "cls"), "structure", listOf())) secureSettings.putInt(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, 1) setupControlsComponent()