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

Commit 0c0d9621 authored by Helen Qin's avatar Helen Qin
Browse files

Allow UI update upon auth/action entry changes.

Also tested that multiple auth entries work. Will submit a follow up for
updating the titles.

Bug: 267669563
Test: manual (see demo in comment)
Change-Id: I1cabc35f8e94d81b6ac0d04320dd8ce378f42ece
parent 6c10afbf
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@@ -43,17 +44,6 @@ class CredentialSelectorActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(Constants.LOG_TAG, "Creating new CredentialSelectorActivity")
        init(intent)
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        setIntent(intent)
        Log.d(Constants.LOG_TAG, "Existing activity received new intent")
        init(intent)
    }

    fun init(intent: Intent) {
        try {
            val userConfigRepo = UserConfigRepo(this)
            val credManRepo = CredentialManagerRepo(this, intent, userConfigRepo)
@@ -70,6 +60,20 @@ class CredentialSelectorActivity : ComponentActivity() {
        }
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        setIntent(intent)
        Log.d(Constants.LOG_TAG, "Existing activity received new intent")
        try {
            val userConfigRepo = UserConfigRepo(this)
            val credManRepo = CredentialManagerRepo(this, intent, userConfigRepo)
            val viewModel: CredentialSelectorViewModel by viewModels()
            viewModel.onNewCredentialManagerRepo(credManRepo)
        } catch (e: Exception) {
            onInitializationError(e, intent)
        }
    }

    @ExperimentalMaterialApi
    @Composable
    fun CredentialManagerBottomSheet(
+3 −1
Original line number Diff line number Diff line
@@ -104,7 +104,9 @@ class CredentialSelectorViewModel(
                    entry.providerId, entry.entryKey, entry.entrySubkey,
                    resultCode, resultData,
                )
                if (entry.shouldTerminateUiUponSuccessfulProviderResult) {
                    uiState = uiState.copy(dialogState = DialogState.COMPLETE)
                }
            } else {
                Log.w(Constants.LOG_TAG,
                    "Illegal state: received a provider result but found no matching entry.")
+1 −0
Original line number Diff line number Diff line
@@ -25,4 +25,5 @@ open class BaseEntry (
    val entrySubkey: String,
    val pendingIntent: PendingIntent?,
    val fillInIntent: Intent?,
    val shouldTerminateUiUponSuccessfulProviderResult: Boolean,
)
 No newline at end of file
+16 −2
Original line number Diff line number Diff line
@@ -69,7 +69,14 @@ class CreateOptionInfo(
    val totalCredentialCount: Int?,
    val lastUsedTime: Instant?,
    val footerDescription: String?,
) : BaseEntry(providerId, entryKey, entrySubkey, pendingIntent, fillInIntent)
) : BaseEntry(
    providerId,
    entryKey,
    entrySubkey,
    pendingIntent,
    fillInIntent,
    shouldTerminateUiUponSuccessfulProviderResult = true,
)

class RemoteInfo(
  providerId: String,
@@ -77,7 +84,14 @@ class RemoteInfo(
  entrySubkey: String,
  pendingIntent: PendingIntent?,
  fillInIntent: Intent?,
) : BaseEntry(providerId, entryKey, entrySubkey, pendingIntent, fillInIntent)
) : BaseEntry(
    providerId,
    entryKey,
    entrySubkey,
    pendingIntent,
    fillInIntent,
    shouldTerminateUiUponSuccessfulProviderResult = true,
)

data class RequestDisplayInfo(
  val title: String,
+183 −154
Original line number Diff line number Diff line
@@ -74,7 +74,14 @@ class CredentialEntryInfo(
    val displayName: String?,
    val icon: Drawable?,
    val lastUsedTimeMillis: Instant?,
) : BaseEntry(providerId, entryKey, entrySubkey, pendingIntent, fillInIntent)
) : BaseEntry(
    providerId,
    entryKey,
    entrySubkey,
    pendingIntent,
    fillInIntent,
    shouldTerminateUiUponSuccessfulProviderResult = true,
)

class AuthenticationEntryInfo(
    providerId: String,
@@ -84,7 +91,13 @@ class AuthenticationEntryInfo(
    fillInIntent: Intent?,
    val title: String,
    val icon: Drawable,
) : BaseEntry(providerId, entryKey, entrySubkey, pendingIntent, fillInIntent)
) : BaseEntry(
    providerId,
    entryKey, entrySubkey,
    pendingIntent,
    fillInIntent,
    shouldTerminateUiUponSuccessfulProviderResult = false,
)

class RemoteEntryInfo(
    providerId: String,
@@ -92,7 +105,14 @@ class RemoteEntryInfo(
    entrySubkey: String,
    pendingIntent: PendingIntent?,
    fillInIntent: Intent?,
) : BaseEntry(providerId, entryKey, entrySubkey, pendingIntent, fillInIntent)
) : BaseEntry(
    providerId,
    entryKey,
    entrySubkey,
    pendingIntent,
    fillInIntent,
    shouldTerminateUiUponSuccessfulProviderResult = true,
)

class ActionEntryInfo(
    providerId: String,
@@ -103,7 +123,14 @@ class ActionEntryInfo(
    val title: String,
    val icon: Drawable,
    val subTitle: String?,
) : BaseEntry(providerId, entryKey, entrySubkey, pendingIntent, fillInIntent)
) : BaseEntry(
    providerId,
    entryKey,
    entrySubkey,
    pendingIntent,
    fillInIntent,
    shouldTerminateUiUponSuccessfulProviderResult = false,
)

data class RequestDisplayInfo(
    val appName: String,
@@ -123,8 +150,10 @@ data class PerUserNameCredentialEntryList(
enum class GetScreenState {
    /** The primary credential selection page. */
    PRIMARY_SELECTION,

    /** The secondary credential selection page, where all sign-in options are listed. */
    ALL_SIGN_IN_OPTIONS,

    /** The snackbar only page when there's no account but only a remoteEntry. */
    REMOTE_ONLY,
}