Skip to content

Fix local signer approval sheet stuck empty on cold start - #1121

Open
chadcurtis wants to merge 1 commit into
PrimalHQ:mainfrom
chadcurtis:fix/local-signer-stuck-approval-sheet
Open

chadcurtis wants to merge 1 commit into
PrimalHQ:mainfrom
chadcurtis:fix/local-signer-stuck-approval-sheet

Conversation

@chadcurtis

Copy link
Copy Markdown

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:

  1. The content provider runs before the app is initialized. LocalSignerContentProvider.query runs on a binder thread, which can start before PrimalApp.onCreate has finished. Resolving LocalSignerService then throws:
    IllegalStateException: You need to call init(ApplicationContext) first.
      at AndroidRepositoryFactory.getAccountDatabase
      at RepositoryFactory.createLocalAppRepository
      at AccountRepositoriesModule.provideLocalAppRepository
      at LocalSignerContentProvider.query
    
    The provider returns null, so the client falls back to the nostrsigner: intent, as NIP-55 says it should.
  2. The sheet never answers requests it handles automatically. In SignerActivity, a request covered by a stored permission is allowed or denied without ever entering the pending queue. PermissionRequestsViewModel only 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

  • PrimalApp exposes awaitInitialization(timeout), a latch released at the end of onCreate. The provider waits on it (up to 5 s) before resolving its dependencies.
  • PermissionRequestsViewModel sends responses immediately after processing a request if nothing is waiting for the user. This uses the new LocalSignerService.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.

Build Cold start, request covered by stored permission Low Trust, user approves
main (3.5.29), also release 3.5.28 Empty sheet, stuck —
ViewModel fix only Provider still fails, sheet opens, then replies and closes on its own —
Both fixes No sheet: provider answers in the background Sheet lists the request, Allow replies, client continues
  • New PermissionRequestsViewModelTest covers 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) and compileGoogleDebugKotlin pass locally. The Google compile skipped processGoogleDebugGoogleServices because I don't have your google-services.json.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant