-
Notifications
You must be signed in to change notification settings - Fork 4
feat(accounts): add platform credential slots #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
veryCrunchy
wants to merge
10
commits into
feature/account-registry-foundation
from
feature/account-credential-slots
+3,535
−614
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
243d327
feat(accounts): add platform credential slots
veryCrunchy b556175
chore(changelog): link pull request
veryCrunchy 892dff5
chore(website): refresh marketing captures
obiente-automations[bot] 8f4bf90
fix(accounts): serialize credential lifecycle state
veryCrunchy e4abb32
fix(accounts): preserve retained account recovery
veryCrunchy 981e5d4
fix(android): defer retained-account uploads
veryCrunchy 595cc08
fix(accounts): harden credential recovery races
veryCrunchy 9d3b08b
fix(accounts): coordinate background account work
veryCrunchy 1d310d0
fix(accounts): close credential lifecycle races
veryCrunchy 9cb08f8
fix(accounts): close remaining removal races
veryCrunchy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
579 changes: 579 additions & 0 deletions
579
androidApp/src/main/kotlin/dev/obiente/nextcloudnative/AndroidAccountCredentialController.kt
Large diffs are not rendered by default.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
androidApp/src/main/kotlin/dev/obiente/nextcloudnative/AndroidAccountOperationGuard.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package dev.obiente.nextcloudnative | ||
|
|
||
| import kotlinx.coroutines.sync.Mutex | ||
| import kotlinx.coroutines.sync.withLock | ||
|
|
||
| internal class AndroidAccountOperationGuard { | ||
| private val monitor = Any() | ||
| private val accountLeases = mutableMapOf<String, AccountLease>() | ||
|
|
||
| suspend fun <Result> withAccount(accountId: String, action: suspend () -> Result): Result { | ||
| val lease = synchronized(monitor) { | ||
| accountLeases.getOrPut(accountId) { AccountLease() }.also { it.references += 1 } | ||
| } | ||
| return try { | ||
| lease.mutex.withLock { action() } | ||
| } finally { | ||
| synchronized(monitor) { | ||
| lease.references -= 1 | ||
| if (lease.references == 0) accountLeases.remove(accountId, lease) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| suspend fun <Result> withAccountSession( | ||
| accountId: String, | ||
| resolveSession: suspend () -> dev.obiente.nextcloudnative.app.NextcloudSession?, | ||
| unavailable: suspend () -> Result, | ||
| action: suspend (dev.obiente.nextcloudnative.app.NextcloudSession) -> Result, | ||
| ): Result = withAccount(accountId) { | ||
| val session = resolveSession() | ||
| if (androidAccountOperationSessionIsCurrent(accountId, session)) { | ||
| action(requireNotNull(session)) | ||
| } else { | ||
| unavailable() | ||
| } | ||
| } | ||
|
|
||
| private class AccountLease( | ||
| val mutex: Mutex = Mutex(), | ||
| var references: Int = 0, | ||
| ) | ||
| } | ||
|
|
||
| internal val ANDROID_ACCOUNT_OPERATION_GUARD = AndroidAccountOperationGuard() | ||
|
|
||
| internal fun androidAccountOperationSessionIsCurrent( | ||
| expectedAccountId: String, | ||
| currentSession: dev.obiente.nextcloudnative.app.NextcloudSession?, | ||
| ): Boolean = currentSession != null && NextcloudDocumentIds.accountKey(currentSession) == expectedAccountId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
androidApp/src/main/kotlin/dev/obiente/nextcloudnative/AndroidDurableUploadAccountCleanup.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package dev.obiente.nextcloudnative | ||
|
|
||
| import android.content.Context | ||
| import androidx.work.WorkManager | ||
| import androidx.work.await | ||
|
|
||
| internal class AndroidDurableUploadAccountCleanup(context: Context) { | ||
| private val appContext = context.applicationContext | ||
| private val store = AndroidDurableMultipartUploadStore(appContext) | ||
|
|
||
| suspend fun removeForAccount(accountId: String) { | ||
| store.list().filter { job -> job.accountId == accountId }.forEach { job -> | ||
| WorkManager.getInstance(appContext).cancelUniqueWork(durableUploadWorkName(job.id)).await() | ||
| } | ||
| val removed = store.removeForAccount(accountId) | ||
| val picker = AndroidLocalUploadPicker(appContext) | ||
| removed.forEach { job -> picker.release(job.request.file) } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When removing an inactive account with queued durable uploads,
AndroidLocalUploadPicker.releasecan returnfalseif deleting its persisted capability metadata fails, but this result is ignored afterremoveForAccounthas already deleted the queue rows. Account removal then reports success while the encrypted URI metadata, and potentially its persisted grant, has no remaining recovery record or cleanup path; retain the job until release succeeds or surface and durably track the partial cleanup.AGENTS.md reference: AGENTS.md:L292-L293
Useful? React with 👍 / 👎.