From 35c3307f7d43591939e7ec3c83c5cb57ec2d95a8 Mon Sep 17 00:00:00 2001 From: Helen Qin Date: Wed, 10 May 2023 07:33:21 +0000 Subject: [PATCH] Fix potential IllegalArgumentException from the auto-select flow. AutoSelect flow animate the bottom sheet directly into empty sheet because it will then immediately launch the provider activity. However, there's a native compose bug that throws IllegalArgumentException when the sheet is animated from/to an empty sheet. The fix was submitted to late for us to merge into our U release b/ 281791945 so we need a temporary solution: for now we'd keep a 1 pixel transparent bar when this could happen; it won't be noticeable. Bug: 281791945 Test: manual Change-Id: I668af5316fa795cf833d0907481373d86bb24ed1 --- .../createflow/CreateCredentialComponents.kt | 14 ++++++++++++++ .../getflow/GetCredentialComponents.kt | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt index a3087cf8004c4..d45b6f687193f 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt @@ -43,6 +43,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap import com.android.credentialmanager.CredentialSelectorViewModel @@ -50,6 +51,7 @@ import com.android.credentialmanager.R import com.android.credentialmanager.common.BaseEntry import com.android.credentialmanager.common.CredentialType import com.android.credentialmanager.common.ProviderActivityState +import com.android.credentialmanager.common.material.ModalBottomSheetDefaults import com.android.credentialmanager.common.ui.ActionButton import com.android.credentialmanager.common.ui.BodyMediumText import com.android.credentialmanager.common.ui.BodySmallText @@ -148,6 +150,13 @@ fun CreateCredentialScreen( } } ProviderActivityState.READY_TO_LAUNCH -> { + // This is a native bug from ModalBottomSheet. For now, use the temporary + // solution of not having an empty state. + if (viewModel.uiState.isAutoSelectFlow) { + Divider( + thickness = Dp.Hairline, color = ModalBottomSheetDefaults.scrimColor + ) + } // Launch only once per providerActivityState change so that the provider // UI will not be accidentally launched twice. LaunchedEffect(viewModel.uiState.providerActivityState) { @@ -158,6 +167,11 @@ fun CreateCredentialScreen( .CREDMAN_CREATE_CRED_PROVIDER_ACTIVITY_READY_TO_LAUNCH) } ProviderActivityState.PENDING -> { + if (viewModel.uiState.isAutoSelectFlow) { + Divider( + thickness = Dp.Hairline, color = ModalBottomSheetDefaults.scrimColor + ) + } // Hide our content when the provider activity is active. viewModel.uiMetrics.log( CreateCredentialEvent.CREDMAN_CREATE_CRED_PROVIDER_ACTIVITY_PENDING) diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt index 934b0aebf4177..72d030b3e6574 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt @@ -43,6 +43,7 @@ import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextLayoutResult +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap import com.android.credentialmanager.CredentialSelectorViewModel @@ -50,6 +51,7 @@ import com.android.credentialmanager.R import com.android.credentialmanager.common.BaseEntry import com.android.credentialmanager.common.CredentialType import com.android.credentialmanager.common.ProviderActivityState +import com.android.credentialmanager.common.material.ModalBottomSheetDefaults import com.android.credentialmanager.common.ui.ActionButton import com.android.credentialmanager.common.ui.ActionEntry import com.android.credentialmanager.common.ui.ConfirmButton @@ -132,6 +134,13 @@ fun GetCredentialScreen( } } ProviderActivityState.READY_TO_LAUNCH -> { + // This is a native bug from ModalBottomSheet. For now, use the temporary + // solution of not having an empty state. + if (viewModel.uiState.isAutoSelectFlow) { + Divider( + thickness = Dp.Hairline, color = ModalBottomSheetDefaults.scrimColor + ) + } // Launch only once per providerActivityState change so that the provider // UI will not be accidentally launched twice. LaunchedEffect(viewModel.uiState.providerActivityState) { @@ -141,6 +150,11 @@ fun GetCredentialScreen( .CREDMAN_GET_CRED_PROVIDER_ACTIVITY_READY_TO_LAUNCH) } ProviderActivityState.PENDING -> { + if (viewModel.uiState.isAutoSelectFlow) { + Divider( + thickness = Dp.Hairline, color = ModalBottomSheetDefaults.scrimColor + ) + } // Hide our content when the provider activity is active. viewModel.uiMetrics.log(GetCredentialEvent .CREDMAN_GET_CRED_PROVIDER_ACTIVITY_PENDING)