Skip to content

Commit 174655b

Browse files
committed
Move ConnectionType to pos module
1 parent f99f1cf commit 174655b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.woocommerce.android.pos.util
2+
3+
enum class ConnectionType {
4+
WIFI,
5+
CELLULAR,
6+
UNKNOWN
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.woocommerce.android.pos.util
2+
3+
import android.content.Context
4+
import android.net.ConnectivityManager
5+
import android.net.NetworkCapabilities
6+
import dagger.Reusable
7+
import dagger.hilt.android.qualifiers.ApplicationContext
8+
import javax.inject.Inject
9+
10+
@Reusable
11+
class WooPosConnectionTypeProvider @Inject constructor(
12+
@ApplicationContext private val context: Context
13+
) {
14+
fun getConnectionType(): ConnectionType {
15+
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
16+
val networkCapabilities = connectivityManager
17+
?.activeNetwork
18+
?.let { connectivityManager.getNetworkCapabilities(it) }
19+
20+
return when {
21+
networkCapabilities?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) == true -> ConnectionType.WIFI
22+
networkCapabilities?.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) == true -> ConnectionType.CELLULAR
23+
else -> ConnectionType.UNKNOWN
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)