Repository navigation
Fix local signer approval sheet stuck empty on cold start - #1121
Open
chadcurtis wants to merge 1 commit into
Open
chadcurtis wants to merge 1 commit into
chadcurtis wants to merge 1 commit into
Conversation
When a NIP-55 client (Ditto, etc.) calls Primal while Primal isn't running, two bugs combine into an empty "App requests" sheet that never answers the client and can't be acted on. LocalSignerContentProvider.query runs on a binder thread and can run before PrimalApp.onCreate has initialized AccountRepositoryFactory. Resolving LocalSignerService then throws "You need to call init(ApplicationContext) first", the provider returns null, and the client falls back to the signer intent. The provider now waits for application initialization before resolving its dependencies. In SignerActivity, a request already allowed or denied by a stored permission is answered without entering the pending queue. Responses were only sent when that queue went from non-empty to empty, so they never were. PermissionRequestsViewModel now sends responses right away when nothing waits for user action.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
If a NIP-55 client app opens while Primal isn't running, Primal shows its "App requests" sheet with no requests listed. Reject Selected and Allow Selected are disabled, the sheet can't be swiped away, and the client never gets an answer. A Ditto user reported this happening every time they opened the app.
Two bugs combine to cause it:
LocalSignerContentProvider.queryruns on a binder thread, which can start beforePrimalApp.onCreatehas finished. ResolvingLocalSignerServicethen throws:null, so the client falls back to thenostrsigner:intent, as NIP-55 says it should.SignerActivity, a request covered by a stored permission is allowed or denied without ever entering the pending queue.PermissionRequestsViewModelonly sends responses when that queue goes from non-empty to empty, so these responses are never sent. The sheet stays open with an empty list.Fix
PrimalAppexposesawaitInitialization(timeout), a latch released at the end ofonCreate. The provider waits on it (up to 5 s) before resolving its dependencies.PermissionRequestsViewModelsends responses immediately after processing a request if nothing is waiting for the user. This uses the newLocalSignerService.hasPendingMethods().Verification
Tested on a Pixel 8a (Android 16) with Ditto 2.46.7 as the client, using a throwaway key and Medium Trust. Each test killed both apps first, then opened Ditto cold.
main(3.5.29), also release 3.5.28PermissionRequestsViewModelTestcovers four cases: stored allow, stored deny, pending, and unknown app. With the ViewModel change reverted, the stored-allow and stored-deny tests fail.ktlintCheck,detekt,testAospDebugUnitTest(351 tests),:data:account:repository:allTests,lintAospDebug(0 errors) andcompileGoogleDebugKotlinpass locally. The Google compile skippedprocessGoogleDebugGoogleServicesbecause I don't have yourgoogle-services.json.