Merge "CredManUI: Use origin to replace the calling app package name." into udc-dev

This commit is contained in:
Helen Qin
2023-02-27 18:38:33 +00:00
committed by Android (Google) Code Review
2 changed files with 22 additions and 9 deletions

View File

@@ -72,6 +72,12 @@ class CredentialManagerRepo(
RequestInfo::class.java
) ?: testCreatePasswordRequestInfo()
val originName: String? = when (requestInfo.type) {
RequestInfo.TYPE_CREATE -> requestInfo.createCredentialRequest?.origin
RequestInfo.TYPE_GET -> requestInfo.getCredentialRequest?.origin
else -> null
}
providerEnabledList = when (requestInfo.type) {
RequestInfo.TYPE_CREATE ->
intent.extras?.getParcelableArrayList(
@@ -105,14 +111,15 @@ class CredentialManagerRepo(
val isPasskeyFirstUse = userConfigRepo.getIsPasskeyFirstUse()
val providerEnableListUiState = getCreateProviderEnableListInitialUiState()
val providerDisableListUiState = getCreateProviderDisableListInitialUiState()
val requestDisplayInfoUiState = getCreateRequestDisplayInfoInitialUiState()!!
val requestDisplayInfoUiState =
getCreateRequestDisplayInfoInitialUiState(originName)!!
UiState(
createCredentialUiState = CreateFlowUtils.toCreateCredentialUiState(
providerEnableListUiState,
providerDisableListUiState,
defaultProviderId,
requestDisplayInfoUiState,
/** isOnPasskeyIntroStateAlready = */
/** isOnPasskeyIntroStateAlready */
false,
isPasskeyFirstUse
)!!,
@@ -121,7 +128,7 @@ class CredentialManagerRepo(
}
RequestInfo.TYPE_GET -> UiState(
createCredentialUiState = null,
getCredentialUiState = getCredentialInitialUiState()!!,
getCredentialUiState = getCredentialInitialUiState(originName)!!,
)
else -> throw IllegalStateException("Unrecognized request type: ${requestInfo.type}")
}
@@ -172,11 +179,11 @@ class CredentialManagerRepo(
}
// IMPORTANT: new invocation should be mindful that this method can throw.
private fun getCredentialInitialUiState(): GetCredentialUiState? {
private fun getCredentialInitialUiState(originName: String?): GetCredentialUiState? {
val providerEnabledList = GetFlowUtils.toProviderList(
providerEnabledList as List<GetCredentialProviderData>, context
)
val requestDisplayInfo = GetFlowUtils.toRequestDisplayInfo(requestInfo, context)
val requestDisplayInfo = GetFlowUtils.toRequestDisplayInfo(requestInfo, context, originName)
return GetCredentialUiState(
providerEnabledList,
requestDisplayInfo ?: return null,
@@ -198,8 +205,10 @@ class CredentialManagerRepo(
)
}
private fun getCreateRequestDisplayInfoInitialUiState(): RequestDisplayInfo? {
return CreateFlowUtils.toRequestDisplayInfo(requestInfo, context)
private fun getCreateRequestDisplayInfoInitialUiState(
originName: String?
): RequestDisplayInfo? {
return CreateFlowUtils.toRequestDisplayInfo(requestInfo, context, originName)
}
companion object {

View File

@@ -170,9 +170,11 @@ class GetFlowUtils {
fun toRequestDisplayInfo(
requestInfo: RequestInfo,
context: Context,
originName: String?,
): com.android.credentialmanager.getflow.RequestDisplayInfo? {
return com.android.credentialmanager.getflow.RequestDisplayInfo(
appName = getAppLabel(context.packageManager, requestInfo.appPackageName)
appName = originName
?: getAppLabel(context.packageManager, requestInfo.appPackageName)
?: return null
)
}
@@ -395,8 +397,10 @@ class CreateFlowUtils {
fun toRequestDisplayInfo(
requestInfo: RequestInfo,
context: Context,
originName: String?,
): RequestDisplayInfo? {
val appLabel = getAppLabel(context.packageManager, requestInfo.appPackageName)
val appLabel = originName
?: getAppLabel(context.packageManager, requestInfo.appPackageName)
?: return null
val createCredentialRequest = requestInfo.createCredentialRequest ?: return null
val createCredentialRequestJetpack = CreateCredentialRequest.createFrom(