mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 17:27:45 +00:00
Hopefully improve PN reliability
This commit is contained in:
parent
86ea104e01
commit
114c08d764
@ -524,7 +524,7 @@
|
|||||||
<service
|
<service
|
||||||
android:name="org.thoughtcrime.securesms.loki.api.PushNotificationService"
|
android:name="org.thoughtcrime.securesms.loki.api.PushNotificationService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@ -681,7 +681,9 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<!-- Session -->
|
<!-- Session -->
|
||||||
<receiver android:name="org.thoughtcrime.securesms.loki.api.BackgroundPollListener" >
|
<receiver
|
||||||
|
android:name="org.thoughtcrime.securesms.loki.api.BackgroundPollListener"
|
||||||
|
android:enabled="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
@ -484,7 +484,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
Context context = this;
|
Context context = this;
|
||||||
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> {
|
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> {
|
||||||
if (!task.isSuccessful()) {
|
if (!task.isSuccessful()) {
|
||||||
Log.w(TAG, "getInstanceId failed", task.getException());
|
Log.w("Loki", "FirebaseInstanceId.getInstance().getInstanceId() failed." + task.getException());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String token = task.getResult().getToken();
|
String token = task.getResult().getToken();
|
||||||
|
@ -51,15 +51,19 @@ object LokiPushNotificationManager {
|
|||||||
val code = json?.get("code") as? Int
|
val code = json?.get("code") as? Int
|
||||||
if (code != null && code != 0) {
|
if (code != null && code != 0) {
|
||||||
TextSecurePreferences.setIsUsingFCM(context, false)
|
TextSecurePreferences.setIsUsingFCM(context, false)
|
||||||
|
Log.d("Loki", "Successfully unregistered from FCM.")
|
||||||
} else {
|
} else {
|
||||||
Log.d("Loki", "Couldn't disable FCM due to error: ${json?.get("message") as? String ?: "null"}.")
|
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) {
|
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
|
// Unsubscribe from all closed groups
|
||||||
@ -91,15 +95,19 @@ object LokiPushNotificationManager {
|
|||||||
TextSecurePreferences.setIsUsingFCM(context, true)
|
TextSecurePreferences.setIsUsingFCM(context, true)
|
||||||
TextSecurePreferences.setFCMToken(context, token)
|
TextSecurePreferences.setFCMToken(context, token)
|
||||||
TextSecurePreferences.setLastFCMUploadTime(context, System.currentTimeMillis())
|
TextSecurePreferences.setLastFCMUploadTime(context, System.currentTimeMillis())
|
||||||
|
Log.d("Loki", "Successfully registered for FCM.")
|
||||||
} else {
|
} else {
|
||||||
Log.d("Loki", "Couldn't register for FCM due to error: ${json?.get("message") as? String ?: "null"}.")
|
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) {
|
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
|
// Subscribe to all closed groups
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
package org.thoughtcrime.securesms.loki.api
|
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.FirebaseMessagingService
|
||||||
import com.google.firebase.messaging.RemoteMessage
|
import com.google.firebase.messaging.RemoteMessage
|
||||||
import org.thoughtcrime.securesms.jobs.PushContentReceiveJob
|
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.internal.util.Base64
|
||||||
import org.whispersystems.signalservice.loki.api.MessageWrapper
|
import org.whispersystems.signalservice.loki.api.MessageWrapper
|
||||||
|
|
||||||
|
|
||||||
class PushNotificationService : FirebaseMessagingService() {
|
class PushNotificationService : FirebaseMessagingService() {
|
||||||
|
|
||||||
override fun onNewToken(token: String) {
|
override fun onNewToken(token: String) {
|
||||||
@ -19,7 +26,8 @@ class PushNotificationService : FirebaseMessagingService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onMessageReceived(message: RemoteMessage) {
|
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) }
|
val data = base64EncodedData?.let { Base64.decode(it) }
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user