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 91e19dbf32..0f12ecd845 100644 --- a/src/org/thoughtcrime/securesms/loki/api/LokiPushNotificationManager.kt +++ b/src/org/thoughtcrime/securesms/loki/api/LokiPushNotificationManager.kt @@ -9,7 +9,6 @@ import org.whispersystems.libsignal.logging.Log import org.whispersystems.signalservice.internal.util.JsonUtil import org.whispersystems.signalservice.loki.api.PushNotificationAcknowledgement import org.whispersystems.signalservice.loki.api.onionrequests.OnionRequestAPI -import java.io.IOException object LokiPushNotificationManager { private val tokenExpirationInterval = 12 * 60 * 60 * 1000 @@ -17,8 +16,8 @@ object LokiPushNotificationManager { private val server by lazy { PushNotificationAcknowledgement.shared.server } - private val PNServerPublicKey by lazy { - PushNotificationAcknowledgement.shared.PNServerPublicKey + private val pnServerPublicKey by lazy { + PushNotificationAcknowledgement.pnServerPublicKey } enum class ClosedGroupOperation { @@ -39,15 +38,14 @@ object LokiPushNotificationManager { val url = "$server/unregister" val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) val request = Request.Builder().url(url).post(body) - val promise = OnionRequestAPI.sendOnionRequest(request.build(), server, PNServerPublicKey).map { json -> + OnionRequestAPI.sendOnionRequest(request.build(), server, pnServerPublicKey).map { json -> val code = json["code"] as? Int if (code != null && code != 0) { TextSecurePreferences.setIsUsingFCM(context, false) } else { Log.d("Loki", "Couldn't disable FCM due to error: ${json["message"] as? String ?: "null"}.") } - } - promise.fail { exception -> + }.fail { exception -> Log.d("Loki", "Couldn't disable FCM due to error: ${exception}.") } // Unsubscribe from all closed groups @@ -67,7 +65,7 @@ object LokiPushNotificationManager { val url = "$server/register" val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) val request = Request.Builder().url(url).post(body) - val promise = OnionRequestAPI.sendOnionRequest(request.build(), server, PNServerPublicKey).map { json -> + OnionRequestAPI.sendOnionRequest(request.build(), server, pnServerPublicKey).map { json -> val code = json["code"] as? Int if (code != null && code != 0) { TextSecurePreferences.setIsUsingFCM(context, true) @@ -76,8 +74,7 @@ object LokiPushNotificationManager { } else { Log.d("Loki", "Couldn't register for FCM due to error: ${json["message"] as? String ?: "null"}.") } - } - promise.fail { exception -> + }.fail { exception -> Log.d("Loki", "Couldn't register for FCM due to error: ${exception}.") } // Subscribe to all closed groups @@ -94,13 +91,12 @@ object LokiPushNotificationManager { val url = "$server/${operation.rawValue}" val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) val request = Request.Builder().url(url).post(body) - val promise = OnionRequestAPI.sendOnionRequest(request.build(), server, PNServerPublicKey).map { json -> + OnionRequestAPI.sendOnionRequest(request.build(), server, pnServerPublicKey).map { json -> val code = json["code"] as? Int if (code == null || code == 0) { Log.d("Loki", "Couldn't subscribe/unsubscribe closed group: $closedGroupPublicKey due to error: ${json["message"] as? String ?: "null"}.") } - } - promise.fail { exception -> + }.fail { exception -> Log.d("Loki", "Couldn't subscribe/unsubscribe closed group: $closedGroupPublicKey due to error: ${exception}.") } } 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 { diff --git a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt index 57310ee18d..da527c5f87 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt @@ -129,7 +129,7 @@ class ClosedGroupUpdateMessageSendJob private constructor(parameters: Parameters // isClosedGroup can always be false as it's only used in the context of legacy closed groups messageSender.sendMessage(0, address, udAccess.get().targetUnidentifiedAccess, Date().time, serializedContentMessage, false, ttl, false, - useFallbackEncryption, false, false) + useFallbackEncryption, false, false, false) } catch (e: Exception) { Log.d("Loki", "Failed to send closed group update message to: $destination due to error: $e.") } diff --git a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt index 2ff6e2a137..84be28d0f4 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt @@ -35,7 +35,7 @@ import java.io.IOException import java.util.* object ClosedGroupsProtocol { - val isSharedSenderKeysEnabled = false + val isSharedSenderKeysEnabled = true val groupSizeLimit = 10 public fun createClosedGroup(context: Context, name: String, members: Collection): Promise { diff --git a/src/org/thoughtcrime/securesms/loki/protocol/NullMessageSendJob.kt b/src/org/thoughtcrime/securesms/loki/protocol/NullMessageSendJob.kt index 821a281eb2..7983ecfbbd 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/NullMessageSendJob.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/NullMessageSendJob.kt @@ -56,7 +56,7 @@ class NullMessageSendJob private constructor(parameters: Parameters, private val try { messageSender.sendMessage(0, address, udAccess.get().targetUnidentifiedAccess, Date().time, serializedContentMessage, false, ttl, false, - false, false, false) + false, false, false, false) } catch (e: Exception) { Log.d("Loki", "Failed to send null message to: $publicKey due to error: $e.") throw e diff --git a/src/org/thoughtcrime/securesms/loki/protocol/SessionRequestMessageSendJob.kt b/src/org/thoughtcrime/securesms/loki/protocol/SessionRequestMessageSendJob.kt index 155ca1e29b..5e2758d8bd 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/SessionRequestMessageSendJob.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/SessionRequestMessageSendJob.kt @@ -72,7 +72,7 @@ class SessionRequestMessageSendJob private constructor(parameters: Parameters, p try { messageSender.sendMessage(0, address, udAccess.get().targetUnidentifiedAccess, Date().time, serializedContentMessage, false, ttl, false, - true, false, false) + true, false, false, false) } catch (e: Exception) { Log.d("Loki", "Failed to send session request to: $publicKey due to error: $e.") throw e