Credential manager UI changes to fix the issue that UI app uses same repo instance for different activities
Test: deployed locally Bug: 265155577 Fix: 265155577 Change-Id: I2bcee2c2891609e4c4eb78bf4213094d0128f3f6
This commit is contained in:
@@ -152,22 +152,6 @@ class CredentialManagerRepo(
|
||||
return CreateFlowUtils.toRequestDisplayInfo(requestInfo, context)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// TODO: find a way to resolve this static field leak problem
|
||||
lateinit var repo: CredentialManagerRepo
|
||||
|
||||
fun setup(
|
||||
context: Context,
|
||||
intent: Intent,
|
||||
) {
|
||||
repo = CredentialManagerRepo(context, intent)
|
||||
}
|
||||
|
||||
fun getInstance(): CredentialManagerRepo {
|
||||
return repo
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: below are prototype functionalities. To be removed for productionization.
|
||||
private fun testCreateCredentialEnabledProviderList(): List<CreateCredentialProviderData> {
|
||||
return listOf(
|
||||
|
||||
@@ -45,19 +45,19 @@ import kotlinx.coroutines.launch
|
||||
class CredentialSelectorActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
CredentialManagerRepo.setup(this, intent)
|
||||
val credManRepo = CredentialManagerRepo(this, intent)
|
||||
UserConfigRepo.setup(this)
|
||||
val requestInfo = CredentialManagerRepo.getInstance().requestInfo
|
||||
val requestInfo = credManRepo.requestInfo
|
||||
setContent {
|
||||
CredentialSelectorTheme {
|
||||
CredentialManagerBottomSheet(DialogType.toDialogType(requestInfo.type))
|
||||
CredentialManagerBottomSheet(DialogType.toDialogType(requestInfo.type), credManRepo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalMaterialApi
|
||||
@Composable
|
||||
fun CredentialManagerBottomSheet(dialogType: DialogType) {
|
||||
fun CredentialManagerBottomSheet(dialogType: DialogType, credManRepo: CredentialManagerRepo) {
|
||||
val providerActivityResult = remember { mutableStateOf<ProviderActivityResult?>(null) }
|
||||
val launcher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.StartIntentSenderForResult()
|
||||
@@ -66,7 +66,9 @@ class CredentialSelectorActivity : ComponentActivity() {
|
||||
}
|
||||
when (dialogType) {
|
||||
DialogType.CREATE_PASSKEY -> {
|
||||
val viewModel: CreateCredentialViewModel = viewModel()
|
||||
val viewModel: CreateCredentialViewModel = viewModel{
|
||||
CreateCredentialViewModel(credManRepo)
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
viewModel.observeDialogResult().collect{ dialogResult ->
|
||||
onCancel(dialogResult)
|
||||
@@ -79,7 +81,9 @@ class CredentialSelectorActivity : ComponentActivity() {
|
||||
CreateCredentialScreen(viewModel = viewModel, providerActivityLauncher = launcher)
|
||||
}
|
||||
DialogType.GET_CREDENTIALS -> {
|
||||
val viewModel: GetCredentialViewModel = viewModel()
|
||||
val viewModel: GetCredentialViewModel = viewModel{
|
||||
GetCredentialViewModel(credManRepo)
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
viewModel.observeDialogResult().collect{ dialogResult ->
|
||||
onCancel(dialogResult)
|
||||
|
||||
@@ -52,10 +52,9 @@ data class CreateCredentialUiState(
|
||||
)
|
||||
|
||||
class CreateCredentialViewModel(
|
||||
credManRepo: CredentialManagerRepo = CredentialManagerRepo.getInstance(),
|
||||
userConfigRepo: UserConfigRepo = UserConfigRepo.getInstance()
|
||||
private val credManRepo: CredentialManagerRepo,
|
||||
userConfigRepo: UserConfigRepo = UserConfigRepo.getInstance(),
|
||||
) : ViewModel() {
|
||||
|
||||
var providerEnableListUiState = credManRepo.getCreateProviderEnableListInitialUiState()
|
||||
|
||||
var providerDisableListUiState = credManRepo.getCreateProviderDisableListInitialUiState()
|
||||
@@ -140,12 +139,12 @@ class CreateCredentialViewModel(
|
||||
}
|
||||
|
||||
fun onDisabledProvidersSelected() {
|
||||
CredentialManagerRepo.getInstance().onCancel()
|
||||
credManRepo.onCancel()
|
||||
dialogResult.tryEmit(DialogResult(ResultState.LAUNCH_SETTING_CANCELED))
|
||||
}
|
||||
|
||||
fun onCancel() {
|
||||
CredentialManagerRepo.getInstance().onCancel()
|
||||
credManRepo.onCancel()
|
||||
dialogResult.tryEmit(DialogResult(ResultState.NORMAL_CANCELED))
|
||||
}
|
||||
|
||||
@@ -187,7 +186,7 @@ class CreateCredentialViewModel(
|
||||
hidden = true,
|
||||
)
|
||||
} else {
|
||||
CredentialManagerRepo.getInstance().onOptionSelected(
|
||||
credManRepo.onOptionSelected(
|
||||
providerId,
|
||||
entryKey,
|
||||
entrySubkey
|
||||
@@ -241,7 +240,7 @@ class CreateCredentialViewModel(
|
||||
"$providerId, key=${entry.entryKey}, subkey=${entry.entrySubkey}, " +
|
||||
"resultCode=$resultCode, resultData=$resultData}"
|
||||
)
|
||||
CredentialManagerRepo.getInstance().onOptionSelected(
|
||||
credManRepo.onOptionSelected(
|
||||
providerId, entry.entryKey, entry.entrySubkey, resultCode, resultData,
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -46,9 +46,7 @@ data class GetCredentialUiState(
|
||||
val isNoAccount: Boolean = false,
|
||||
)
|
||||
|
||||
class GetCredentialViewModel(
|
||||
credManRepo: CredentialManagerRepo = CredentialManagerRepo.getInstance()
|
||||
) : ViewModel() {
|
||||
class GetCredentialViewModel(private val credManRepo: CredentialManagerRepo) : ViewModel() {
|
||||
|
||||
var uiState by mutableStateOf(credManRepo.getCredentialInitialUiState())
|
||||
private set
|
||||
@@ -70,9 +68,7 @@ class GetCredentialViewModel(
|
||||
hidden = true,
|
||||
)
|
||||
} else {
|
||||
CredentialManagerRepo.getInstance().onOptionSelected(
|
||||
entry.providerId, entry.entryKey, entry.entrySubkey,
|
||||
)
|
||||
credManRepo.onOptionSelected(entry.providerId, entry.entryKey, entry.entrySubkey)
|
||||
dialogResult.tryEmit(DialogResult(ResultState.COMPLETE))
|
||||
}
|
||||
}
|
||||
@@ -110,7 +106,7 @@ class GetCredentialViewModel(
|
||||
"${entry.providerId}, key=${entry.entryKey}, subkey=${entry.entrySubkey}, " +
|
||||
"resultCode=$resultCode, resultData=$resultData}"
|
||||
)
|
||||
CredentialManagerRepo.getInstance().onOptionSelected(
|
||||
credManRepo.onOptionSelected(
|
||||
entry.providerId, entry.entryKey, entry.entrySubkey,
|
||||
resultCode, resultData,
|
||||
)
|
||||
@@ -144,7 +140,7 @@ class GetCredentialViewModel(
|
||||
}
|
||||
|
||||
fun onCancel() {
|
||||
CredentialManagerRepo.getInstance().onCancel()
|
||||
credManRepo.onCancel()
|
||||
dialogResult.tryEmit(DialogResult(ResultState.NORMAL_CANCELED))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user