From 75616c019fa36c56d0e98a354934d2a32c3f7d61 Mon Sep 17 00:00:00 2001 From: S1m Date: Thu, 21 Mar 2024 00:07:51 +0100 Subject: [PATCH] Add test notification to help debugging --- app/src/main/res/values/strings2.xml | 1 + .../im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt | 8 +++++++- .../unifiedpush/util/UnifiedPushNotificationBuilder.kt | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings2.xml b/app/src/main/res/values/strings2.xml index 2cb329e932..e64aaafc04 100644 --- a/app/src/main/res/values/strings2.xml +++ b/app/src/main/res/values/strings2.xml @@ -151,6 +151,7 @@ Your UnifiedPush endpoint has changed. You must update your connection on MollySocket. An error occurred while changing your UnifiedPush endpoint. Try to register again to MollySocket. Your UnifiedPush distributor refused the registration. You may not have any connection or a requirement is missing for your distributor. + This is a test notification received from your MollySocket server. UnifiedPush Google Services WebSocket diff --git a/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt b/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt index 5ea99c3e17..834216ff83 100644 --- a/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt +++ b/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt @@ -42,9 +42,15 @@ class UnifiedPushReceiver : MessagingReceiver() { } override fun onMessage(context: Context, message: ByteArray, instance: String) { + val msg = message.toString(Charsets.UTF_8) + if (msg.contains("\"test\":true")) { + Log.d(TAG, "Test message received.") + UnifiedPushNotificationBuilder(context).setNotificationTest() + return + } if (KeyCachingService.isLocked()) { // We look directly in the message to avoid its deserialization - if (message.toString(Charsets.UTF_8).contains("\"urgent\":true") && + if (msg.contains("\"urgent\":true") && TextSecurePreferences.isPassphraseLockNotificationsEnabled(context)) { Log.d(TAG, "New urgent message received while app is locked.") FcmFetchManager.postMayHaveMessagesNotification(context) diff --git a/app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.kt b/app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.kt index 05868e7e1d..179c084db3 100644 --- a/app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.kt +++ b/app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.kt @@ -43,4 +43,9 @@ class UnifiedPushNotificationBuilder(val context: Context) { (context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) .notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__registration_failed))) } + + fun setNotificationTest() { + (context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) + .notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__test))) + } }