Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Add test notification to help debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Mar 20, 2024
1 parent a76da68 commit 7074dc7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<string name="UnifiedPushNotificationBuilder__endpoint_changed_airgaped">Your UnifiedPush endpoint has changed. You must update your connection on MollySocket.</string>
<string name="UnifiedPushNotificationBuilder__endpoint_changed_error">An error occurred while changing your UnifiedPush endpoint. Try to register again to MollySocket.</string>
<string name="UnifiedPushNotificationBuilder__registration_failed">Your UnifiedPush distributor refused the registration. You may not have any connection or a requirement is missing for your distributor.</string>
<string name="UnifiedPushNotificationBuilder__test">This is a test notification received from your MollySocket server.</string>
<string name="NotificationMethod__label_unifiedpush">UnifiedPush</string>
<string name="NotificationMethod__label_fcm">Google Services</string>
<string name="NotificationMethod__label_websocket">WebSocket</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

0 comments on commit 7074dc7

Please sign in to comment.