Last active
May 6, 2019 06:27
-
-
Save miensol/c4b5999ba1d21741d150a58ed4d257a0 to your computer and use it in GitHub Desktop.
Override android strict mode policy when in android tests to allow calling network on main thread.Useful when you want to access mock web server address and you don't care about the threading.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.StrictMode | |
fun <T> withStrictModeThreadPolicy(threadPolicy: StrictMode.ThreadPolicy, block: () -> T): T { | |
val previousPolicy = StrictMode.getThreadPolicy() | |
StrictMode.setThreadPolicy(threadPolicy) | |
try { | |
return block() | |
} finally { | |
StrictMode.setThreadPolicy(previousPolicy) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment