Dumpsys support for quick affordances.

Should aid in debugging.

Bug: 257066487
Test: Manually verified that running:

adb shell dumpsys activity service com.android.systemui/.SystemUIService KeyguardQuickAffordances

Properly outputs the right text, for example:

    KeyguardQuickAffordances:
    ----------------------------------------------------------------------------
    Slots & selections:
        bottom_start: home (capacity = 1)
        bottom_end is empty (capacity = 1)
    Available affordances on device:
        home ("Home")
        wallet ("Wallet")
        qr_code_scanner ("QR code scanner")

Change-Id: I5278e977a775aa7346914514a964fdacfc082bf0
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt
index d300500..d95a1a7 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt
@@ -18,14 +18,17 @@
 package com.android.systemui.keyguard.data.repository
 
 import android.content.Context
+import com.android.systemui.Dumpable
 import com.android.systemui.R
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.dump.DumpManager
 import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig
 import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceLegacySettingSyncer
 import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceSelectionManager
 import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePickerRepresentation
 import com.android.systemui.keyguard.shared.model.KeyguardSlotPickerRepresentation
+import java.io.PrintWriter
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.flow.SharingStarted
@@ -43,6 +46,7 @@
     private val selectionManager: KeyguardQuickAffordanceSelectionManager,
     legacySettingSyncer: KeyguardQuickAffordanceLegacySettingSyncer,
     private val configs: Set<@JvmSuppressWildcards KeyguardQuickAffordanceConfig>,
+    dumpManager: DumpManager,
 ) {
     /**
      * List of [KeyguardQuickAffordanceConfig] instances of the affordances at the slot with the
@@ -87,6 +91,7 @@
 
     init {
         legacySettingSyncer.startSyncing()
+        dumpManager.registerDumpable("KeyguardQuickAffordances", Dumpster())
     }
 
     /**
@@ -158,6 +163,30 @@
         return _slotPickerRepresentations
     }
 
+    private inner class Dumpster : Dumpable {
+        override fun dump(pw: PrintWriter, args: Array<out String>) {
+            val slotPickerRepresentations = getSlotPickerRepresentations()
+            val selectionsBySlotId = getSelections()
+            pw.println("Slots & selections:")
+            slotPickerRepresentations.forEach { slotPickerRepresentation ->
+                val slotId = slotPickerRepresentation.id
+                val capacity = slotPickerRepresentation.maxSelectedAffordances
+                val affordanceIds = selectionsBySlotId[slotId]
+
+                val selectionText =
+                    if (!affordanceIds.isNullOrEmpty()) {
+                        ": ${affordanceIds.joinToString(", ")}"
+                    } else {
+                        " is empty"
+                    }
+
+                pw.println("    $slotId$selectionText (capacity = $capacity)")
+            }
+            pw.println("Available affordances on device:")
+            configs.forEach { config -> pw.println("    ${config.key} (\"${config.pickerName}\")") }
+        }
+    }
+
     companion object {
         private const val SLOT_CONFIG_DELIMITER = ":"
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardQuickAffordanceProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardQuickAffordanceProviderTest.kt
index 5e27a50..cedde58 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardQuickAffordanceProviderTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardQuickAffordanceProviderTest.kt
@@ -115,6 +115,7 @@
                         secureSettings = FakeSettings(),
                         selectionsManager = selectionManager,
                     ),
+                dumpManager = mock(),
             )
         underTest.interactor =
             KeyguardQuickAffordanceInteractor(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryTest.kt
index bfd5190..5c75417 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryTest.kt
@@ -91,6 +91,7 @@
                         selectionsManager = selectionManager,
                     ),
                 configs = setOf(config1, config2),
+                dumpManager = mock(),
             )
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorParameterizedTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorParameterizedTest.kt
index 1e1d3f1..c2650ec 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorParameterizedTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorParameterizedTest.kt
@@ -266,6 +266,7 @@
                         selectionsManager = selectionManager,
                     ),
                 configs = setOf(homeControls, quickAccessWallet, qrCodeScanner),
+                dumpManager = mock(),
             )
         underTest =
             KeyguardQuickAffordanceInteractor(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt
index 4850ea5..b790306 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt
@@ -127,6 +127,7 @@
                         selectionsManager = selectionManager,
                     ),
                 configs = setOf(homeControls, quickAccessWallet, qrCodeScanner),
+                dumpManager = mock(),
             )
         featureFlags =
             FakeFeatureFlags().apply {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt
index ecc63ec..8b166bd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt
@@ -155,6 +155,7 @@
                         quickAccessWalletAffordanceConfig,
                         qrCodeScannerAffordanceConfig,
                     ),
+                dumpManager = mock(),
             )
         underTest =
             KeyguardBottomAreaViewModel(