From bcf925c132fcbded7b225f25536c47afb4504acb Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 6 Aug 2023 22:22:39 +0930 Subject: [PATCH] Cleanup --- app/src/huawei/AndroidManifest.xml | 2 +- .../notifications/HuaweiPushManager.kt | 52 ------------------- .../notifications/HuaweiPushModule.kt | 7 +-- ...icationService.kt => HuaweiPushService.kt} | 17 +++--- .../notifications/HuaweiTokenFetcher.kt | 27 ++++++++++ .../securesms/ApplicationContext.java | 6 +-- .../securesms/database/Storage.kt | 4 +- .../securesms/dependencies/PushComponent.kt | 2 +- .../securesms/groups/ClosedGroupManager.kt | 4 +- .../securesms/home/HomeActivity.kt | 6 +-- .../securesms/notifications/ExpiryManager.kt | 4 +- .../{PushHandler.kt => PushReceiver.kt} | 2 +- ...FcmTokenManager.kt => PushTokenManager.kt} | 11 ++-- .../securesms/notifications/TokenFetcher.kt | 7 +++ .../securesms/onboarding/PNModeActivity.kt | 5 +- .../NotificationsPreferenceFragment.java | 6 +-- ...{GenericPushManager.kt => PushRegistry.kt} | 30 ++++++++--- .../{PushManagerV2.kt => PushRegistryV2.kt} | 4 +- app/src/play/AndroidManifest.xml | 2 +- .../securesms/notifications/FcmUtils.kt | 16 ------ .../notifications/FirebasePushManager.kt | 37 ------------- .../notifications/FirebasePushModule.kt | 2 +- ...ationService.kt => FirebasePushService.kt} | 19 ++++--- .../notifications/FirebaseTokenFetcher.kt | 45 ++++++++++++++++ .../notifications/NoOpPushManager.kt | 10 ---- .../securesms/notifications/NoOpPushModule.kt | 4 +- .../MessageSenderClosedGroupHandler.kt | 4 +- .../ReceivedMessageHandler.kt | 6 +-- .../{PushManagerV1.kt => PushRegistryV1.kt} | 8 +-- .../utilities/TextSecurePreferences.kt | 18 +++---- .../utilities/ExternalStorageUtil.kt | 13 ++--- 31 files changed, 176 insertions(+), 204 deletions(-) delete mode 100644 app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt rename app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/{HuaweiPushNotificationService.kt => HuaweiPushService.kt} (74%) create mode 100644 app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt rename app/src/main/java/org/thoughtcrime/securesms/notifications/{PushHandler.kt => PushReceiver.kt} (98%) rename app/src/main/java/org/thoughtcrime/securesms/notifications/{FcmTokenManager.kt => PushTokenManager.kt} (68%) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/notifications/TokenFetcher.kt rename app/src/main/kotlin/org/thoughtcrime/securesms/notifications/{GenericPushManager.kt => PushRegistry.kt} (79%) rename app/src/main/kotlin/org/thoughtcrime/securesms/notifications/{PushManagerV2.kt => PushRegistryV2.kt} (96%) delete mode 100644 app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FcmUtils.kt delete mode 100644 app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt rename app/src/play/kotlin/org/thoughtcrime/securesms/notifications/{FirebasePushNotificationService.kt => FirebasePushService.kt} (60%) create mode 100644 app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebaseTokenFetcher.kt delete mode 100644 app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushManager.kt rename libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/{PushManagerV1.kt => PushRegistryV1.kt} (96%) diff --git a/app/src/huawei/AndroidManifest.xml b/app/src/huawei/AndroidManifest.xml index 57279978c1..0483deac1c 100644 --- a/app/src/huawei/AndroidManifest.xml +++ b/app/src/huawei/AndroidManifest.xml @@ -4,7 +4,7 @@ diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt deleted file mode 100644 index c6f0161a43..0000000000 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt +++ /dev/null @@ -1,52 +0,0 @@ -package org.thoughtcrime.securesms.notifications - -import android.content.Context -import android.util.Log -import com.huawei.hmf.tasks.Tasks -import com.huawei.hms.aaid.HmsInstanceId -import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.MainScope -import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch -import org.session.libsession.utilities.TextSecurePreferences -import javax.inject.Inject -import javax.inject.Singleton - -private val TAG = HuaweiPushManager::class.java.name - -@Singleton -class HuaweiPushManager @Inject constructor( - @ApplicationContext private val context: Context, - private val genericPushManager: GenericPushManager -): PushManager { - private var huaweiPushInstanceIdJob: Job? = null - - @Synchronized - override fun refresh(force: Boolean) { - Log.d(TAG, "refresh() called with: force = $force") - - val huaweiPushInstanceIdJob = huaweiPushInstanceIdJob - - huaweiPushInstanceIdJob?.apply { - if (force) cancel() else if (isActive) return - } - - val appId = "107205081" - val tokenScope = "HCM" - val hmsInstanceId = HmsInstanceId.getInstance(context) - - Log.d(TAG, "hmsInstanceId: $hmsInstanceId") - -// genericPushManager.refresh(TextSecurePreferences.getFCMToken(context), force) - - MainScope().launch(Dispatchers.IO) { - Log.d(TAG, "hmInstanceId getting token...") - val token = hmsInstanceId.getToken(appId, tokenScope) - Log.d(TAG, "refresh() hmsInstanceId => huawei token: $token") -// -//// genericPushManager.refresh(token, force) - } - } -} diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt index c1be786afc..26a484df16 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt @@ -1,16 +1,13 @@ package org.thoughtcrime.securesms.notifications -import android.content.Context import dagger.Binds import dagger.Module -import dagger.Provides import dagger.hilt.InstallIn -import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton + @Module @InstallIn(SingletonComponent::class) abstract class HuaweiBindingModule { @Binds - abstract fun bindPushManager(pushManager: HuaweiPushManager): PushManager + abstract fun bindTokenFetcher(tokenFetcher: HuaweiTokenFetcher): TokenFetcher } diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushService.kt similarity index 74% rename from app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt rename to app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushService.kt index a0ce0283d4..2c3512acc7 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushService.kt @@ -10,18 +10,17 @@ import org.session.libsignal.utilities.Log import java.lang.Exception import javax.inject.Inject -private val TAG = HuaweiPushNotificationService::class.java.simpleName +private val TAG = HuaweiPushService::class.java.simpleName @AndroidEntryPoint -class HuaweiPushNotificationService: HmsMessageService() { +class HuaweiPushService: HmsMessageService() { init { Log.d(TAG, "init Huawei Service") } - @Inject lateinit var pushManager: PushManager - @Inject lateinit var genericPushManager: GenericPushManager - @Inject lateinit var pushHandler: PushHandler + @Inject lateinit var pushRegistry: PushRegistry + @Inject lateinit var pushReceiver: PushReceiver override fun onCreate() { Log.d(TAG, "onCreate Huawei Service") @@ -30,7 +29,7 @@ class HuaweiPushNotificationService: HmsMessageService() { override fun onMessageReceived(message: RemoteMessage?) { Log.d(TAG, "onMessageReceived: $message.") - pushHandler.onPush(message?.data?.let(Base64::decode)) + pushReceiver.onPush(message?.data?.let(Base64::decode)) } override fun onMessageSent(p0: String?) { @@ -57,12 +56,12 @@ class HuaweiPushNotificationService: HmsMessageService() { override fun onNewToken(token: String?, bundle: Bundle?) { Log.d(TAG, "New HCM token: $token.") - TextSecurePreferences.setFCMToken(this, token) + TextSecurePreferences.setPushToken(this, token) - genericPushManager.refresh(token, true) + pushRegistry.refresh(token, true) } override fun onDeletedMessages() { - pushManager.refresh(true) + pushRegistry.refresh(true) } } diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt new file mode 100644 index 0000000000..e3b6afe4cc --- /dev/null +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt @@ -0,0 +1,27 @@ +package org.thoughtcrime.securesms.notifications + +import android.content.Context +import com.huawei.hms.aaid.HmsInstanceId +import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.launch +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class HuaweiTokenFetcher @Inject constructor( + @ApplicationContext private val context: Context +): TokenFetcher { + override fun fetch(): Job { + val hmsInstanceId = HmsInstanceId.getInstance(context) + + return MainScope().launch(Dispatchers.IO) { + val appId = "107205081" + val tokenScope = "HCM" + // getToken returns an empty string, but triggers the service to initialize. + hmsInstanceId.getToken(appId, tokenScope) + } + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index f3cf59255f..73b0af55f7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -76,7 +76,7 @@ import org.thoughtcrime.securesms.notifications.BackgroundPollWorker; import org.thoughtcrime.securesms.notifications.DefaultMessageNotifier; import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.notifications.OptimizedMessageNotifier; -import org.thoughtcrime.securesms.notifications.PushManager; +import org.thoughtcrime.securesms.notifications.PushRegistry; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.service.ExpiringMessageManager; import org.thoughtcrime.securesms.service.KeyCachingService; @@ -146,7 +146,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO @Inject Device device; @Inject MessageDataProvider messageDataProvider; @Inject TextSecurePreferences textSecurePreferences; - @Inject PushManager pushManager; + @Inject PushRegistry pushRegistry; @Inject ConfigFactory configFactory; CallMessageProcessor callMessageProcessor; MessagingModuleConfiguration messagingModuleConfiguration; @@ -429,7 +429,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO private static class ProviderInitializationException extends RuntimeException { } public void registerForPnIfNeeded(final Boolean force) { - pushManager.refresh(force); + pushRegistry.refresh(force); } private void setUpPollingIfNeeded() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 5a95ed64f6..9b038b9955 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -50,7 +50,7 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview -import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1 +import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1 import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2 import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel import org.session.libsession.messaging.utilities.SessionId @@ -591,7 +591,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val expireTimer = group.disappearingTimer setExpirationTimer(groupId, expireTimer.toInt()) // Notify the PN server - PushManagerV1.subscribeGroup(group.sessionId, publicKey = localUserPublicKey) + PushRegistryV1.subscribeGroup(group.sessionId, publicKey = localUserPublicKey) // Notify the user val threadID = getOrCreateThreadIdFor(Address.fromSerialized(groupId)) threadDb.setDate(threadID, formationTimestamp) diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/PushComponent.kt b/app/src/main/java/org/thoughtcrime/securesms/dependencies/PushComponent.kt index cd4e00416c..69baf1f208 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/PushComponent.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/PushComponent.kt @@ -8,5 +8,5 @@ import org.thoughtcrime.securesms.notifications.PushManager @EntryPoint @InstallIn(SingletonComponent::class) interface PushComponent { - fun providePushManager(): PushManager + } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ClosedGroupManager.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/ClosedGroupManager.kt index 46142a4c58..f8e64dd381 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ClosedGroupManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ClosedGroupManager.kt @@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.groups import android.content.Context import network.loki.messenger.libsession_util.ConfigBase import org.session.libsession.messaging.MessagingModuleConfiguration -import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1 +import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1 import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2 import org.session.libsession.utilities.Address import org.session.libsession.utilities.GroupRecord @@ -24,7 +24,7 @@ object ClosedGroupManager { storage.removeAllClosedGroupEncryptionKeyPairs(groupPublicKey) storage.removeMember(groupID, Address.fromSerialized(userPublicKey)) // Notify the PN server - PushManagerV1.unsubscribeGroup(closedGroupPublicKey = groupPublicKey, publicKey = userPublicKey) + PushRegistryV1.unsubscribeGroup(closedGroupPublicKey = groupPublicKey, publicKey = userPublicKey) // Stop polling ClosedGroupPollerV2.shared.stopPolling(groupPublicKey) storage.cancelPendingMessageSendJobs(threadId) diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index c64d6ef071..59f324b525 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -67,7 +67,7 @@ import org.thoughtcrime.securesms.home.search.GlobalSearchViewModel import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideRequests -import org.thoughtcrime.securesms.notifications.PushManager +import org.thoughtcrime.securesms.notifications.PushRegistry import org.thoughtcrime.securesms.onboarding.SeedActivity import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate import org.thoughtcrime.securesms.permissions.Permissions @@ -107,7 +107,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), @Inject lateinit var groupDatabase: GroupDatabase @Inject lateinit var textSecurePreferences: TextSecurePreferences @Inject lateinit var configFactory: ConfigFactory - @Inject lateinit var pushManager: PushManager + @Inject lateinit var pushRegistry: PushRegistry private val globalSearchViewModel by viewModels() private val homeViewModel by viewModels() @@ -232,7 +232,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), (applicationContext as ApplicationContext).startPollingIfNeeded() // update things based on TextSecurePrefs (profile info etc) // Set up remaining components if needed - pushManager.refresh(false) + pushRegistry.refresh(false) if (textSecurePreferences.getLocalNumber() != null) { OpenGroupManager.startPolling() JobQueue.shared.resumePendingJobs() diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt index 45318d43ad..2b3f0aa860 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt @@ -21,8 +21,8 @@ class ExpiryManager( } private var time - get() = TextSecurePreferences.getLastFCMUploadTime(context) - set(value) = TextSecurePreferences.setLastFCMUploadTime(context, value) + get() = TextSecurePreferences.getPushRegisterTime(context) + set(value) = TextSecurePreferences.setPushRegisterTime(context, value) private fun currentTime() = System.currentTimeMillis() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushHandler.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt similarity index 98% rename from app/src/main/java/org/thoughtcrime/securesms/notifications/PushHandler.kt rename to app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt index 087d1ee982..56871ba64e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushHandler.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt @@ -26,7 +26,7 @@ import javax.inject.Inject private const val TAG = "PushHandler" -class PushHandler @Inject constructor(@ApplicationContext val context: Context) { +class PushReceiver @Inject constructor(@ApplicationContext val context: Context) { private val sodium = LazySodiumAndroid(SodiumAndroid()) fun onPush(dataMap: Map?) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/FcmTokenManager.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushTokenManager.kt similarity index 68% rename from app/src/main/java/org/thoughtcrime/securesms/notifications/FcmTokenManager.kt rename to app/src/main/java/org/thoughtcrime/securesms/notifications/PushTokenManager.kt index cfccb7f721..45469a3dd9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/FcmTokenManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushTokenManager.kt @@ -2,22 +2,24 @@ package org.thoughtcrime.securesms.notifications import android.content.Context import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.Job import org.session.libsession.utilities.TextSecurePreferences import javax.inject.Inject import javax.inject.Singleton @Singleton -class FcmTokenManager @Inject constructor( +class PushTokenManager @Inject constructor( @ApplicationContext private val context: Context, + private val tokenFetcher: TokenFetcher ) { private val expiryManager = ExpiryManager(context) - val isUsingFCM get() = TextSecurePreferences.isPushEnabled(context) + val isPushEnabled get() = TextSecurePreferences.isPushEnabled(context) var fcmToken - get() = TextSecurePreferences.getFCMToken(context) + get() = TextSecurePreferences.getPushToken(context) set(value) { - TextSecurePreferences.setFCMToken(context, value) + TextSecurePreferences.setPushToken(context, value) if (value != null) markTime() else clearTime() } @@ -28,4 +30,5 @@ class FcmTokenManager @Inject constructor( private fun isExpired() = expiryManager.isExpired() fun isInvalid(): Boolean = fcmToken == null || isExpired() + fun fetchToken(): Job = tokenFetcher.fetch() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/TokenFetcher.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/TokenFetcher.kt new file mode 100644 index 0000000000..d8657e95d3 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/TokenFetcher.kt @@ -0,0 +1,7 @@ +package org.thoughtcrime.securesms.notifications + +import kotlinx.coroutines.Job + +interface TokenFetcher { + fun fetch(): Job +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt index c6de3cd676..e4e8e6a9a6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt @@ -21,6 +21,7 @@ import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.home.HomeActivity import org.thoughtcrime.securesms.notifications.PushManager +import org.thoughtcrime.securesms.notifications.PushRegistry import org.thoughtcrime.securesms.showSessionDialog import org.thoughtcrime.securesms.util.GlowViewUtilities import org.thoughtcrime.securesms.util.PNModeView @@ -34,7 +35,7 @@ import javax.inject.Inject @AndroidEntryPoint class PNModeActivity : BaseActionBarActivity() { - @Inject lateinit var pushManager: PushManager + @Inject lateinit var pushRegistry: PushRegistry private lateinit var binding: ActivityPnModeBinding private var selectedOptionView: PNModeView? = null @@ -168,7 +169,7 @@ class PNModeActivity : BaseActionBarActivity() { TextSecurePreferences.setPushEnabled(this, (selectedOptionView == binding.fcmOptionView)) val application = ApplicationContext.getInstance(this) application.startPollingIfNeeded() - pushManager.refresh(true) + pushRegistry.refresh(true) val intent = Intent(this, HomeActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.putExtra(HomeActivity.FROM_ONBOARDING, true) diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java index ea0510d579..4cb316f40f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java @@ -23,7 +23,7 @@ import org.session.libsession.utilities.TextSecurePreferences; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.components.SwitchPreferenceCompat; import org.thoughtcrime.securesms.notifications.NotificationChannels; -import org.thoughtcrime.securesms.notifications.PushManager; +import org.thoughtcrime.securesms.notifications.PushRegistry; import javax.inject.Inject; @@ -37,7 +37,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme private static final String TAG = NotificationsPreferenceFragment.class.getSimpleName(); @Inject - PushManager pushManager; + PushRegistry pushRegistry; @Override public void onCreate(Bundle paramBundle) { @@ -49,7 +49,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme this.findPreference(fcmKey) .setOnPreferenceChangeListener((preference, newValue) -> { TextSecurePreferences.setPushEnabled(getContext(), (boolean) newValue); - pushManager.refresh(true); + pushRegistry.refresh(true); return true; }); diff --git a/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushRegistry.kt similarity index 79% rename from app/src/main/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt rename to app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushRegistry.kt index f3e0443eed..872b2956a3 100644 --- a/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt +++ b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushRegistry.kt @@ -3,9 +3,10 @@ package org.thoughtcrime.securesms.notifications import android.content.Context import com.goterl.lazysodium.utils.KeyPair import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.Job import nl.komponents.kovenant.Promise import nl.komponents.kovenant.combine.and -import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1 +import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1 import org.session.libsession.utilities.Device import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.utilities.Log @@ -18,12 +19,25 @@ import javax.inject.Singleton private const val TAG = "GenericPushManager" @Singleton -class GenericPushManager @Inject constructor( +class PushRegistry @Inject constructor( @ApplicationContext private val context: Context, private val device: Device, - private val tokenManager: FcmTokenManager, - private val pushManagerV2: PushManagerV2, + private val tokenManager: PushTokenManager, + private val pushRegistryV2: PushRegistryV2, ) { + + private var firebaseInstanceIdJob: Job? = null + + fun refresh(force: Boolean) { + Log.d(TAG, "refresh() called with: force = $force") + + firebaseInstanceIdJob?.apply { + if (force) cancel() else if (isActive) return + } + + firebaseInstanceIdJob = tokenManager.fetchToken() + } + fun refresh(token: String?, force: Boolean): Promise<*, Exception> { Log.d(TAG, "refresh($token, $force) called") @@ -32,7 +46,7 @@ class GenericPushManager @Inject constructor( val userEdKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return emptyPromise() return when { - tokenManager.isUsingFCM -> register(force, token, userPublicKey, userEdKey) + tokenManager.isPushEnabled -> register(force, token, userPublicKey, userEdKey) tokenManager.requiresUnregister -> unregister(token, userPublicKey, userEdKey) else -> emptyPromise() } @@ -68,7 +82,7 @@ class GenericPushManager @Inject constructor( "register() called with: token = $token, publicKey = $publicKey, userEd25519Key = $userEd25519Key, namespaces = $namespaces" ) - val v1 = PushManagerV1.register( + val v1 = PushRegistryV1.register( device = device, token = token, publicKey = publicKey @@ -76,7 +90,7 @@ class GenericPushManager @Inject constructor( Log.e(TAG, "register v1 failed", it) } - val v2 = pushManagerV2.register( + val v2 = pushRegistryV2.register( device, token, publicKey, userEd25519Key, namespaces ) fail { Log.e(TAG, "register v2 failed", it) @@ -92,7 +106,7 @@ class GenericPushManager @Inject constructor( token: String, userPublicKey: String, userEdKey: KeyPair - ): Promise<*, Exception> = PushManagerV1.unregister() and pushManagerV2.unregister( + ): Promise<*, Exception> = PushRegistryV1.unregister() and pushRegistryV2.unregister( device, token, userPublicKey, userEdKey ) fail { Log.e(TAG, "unregisterBoth failed", it) diff --git a/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushRegistryV2.kt similarity index 96% rename from app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt rename to app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushRegistryV2.kt index 93e6fc6819..d03af92e6d 100644 --- a/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt +++ b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushRegistryV2.kt @@ -28,7 +28,7 @@ private const val TAG = "PushManagerV2" private const val maxRetryCount = 4 @Singleton -class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) { +class PushRegistryV2 @Inject constructor(private val pushReceiver: PushReceiver) { private val sodium = LazySodiumAndroid(SodiumAndroid()) fun register( @@ -38,7 +38,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) { userEd25519Key: KeyPair, namespaces: List ): Promise { - val pnKey = pushHandler.getOrCreateNotificationKey() + val pnKey = pushReceiver.getOrCreateNotificationKey() val timestamp = SnodeAPI.nowWithOffset / 1000 // get timestamp in ms -> s // if we want to support passing namespace list, here is the place to do it diff --git a/app/src/play/AndroidManifest.xml b/app/src/play/AndroidManifest.xml index 8b975b0634..b3e5ead475 100644 --- a/app/src/play/AndroidManifest.xml +++ b/app/src/play/AndroidManifest.xml @@ -4,7 +4,7 @@ diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FcmUtils.kt b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FcmUtils.kt deleted file mode 100644 index af3f49a26a..0000000000 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FcmUtils.kt +++ /dev/null @@ -1,16 +0,0 @@ -@file:JvmName("FcmUtils") -package org.thoughtcrime.securesms.notifications - -import com.google.android.gms.tasks.Task -import com.google.android.gms.tasks.Tasks -import com.google.firebase.iid.FirebaseInstanceId -import com.google.firebase.iid.InstanceIdResult -import kotlinx.coroutines.* - - -fun getFcmInstanceId(body: (Task)->Unit): Job = MainScope().launch(Dispatchers.IO) { - val task = FirebaseInstanceId.getInstance().instanceId - Tasks.await(task) - if (!isActive) return@launch // don't 'complete' task if we were canceled - body(task) -} diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt deleted file mode 100644 index 8bd19de61d..0000000000 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.thoughtcrime.securesms.notifications - -import kotlinx.coroutines.Job -import org.session.libsignal.utilities.Log -import javax.inject.Inject -import javax.inject.Singleton - -private const val TAG = "FirebasePushManager" - -@Singleton -class FirebasePushManager @Inject constructor( - private val genericPushManager: GenericPushManager -): PushManager { - - private var firebaseInstanceIdJob: Job? = null - - @Synchronized - override fun refresh(force: Boolean) { - Log.d(TAG, "refresh() called with: force = $force") - - firebaseInstanceIdJob?.apply { - when { - force -> cancel() - isActive -> return - } - } - - firebaseInstanceIdJob = getFcmInstanceId { task -> - when { - task.isSuccessful -> try { task.result?.token?.let { - genericPushManager.refresh(it, force).get() - } } catch(e: Exception) { Log.e(TAG, "refresh() failed", e) } - else -> Log.w(TAG, "getFcmInstanceId failed." + task.exception) - } - } - } -} diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushModule.kt b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushModule.kt index 925ad9d4d7..2dac25072e 100644 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushModule.kt +++ b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushModule.kt @@ -9,5 +9,5 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) abstract class FirebaseBindingModule { @Binds - abstract fun bindPushManager(firebasePushManager: FirebasePushManager): PushManager + abstract fun bindTokenFetcher(tokenFetcher: FirebaseTokenFetcher): TokenFetcher } diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushNotificationService.kt b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushService.kt similarity index 60% rename from app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushNotificationService.kt rename to app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushService.kt index b8640296fa..1ebf405a28 100644 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushNotificationService.kt +++ b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushService.kt @@ -9,26 +9,25 @@ import javax.inject.Inject private const val TAG = "FirebasePushNotificationService" @AndroidEntryPoint -class FirebasePushNotificationService : FirebaseMessagingService() { +class FirebasePushService : FirebaseMessagingService() { - @Inject lateinit var pushManager: PushManager - @Inject lateinit var pushHandler: PushHandler + @Inject lateinit var prefs: TextSecurePreferences + @Inject lateinit var pushReceiver: PushReceiver + @Inject lateinit var pushRegistry: PushRegistry override fun onNewToken(token: String) { - super.onNewToken(token) - TextSecurePreferences.getLocalNumber(this) ?: return - if (TextSecurePreferences.getFCMToken(this) != token) { - pushManager.refresh(true) - } + if (token == prefs.getPushToken()) return + + pushRegistry.refresh(token, true) } override fun onMessageReceived(message: RemoteMessage) { Log.d(TAG, "Received a push notification.") - pushHandler.onPush(message.data) + pushReceiver.onPush(message.data) } override fun onDeletedMessages() { Log.d(TAG, "Called onDeletedMessages.") - pushManager.refresh(true) + pushRegistry.refresh(true) } } diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebaseTokenFetcher.kt b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebaseTokenFetcher.kt new file mode 100644 index 0000000000..e0aa14f6d2 --- /dev/null +++ b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebaseTokenFetcher.kt @@ -0,0 +1,45 @@ +package org.thoughtcrime.securesms.notifications + +import com.google.android.gms.tasks.Task +import com.google.android.gms.tasks.Tasks +import com.google.firebase.iid.FirebaseInstanceId +import com.google.firebase.iid.InstanceIdResult +import dagger.Lazy +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch +import org.session.libsignal.utilities.Log +import javax.inject.Inject +import javax.inject.Singleton + +private val TAG = FirebaseTokenFetcher::class.java.name + +@Singleton +class FirebaseTokenFetcher @Inject constructor( + private val pushRegistry: Lazy, +): TokenFetcher { + override fun fetch(): Job = MainScope().launch(Dispatchers.IO) { + FirebaseInstanceId.getInstance().instanceId + .also(Tasks::await) + .also { if (!isActive) return@launch } // don't 'complete' task if we were canceled + .process() + } + + private fun Task.process() { + when { + isSuccessful -> try { + result?.token?.let { + pushRegistry.get().refresh(it, force = true).get() + } + } catch (e: Exception) { + onFail(e) + } + else -> exception?.let(::onFail) + } + } + + private fun onFail(e: Exception) = Log.e(TAG, "fetch failed", e) +} + diff --git a/app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushManager.kt b/app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushManager.kt deleted file mode 100644 index a817e59d5d..0000000000 --- a/app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushManager.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.thoughtcrime.securesms.notifications - -import org.session.libsignal.utilities.Log - -class NoOpPushManager: PushManager { - - override fun refresh(force: Boolean) { - Log.d("NoOpPushManager", "Push notifications not supported, not registering for push notifications") - } -} diff --git a/app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushModule.kt b/app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushModule.kt index 1c8f2f936c..af907b51ca 100644 --- a/app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushModule.kt +++ b/app/src/website/kotlin/org/thoughtcrime/securesms/notifications/NoOpPushModule.kt @@ -9,7 +9,5 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) class NoOpPushModule { - @Provides - @Singleton - fun provideNoOpManager(): PushManager = NoOpPushManager() + } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt index 022d32f170..1a7e3d8eaa 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt @@ -8,7 +8,7 @@ import nl.komponents.kovenant.deferred import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage import org.session.libsession.messaging.sending_receiving.MessageSender.Error -import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1 +import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1 import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2 import org.session.libsession.snode.SnodeAPI import org.session.libsession.utilities.Address @@ -94,7 +94,7 @@ fun MessageSender.create( // Add the group to the config now that it was successfully created storage.createInitialConfigGroup(groupPublicKey, name, GroupUtil.createConfigMemberMap(members, admins), sentTime, encryptionKeyPair) // Notify the PN server - PushManagerV1.register(device = device, publicKey = userPublicKey) + PushRegistryV1.register(device = device, publicKey = userPublicKey) // Start polling ClosedGroupPollerV2.shared.startPolling(groupPublicKey) // Fulfill the promise diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt index 7c5092e5ea..b101e9db0b 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt @@ -23,7 +23,7 @@ import org.session.libsession.messaging.open_groups.OpenGroupApi import org.session.libsession.messaging.sending_receiving.attachments.PointerAttachment import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview -import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1 +import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1 import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2 import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel import org.session.libsession.messaging.utilities.SessionId @@ -556,7 +556,7 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli // Set expiration timer storage.setExpirationTimer(groupID, expireTimer) // Notify the PN server - PushManagerV1.register(device = MessagingModuleConfiguration.shared.device, publicKey = userPublicKey) + PushRegistryV1.register(device = MessagingModuleConfiguration.shared.device, publicKey = userPublicKey) // Notify the user if (userPublicKey == sender && !groupExists) { val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID)) @@ -869,7 +869,7 @@ fun MessageReceiver.disableLocalGroupAndUnsubscribe(groupPublicKey: String, grou storage.setActive(groupID, false) storage.removeMember(groupID, Address.fromSerialized(userPublicKey)) // Notify the PN server - PushManagerV1.unsubscribeGroup(groupPublicKey, publicKey = userPublicKey) + PushRegistryV1.unsubscribeGroup(groupPublicKey, publicKey = userPublicKey) // Stop polling ClosedGroupPollerV2.shared.stopPolling(groupPublicKey) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushRegistryV1.kt similarity index 96% rename from libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt rename to libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushRegistryV1.kt index d1a822ae3d..d7d84b5c61 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushRegistryV1.kt @@ -18,8 +18,8 @@ import org.session.libsignal.utilities.retryIfNeeded import org.session.libsignal.utilities.sideEffect @SuppressLint("StaticFieldLeak") -object PushManagerV1 { - private const val TAG = "PushManagerV1" +object PushRegistryV1 { + private val TAG = PushRegistryV1::class.java.name val context = MessagingModuleConfiguration.shared.context private const val maxRetryCount = 4 @@ -29,7 +29,7 @@ object PushManagerV1 { fun register( device: Device, isUsingFCM: Boolean = TextSecurePreferences.isPushEnabled(context), - token: String? = TextSecurePreferences.getFCMToken(context), + token: String? = TextSecurePreferences.getPushToken(context), publicKey: String? = TextSecurePreferences.getLocalNumber(context), legacyGroupPublicKeys: Collection = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys() ): Promise<*, Exception> = when { @@ -84,7 +84,7 @@ object PushManagerV1 { fun unregister(): Promise<*, Exception> { Log.d(TAG, "unregisterV1 requested") - val token = TextSecurePreferences.getFCMToken(context) ?: emptyPromise() + val token = TextSecurePreferences.getPushToken(context) ?: emptyPromise() return retryIfNeeded(maxRetryCount) { val parameters = mapOf("token" to token) diff --git a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt index ee17fb2c26..2b92b9836e 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt @@ -252,7 +252,7 @@ interface TextSecurePreferences { const val GIF_METADATA_WARNING = "has_seen_gif_metadata_warning" const val GIF_GRID_LAYOUT = "pref_gif_grid_layout" const val IS_PUSH_ENABLED = "pref_is_using_fcm" - const val FCM_TOKEN = "pref_fcm_token_2" + const val PUSH_TOKEN = "pref_fcm_token_2" const val PUSH_REGISTER_TIME = "pref_last_fcm_token_upload_time_2" const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time" const val CONFIGURATION_SYNCED = "pref_configuration_synced" @@ -319,20 +319,20 @@ interface TextSecurePreferences { } @JvmStatic - fun getFCMToken(context: Context): String? { - return getStringPreference(context, FCM_TOKEN, "") + fun getPushToken(context: Context): String? { + return getStringPreference(context, PUSH_TOKEN, "") } @JvmStatic - fun setFCMToken(context: Context, value: String?) { - setStringPreference(context, FCM_TOKEN, value) + fun setPushToken(context: Context, value: String?) { + setStringPreference(context, PUSH_TOKEN, value) } - fun getLastFCMUploadTime(context: Context): Long { + fun getPushRegisterTime(context: Context): Long { return getLongPreference(context, PUSH_REGISTER_TIME, 0) } - fun setLastFCMUploadTime(context: Context, value: Long) { + fun setPushRegisterTime(context: Context, value: Long) { setLongPreference(context, PUSH_REGISTER_TIME, value) } @@ -1041,11 +1041,11 @@ class AppTextSecurePreferences @Inject constructor( } override fun getPushToken(): String? { - return getStringPreference(TextSecurePreferences.FCM_TOKEN, "") + return getStringPreference(TextSecurePreferences.PUSH_TOKEN, "") } override fun setPushToken(value: String) { - setStringPreference(TextSecurePreferences.FCM_TOKEN, value) + setStringPreference(TextSecurePreferences.PUSH_TOKEN, value) } override fun getPushRegisterTime(): Long { diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/ExternalStorageUtil.kt b/libsignal/src/main/java/org/session/libsignal/utilities/ExternalStorageUtil.kt index a8a8fd662f..f9ccb315cb 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/ExternalStorageUtil.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/ExternalStorageUtil.kt @@ -15,7 +15,7 @@ object ExternalStorageUtil { @Throws(NoExternalStorageException::class) fun getDir(context: Context, type: String?): File { return context.getExternalFilesDir(type) - ?: throw NoExternalStorageException("External storage dir is currently unavailable: $type") + ?: throw NoExternalStorageException("External storage dir is currently unavailable: $type") } @Throws(NoExternalStorageException::class) @@ -73,10 +73,7 @@ object ExternalStorageUtil { } @JvmStatic - fun getCleanFileName(fileName: String?): String? { - var fileName = fileName ?: return null - fileName = fileName.replace('\u202D', '\uFFFD') - fileName = fileName.replace('\u202E', '\uFFFD') - return fileName - } -} \ No newline at end of file + fun getCleanFileName(fileName: String?): String? = + fileName?.replace('\u202D', '\uFFFD') + ?.replace('\u202E', '\uFFFD') +}