Act as an Android Kotlin engineer. Create a production-ready Android WebView application for our chat app with the following requirements:
- Configure a modern WebView with JavaScript enabled, DomStorage enabled, and Database enabled.
- Attach a WebChromeClient with onPermissionRequest overridden to automatically grant android.webkit.PermissionRequest.RESOURCE_AUDIO_CAPTURE and RESOURCE_VIDEO_CAPTURE for WebRTC audio/video calls.
- Ensure the WebView user agent includes "IndoGramAndroid" tag for environment detection.
- Add a JavascriptInterface named "AndroidBridge" with the following methods:
getFCMToken(): returns the cached Firebase Cloud Messaging registration token as a String.onUserLoggedIn(userId: String, phone: String, extraJson: String): stores the active logged-in user state.onUserLoggedOut(): clears native user sessions and unregisters token if needed.onCallStateChanged(state: String, callDataJson: String): handles incoming/outgoing call notifications.showNotification(title: String, body: String, payloadJson: String): shows an Android native status bar notification.
- Implement FirebaseMessagingService (
onNewTokenandonMessageReceived). - On new token, pass the token into the WebView via
evaluateJavascript("window.setDeviceFCMToken('$token')"). - In
onMessageReceived, build and display a standard Android Notification withNotificationCompat.Builder(usingNotificationChannelon Android 8.0+). - Attach a
PendingIntentto the notification with a target"chatId"extra. - When the user taps the notification, the
MainActivityshould launch and call:evaluateJavascript("window.onAndroidNotificationClick('$chatId')", null).
- Request
POST_NOTIFICATIONS(Android 13+),CAMERA, andRECORD_AUDIOat runtime before initiating calls.