aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorMarvin Borner2018-09-03 14:31:12 +0200
committerMarvin Borner2018-09-03 14:31:12 +0200
commit728720a901d1d48218e4ed37ae5fc1946aa340b5 (patch)
tree235f97236c437bb75db7b4b6ec187408f39fe9e0 /app/src/main
parent42037fcac77ff233cd7e22a95b58b0389828ed1f (diff)
Made internet connection check faster :zap:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/me/texx/Texx/RoutingActivity.kt22
1 files changed, 18 insertions, 4 deletions
diff --git a/app/src/main/java/me/texx/Texx/RoutingActivity.kt b/app/src/main/java/me/texx/Texx/RoutingActivity.kt
index d316c07..86ad359 100644
--- a/app/src/main/java/me/texx/Texx/RoutingActivity.kt
+++ b/app/src/main/java/me/texx/Texx/RoutingActivity.kt
@@ -1,6 +1,7 @@
package me.texx.Texx
import android.os.Bundle
+import android.os.StrictMode
import android.support.v7.app.AppCompatActivity
import com.github.kittinunf.fuel.android.extension.responseJson
import com.github.kittinunf.fuel.core.FuelManager
@@ -11,6 +12,9 @@ import daio.io.dresscode.matchDressCode
import me.texx.Texx.util.ThemeUtil.getThemeName
import org.jetbrains.anko.*
import java.io.IOException
+import java.net.InetSocketAddress
+import java.net.Socket
+
/**
* Activity which will be run before any other to verify user and choose which activity
@@ -44,10 +48,20 @@ class RoutingActivity : AppCompatActivity() {
/**
* Checks if client is connected to the internet by pinging google
*/
- @Throws(InterruptedException::class, IOException::class)
- fun isConnected(): Boolean {
- val command = "ping -c 1 google.com"
- return Runtime.getRuntime().exec(command).waitFor() == 0
+ private fun isConnected(): Boolean {
+ return try {
+ val policy = StrictMode.ThreadPolicy.Builder()
+ .permitAll().build()
+ StrictMode.setThreadPolicy(policy)
+ val timeoutMs = 1500
+ val socket = Socket()
+ val socketAddress = InetSocketAddress("8.8.8.8", 53)
+ socket.connect(socketAddress, timeoutMs)
+ socket.close()
+ true
+ } catch (e: IOException) {
+ false
+ }
}
private fun verifyLogin() {