Merge "Use activityStarter of KeyguardQuickAffordancePickerViewModel to launch button intent" into udc-dev
diff --git a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
index 029d76e..0a52e8f 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
@@ -64,7 +64,7 @@
     private val quickAffordanceInteractor: KeyguardQuickAffordancePickerInteractor,
     private val wallpaperInteractor: WallpaperInteractor,
     private val wallpaperInfoFactory: CurrentWallpaperInfoFactory,
-    activityStarter: (Intent) -> Unit,
+    private val activityStarter: (Intent) -> Unit,
 ) : ViewModel() {
 
     @SuppressLint("StaticFieldLeak") private val applicationContext = context.applicationContext
@@ -361,7 +361,7 @@
                             style = ButtonStyle.Primary,
                             onClicked = {
                                 actionComponentName.toIntent()?.let { intent ->
-                                    applicationContext.startActivity(intent)
+                                    activityStarter(intent)
                                 }
                             }
                         ),
diff --git a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
index 155b912..1b241ca 100644
--- a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
+++ b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
@@ -282,9 +282,14 @@
             assertThat(dialog()?.buttons?.first()?.text)
                 .isEqualTo(Text.Loaded(enablementActionText))
 
+            // When the button is clicked, we expect an intent of the given enablement action
+            // component name is launched.
+            dialog()?.buttons?.first()?.onClicked?.invoke()
+            assertThat(latestStartedActivityIntent?.`package`).isEqualTo(packageName)
+            assertThat(latestStartedActivityIntent?.action).isEqualTo(action)
+
             // Once we report that the dialog has been dismissed by the user, we expect there to be
-            // no
-            // dialog to be shown:
+            // no dialog to be shown:
             underTest.onDialogDismissed()
             assertThat(dialog()).isNull()
         }