From 114c08d764e33f7bb93b64d8089cc114d87a00b1 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 18 Sep 2020 10:34:30 +1000 Subject: [PATCH] Hopefully improve PN reliability --- AndroidManifest.xml | 6 ++++-- .../thoughtcrime/securesms/ApplicationContext.java | 2 +- .../loki/api/LokiPushNotificationManager.kt | 12 ++++++++++-- .../securesms/loki/api/PushNotificationService.kt | 10 +++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2c6f4ee9e7..13dbb534ab 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -524,7 +524,7 @@ + android:exported="false"> @@ -681,7 +681,9 @@ - + diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 2961ddbd8a..98545215fe 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -484,7 +484,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc Context context = this; FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> { if (!task.isSuccessful()) { - Log.w(TAG, "getInstanceId failed", task.getException()); + Log.w("Loki", "FirebaseInstanceId.getInstance().getInstanceId() failed." + task.getException()); return; } String token = task.getResult().getToken(); diff --git a/src/org/thoughtcrime/securesms/loki/api/LokiPushNotificationManager.kt b/src/org/thoughtcrime/securesms/loki/api/LokiPushNotificationManager.kt index 19f49bf67e..39e9f57b3c 100644 --- a/src/org/thoughtcrime/securesms/loki/api/LokiPushNotificationManager.kt +++ b/src/org/thoughtcrime/securesms/loki/api/LokiPushNotificationManager.kt @@ -51,15 +51,19 @@ object LokiPushNotificationManager { val code = json?.get("code") as? Int if (code != null && code != 0) { TextSecurePreferences.setIsUsingFCM(context, false) + Log.d("Loki", "Successfully unregistered from FCM.") } else { Log.d("Loki", "Couldn't disable FCM due to error: ${json?.get("message") as? String ?: "null"}.") } } + else -> { + Log.d("Loki", "Couldn't disable FCM.") + } } } override fun onFailure(call: Call, exception: IOException) { - Log.d("Loki", "Couldn't disable FCM.") + Log.d("Loki", "Couldn't disable FCM due to error: $exception.") } }) // Unsubscribe from all closed groups @@ -91,15 +95,19 @@ object LokiPushNotificationManager { TextSecurePreferences.setIsUsingFCM(context, true) TextSecurePreferences.setFCMToken(context, token) TextSecurePreferences.setLastFCMUploadTime(context, System.currentTimeMillis()) + Log.d("Loki", "Successfully registered for FCM.") } else { Log.d("Loki", "Couldn't register for FCM due to error: ${json?.get("message") as? String ?: "null"}.") } } + else -> { + Log.d("Loki", "Couldn't register for FCM due.") + } } } override fun onFailure(call: Call, exception: IOException) { - Log.d("Loki", "Couldn't register for FCM.") + Log.d("Loki", "Couldn't register for FCM due to error: $exception.") } }) // Subscribe to all closed groups diff --git a/src/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt b/src/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt index 90ef502e96..b4b2ec11d3 100644 --- a/src/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt +++ b/src/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt @@ -1,5 +1,11 @@ package org.thoughtcrime.securesms.loki.api +import android.R +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.Intent +import android.graphics.Color +import android.media.RingtoneManager import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import org.thoughtcrime.securesms.jobs.PushContentReceiveJob @@ -9,6 +15,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope import org.whispersystems.signalservice.internal.util.Base64 import org.whispersystems.signalservice.loki.api.MessageWrapper + class PushNotificationService : FirebaseMessagingService() { override fun onNewToken(token: String) { @@ -19,7 +26,8 @@ class PushNotificationService : FirebaseMessagingService() { } override fun onMessageReceived(message: RemoteMessage) { - val base64EncodedData = message.data["ENCRYPTED_DATA"] + Log.d("Loki", "Received a push notification.") + val base64EncodedData = message.data?.get("ENCRYPTED_DATA") val data = base64EncodedData?.let { Base64.decode(it) } if (data != null) { try {