mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
Fix
This commit is contained in:
parent
55216875ac
commit
d3ea4e2e30
@ -1,10 +1,22 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import com.huawei.hmf.tasks.Tasks
|
||||||
import com.huawei.hms.aaid.HmsInstanceId
|
import com.huawei.hms.aaid.HmsInstanceId
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.MainScope
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
class HuaweiPushManager(val context: Context): PushManager {
|
@Singleton
|
||||||
|
class HuaweiPushManager @Inject constructor(
|
||||||
|
@ApplicationContext private val context: Context,
|
||||||
|
private val genericPushManager: GenericPushManager
|
||||||
|
): PushManager {
|
||||||
private var huaweiPushInstanceIdJob: Job? = null
|
private var huaweiPushInstanceIdJob: Job? = null
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@ -17,13 +29,11 @@ class HuaweiPushManager(val context: Context): PushManager {
|
|||||||
|
|
||||||
val hmsInstanceId = HmsInstanceId.getInstance(context)
|
val hmsInstanceId = HmsInstanceId.getInstance(context)
|
||||||
|
|
||||||
val task = hmsInstanceId.aaid
|
MainScope().launch(Dispatchers.IO) {
|
||||||
|
val task = hmsInstanceId.aaid
|
||||||
// HuaweiPushNotificationService().start()
|
Tasks.await(task)
|
||||||
//
|
if (!isActive) return@launch // don't 'complete' task if we were canceled
|
||||||
// huaweiPushInstanceIdJob = HmsInstanceId.getInstance(this) { hmsInstanceId ->
|
task.result?.id?.let { genericPushManager.refresh(it, force) }
|
||||||
// RegisterHuaweiPushService(hmsInstanceId, this, force).start()
|
}
|
||||||
// Unit.INSTANCE
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,6 @@ import dagger.hilt.InstallIn
|
|||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
|
||||||
@InstallIn(SingletonComponent::class)
|
|
||||||
object HuaweiPushModule {
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideFirebasePushManager(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
) = HuaweiPushManager(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
abstract class HuaweiBindingModule {
|
abstract class HuaweiBindingModule {
|
||||||
|
@ -1,17 +1,9 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.core.app.NotificationCompat
|
|
||||||
import androidx.core.app.NotificationManagerCompat
|
|
||||||
import com.huawei.hms.push.HmsMessageService
|
import com.huawei.hms.push.HmsMessageService
|
||||||
import com.huawei.hms.push.RemoteMessage
|
import com.huawei.hms.push.RemoteMessage
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.session.libsession.messaging.jobs.BatchMessageReceiveJob
|
|
||||||
import org.session.libsession.messaging.jobs.JobQueue
|
|
||||||
import org.session.libsession.messaging.jobs.MessageReceiveParameters
|
|
||||||
import org.session.libsession.messaging.utilities.MessageWrapper
|
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
|
||||||
import org.session.libsignal.utilities.Base64
|
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -20,16 +12,13 @@ class HuaweiPushNotificationService: HmsMessageService() {
|
|||||||
|
|
||||||
@Inject lateinit var pushManager: PushManager
|
@Inject lateinit var pushManager: PushManager
|
||||||
@Inject lateinit var pushHandler: PushHandler
|
@Inject lateinit var pushHandler: PushHandler
|
||||||
|
|
||||||
override fun onNewToken(token: String?, bundle: Bundle?) {
|
override fun onNewToken(token: String?, bundle: Bundle?) {
|
||||||
Log.d("Loki", "New HCM token: $token.")
|
Log.d("Loki", "New HCM token: $token.")
|
||||||
pushManager.refresh(true)
|
pushManager.refresh(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMessageReceived(message: RemoteMessage?) {
|
override fun onMessageReceived(message: RemoteMessage?) {
|
||||||
pushHandler.onPush(message?.dataOfMap)
|
pushHandler.onPush(message?.dataOfMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDeletedMessages() {
|
override fun onDeletedMessages() {
|
||||||
pushManager.refresh(true)
|
pushManager.refresh(true)
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ import org.thoughtcrime.securesms.home.search.GlobalSearchViewModel
|
|||||||
import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity
|
import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
|
import org.thoughtcrime.securesms.notifications.PushManager
|
||||||
import org.thoughtcrime.securesms.onboarding.SeedActivity
|
import org.thoughtcrime.securesms.onboarding.SeedActivity
|
||||||
import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate
|
import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions
|
import org.thoughtcrime.securesms.permissions.Permissions
|
||||||
@ -106,6 +107,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
@Inject lateinit var groupDatabase: GroupDatabase
|
@Inject lateinit var groupDatabase: GroupDatabase
|
||||||
@Inject lateinit var textSecurePreferences: TextSecurePreferences
|
@Inject lateinit var textSecurePreferences: TextSecurePreferences
|
||||||
@Inject lateinit var configFactory: ConfigFactory
|
@Inject lateinit var configFactory: ConfigFactory
|
||||||
|
@Inject lateinit var pushManager: PushManager
|
||||||
|
|
||||||
private val globalSearchViewModel by viewModels<GlobalSearchViewModel>()
|
private val globalSearchViewModel by viewModels<GlobalSearchViewModel>()
|
||||||
private val homeViewModel by viewModels<HomeViewModel>()
|
private val homeViewModel by viewModels<HomeViewModel>()
|
||||||
@ -230,8 +232,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
(applicationContext as ApplicationContext).startPollingIfNeeded()
|
(applicationContext as ApplicationContext).startPollingIfNeeded()
|
||||||
// update things based on TextSecurePrefs (profile info etc)
|
// update things based on TextSecurePrefs (profile info etc)
|
||||||
// Set up remaining components if needed
|
// Set up remaining components if needed
|
||||||
val application = ApplicationContext.getInstance(this@HomeActivity)
|
pushManager.refresh(false)
|
||||||
application.registerForPnIfNeeded(false)
|
|
||||||
if (textSecurePreferences.getLocalNumber() != null) {
|
if (textSecurePreferences.getLocalNumber() != null) {
|
||||||
OpenGroupManager.startPolling()
|
OpenGroupManager.startPolling()
|
||||||
JobQueue.shared.resumePendingJobs()
|
JobQueue.shared.resumePendingJobs()
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
class ExpiryManager(
|
class ExpiryManager(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
class FcmTokenManager(
|
@Singleton
|
||||||
private val context: Context,
|
class FcmTokenManager @Inject constructor(
|
||||||
private val expiryManager: ExpiryManager
|
@ApplicationContext private val context: Context,
|
||||||
) {
|
) {
|
||||||
|
private val expiryManager = ExpiryManager(context)
|
||||||
|
|
||||||
val isUsingFCM get() = TextSecurePreferences.isUsingFCM(context)
|
val isUsingFCM get() = TextSecurePreferences.isUsingFCM(context)
|
||||||
|
|
||||||
var fcmToken
|
var fcmToken
|
||||||
|
@ -19,6 +19,7 @@ import org.session.libsession.utilities.ThemeUtil
|
|||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||||
import org.thoughtcrime.securesms.home.HomeActivity
|
import org.thoughtcrime.securesms.home.HomeActivity
|
||||||
|
import org.thoughtcrime.securesms.notifications.PushManager
|
||||||
import org.thoughtcrime.securesms.showSessionDialog
|
import org.thoughtcrime.securesms.showSessionDialog
|
||||||
import org.thoughtcrime.securesms.util.GlowViewUtilities
|
import org.thoughtcrime.securesms.util.GlowViewUtilities
|
||||||
import org.thoughtcrime.securesms.util.PNModeView
|
import org.thoughtcrime.securesms.util.PNModeView
|
||||||
@ -27,8 +28,12 @@ import org.thoughtcrime.securesms.util.getAccentColor
|
|||||||
import org.thoughtcrime.securesms.util.getColorWithID
|
import org.thoughtcrime.securesms.util.getColorWithID
|
||||||
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
|
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
|
||||||
import org.thoughtcrime.securesms.util.show
|
import org.thoughtcrime.securesms.util.show
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class PNModeActivity : BaseActionBarActivity() {
|
class PNModeActivity : BaseActionBarActivity() {
|
||||||
|
|
||||||
|
@Inject lateinit var pushManager: PushManager
|
||||||
|
|
||||||
private lateinit var binding: ActivityPnModeBinding
|
private lateinit var binding: ActivityPnModeBinding
|
||||||
private var selectedOptionView: PNModeView? = null
|
private var selectedOptionView: PNModeView? = null
|
||||||
|
|
||||||
@ -161,7 +166,7 @@ class PNModeActivity : BaseActionBarActivity() {
|
|||||||
TextSecurePreferences.setIsUsingFCM(this, (selectedOptionView == binding.fcmOptionView))
|
TextSecurePreferences.setIsUsingFCM(this, (selectedOptionView == binding.fcmOptionView))
|
||||||
val application = ApplicationContext.getInstance(this)
|
val application = ApplicationContext.getInstance(this)
|
||||||
application.startPollingIfNeeded()
|
application.startPollingIfNeeded()
|
||||||
application.registerForPnIfNeeded(true)
|
pushManager.refresh(true)
|
||||||
val intent = Intent(this, HomeActivity::class.java)
|
val intent = Intent(this, HomeActivity::class.java)
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
intent.putExtra(HomeActivity.FROM_ONBOARDING, true)
|
intent.putExtra(HomeActivity.FROM_ONBOARDING, true)
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package org.thoughtcrime.securesms.preferences
|
package org.thoughtcrime.securesms.preferences
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment
|
import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
class NotificationSettingsActivity : PassphraseRequiredActionBarActivity() {
|
class NotificationSettingsActivity : PassphraseRequiredActionBarActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||||
|
@ -23,14 +23,22 @@ import org.session.libsession.utilities.TextSecurePreferences;
|
|||||||
import org.thoughtcrime.securesms.ApplicationContext;
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
||||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||||
|
import org.thoughtcrime.securesms.notifications.PushManager;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
import network.loki.messenger.R;
|
import network.loki.messenger.R;
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment {
|
public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static final String TAG = NotificationsPreferenceFragment.class.getSimpleName();
|
private static final String TAG = NotificationsPreferenceFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PushManager pushManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle paramBundle) {
|
public void onCreate(Bundle paramBundle) {
|
||||||
super.onCreate(paramBundle);
|
super.onCreate(paramBundle);
|
||||||
@ -41,7 +49,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||||||
this.findPreference(fcmKey)
|
this.findPreference(fcmKey)
|
||||||
.setOnPreferenceChangeListener((preference, newValue) -> {
|
.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
TextSecurePreferences.setIsUsingFCM(getContext(), (boolean) newValue);
|
TextSecurePreferences.setIsUsingFCM(getContext(), (boolean) newValue);
|
||||||
ApplicationContext.getInstance(getContext()).registerForPnIfNeeded(true);
|
pushManager.refresh(true);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.notifications
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.goterl.lazysodium.utils.KeyPair
|
import com.goterl.lazysodium.utils.KeyPair
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import nl.komponents.kovenant.Promise
|
import nl.komponents.kovenant.Promise
|
||||||
import nl.komponents.kovenant.combine.and
|
import nl.komponents.kovenant.combine.and
|
||||||
import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1
|
import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1
|
||||||
@ -18,7 +19,7 @@ private const val TAG = "GenericPushManager"
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class GenericPushManager @Inject constructor(
|
class GenericPushManager @Inject constructor(
|
||||||
private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val device: Device,
|
private val device: Device,
|
||||||
private val tokenManager: FcmTokenManager,
|
private val tokenManager: FcmTokenManager,
|
||||||
private val pushManagerV2: PushManagerV2,
|
private val pushManagerV2: PushManagerV2,
|
||||||
@ -60,17 +61,25 @@ class GenericPushManager @Inject constructor(
|
|||||||
publicKey: String,
|
publicKey: String,
|
||||||
userEd25519Key: KeyPair,
|
userEd25519Key: KeyPair,
|
||||||
namespaces: List<Int> = listOf(Namespace.DEFAULT)
|
namespaces: List<Int> = listOf(Namespace.DEFAULT)
|
||||||
): Promise<*, Exception> = PushManagerV1.register(
|
): Promise<*, Exception> {
|
||||||
token = token,
|
val v1 = PushManagerV1.register(
|
||||||
device = device,
|
device = device,
|
||||||
publicKey = publicKey
|
token = token,
|
||||||
) and pushManagerV2.register(
|
publicKey = publicKey
|
||||||
token, publicKey, userEd25519Key, namespaces
|
) fail {
|
||||||
) fail {
|
Log.e(TAG, "register v1 failed", it)
|
||||||
Log.e(TAG, "registerBoth failed", it)
|
}
|
||||||
} success {
|
|
||||||
Log.d(TAG, "registerBoth success... saving token!!")
|
val v2 = pushManagerV2.register(
|
||||||
tokenManager.fcmToken = token
|
Device.ANDROID, token, publicKey, userEd25519Key, namespaces
|
||||||
|
) fail {
|
||||||
|
Log.e(TAG, "register v2 failed", it)
|
||||||
|
}
|
||||||
|
|
||||||
|
return v1 and v2 success {
|
||||||
|
Log.d(TAG, "registerBoth success... saving token!!")
|
||||||
|
tokenManager.fcmToken = token
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unregister(
|
private fun unregister(
|
||||||
@ -78,10 +87,10 @@ class GenericPushManager @Inject constructor(
|
|||||||
userPublicKey: String,
|
userPublicKey: String,
|
||||||
userEdKey: KeyPair
|
userEdKey: KeyPair
|
||||||
): Promise<*, Exception> = PushManagerV1.unregister() and pushManagerV2.unregister(
|
): Promise<*, Exception> = PushManagerV1.unregister() and pushManagerV2.unregister(
|
||||||
token, userPublicKey, userEdKey
|
Device.ANDROID, token, userPublicKey, userEdKey
|
||||||
) fail {
|
) fail {
|
||||||
Log.e(TAG, "unregisterBoth failed", it)
|
Log.e(TAG, "unregisterBoth failed", it)
|
||||||
} success {
|
} success {
|
||||||
tokenManager.fcmToken = null
|
tokenManager.fcmToken = null
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,6 +16,7 @@ import org.session.libsession.messaging.sending_receiving.notifications.*
|
|||||||
import org.session.libsession.snode.OnionRequestAPI
|
import org.session.libsession.snode.OnionRequestAPI
|
||||||
import org.session.libsession.snode.SnodeAPI
|
import org.session.libsession.snode.SnodeAPI
|
||||||
import org.session.libsession.snode.Version
|
import org.session.libsession.snode.Version
|
||||||
|
import org.session.libsession.utilities.Device
|
||||||
import org.session.libsignal.utilities.Base64
|
import org.session.libsignal.utilities.Base64
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import org.session.libsignal.utilities.Namespace
|
import org.session.libsignal.utilities.Namespace
|
||||||
@ -31,6 +32,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) {
|
|||||||
private val sodium = LazySodiumAndroid(SodiumAndroid())
|
private val sodium = LazySodiumAndroid(SodiumAndroid())
|
||||||
|
|
||||||
fun register(
|
fun register(
|
||||||
|
device: Device,
|
||||||
token: String,
|
token: String,
|
||||||
publicKey: String,
|
publicKey: String,
|
||||||
userEd25519Key: KeyPair,
|
userEd25519Key: KeyPair,
|
||||||
@ -48,7 +50,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) {
|
|||||||
session_ed25519 = userEd25519Key.publicKey.asHexString,
|
session_ed25519 = userEd25519Key.publicKey.asHexString,
|
||||||
namespaces = listOf(Namespace.DEFAULT),
|
namespaces = listOf(Namespace.DEFAULT),
|
||||||
data = true, // only permit data subscription for now (?)
|
data = true, // only permit data subscription for now (?)
|
||||||
service = "firebase",
|
service = device.service,
|
||||||
sig_ts = timestamp,
|
sig_ts = timestamp,
|
||||||
signature = Base64.encodeBytes(signature),
|
signature = Base64.encodeBytes(signature),
|
||||||
service_info = mapOf("token" to token),
|
service_info = mapOf("token" to token),
|
||||||
@ -61,6 +63,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun unregister(
|
fun unregister(
|
||||||
|
device: Device,
|
||||||
token: String,
|
token: String,
|
||||||
userPublicKey: String,
|
userPublicKey: String,
|
||||||
userEdKey: KeyPair
|
userEdKey: KeyPair
|
||||||
@ -74,7 +77,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) {
|
|||||||
val requestParameters = UnsubscriptionRequest(
|
val requestParameters = UnsubscriptionRequest(
|
||||||
pubkey = userPublicKey,
|
pubkey = userPublicKey,
|
||||||
session_ed25519 = userEdKey.publicKey.asHexString,
|
session_ed25519 = userEdKey.publicKey.asHexString,
|
||||||
service = "firebase",
|
service = device.service,
|
||||||
sig_ts = timestamp,
|
sig_ts = timestamp,
|
||||||
signature = Base64.encodeBytes(signature),
|
signature = Base64.encodeBytes(signature),
|
||||||
service_info = mapOf("token" to token),
|
service_info = mapOf("token" to token),
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<application tools:node="merge">
|
<application tools:node="merge">
|
||||||
<service
|
<service
|
||||||
android:name="org.thoughtcrime.securesms.notifications.PushNotificationService"
|
android:name="org.thoughtcrime.securesms.notifications.FirebasePushNotificationService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import org.session.libsession.utilities.Device
|
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@ -12,11 +9,9 @@ private const val TAG = "FirebasePushManager"
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class FirebasePushManager @Inject constructor(
|
class FirebasePushManager @Inject constructor(
|
||||||
@ApplicationContext private val context: Context
|
private val genericPushManager: GenericPushManager
|
||||||
): PushManager {
|
): PushManager {
|
||||||
|
|
||||||
@Inject lateinit var genericPushManager: GenericPushManager
|
|
||||||
|
|
||||||
private var firebaseInstanceIdJob: Job? = null
|
private var firebaseInstanceIdJob: Job? = null
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@ -24,7 +19,10 @@ class FirebasePushManager @Inject constructor(
|
|||||||
Log.d(TAG, "refresh() called with: force = $force")
|
Log.d(TAG, "refresh() called with: force = $force")
|
||||||
|
|
||||||
firebaseInstanceIdJob?.apply {
|
firebaseInstanceIdJob?.apply {
|
||||||
if (force) cancel() else if (isActive) return
|
when {
|
||||||
|
force -> cancel()
|
||||||
|
isActive -> return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
firebaseInstanceIdJob = getFcmInstanceId { task ->
|
firebaseInstanceIdJob = getFcmInstanceId { task ->
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat
|
|
||||||
import androidx.core.app.NotificationManagerCompat
|
|
||||||
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 dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.session.libsession.messaging.jobs.BatchMessageReceiveJob
|
|
||||||
import org.session.libsession.messaging.jobs.JobQueue
|
|
||||||
import org.session.libsession.messaging.jobs.MessageReceiveParameters
|
|
||||||
import org.session.libsession.messaging.utilities.MessageWrapper
|
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
import org.session.libsignal.utilities.Base64
|
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val TAG = "PushNotificationService"
|
private const val TAG = "FirebasePushNotificationService"
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class PushNotificationService : FirebaseMessagingService() {
|
class FirebasePushNotificationService : FirebaseMessagingService() {
|
||||||
|
|
||||||
@Inject lateinit var pushManager: PushManager
|
@Inject lateinit var pushManager: PushManager
|
||||||
@Inject lateinit var pushHandler: PushHandler
|
@Inject lateinit var pushHandler: PushHandler
|
||||||
@ -37,7 +29,6 @@ class PushNotificationService : FirebaseMessagingService() {
|
|||||||
|
|
||||||
override fun onDeletedMessages() {
|
override fun onDeletedMessages() {
|
||||||
Log.d(TAG, "Called onDeletedMessages.")
|
Log.d(TAG, "Called onDeletedMessages.")
|
||||||
super.onDeletedMessages()
|
|
||||||
pushManager.refresh(true)
|
pushManager.refresh(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -94,7 +94,7 @@ fun MessageSender.create(
|
|||||||
// Add the group to the config now that it was successfully created
|
// Add the group to the config now that it was successfully created
|
||||||
storage.createInitialConfigGroup(groupPublicKey, name, GroupUtil.createConfigMemberMap(members, admins), sentTime, encryptionKeyPair)
|
storage.createInitialConfigGroup(groupPublicKey, name, GroupUtil.createConfigMemberMap(members, admins), sentTime, encryptionKeyPair)
|
||||||
// Notify the PN server
|
// Notify the PN server
|
||||||
PushManagerV1.register(publicKey = userPublicKey, device = device)
|
PushManagerV1.register(device = device, publicKey = userPublicKey)
|
||||||
// Start polling
|
// Start polling
|
||||||
ClosedGroupPollerV2.shared.startPolling(groupPublicKey)
|
ClosedGroupPollerV2.shared.startPolling(groupPublicKey)
|
||||||
// Fulfill the promise
|
// Fulfill the promise
|
||||||
|
@ -556,7 +556,7 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli
|
|||||||
// Set expiration timer
|
// Set expiration timer
|
||||||
storage.setExpirationTimer(groupID, expireTimer)
|
storage.setExpirationTimer(groupID, expireTimer)
|
||||||
// Notify the PN server
|
// Notify the PN server
|
||||||
PushManagerV1.register(publicKey = userPublicKey, device = MessagingModuleConfiguration.shared.device)
|
PushManagerV1.register(device = MessagingModuleConfiguration.shared.device, publicKey = userPublicKey)
|
||||||
// Notify the user
|
// Notify the user
|
||||||
if (userPublicKey == sender && !groupExists) {
|
if (userPublicKey == sender && !groupExists) {
|
||||||
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
||||||
|
@ -27,18 +27,19 @@ object PushManagerV1 {
|
|||||||
private val server = Server.LEGACY
|
private val server = Server.LEGACY
|
||||||
|
|
||||||
fun register(
|
fun register(
|
||||||
|
device: Device,
|
||||||
isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context),
|
isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context),
|
||||||
token: String? = TextSecurePreferences.getFCMToken(context),
|
token: String? = TextSecurePreferences.getFCMToken(context),
|
||||||
publicKey: String? = TextSecurePreferences.getLocalNumber(context),
|
publicKey: String? = TextSecurePreferences.getLocalNumber(context),
|
||||||
device: Device,
|
|
||||||
legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
|
legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
|
||||||
): Promise<*, Exception> =
|
): Promise<*, Exception> =
|
||||||
if (!isUsingFCM) {
|
when {
|
||||||
emptyPromise()
|
isUsingFCM -> retryIfNeeded(maxRetryCount) {
|
||||||
} else retryIfNeeded(maxRetryCount) {
|
doRegister(token, publicKey, device, legacyGroupPublicKeys)
|
||||||
doRegister(token, publicKey, device, legacyGroupPublicKeys)
|
} fail { exception ->
|
||||||
} fail { exception ->
|
Log.d(TAG, "Couldn't register for FCM due to error: $exception.")
|
||||||
Log.d(TAG, "Couldn't register for FCM due to error: $exception.")
|
}
|
||||||
|
else -> emptyPromise()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doRegister(token: String?, publicKey: String?, device: Device, legacyGroupPublicKeys: Collection<String>): Promise<*, Exception> {
|
private fun doRegister(token: String?, publicKey: String?, device: Device, legacyGroupPublicKeys: Collection<String>): Promise<*, Exception> {
|
||||||
@ -50,7 +51,7 @@ object PushManagerV1 {
|
|||||||
val parameters = mapOf(
|
val parameters = mapOf(
|
||||||
"token" to token,
|
"token" to token,
|
||||||
"pubKey" to publicKey,
|
"pubKey" to publicKey,
|
||||||
"device" to device,
|
"device" to device.value,
|
||||||
"legacyGroupPublicKeys" to legacyGroupPublicKeys
|
"legacyGroupPublicKeys" to legacyGroupPublicKeys
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.session.libsession.utilities
|
package org.session.libsession.utilities
|
||||||
|
|
||||||
enum class Device(val value: String) {
|
enum class Device(val value: String, val service: String = value) {
|
||||||
ANDROID("android"),
|
ANDROID("android", "firebase"),
|
||||||
HUAWEI("huawei");
|
HUAWEI("huawei");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user