in azure-communication-ui/demo-app/src/calling-test/java/com/azure/android/communication/ui/callingcompositedemoapp/util/NetworkUtils.kt [21:46]
fun enableNetworkThatWasDisabled(onNetworkAvailable: () -> Unit) {
InstrumentationRegistry.getInstrumentation().run {
uiAutomation.run {
executeShellCommand("svc wifi enable")
executeShellCommand("svc data enable")
}
val cm = targetContext
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
var timeOut = 0L
timeout@ while (timeOut < TIMED_OUT_VALUE) {
val activeNetwork = cm.activeNetwork
val networkCap = cm.getNetworkCapabilities(activeNetwork)
if (activeNetwork != null && networkCap != null &&
networkCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
networkCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
) {
onNetworkAvailable()
break@timeout
}
Thread.sleep(100)
timeOut++
}
}
}