mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 04:52:00 +03:00
FastLane: Only is Wifi is detected
This commit is contained in:
parent
9a124f7630
commit
b89a258fdf
4 changed files with 61 additions and 4 deletions
|
@ -23,6 +23,10 @@ interface EventService {
|
|||
/**
|
||||
* Ask the homeserver for an event content. The SDK will try to decrypt it if it is possible
|
||||
* The result will not be stored into cache
|
||||
* @param onlyOnWifi if true and if WiFi is not available, no request will be done,
|
||||
* and null will be returned
|
||||
*/
|
||||
suspend fun getEvent(roomId: String, eventId: String): Event
|
||||
suspend fun getEvent(roomId: String,
|
||||
eventId: String,
|
||||
onlyOnWifi: Boolean): Event?
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2021 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 org.matrix.android.sdk.internal.network
|
||||
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
import android.os.Build
|
||||
import androidx.core.content.getSystemService
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class WifiDetector @Inject constructor(
|
||||
context: Context
|
||||
) {
|
||||
private val connectivityManager = context.getSystemService<ConnectivityManager>()!!
|
||||
|
||||
fun isConnectedToWifi(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
connectivityManager.activeNetwork
|
||||
?.let { connectivityManager.getNetworkCapabilities(it) }
|
||||
?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|
||||
.orFalse()
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
connectivityManager.activeNetworkInfo?.type == ConnectivityManager.TYPE_WIFI
|
||||
}
|
||||
.also { Timber.d("isConnected to WiFi: $it") }
|
||||
}
|
||||
}
|
|
@ -18,16 +18,24 @@ package org.matrix.android.sdk.internal.session.events
|
|||
|
||||
import org.matrix.android.sdk.api.session.events.EventService
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.internal.network.WifiDetector
|
||||
import org.matrix.android.sdk.internal.session.call.CallEventProcessor
|
||||
import org.matrix.android.sdk.internal.session.room.timeline.GetEventTask
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultEventService @Inject constructor(
|
||||
private val getEventTask: GetEventTask,
|
||||
private val callEventProcessor: CallEventProcessor
|
||||
private val callEventProcessor: CallEventProcessor,
|
||||
private val wifiDetector: WifiDetector
|
||||
) : EventService {
|
||||
|
||||
override suspend fun getEvent(roomId: String, eventId: String): Event {
|
||||
override suspend fun getEvent(roomId: String, eventId: String, onlyOnWifi: Boolean): Event? {
|
||||
if (onlyOnWifi && !wifiDetector.isConnectedToWifi()) {
|
||||
Timber.d("No WiFi network, do not get Event")
|
||||
return null
|
||||
}
|
||||
|
||||
val event = getEventTask.execute(GetEventTask.Params(roomId, eventId))
|
||||
|
||||
// Fast lane to the call event processors: try to make the incoming call ring faster
|
||||
|
|
|
@ -190,7 +190,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
|
||||
coroutineScope.launch {
|
||||
Timber.d("Fast lane: start request")
|
||||
val event = session.getEvent(roomId, eventId)
|
||||
val event = session.getEvent(roomId, eventId, onlyOnWifi = true)?: return@launch
|
||||
|
||||
val resolvedEvent = notifiableEventResolver.resolveInMemoryEvent(session, event)
|
||||
|
||||
|
|
Loading…
Reference in a new issue