feat: p2p wifi hotspot sync - android implementation#431
Open
paulpascal wants to merge 11 commits intomedic:masterfrom
Open
feat: p2p wifi hotspot sync - android implementation#431paulpascal wants to merge 11 commits intomedic:masterfrom
paulpascal wants to merge 11 commits intomedic:masterfrom
Conversation
Wave 1 zero-dependency modules: ScopeGuard for doc classification (IN_SCOPE/TRANSIT/REJECTED), JWT authentication with ECDSA P-256, revocation list, sync mutex, P2P config reader, and session model.
Wave 2 core integration: NanoHTTPD local server with auth, get-ids, bulk-get, accept-docs, get-deletes, and status endpoints. WiFi hotspot management (production + loopback for dev). Foreground service, notification channel, OEM battery helper. Session tracking, telemetry reporter, transit doc manager with PouchDB bridge.
Wave 3 wiring: P2pManager orchestrates full sync lifecycle. P2pBridgeMethods exposes @JavascriptInterface to WebView. QR code generation (Supervisor) and scanning (CHW). P2pSyncClient for CHW-side HTTP sync. Permission activity for camera/WiFi/location. Integrates into build.gradle (NanoHTTPD + ZXing deps), AndroidManifest.xml, MedicAndroidJavascript bridge, and EmbeddedBrowserActivity.
Wave 4 tests: ScopeGuard classify() determinism, P2pAuthenticator JWT verification, SyncMutex concurrency, TransitDocManager lifecycle.
Default allowed roles changed from ['chw', 'chw_supervisor'] to empty list. Roles must come from app_settings p2p_sync config. Removed hardcoded 'chw_supervisor' string in tracker session start.
14 tasks
- Add serialVersionUID to JwtVerificationException and P2pInitException - Use try-with-resources in P2pSyncClient.readBody() - Suppress CloseResource in LocalHttpServer (stream owned by NanoHTTPD) - Fix CallSuperLast in QrScannerActivity.onSaveInstanceState() - Fix EmptyCatchBlock in P2pAuthenticatorTest
- Extract string constants to reduce duplication (S1192) - Reduce cognitive complexity by extracting helpers (S3776) - Replace generic Exception catches with specific types (S112) - Use Builder pattern for P2pConfig constructor (S107) - Introduce ServerDeps/HotspotCredentials to reduce param counts (S107) - Add synchronized to getState() matching setState() (S2886) - Remove unused imports (S1128) - Fix int overflow in time calculations (S2184) - Handle InterruptedException properly (S2142) - Merge switch cases (S6208)
- JwtVerifier: replace switch with if, add default, use specific exception - P2pAuthenticator: use pattern matching instanceof - RevocationList: extract helpers for complexity - ScopeManifest: extract helpers, use pattern matching instanceof - StatusEndpoint: use specific exception - TransitDocManager: remove unused import, fix int overflow, extract helpers, extract constants for duplicated literals
AcceptDocsEndpoint: extract KEY_PARENT constant, break doHandle/hydrateParentLineage/ fetchAndCacheParentChains/classifyTransitDocs into helpers, remove unused param ScopeGuard: extract constants, break classify into helpers, remove throws JSONException WifiHotspotProvider: extract helpers, fix InterruptedException handling, add logging LocalHttpServer: consolidate constructors, extract helpers P2pBridgeMethods: extract 7 constants, extract nested try blocks into methods, remove commented code, reduce complexity P2pManager: remove unused params, extract constant, merge nested if QrCodeHelper: use EnumMap, extract validation helpers OemBatteryHelper: data-driven brand guidance AuthEndpoint/P2pConfig: extract helpers Tests: assertNull, add assertions, suppress parameterized test suggestions
bbea9a8 to
3163fc4
Compare
- Convert all indentation to tabs (cht-android convention) - Move string concatenation operators to end of previous line (OperatorWrap) - Fix ParenPad violation in LocalHttpServer
3163fc4 to
ef5e4a9
Compare
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.
Summary
Android implementation of P2P WiFi Hotspot sync for CHT. Enables a Supervisor's phone to create a local WiFi hotspot and receive health data from CHW phones, without internet access.
This PR covers the full Android P2P module. The related server/webapp PR is at medic/cht-core#10893.
What's included
Foundation:
ScopeGuard: Deterministic document classification (IN_SCOPE / TRANSIT / REJECTED) based on facility hierarchy and replication depthP2pAuthenticator+JwtVerifier— Offline JWT verification with ECDSA P-256SyncMutex: Ensures only one sync (P2P or server) runs at a timeP2pConfig: Reads P2P configuration from app_settingsHTTP Server:
LocalHttpServer: NanoHTTPD-based HTTPS server running on the Supervisor's phoneAcceptDocsEndpoint: Receives docs, classifies via ScopeGuard, writes withnew_edits: falseWiFi + Service:
WifiHotspotProvider: Android LocalOnlyHotspot (API 26+), isolated network with no internet routingLoopbackHotspotProvider: Dev/emulator fallbackP2pForegroundService: Keeps hotspot alive during syncOemBatteryHelper: Per-OEM battery optimization guidanceTransit + Tracking:
TransitDocManager: Tracks transit docs in_local/p2p-transit-docsP2pTracker+P2pTelemetryReporter: Session metrics and telemetryOrchestrator + Bridge:
P2pManager: Master orchestrator: capability check , permissions , hotspot , HTTP server , QR , sync , teardownP2pBridgeMethods: 20@JavascriptInterfacemethods for WebView communicationQrCodeHelper+QrScannerActivity: ZXing QR generation and scanningKey design decisions:
Files changed
p2p/package