7.4 KiB
7.4 KiB
39. Android App — Push Notifications, Biometrics, Voice Enrollment, Call Screening
meta: id: shieldai-unified-restructure-39 feature: shieldai-unified-restructure priority: P1 depends_on: [shieldai-unified-restructure-34, shieldai-unified-restructure-35, shieldai-unified-restructure-36, shieldai-unified-restructure-37, shieldai-unified-restructure-38] tags: [android, jetpack-compose, native-features, push, biometrics, call-screening, mobile]
objective:
- Implement native Android features that differentiate the mobile experience: push notifications via FCM, biometric authentication, voice enrollment with audio recording, and call screening integration for SpamShield.
deliverables:
android/app/src/main/java/com/shieldai/android/service/FCMService.kt— Firebase Cloud Messaging:- Extends
FirebaseMessagingService onMessageReceived— processes incoming notificationsonNewToken— sends token to backend (task 14)- Creates notification channels for different alert types
- Rich notifications with images and actions
- Deep links to relevant screens based on payload
- Extends
android/app/src/main/java/com/shieldai/android/ui/screens/auth/BiometricAuthScreen.kt— Biometric prompt:- Uses
BiometricPromptfromandroidx.biometric:biometric - Face/fingerprint authentication
- Fallback to device PIN/pattern/password
- Stores credential in
EncryptedSharedPreferences
- Uses
android/app/src/main/java/com/shieldai/android/ui/screens/voiceprint/RecordingScreen.kt— Voice recording:- Real-time waveform visualization using
AudioRecord+Canvas - Record / stop / playback controls
- Duration timer
- Quality check (minimum duration, amplitude threshold)
- Submit enrollment to API
- Real-time waveform visualization using
android/app/src/main/java/com/shieldai/android/service/CallScreeningService.kt— Call screening:- Extends
CallScreeningService(API 29+) - Intercepts incoming calls
- Queries
spamshield.checkNumbervia API - Displays caller info overlay with reputation score
- Auto-blocks known spam numbers based on user rules
- Logs screened calls for history
- Extends
android/app/src/main/java/com/shieldai/android/util/PermissionManager.kt— Permission handling:- Centralized manager for all runtime permissions
- Camera, microphone, phone, notifications, call screening
- Handles permission rationale and denied states
android/app/src/main/AndroidManifest.xml— Updated permissions and services:INTERNET,RECORD_AUDIO,READ_PHONE_STATE,CALL_PHONEBIND_CALL_SCREENING_SERVICERECEIVE_BOOT_COMPLETED(for starting services)- FCM service declaration
- Call screening service declaration
steps:
- Push Notifications (FCM):
- Add
google-services.jsontoapp/directory - Add
com.google.gms:google-servicesplugin to build.gradle - Create
FCMService.ktextendingFirebaseMessagingService onNewToken: send to backend viaapi.notification.registerDeviceonMessageReceived:- Parse notification payload
- Create notification channel if not exists (Android 8+)
- Show notification with
NotificationManager - Handle data messages (silent pushes) for background sync
- Add
FirebaseMessaging.getInstance().subscribeToTopic("alerts")for broadcast alerts - Handle notification tap: extract
screenandid, navigate via deep link
- Add
- Biometric Auth:
BiometricPromptwithBiometricPrompt.PromptInfosetDeviceCredentialAllowed(true)for fallbacksetConfirmationRequired(false)for faster auth- On success: unlock
EncryptedSharedPreferences - Show prompt on app launch if biometric is enabled
- Voice Recording:
- Request
RECORD_AUDIOpermission at runtime AudioRecordwithMediaRecorder.AudioSource.MIC- Configuration: 16kHz, mono, 16-bit PCM
- Real-time waveform: read amplitude in a coroutine, update
Canvaspath - Minimum duration: 5 seconds
- Save as WAV file
- Playback with
MediaPlayer - Submit to API via multipart upload
- Request
- Call Screening:
- Extend
CallScreeningService onScreenCall(details)callback when incoming call arrives- Extract phone number from
Call.Details - Query API:
spamshield.checkNumber(use cached result if available) respondToCallwithCallResponse.Builder:- If spam:
setDisallowCall(true),setRejectCall(true),setSkipCallLog(false) - If suspicious:
setDisallowCall(false)but show warning notification - If clean:
setDisallowCall(false)
- If spam:
- Show custom incoming call UI overlay (optional, requires additional permissions)
- Log all screened calls to local DB
- Extend
- Permission Manager:
checkPermission(permission)→ booleanrequestPermission(permission, rationale)→ shows dialog, then system prompthandlePermissionResult(requestCode, permissions, grantResults)- Guides user to Settings if permission permanently denied
- Update manifest:
- Add all required permissions
- Declare FCM service with
android:exported="false" - Declare call screening service with
android:permission="android.permission.BIND_CALL_SCREENING_SERVICE"
- Test on physical device (emulator cannot test FCM, biometrics, or call screening accurately).
steps:
- Unit: FCMService parses notification payload correctly
- Unit: BiometricPrompt configuration is valid
- Unit: PermissionManager returns correct status for each permission
- Integration: FCM token registration sends correct data to backend
- E2E: Receive test push notification and verify deep link navigation
- E2E: Record voice sample and submit enrollment successfully
- E2E: Simulate incoming call and verify screening logic
acceptance_criteria:
- App registers for FCM and sends device token to backend
- Incoming push notifications display correctly with channels and actions
- Tapping a notification deep links to the correct screen
- Face/fingerprint authentication works for app unlock
- Voice recording captures audio, shows waveform, and submits enrollment
- Call screening intercepts incoming calls and blocks known spam
- All permission requests include explanatory rationale
- Denied permissions show helpful guidance to Settings app
- Native features work on phones with API 26+
validation:
- Test push notifications using Firebase Console
- Verify biometric auth on device with face/fingerprint sensor
- Record a 10-second voice sample and verify enrollment created in backend
- Simulate incoming call using
adb shell am start -a android.intent.action.CALL -d tel:1234567890 - Run
./gradlew testfor unit tests
notes:
- FCM requires a
google-services.jsonfile from Firebase Console. Add setup instructions to README. - Call screening (
CallScreeningService) is only available on Android 10+ (API 29+). For older versions, use a broadcast receiver forPHONE_STATEchanges as fallback. - The call screening service runs in the background and must be lightweight. Offload API calls to a coroutine.
- For call screening UI, the system provides a default incoming call screen. Custom UI overlays require
SYSTEM_ALERT_WINDOWpermission and are complex to implement correctly. - Voice recording quality matters for ML model accuracy. Use 16kHz mono WAV — this matches the web app's preprocessing pipeline.
- Biometric auth should be optional. Users can always use password login.
- Consider adding a Quick Settings tile for toggling call screening on/off.
- For Android 14+ (API 34+), use the new
android.telecom.Call ScreeningAPIs if available.