diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
index cbe3103..8ef5cbd 100644
--- a/library/src/main/AndroidManifest.xml
+++ b/library/src/main/AndroidManifest.xml
@@ -14,4 +14,7 @@
~ and limitations under the License.
-->
-
+
+
+
diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt b/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt
index 4601dd6..c0c6bec 100644
--- a/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt
+++ b/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt
@@ -37,8 +37,8 @@ import com.wultra.android.powerauth.networking.tokens.IPowerAuthTokenListener
import com.wultra.android.powerauth.networking.tokens.IPowerAuthTokenProvider
import com.wultra.android.powerauth.networking.tokens.TokenManager
import com.wultra.android.powerauth.networking.utils.AppUtils
+import com.wultra.android.powerauth.networking.utils.ConnectionMonitor
import com.wultra.android.powerauth.networking.utils.getCurrentLocale
-import com.wultra.android.powerauth.networking.utils.toBcp47LanguageTag
import io.getlime.security.powerauth.core.EciesCryptogram
import io.getlime.security.powerauth.core.EciesEncryptor
import io.getlime.security.powerauth.sdk.PowerAuthAuthentication
@@ -243,11 +243,17 @@ class UserAgent internal constructor(@PublishedApi internal val value: String? =
companion object {
fun libraryDefault(appContext: Context): UserAgent {
val appInfo = AppUtils.getMyPackageBasicInfo(appContext)
- return UserAgent(
- "PowerAuthNetworking/${BuildConfig.VERSION_NAME} " +
- "(${Build.BRAND}; ${appContext.getCurrentLocale().toBcp47LanguageTag()}) " +
- "${appInfo.packageName}/${appInfo.versionName}"
- )
+ val product = "PowerAuthNetworking"
+ val sdkVer = BuildConfig.VERSION_NAME
+ val appVer = appInfo.versionName
+ val appId = appInfo.packageName
+ val lang = appContext.getCurrentLocale().language // we use here only language to fit iOS implementation
+ val maker = Build.BRAND
+ val os = "Android"
+ val osVer = Build.VERSION.RELEASE
+ val model = Build.MODEL
+ val network = ConnectionMonitor.getConnectivityStatus(appContext)
+ return UserAgent("$product/$sdkVer ($lang; $network) $appId/$appVer ($maker; $os/$osVer; $model)")
}
fun systemDefault() = UserAgent()
diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt b/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt
index b3d2e5f..371b6d8 100644
--- a/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt
+++ b/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt
@@ -19,7 +19,10 @@ package com.wultra.android.powerauth.networking.utils
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
+import android.net.*
import android.os.Build
+import androidx.annotation.RequiresApi
+import com.wultra.android.powerauth.networking.Logger
class AppUtils {
companion object {
@@ -34,4 +37,59 @@ class AppUtils {
return appContext.packageManager.getPackageInfo(appContext.packageName, flags)
}
}
-}
\ No newline at end of file
+}
+
+object ConnectionMonitor {
+
+ enum class Status(val value: String) {
+ UNKNOWN("unknown"),
+ NO_CONNECTION("noConnection"),
+ WIFI("wifi"),
+ CELLULAR("cellular"),
+ WIRED("wired")
+ }
+
+ fun getConnectivityStatus(context: Context): String {
+ var status: Status
+ try {
+ val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
+ status = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ getConnectionStatus(connectivityManager)
+ } else {
+ val activeNetworkInfo = connectivityManager.activeNetworkInfo
+ if (activeNetworkInfo != null && activeNetworkInfo.isConnected) {
+ getOlderConnectionStatus(activeNetworkInfo)
+ } else {
+ Status.UNKNOWN
+ }
+ }
+ } catch (e: Throwable) {
+ status = Status.UNKNOWN
+ Logger.d("Failed to create Connectivity Manager with Exception: $e")
+ }
+ return status.value
+ }
+
+ @RequiresApi(Build.VERSION_CODES.M)
+ private fun getConnectionStatus(connectivityManager: ConnectivityManager): Status {
+ val activeNetwork = connectivityManager.activeNetwork
+ val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork)
+
+ return when {
+ networkCapabilities == null -> Status.NO_CONNECTION
+ networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> Status.WIFI
+ networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> Status.CELLULAR
+ networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> Status.WIRED
+ else -> Status.UNKNOWN
+ }
+ }
+
+ private fun getOlderConnectionStatus(networkInfo: NetworkInfo): Status {
+ return when (networkInfo.type) {
+ ConnectivityManager.TYPE_WIFI -> Status.WIFI
+ ConnectivityManager.TYPE_MOBILE -> Status.CELLULAR
+ ConnectivityManager.TYPE_ETHERNET -> Status.WIRED
+ else -> Status.UNKNOWN
+ }
+ }
+}