Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add more debug information for sync #WPB-11603 #3066

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.os.Build
import com.wire.kalium.logger.KaliumLogLevel
import com.wire.kalium.logic.kaliumLogger
import com.wire.kalium.logic.logStructuredJson
import com.wire.kalium.network.NetworkState
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.util.KaliumDispatcher
Expand Down Expand Up @@ -56,7 +59,8 @@ internal actual class NetworkStateObserverImpl(

init {
val initialDefaultNetworkData = connectivityManager.activeNetwork?.let {
val defaultNetworkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
val defaultNetworkCapabilities =
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
DefaultNetworkData.Connected(it, defaultNetworkCapabilities)
} ?: DefaultNetworkData.NotConnected
defaultNetworkDataStateFlow = MutableStateFlow(initialDefaultNetworkData)
Expand All @@ -76,14 +80,33 @@ internal actual class NetworkStateObserverImpl(

val callback = object : ConnectivityManager.NetworkCallback() {

override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities) {
override fun onCapabilitiesChanged(
network: Network,
networkCapabilities: NetworkCapabilities
) {
super.onCapabilitiesChanged(network, networkCapabilities)
kaliumLogger.i(
"${NetworkStateObserver.TAG} capabilities changed " +
"internet:${networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)} " +
"validated:${networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)}"
)
defaultNetworkDataStateFlow.update { DefaultNetworkData.Connected(network, networkCapabilities) }
val loggerMessage = mutableMapOf<String, String>().apply {
put("internet", networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).toString())
put("validated", networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).toString())
put("not restricted", networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED).toString())

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
put("foreground", networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOREGROUND).toString())
put("not congested", networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED).toString())
put("not suspended", networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED).toString())
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
put("signalStrength", networkCapabilities.signalStrength.toString())
}
}
kaliumLogger.logStructuredJson(KaliumLogLevel.INFO, "${NetworkStateObserver.TAG} capabilities changed", loggerMessage)
defaultNetworkDataStateFlow.update {
DefaultNetworkData.Connected(
network,
networkCapabilities
)
}
}

override fun onLost(network: Network) {
Expand Down Expand Up @@ -112,8 +135,7 @@ internal actual class NetworkStateObserverImpl(
override fun onBlockedStatusChanged(network: Network, blocked: Boolean) {
kaliumLogger.i("${NetworkStateObserver.TAG} block connection changed to $blocked")
defaultNetworkDataStateFlow.update {
kaliumLogger.d("${NetworkStateObserver.TAG} block connection changed to $blocked current state is $it")
when (it) {
val updatedValue = when (it) {
is DefaultNetworkData.Connected -> {
it.copy(isBlocked = blocked)
}
Expand All @@ -123,6 +145,8 @@ internal actual class NetworkStateObserverImpl(
else DefaultNetworkData.Connected(network)
}
}
kaliumLogger.d("${NetworkStateObserver.TAG} default network state $it changed to $updatedValue")
updatedValue
}
super.onBlockedStatusChanged(network, blocked)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface NetworkStateObserver {
// Delay which will be completed earlier if there is a reconnection in the meantime.
suspend fun delayUntilConnectedWithInternetAgain(delay: Duration) {
// Delay for given amount but break it if reconnected again.
kaliumUtilLogger.i("$TAG delayUntilConnectedWithInternetAgain")
kaliumUtilLogger.i("$TAG delayUntilConnectedWithInternetAgain for $delay")
withTimeoutOrNull(delay) {
// Drop the current value, so it will complete only if the connection changed again to connected during that time.
observeNetworkState()
Expand Down
Loading