Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59bce679 authored by Qinmei Du's avatar Qinmei Du Committed by Android (Google) Code Review
Browse files

Merge "Credential manager UI changes to fix the issue that UI app uses same...

Merge "Credential manager UI changes to fix the issue that UI app uses same repo instance for different activities"
parents 6869a62f efe74cf4
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -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(
+10 −6
Original line number Diff line number Diff line
@@ -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)
+6 −7
Original line number Diff line number Diff line
@@ -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()
@@ -142,12 +141,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))
  }

@@ -189,7 +188,7 @@ class CreateCredentialViewModel(
        hidden = true,
      )
    } else {
      CredentialManagerRepo.getInstance().onOptionSelected(
      credManRepo.onOptionSelected(
        providerId,
        entryKey,
        entrySubkey
@@ -243,7 +242,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 {
+4 −8
Original line number Diff line number Diff line
@@ -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))
  }
}