Tower Guidev2
04/14/2022, 11:58 AMGlobalScope
is there a Best Practice approach?stojan
04/14/2022, 12:24 PMsuspend fun , test that... then the only remaining untested part becomes GlobalScope.launch { myFun() } which is trivialursus
04/14/2022, 2:42 PMTower Guidev2
04/14/2022, 3:27 PMGlobalScope.launch {} so that I could place disk reads/writes (AndroidKeyStore calls) off the main thread and also so they did not impact app start up time
im employing the google tink library (com.google.crypto.tink) for my in app encryptionursus
04/14/2022, 3:29 PMursus
04/14/2022, 3:31 PMclass Whatever(dispatcher) {
private val scope = CoroutineScope(SupervisorJob() + dispatcher)
fun foo() {
scope.launch { ... }
}
}ursus
04/14/2022, 3:31 PMTower Guidev2
04/14/2022, 3:34 PMjava.lang.NullPointerException:
at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.<init> (SharedPrefKeysetReader.java:60)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.withSharedPref (AndroidKeysetManager.kt:162)Tower Guidev2
04/14/2022, 3:36 PMin real code pass in the Dispatchers.Io
in test code pass in Dispatchers.Unconfinedthis is not possible as the code is in my
onCreate() function within my Application classursus
04/14/2022, 3:39 PMTower Guidev2
04/14/2022, 3:47 PMoverride fun onCreate() {
super.onCreate()
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
manageTink()
}
if (BuildConfig.DEBUG) manageStrictMode()
DynamicColors.applyToActivitiesIfAvailable(this@MyApplication)
upgradeSecurityProvider()
registerActivityLifecycleCallbacks(this@MyApplication)
}Tower Guidev2
04/14/2022, 3:47 PMprivate fun manageTink() {
try {
AeadConfig.register()
authenticatedEncryption = generateNewKeysetHandle().getPrimitive(Aead::class.java)
} catch (e: GeneralSecurityException) {
throw RuntimeException(e)
} catch (e: IOException) {
throw RuntimeException(e)
}
}ursus
04/14/2022, 3:51 PMursus
04/14/2022, 3:53 PMApp.onCreate() {
TinkInitializer(this, <http://Dispatcher.Io|Dispatcher.Io>)
}
``````ursus
04/14/2022, 3:53 PMTower Guidev2
04/14/2022, 3:57 PMmanageTink() from an init block in my Application class
init {
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
manageTink()
}
}
and as i pass this@MyApplication within the manageTink() function "sometimes" the appContext was found to be nullursus
04/14/2022, 4:19 PM