Use activityStarter of KeyguardQuickAffordancePickerViewModel to launch button intent

Before this change, we use application context to launch the enablement action intent, which doesn't have FLAG_ACTIVITY_NEW_TASK. This caused a crash. By launching the enablement action intent using activityStarter, we would avoid the crash and the use of FLAG_ACTIVITY_NEW_TASK because the call site has already used the activity context to start the intent.

Test: run KeyguardQuickAffordancePickerViewModelTest in astudio
Manual:
1. Go to wallpaper & styles > lock screen > shortcuts
2. Pick a shortcut that is disabled and has a custom action button, e.g. notes app
3. Click the disabled shortcut
4. Click the custom action.
5. The desired activity is launched with no crash.
Fix: 279757109

Change-Id: I2f93bdbfb490839d92b694f60c473a61f1c5f63e
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()
         }