diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidNetworkObserver.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidNetworkObserver.kt index 449b6e5b..3ce71701 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidNetworkObserver.kt +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidNetworkObserver.kt @@ -31,6 +31,8 @@ import kotlinx.coroutines.withContext import java.io.IOException import java.lang.Exception import java.net.InetSocketAddress +import java.net.URL +import javax.net.ssl.HttpsURLConnection const val TAG = "C-Manager" @@ -103,17 +105,16 @@ class ConnectionLiveData(context: Context) : LiveData() { } /** - * Send a ping to googles primary DNS. + * Try Establishing an Actual Internet Connection. * If successful, that means we have internet. */ object DoesNetworkHaveInternet { suspend fun execute(network: Network): Boolean = withContext(Dispatchers.IO) { try { - Log.d(TAG, "PINGING google.") - val socket = network.socketFactory.createSocket() ?: throw IOException("Socket is null.") - socket.connect(InetSocketAddress("8.8.8.8", 53), 1500) - socket.close() - Log.d(TAG, "PING success.") + val url = URL("https://open.spotify.com/") + val connection = network.openConnection(url) as HttpsURLConnection + connection.connect() + connection.disconnect() true } catch (e: Exception) { e.printStackTrace() diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt index 51be74bc..97fb7c46 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt @@ -41,7 +41,7 @@ expect val currentPlatform: AllPlatforms suspend fun isInternetAccessible(): Boolean { return withContext(dispatcherIO) { try { - ktorHttpClient.head("https://google.com") + ktorHttpClient.head("https://open.spotify.com/") true } catch (e: Exception) { e.printStackTrace()