Merge "Add go/aster logging to GetCredentialComponents" into udc-dev
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
index 5240777..16827da 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
@@ -171,9 +171,6 @@
                                 onLog = { viewModel.logUiEvent(it) },
                         )
                     }
-                    viewModel.uiMetrics.log(
-                            CreateCredentialEvent
-                                    .CREDMAN_CREATE_CRED_PROVIDER_ACTIVITY_NOT_APPLICABLE)
                 }
                 ProviderActivityState.READY_TO_LAUNCH -> {
                     // Launch only once per providerActivityState change so that the provider
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
index a9f994d..96798a3 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
@@ -62,6 +62,8 @@
 import com.android.credentialmanager.common.ui.Snackbar
 import com.android.credentialmanager.common.ui.setTransparentSystemBarsColor
 import com.android.credentialmanager.common.ui.setBottomSheetSystemBarsColor
+import com.android.credentialmanager.logging.GetCredentialEvent
+import com.android.internal.logging.UiEventLogger.UiEventEnum
 
 @Composable
 fun GetCredentialScreen(
@@ -75,7 +77,9 @@
         RemoteCredentialSnackBarScreen(
             onClick = viewModel::getFlowOnMoreOptionOnSnackBarSelected,
             onCancel = viewModel::onUserCancel,
+            onLog = { viewModel.logUiEvent(it) },
         )
+        viewModel.uiMetrics.log(GetCredentialEvent.CREDMAN_GET_CRED_SCREEN_REMOTE_ONLY)
     } else if (getCredentialUiState.currentScreenState
         == GetScreenState.UNLOCKED_AUTH_ENTRIES_ONLY) {
         setTransparentSystemBarsColor(sysUiController)
@@ -84,7 +88,10 @@
             getCredentialUiState.providerDisplayInfo.authenticationEntryList,
             onCancel = viewModel::silentlyFinishActivity,
             onLastLockedAuthEntryNotFound = viewModel::onLastLockedAuthEntryNotFoundError,
+            onLog = { viewModel.logUiEvent(it) },
         )
+        viewModel.uiMetrics.log(GetCredentialEvent
+                .CREDMAN_GET_CRED_SCREEN_UNLOCKED_AUTH_ENTRIES_ONLY)
     } else {
         setBottomSheetSystemBarsColor(sysUiController)
         ModalBottomSheet(
@@ -104,7 +111,10 @@
                                 onEntrySelected = viewModel::getFlowOnEntrySelected,
                                 onConfirm = viewModel::getFlowOnConfirmEntrySelected,
                                 onMoreOptionSelected = viewModel::getFlowOnMoreOptionSelected,
+                                onLog = { viewModel.logUiEvent(it) },
                             )
+                            viewModel.uiMetrics.log(GetCredentialEvent
+                                    .CREDMAN_GET_CRED_SCREEN_PRIMARY_SELECTION)
                         } else {
                             AllSignInOptionCard(
                                 providerInfoList = getCredentialUiState.providerInfoList,
@@ -114,7 +124,10 @@
                                 viewModel::getFlowOnBackToPrimarySelectionScreen,
                                 onCancel = viewModel::onUserCancel,
                                 isNoAccount = getCredentialUiState.isNoAccount,
+                                onLog = { viewModel.logUiEvent(it) },
                             )
+                            viewModel.uiMetrics.log(GetCredentialEvent
+                                    .CREDMAN_GET_CRED_SCREEN_ALL_SIGN_IN_OPTIONS)
                         }
                     }
                     ProviderActivityState.READY_TO_LAUNCH -> {
@@ -123,9 +136,13 @@
                         LaunchedEffect(viewModel.uiState.providerActivityState) {
                             viewModel.launchProviderUi(providerActivityLauncher)
                         }
+                        viewModel.uiMetrics.log(GetCredentialEvent
+                                .CREDMAN_GET_CRED_PROVIDER_ACTIVITY_READY_TO_LAUNCH)
                     }
                     ProviderActivityState.PENDING -> {
                         // Hide our content when the provider activity is active.
+                        viewModel.uiMetrics.log(GetCredentialEvent
+                                .CREDMAN_GET_CRED_PROVIDER_ACTIVITY_PENDING)
                     }
                 }
             },
@@ -144,6 +161,7 @@
     onEntrySelected: (BaseEntry) -> Unit,
     onConfirm: () -> Unit,
     onMoreOptionSelected: () -> Unit,
+    onLog: @Composable (UiEventEnum) -> Unit,
 ) {
     val sortedUserNameToCredentialEntryList =
         providerDisplayInfo.sortedUserNameToCredentialEntryList
@@ -248,6 +266,7 @@
             )
         }
     }
+    onLog(GetCredentialEvent.CREDMAN_GET_CRED_PRIMARY_SELECTION_CARD)
 }
 
 /** Draws the secondary credential selection page, where all sign-in options are listed. */
@@ -259,6 +278,7 @@
     onBackButtonClicked: () -> Unit,
     onCancel: () -> Unit,
     isNoAccount: Boolean,
+    onLog: @Composable (UiEventEnum) -> Unit,
 ) {
     val sortedUserNameToCredentialEntryList =
         providerDisplayInfo.sortedUserNameToCredentialEntryList
@@ -303,6 +323,7 @@
             )
         }
     }
+    onLog(GetCredentialEvent.CREDMAN_GET_CRED_ALL_SIGN_IN_OPTION_CARD)
 }
 
 // TODO: create separate rows for primary and secondary pages.
@@ -466,6 +487,7 @@
 fun RemoteCredentialSnackBarScreen(
     onClick: (Boolean) -> Unit,
     onCancel: () -> Unit,
+    onLog: @Composable (UiEventEnum) -> Unit,
 ) {
     Snackbar(
         action = {
@@ -482,6 +504,7 @@
         onDismiss = onCancel,
         contentText = stringResource(R.string.get_dialog_use_saved_passkey_for),
     )
+    onLog(GetCredentialEvent.CREDMAN_GET_CRED_REMOTE_CRED_SNACKBAR_SCREEN)
 }
 
 @Composable
@@ -489,6 +512,7 @@
     authenticationEntryList: List<AuthenticationEntryInfo>,
     onCancel: () -> Unit,
     onLastLockedAuthEntryNotFound: () -> Unit,
+    onLog: @Composable (UiEventEnum) -> Unit,
 ) {
     val lastLocked = authenticationEntryList.firstOrNull({ it.isLastUnlocked })
     if (lastLocked == null) {
@@ -500,4 +524,5 @@
         onDismiss = onCancel,
         contentText = stringResource(R.string.no_sign_in_info_in, lastLocked.providerDisplayName),
     )
+    onLog(GetCredentialEvent.CREDMAN_GET_CRED_SCREEN_EMPTY_AUTH_SNACKBAR_SCREEN)
 }
\ No newline at end of file
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt b/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt
new file mode 100644
index 0000000..8de8895
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.credentialmanager.logging
+
+import com.android.internal.logging.UiEvent
+import com.android.internal.logging.UiEventLogger
+
+enum class GetCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnum {
+
+    @UiEvent(doc = "The The snackbar only page when there's no account but only a remoteEntry " +
+            "visible on the screen.")
+    CREDMAN_GET_CRED_SCREEN_REMOTE_ONLY(1332),
+
+    @UiEvent(doc = "The snackbar when there are only auth entries and all of them are empty.")
+    CREDMAN_GET_CRED_SCREEN_UNLOCKED_AUTH_ENTRIES_ONLY(1333),
+
+    @UiEvent(doc = "The primary credential selection page is displayed on screen.")
+    CREDMAN_GET_CRED_SCREEN_PRIMARY_SELECTION(1334),
+
+    @UiEvent(doc = "The secondary credential selection page, where all sign-in options are " +
+            "listed is displayed on the screen.")
+    CREDMAN_GET_CRED_SCREEN_ALL_SIGN_IN_OPTIONS(1335),
+
+    @UiEvent(doc = "The provider activity is not active nor is any ready for launch on the screen.")
+    CREDMAN_GET_CRED_PROVIDER_ACTIVITY_NOT_APPLICABLE(1336),
+
+    @UiEvent(doc = "The provider activity is ready to be launched on the screen.")
+    CREDMAN_GET_CRED_PROVIDER_ACTIVITY_READY_TO_LAUNCH(1337),
+
+    @UiEvent(doc = "The provider activity is launched and we are waiting for its result. " +
+            "Contents Hidden.")
+    CREDMAN_GET_CRED_PROVIDER_ACTIVITY_PENDING(1338),
+
+    @UiEvent(doc = "The remote credential snackbar screen is visible.")
+    CREDMAN_GET_CRED_REMOTE_CRED_SNACKBAR_SCREEN(1339),
+
+    @UiEvent(doc = "The empty auth snackbar screen is visible.")
+    CREDMAN_GET_CRED_SCREEN_EMPTY_AUTH_SNACKBAR_SCREEN(1340),
+
+    @UiEvent(doc = "The primary selection card is visible on screen.")
+    CREDMAN_GET_CRED_PRIMARY_SELECTION_CARD(1341),
+
+    @UiEvent(doc = "The all sign in option card is visible on screen.")
+    CREDMAN_GET_CRED_ALL_SIGN_IN_OPTION_CARD(1342);
+
+    override fun getId(): Int {
+        return this.id
+    }
+}
\ No newline at end of file