From 7f22c6b211b3a3dd1a7f47cd6d30318a66a582e2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 11 Apr 2023 17:02:14 +0200 Subject: [PATCH] Use Firebase by default and cleanup --- .../appnav/loggedin/LoggedInPresenter.kt | 4 +- .../push/api/model/BackgroundSyncMode.kt | 48 ------------------- .../push/providers/api/PushProvider.kt | 8 ++-- .../firebase/FirebasePushProvider.kt | 2 - 4 files changed, 6 insertions(+), 56 deletions(-) delete mode 100644 libraries/push/api/src/main/kotlin/io/element/android/libraries/push/api/model/BackgroundSyncMode.kt diff --git a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt index a798f95bae..50bc09d0a0 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt @@ -47,8 +47,8 @@ class LoggedInPresenter @Inject constructor( LaunchedEffect(Unit) { // Ensure pusher is registered // TODO Manually select push provider for now - val pushProvider = pushService.getAvailablePushProviders().find { it.name == "UnifiedPush" } ?: return@LaunchedEffect - val distributor = pushProvider.getDistributors().first() + val pushProvider = pushService.getAvailablePushProviders().firstOrNull() ?: return@LaunchedEffect + val distributor = pushProvider.getDistributors().firstOrNull() ?: return@LaunchedEffect pushService.registerWith(matrixClient, pushProvider, distributor) } diff --git a/libraries/push/api/src/main/kotlin/io/element/android/libraries/push/api/model/BackgroundSyncMode.kt b/libraries/push/api/src/main/kotlin/io/element/android/libraries/push/api/model/BackgroundSyncMode.kt deleted file mode 100644 index 3fb4841aba..0000000000 --- a/libraries/push/api/src/main/kotlin/io/element/android/libraries/push/api/model/BackgroundSyncMode.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2023 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.element.android.libraries.push.api.model - -/** - * Different strategies for Background sync, only applicable to F-Droid version of the app. - */ -enum class BackgroundSyncMode { - /** - * In this mode background syncs are scheduled via Workers, meaning that the system will have control on the periodicity - * of syncs when battery is low or when the phone is idle (sync will occur in allowed maintenance windows). After completion - * the sync work will schedule another one. - */ - FDROID_BACKGROUND_SYNC_MODE_FOR_BATTERY, - - /** - * This mode requires the app to be exempted from battery optimization. Alarms will be launched and will wake up the app - * in order to perform the background sync as a foreground service. After completion the service will schedule another alarm - */ - FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME, - - /** - * The app won't sync in background. - */ - FDROID_BACKGROUND_SYNC_MODE_DISABLED; - - companion object { - const val DEFAULT_SYNC_DELAY_SECONDS = 60 - const val DEFAULT_SYNC_TIMEOUT_SECONDS = 6 - - fun fromString(value: String?): BackgroundSyncMode = values().firstOrNull { it.name == value } - ?: FDROID_BACKGROUND_SYNC_MODE_DISABLED - } -} diff --git a/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/push/providers/api/PushProvider.kt b/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/push/providers/api/PushProvider.kt index ebcdd962d6..7e16121ed4 100644 --- a/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/push/providers/api/PushProvider.kt +++ b/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/push/providers/api/PushProvider.kt @@ -23,7 +23,7 @@ import io.element.android.libraries.matrix.api.MatrixClient */ interface PushProvider { /** - * Allow to sort provider, from lower index to higher index + * Allow to sort providers, from lower index to higher index. */ val index: Int @@ -35,17 +35,17 @@ interface PushProvider { fun getDistributors(): List /** - * Register the pusher to the homeserver + * Register the pusher to the homeserver. */ suspend fun registerWith(matrixClient: MatrixClient, distributor: Distributor) /** - * Unregister the pusher + * Unregister the pusher. */ suspend fun unregister(matrixClient: MatrixClient) /** - * Attempt to troubleshoot the push provider + * Attempt to troubleshoot the push provider. */ suspend fun troubleshoot(): Result } diff --git a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/push/providers/firebase/FirebasePushProvider.kt b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/push/providers/firebase/FirebasePushProvider.kt index cfddff0bdf..15530033d5 100644 --- a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/push/providers/firebase/FirebasePushProvider.kt +++ b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/push/providers/firebase/FirebasePushProvider.kt @@ -21,7 +21,6 @@ import io.element.android.libraries.matrix.api.MatrixClient import io.element.android.libraries.push.providers.api.Distributor import io.element.android.libraries.push.providers.api.PushProvider import io.element.android.libraries.push.providers.api.PusherSubscriber -import io.element.android.libraries.pushstore.api.clientsecret.PushClientSecret import timber.log.Timber import javax.inject.Inject @@ -31,7 +30,6 @@ class FirebasePushProvider @Inject constructor( private val firebaseStore: FirebaseStore, private val firebaseTroubleshooter: FirebaseTroubleshooter, private val pusherSubscriber: PusherSubscriber, - private val pushClientSecret: PushClientSecret, ) : PushProvider { override val index = FirebaseConfig.index override val name = FirebaseConfig.name