Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/6023.wip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FTUE - Adds homeserver login/register deeplink support
5 changes: 5 additions & 0 deletions vector/src/main/java/im/vector/app/core/di/SingletonModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import im.vector.app.config.analyticsConfig
import im.vector.app.core.dispatchers.CoroutineDispatchers
import im.vector.app.core.error.DefaultErrorFormatter
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.BuildMeta
import im.vector.app.core.time.Clock
import im.vector.app.core.time.DefaultClock
import im.vector.app.features.analytics.AnalyticsConfig
Expand Down Expand Up @@ -185,4 +186,8 @@ object VectorStaticModule {
fun providesAnalyticsConfig(): AnalyticsConfig {
return analyticsConfig
}

@Provides
@Singleton
fun providesBuildMeta() = BuildMeta()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces a build meta abstraction to allow for providing Build version overrides for unit tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome idea!

}
34 changes: 34 additions & 0 deletions vector/src/main/java/im/vector/app/core/extensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package im.vector.app.core.extensions

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.net.Uri
import android.os.Build
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ImageSpan
Expand All @@ -27,11 +31,13 @@ import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.FloatRange
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import dagger.hilt.EntryPoints
import im.vector.app.core.datastore.dataStoreProvider
import im.vector.app.core.di.SingletonEntryPoint
import im.vector.app.core.resources.BuildMeta
import java.io.OutputStream
import kotlin.math.roundToInt

Expand Down Expand Up @@ -77,3 +83,31 @@ val Context.dataStoreProvider: (String) -> DataStore<Preferences> by dataStorePr
fun Context.safeOpenOutputStream(uri: Uri): OutputStream? {
return contentResolver.openOutputStream(uri, "wt")
}

/**
* Checks for an active connection to infer if the device is offline.
* This is useful for breaking down UnknownHost exceptions and should not be used to determine if a valid connection is present
*
* @return true if no active connection is found
*/
@Suppress("deprecation")
@SuppressLint("NewApi") // false positive
fun Context.inferNoConnectivity(buildMeta: BuildMeta): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a description about buildMeta parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add some java doc 👍

val connectivityManager = getSystemService<ConnectivityManager>()!!
return if (buildMeta.sdkInt > Build.VERSION_CODES.M) {
val networkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
when {
networkCapabilities?.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) == true -> false
networkCapabilities?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) == true -> false
networkCapabilities?.hasTransport(NetworkCapabilities.TRANSPORT_VPN) == true -> false
else -> true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a silly question/use case but should we check the internet connection over TRANSPORT_ETHERNET and TRANSPORT_BLUETOOTH?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! I will double check if hasTransport considers bluetooth as an internet provider or simply if a bluetooth connection is present

}
} else {
when (connectivityManager.activeNetworkInfo?.type) {
ConnectivityManager.TYPE_WIFI -> false
ConnectivityManager.TYPE_MOBILE -> false
ConnectivityManager.TYPE_VPN -> false
else -> true
}
}
}
23 changes: 23 additions & 0 deletions vector/src/main/java/im/vector/app/core/resources/BuildMeta.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2022 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 im.vector.app.core.resources

import android.os.Build

data class BuildMeta(
val sdkInt: Int = Build.VERSION.SDK_INT
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.network.ssl.Fingerprint

sealed interface OnboardingAction : VectorViewModelAction {
data class OnGetStarted(val resetLoginConfig: Boolean, val onboardingFlow: OnboardingFlow) : OnboardingAction
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetLoginConfig has become a dedicated reset action ResetDeeplinkConfig

data class OnIAlreadyHaveAnAccount(val resetLoginConfig: Boolean, val onboardingFlow: OnboardingFlow) : OnboardingAction
sealed interface SplashAction : OnboardingAction {
val onboardingFlow: OnboardingFlow

data class OnGetStarted(override val onboardingFlow: OnboardingFlow) : SplashAction
data class OnIAlreadyHaveAnAccount(override val onboardingFlow: OnboardingFlow) : SplashAction
}

data class UpdateServerType(val serverType: ServerType) : OnboardingAction

Expand Down Expand Up @@ -58,7 +62,7 @@ sealed interface OnboardingAction : VectorViewModelAction {

// Reset actions
sealed interface ResetAction : OnboardingAction

object ResetDeeplinkConfig : ResetAction
object ResetHomeServerType : ResetAction
object ResetHomeServerUrl : ResetAction
object ResetSignMode : ResetAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.matrix.android.sdk.api.auth.registration.FlowResult
sealed class OnboardingViewEvents : VectorViewEvents {
data class Loading(val message: CharSequence? = null) : OnboardingViewEvents()
data class Failure(val throwable: Throwable) : OnboardingViewEvents()
data class DeeplinkAuthenticationFailure(val retryAction: OnboardingAction) : OnboardingViewEvents()

data class RegistrationFlowResult(val flowResult: FlowResult, val isRegistrationStarted: Boolean) : OnboardingViewEvents()
object OutdatedHomeserver : OnboardingViewEvents()
Expand Down
Loading