From 3e0f50e0bdc55b85a384ca51ae2e09c74689e744 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 12 Jul 2020 21:07:27 +0500 Subject: [PATCH 1/9] Added device utils extensions --- .../ru/touchin/templates/DeviceUtils.java | 60 +++---------------- .../templates/DeviceUtilsExtensions.kt | 52 ++++++++++++++++ 2 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt diff --git a/utils/src/main/java/ru/touchin/templates/DeviceUtils.java b/utils/src/main/java/ru/touchin/templates/DeviceUtils.java index 4a48f10..b4663bf 100644 --- a/utils/src/main/java/ru/touchin/templates/DeviceUtils.java +++ b/utils/src/main/java/ru/touchin/templates/DeviceUtils.java @@ -19,15 +19,10 @@ package ru.touchin.templates; -import android.Manifest; -import android.annotation.SuppressLint; import android.content.Context; -import android.content.pm.PackageManager; -import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.os.Process; + import androidx.annotation.NonNull; -import android.telephony.TelephonyManager; /** * Utility class that is providing common methods related to android device. @@ -40,28 +35,10 @@ public final class DeviceUtils { * @param context Application context * @return Active network type {@link NetworkType} */ + @Deprecated @NonNull public static NetworkType getNetworkType(@NonNull final Context context) { - if (context.checkPermission(Manifest.permission.ACCESS_NETWORK_STATE, Process.myPid(), Process.myUid()) - != PackageManager.PERMISSION_GRANTED) { - return NetworkType.UNKNOWN; - } - final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (cm == null) { - return NetworkType.UNKNOWN; - } - @SuppressLint("MissingPermission") final NetworkInfo info = cm.getActiveNetworkInfo(); - if (info == null || !info.isConnected()) { - return NetworkType.NONE; - } - switch (info.getType()) { - case ConnectivityManager.TYPE_WIFI: - return NetworkType.WI_FI; - case ConnectivityManager.TYPE_MOBILE: - return getMobileNetworkType(info); - default: - return NetworkType.UNKNOWN; - } + return DeviceUtilsExtensionsKt.getNetworkType(context); } /** @@ -70,36 +47,15 @@ public final class DeviceUtils { * @param context Application context * @return true if network connected, false otherwise. */ + @Deprecated public static boolean isNetworkConnected(@NonNull final Context context) { - return getNetworkType(context) != NetworkType.NONE; + return DeviceUtilsExtensionsKt.isNetworkConnected(context); } + @Deprecated @NonNull - private static NetworkType getMobileNetworkType(@NonNull final NetworkInfo info) { - switch (info.getSubtype()) { - case TelephonyManager.NETWORK_TYPE_GPRS: - case TelephonyManager.NETWORK_TYPE_EDGE: - case TelephonyManager.NETWORK_TYPE_CDMA: - case TelephonyManager.NETWORK_TYPE_1xRTT: - case TelephonyManager.NETWORK_TYPE_IDEN: - return NetworkType.MOBILE_2G; - case TelephonyManager.NETWORK_TYPE_UMTS: - case TelephonyManager.NETWORK_TYPE_EVDO_0: - case TelephonyManager.NETWORK_TYPE_EVDO_A: - case TelephonyManager.NETWORK_TYPE_HSDPA: - case TelephonyManager.NETWORK_TYPE_HSUPA: - case TelephonyManager.NETWORK_TYPE_HSPA: - case TelephonyManager.NETWORK_TYPE_EVDO_B: - case TelephonyManager.NETWORK_TYPE_EHRPD: - case TelephonyManager.NETWORK_TYPE_HSPAP: - return NetworkType.MOBILE_3G; - case TelephonyManager.NETWORK_TYPE_LTE: - case 19: // NETWORK_TYPE_LTE_CA is hide - return NetworkType.MOBILE_LTE; - case TelephonyManager.NETWORK_TYPE_UNKNOWN: - default: - return NetworkType.UNKNOWN; - } + static NetworkType getMobileNetworkType(@NonNull final NetworkInfo info) { + return DeviceUtilsExtensionsKt.getMobileNetworkType(info); } private DeviceUtils() { diff --git a/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt new file mode 100644 index 0000000..2259cf3 --- /dev/null +++ b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt @@ -0,0 +1,52 @@ +package ru.touchin.templates + +import android.Manifest +import android.annotation.SuppressLint +import android.content.Context +import android.content.pm.PackageManager +import android.net.ConnectivityManager +import android.net.NetworkInfo +import android.os.Process +import android.telephony.TelephonyManager +import ru.touchin.templates.DeviceUtils.NetworkType + +fun Context.isNetworkConnected(): Boolean = getNetworkType() != NetworkType.NONE + +fun Context.getNetworkType(): NetworkType { + if (checkPermission(Manifest.permission.ACCESS_NETWORK_STATE, Process.myPid(), Process.myUid()) + != PackageManager.PERMISSION_GRANTED) { + return NetworkType.UNKNOWN + } + val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager? + ?: return NetworkType.UNKNOWN + @SuppressLint("MissingPermission") val info = cm.activeNetworkInfo + return if (info == null || !info.isConnected) { + NetworkType.NONE + } else when (info.type) { + ConnectivityManager.TYPE_WIFI -> NetworkType.WI_FI + ConnectivityManager.TYPE_MOBILE -> getMobileNetworkType(info) + else -> NetworkType.UNKNOWN + } +} + +fun getMobileNetworkType(info: NetworkInfo): NetworkType = + when (info.subtype) { + TelephonyManager.NETWORK_TYPE_GPRS, + TelephonyManager.NETWORK_TYPE_EDGE, + TelephonyManager.NETWORK_TYPE_CDMA, + TelephonyManager.NETWORK_TYPE_1xRTT, + TelephonyManager.NETWORK_TYPE_IDEN -> NetworkType.MOBILE_2G + TelephonyManager.NETWORK_TYPE_UMTS, + TelephonyManager.NETWORK_TYPE_EVDO_0, + TelephonyManager.NETWORK_TYPE_EVDO_A, + TelephonyManager.NETWORK_TYPE_HSDPA, + TelephonyManager.NETWORK_TYPE_HSUPA, + TelephonyManager.NETWORK_TYPE_HSPA, + TelephonyManager.NETWORK_TYPE_EVDO_B, + TelephonyManager.NETWORK_TYPE_EHRPD, + TelephonyManager.NETWORK_TYPE_HSPAP -> NetworkType.MOBILE_3G + TelephonyManager.NETWORK_TYPE_LTE, + 19 -> NetworkType.MOBILE_LTE + TelephonyManager.NETWORK_TYPE_UNKNOWN -> NetworkType.UNKNOWN + else -> NetworkType.UNKNOWN + } From b254a07eb505a27c9a6fa16f2b29d790fa317493 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 13 Jul 2020 19:55:47 +0500 Subject: [PATCH 2/9] added biometric extension --- .../touchin/templates/DeviceUtilsExtensions.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt index 2259cf3..f840b19 100644 --- a/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt +++ b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt @@ -4,10 +4,14 @@ import android.Manifest import android.annotation.SuppressLint import android.content.Context import android.content.pm.PackageManager +import android.hardware.biometrics.BiometricManager import android.net.ConnectivityManager import android.net.NetworkInfo +import android.os.Build import android.os.Process import android.telephony.TelephonyManager +import androidx.annotation.RequiresPermission +import androidx.core.hardware.fingerprint.FingerprintManagerCompat import ru.touchin.templates.DeviceUtils.NetworkType fun Context.isNetworkConnected(): Boolean = getNetworkType() != NetworkType.NONE @@ -50,3 +54,16 @@ fun getMobileNetworkType(info: NetworkInfo): NetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN -> NetworkType.UNKNOWN else -> NetworkType.UNKNOWN } + + +@RequiresPermission(anyOf = [Manifest.permission.USE_FINGERPRINT, Manifest.permission.USE_BIOMETRIC]) +fun Context.canAuthenticateWithBiometrics(): Boolean { + return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + val fingerprintManagerCompat = FingerprintManagerCompat.from(this) + fingerprintManagerCompat.hasEnrolledFingerprints() && fingerprintManagerCompat.isHardwareDetected + } else { + getSystemService(BiometricManager::class.java)?.let { biometricManager -> + (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) + } ?: false + } +} From c62a905120dd1aaaee80fa2cd5295444135722d1 Mon Sep 17 00:00:00 2001 From: Maxim Bachinsky Date: Wed, 15 Jul 2020 12:28:55 +0300 Subject: [PATCH 3/9] fix static analysis --- .../main/java/ru/touchin/roboswag/components/utils/UiUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.kt b/utils/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.kt index 14eee85..4ea8a15 100644 --- a/utils/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.kt +++ b/utils/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.kt @@ -122,7 +122,7 @@ object UiUtils { * @param activity Activity of action bar; * @return Height of action bar. */ - fun getActionBarHeight(activity: Activity): Int = 56.px + fun getActionBarHeight(): Int = 56.px /** * Returns status bar (on top where system info is) common height. From 948538e273dd597a5b561fbff54350de2803c476 Mon Sep 17 00:00:00 2001 From: Maxim Bachinsky Date: Wed, 15 Jul 2020 12:43:25 +0300 Subject: [PATCH 4/9] fixed static analysis --- .../templates/DeviceUtilsExtensions.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt index f840b19..9c1eb24 100644 --- a/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt +++ b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt @@ -10,6 +10,7 @@ import android.net.NetworkInfo import android.os.Build import android.os.Process import android.telephony.TelephonyManager +import androidx.annotation.RequiresApi import androidx.annotation.RequiresPermission import androidx.core.hardware.fingerprint.FingerprintManagerCompat import ru.touchin.templates.DeviceUtils.NetworkType @@ -56,14 +57,14 @@ fun getMobileNetworkType(info: NetworkInfo): NetworkType = } +@RequiresApi(Build.VERSION_CODES.M) +@Suppress("InlinedApi") @RequiresPermission(anyOf = [Manifest.permission.USE_FINGERPRINT, Manifest.permission.USE_BIOMETRIC]) -fun Context.canAuthenticateWithBiometrics(): Boolean { - return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { - val fingerprintManagerCompat = FingerprintManagerCompat.from(this) - fingerprintManagerCompat.hasEnrolledFingerprints() && fingerprintManagerCompat.isHardwareDetected - } else { - getSystemService(BiometricManager::class.java)?.let { biometricManager -> - (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) - } ?: false - } +fun Context.canAuthenticateWithBiometrics(): Boolean = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + val fingerprintManagerCompat = FingerprintManagerCompat.from(this) + fingerprintManagerCompat.hasEnrolledFingerprints() && fingerprintManagerCompat.isHardwareDetected +} else { + getSystemService(BiometricManager::class.java)?.let { biometricManager -> + biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS + } ?: false } From 8afda9e4052a60ae68170005836acf9165878273 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 28 Jul 2020 15:07:21 +0500 Subject: [PATCH 5/9] added extensions --- .../roboswag/components/utils/ContextExtensions.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 utils/src/main/java/ru/touchin/roboswag/components/utils/ContextExtensions.kt diff --git a/utils/src/main/java/ru/touchin/roboswag/components/utils/ContextExtensions.kt b/utils/src/main/java/ru/touchin/roboswag/components/utils/ContextExtensions.kt new file mode 100644 index 0000000..b8522ad --- /dev/null +++ b/utils/src/main/java/ru/touchin/roboswag/components/utils/ContextExtensions.kt @@ -0,0 +1,11 @@ +package ru.touchin.roboswag.components.utils + +import android.content.Context +import android.graphics.drawable.Drawable +import androidx.annotation.ColorRes +import androidx.annotation.DrawableRes +import androidx.core.content.ContextCompat + +fun Context.getColorSimple(@ColorRes id: Int): Int = ContextCompat.getColor(this, id) + +fun Context.getDrawableSimple(@DrawableRes id: Int): Drawable? = ContextCompat.getDrawable(this, id) From 61d7a4a0754e20bdfd2dfa641e1075c0dd3908e1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 30 Jul 2020 13:41:12 +0500 Subject: [PATCH 6/9] removed distinct --- .../java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt b/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt index 71ef368..0f08467 100644 --- a/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt +++ b/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt @@ -1,6 +1,7 @@ package ru.touchin.roboswag.mvi_arch.core import android.os.Parcelable +import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.Transformations @@ -36,7 +37,7 @@ abstract class MviViewModel protected val currentState: State get() = state.value ?: initialState From c6e9b718ae86d308eaab9745bad8a4fa84831f98 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 30 Jul 2020 13:41:12 +0500 Subject: [PATCH 7/9] Revert "removed distinct" This reverts commit 61d7a4a0754e20bdfd2dfa641e1075c0dd3908e1. --- .../java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt b/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt index 0f08467..71ef368 100644 --- a/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt +++ b/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt @@ -1,7 +1,6 @@ package ru.touchin.roboswag.mvi_arch.core import android.os.Parcelable -import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.Transformations @@ -37,7 +36,7 @@ abstract class MviViewModel + internal val state = Transformations.distinctUntilChanged(_state) protected val currentState: State get() = state.value ?: initialState From abf95d4abb7738db97f82a764dcee8e3b38d45e8 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 20 Aug 2020 14:17:39 +0500 Subject: [PATCH 8/9] fixed state race --- .../main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt b/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt index 71ef368..d3df82c 100644 --- a/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt +++ b/mvi-arch/src/main/java/ru/touchin/roboswag/mvi_arch/core/MviViewModel.kt @@ -39,7 +39,7 @@ abstract class MviViewModel Date: Thu, 20 Aug 2020 15:09:17 +0500 Subject: [PATCH 9/9] fixed static --- .../ru/touchin/templates/DeviceUtils.java | 110 ----------------- .../java/ru/touchin/templates/DeviceUtils.kt | 115 ++++++++++++++++++ .../templates/DeviceUtilsExtensions.kt | 26 +--- 3 files changed, 116 insertions(+), 135 deletions(-) delete mode 100644 utils/src/main/java/ru/touchin/templates/DeviceUtils.java create mode 100644 utils/src/main/java/ru/touchin/templates/DeviceUtils.kt diff --git a/utils/src/main/java/ru/touchin/templates/DeviceUtils.java b/utils/src/main/java/ru/touchin/templates/DeviceUtils.java deleted file mode 100644 index b4663bf..0000000 --- a/utils/src/main/java/ru/touchin/templates/DeviceUtils.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2016 Touch Instinct - * - * This file is part of RoboSwag library. - * - * 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 ru.touchin.templates; - -import android.content.Context; -import android.net.NetworkInfo; - -import androidx.annotation.NonNull; - -/** - * Utility class that is providing common methods related to android device. - */ -public final class DeviceUtils { - - /** - * Detects active network type. - * - * @param context Application context - * @return Active network type {@link NetworkType} - */ - @Deprecated - @NonNull - public static NetworkType getNetworkType(@NonNull final Context context) { - return DeviceUtilsExtensionsKt.getNetworkType(context); - } - - /** - * Detects if some network connected. - * - * @param context Application context - * @return true if network connected, false otherwise. - */ - @Deprecated - public static boolean isNetworkConnected(@NonNull final Context context) { - return DeviceUtilsExtensionsKt.isNetworkConnected(context); - } - - @Deprecated - @NonNull - static NetworkType getMobileNetworkType(@NonNull final NetworkInfo info) { - return DeviceUtilsExtensionsKt.getMobileNetworkType(info); - } - - private DeviceUtils() { - } - - /** - * Available network types. - */ - public enum NetworkType { - /** - * Mobile 2G network. - */ - MOBILE_2G("2g"), - /** - * Mobile 3G network. - */ - MOBILE_3G("3g"), - /** - * Mobile LTE network. - */ - MOBILE_LTE("lte"), - /** - * Wi-Fi network. - */ - WI_FI("Wi-Fi"), - /** - * Unknown network type. - */ - UNKNOWN("unknown"), - /** - * No network. - */ - NONE("none"); - - @NonNull - private final String name; - - NetworkType(@NonNull final String name) { - this.name = name; - } - - /** - * @return Network type readable name. - */ - @NonNull - public String getName() { - return name; - } - - } - -} diff --git a/utils/src/main/java/ru/touchin/templates/DeviceUtils.kt b/utils/src/main/java/ru/touchin/templates/DeviceUtils.kt new file mode 100644 index 0000000..db3b7d0 --- /dev/null +++ b/utils/src/main/java/ru/touchin/templates/DeviceUtils.kt @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016 Touch Instinct + * + * This file is part of RoboSwag library. + * + * 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 ru.touchin.templates + +import android.content.Context +import android.net.NetworkInfo +import android.telephony.TelephonyManager + +/** + * Utility class that is providing common methods related to android device. + */ +object DeviceUtils { + /** + * Detects active network type. + * + * @param context Application context + * @return Active network type [NetworkType] + */ + @Deprecated( + "Use extension instead", + ReplaceWith("context.getNetworkType()") + ) + fun getNetworkType(context: Context) = context.getNetworkType() + + /** + * Detects if some network connected. + * + * @param context Application context + * @return true if network connected, false otherwise. + */ + @Deprecated( + "Use extension instead", + ReplaceWith("context.isNetworkConnected()") + ) + fun isNetworkConnected(context: Context) = context.isNetworkConnected() + + + fun getMobileNetworkType(info: NetworkInfo): NetworkType = + when (info.subtype) { + TelephonyManager.NETWORK_TYPE_GPRS, + TelephonyManager.NETWORK_TYPE_EDGE, + TelephonyManager.NETWORK_TYPE_CDMA, + TelephonyManager.NETWORK_TYPE_1xRTT, + TelephonyManager.NETWORK_TYPE_IDEN -> NetworkType.MOBILE_2G + TelephonyManager.NETWORK_TYPE_UMTS, + TelephonyManager.NETWORK_TYPE_EVDO_0, + TelephonyManager.NETWORK_TYPE_EVDO_A, + TelephonyManager.NETWORK_TYPE_HSDPA, + TelephonyManager.NETWORK_TYPE_HSUPA, + TelephonyManager.NETWORK_TYPE_HSPA, + TelephonyManager.NETWORK_TYPE_EVDO_B, + TelephonyManager.NETWORK_TYPE_EHRPD, + TelephonyManager.NETWORK_TYPE_HSPAP -> NetworkType.MOBILE_3G + TelephonyManager.NETWORK_TYPE_LTE, + 19 -> NetworkType.MOBILE_LTE + TelephonyManager.NETWORK_TYPE_UNKNOWN -> NetworkType.UNKNOWN + else -> NetworkType.UNKNOWN + } + + /** + * Available network types. + */ + enum class NetworkType(val networkName: String) { + /** + * Mobile 2G network. + */ + MOBILE_2G("2g"), + + /** + * Mobile 3G network. + */ + MOBILE_3G("3g"), + + /** + * Mobile LTE network. + */ + MOBILE_LTE("lte"), + + /** + * Wi-Fi network. + */ + WI_FI("Wi-Fi"), + + /** + * Unknown network type. + */ + UNKNOWN("unknown"), + + /** + * No network. + */ + NONE("none"); + + /** + * @return Network type readable name. + */ + + } +} diff --git a/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt index 9c1eb24..ef213a9 100644 --- a/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt +++ b/utils/src/main/java/ru/touchin/templates/DeviceUtilsExtensions.kt @@ -6,14 +6,13 @@ import android.content.Context import android.content.pm.PackageManager import android.hardware.biometrics.BiometricManager import android.net.ConnectivityManager -import android.net.NetworkInfo import android.os.Build import android.os.Process -import android.telephony.TelephonyManager import androidx.annotation.RequiresApi import androidx.annotation.RequiresPermission import androidx.core.hardware.fingerprint.FingerprintManagerCompat import ru.touchin.templates.DeviceUtils.NetworkType +import ru.touchin.templates.DeviceUtils.getMobileNetworkType fun Context.isNetworkConnected(): Boolean = getNetworkType() != NetworkType.NONE @@ -34,29 +33,6 @@ fun Context.getNetworkType(): NetworkType { } } -fun getMobileNetworkType(info: NetworkInfo): NetworkType = - when (info.subtype) { - TelephonyManager.NETWORK_TYPE_GPRS, - TelephonyManager.NETWORK_TYPE_EDGE, - TelephonyManager.NETWORK_TYPE_CDMA, - TelephonyManager.NETWORK_TYPE_1xRTT, - TelephonyManager.NETWORK_TYPE_IDEN -> NetworkType.MOBILE_2G - TelephonyManager.NETWORK_TYPE_UMTS, - TelephonyManager.NETWORK_TYPE_EVDO_0, - TelephonyManager.NETWORK_TYPE_EVDO_A, - TelephonyManager.NETWORK_TYPE_HSDPA, - TelephonyManager.NETWORK_TYPE_HSUPA, - TelephonyManager.NETWORK_TYPE_HSPA, - TelephonyManager.NETWORK_TYPE_EVDO_B, - TelephonyManager.NETWORK_TYPE_EHRPD, - TelephonyManager.NETWORK_TYPE_HSPAP -> NetworkType.MOBILE_3G - TelephonyManager.NETWORK_TYPE_LTE, - 19 -> NetworkType.MOBILE_LTE - TelephonyManager.NETWORK_TYPE_UNKNOWN -> NetworkType.UNKNOWN - else -> NetworkType.UNKNOWN - } - - @RequiresApi(Build.VERSION_CODES.M) @Suppress("InlinedApi") @RequiresPermission(anyOf = [Manifest.permission.USE_FINGERPRINT, Manifest.permission.USE_BIOMETRIC])