mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Hopefully improve PN reliability
This commit is contained in:
parent
86ea104e01
commit
114c08d764
@ -524,7 +524,7 @@
|
||||
<service
|
||||
android:name="org.thoughtcrime.securesms.loki.api.PushNotificationService"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
@ -681,7 +681,9 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<!-- Session -->
|
||||
<receiver android:name="org.thoughtcrime.securesms.loki.api.BackgroundPollListener" >
|
||||
<receiver
|
||||
android:name="org.thoughtcrime.securesms.loki.api.BackgroundPollListener"
|
||||
android:enabled="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user