--- a/app/src/main/java/com/geekorum/ttrss/accounts/TinyrssAcountManager.kt Mon May 20 15:08:22 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/accounts/TinyrssAcountManager.kt Mon May 20 16:35:57 2019 -0700
@@ -23,9 +23,11 @@
import android.accounts.AccountManager
import android.content.ContentResolver
import android.os.Bundle
+import android.os.StrictMode
import android.util.Base64
import com.geekorum.geekdroid.security.SecretCipher
import com.geekorum.ttrss.BackgroundJobManager
+import com.geekorum.ttrss.debugtools.withStrictMode
import com.geekorum.ttrss.providers.ArticlesContract
import com.geekorum.ttrss.sync.SyncContract
import timber.log.Timber
@@ -106,7 +108,7 @@
}
@Throws(GeneralSecurityException::class, IllegalArgumentException::class)
- fun getPassword(account: Account) : String? {
+ fun getPassword(account: Account): String? {
val encryptedPassword: String? = android.accounts.Account(account.username, ACCOUNT_TYPE).let {
accountManager.getPassword(it)
}
@@ -114,9 +116,11 @@
}
fun fromAndroidAccount(androidAccount: android.accounts.Account): Account {
- check(ACCOUNT_TYPE == androidAccount.type) {"Invalid account type ${androidAccount.type}"}
- val url = accountManager.getUserData(androidAccount, AccountAuthenticator.USERDATA_URL)
- return Account(androidAccount.name, url)
+ return withStrictMode(StrictMode.allowThreadDiskReads()) {
+ check(ACCOUNT_TYPE == androidAccount.type) { "Invalid account type ${androidAccount.type}" }
+ val url = accountManager.getUserData(androidAccount, AccountAuthenticator.USERDATA_URL)
+ Account(androidAccount.name, url)
+ }
}
fun updateServerInformation(account: Account, serverInformation: ServerInformation) {
@@ -124,19 +128,21 @@
val encryptedPassword = serverInformation.basicHttpAuthPassword?.let { encrypt(it) }
accountManager.run {
setUserData(androidAccount, AccountAuthenticator.USERDATA_URL, serverInformation.apiUrl)
- setUserData(androidAccount, AccountAuthenticator.USERDATA_BASIC_HTTP_AUTH_USERNAME, serverInformation.basicHttpAuthUsername)
+ setUserData(androidAccount, AccountAuthenticator.USERDATA_BASIC_HTTP_AUTH_USERNAME,
+ serverInformation.basicHttpAuthUsername)
setUserData(androidAccount, AccountAuthenticator.USERDATA_BASIC_HTTP_AUTH_PASSWORD, encryptedPassword)
}
}
- fun getServerInformation(account: Account) : ServerInformation {
+ fun getServerInformation(account: Account): ServerInformation {
val androidAccount = android.accounts.Account(account.username, ACCOUNT_TYPE)
return object : ServerInformation() {
override val apiUrl: String
- get() = accountManager.getUserData(androidAccount, AccountAuthenticator.USERDATA_URL)
+ get() = accountManager.getUserData(androidAccount, AccountAuthenticator.USERDATA_URL)
override val basicHttpAuthUsername: String?
- get() = accountManager.getUserData(androidAccount, AccountAuthenticator.USERDATA_BASIC_HTTP_AUTH_USERNAME)
+ get() = accountManager.getUserData(androidAccount,
+ AccountAuthenticator.USERDATA_BASIC_HTTP_AUTH_USERNAME)
override val basicHttpAuthPassword: String?
get() {
@@ -170,7 +176,7 @@
val base64EncryptedPassword = Base64.encodeToString(output, Base64.NO_WRAP)
val gcmParameterSpec = secretCipher.parametersSpec
val base64IV = Base64.encodeToString(gcmParameterSpec.iv, Base64.NO_WRAP)
- return "${base64EncryptedPassword}\n$${base64IV}\n${gcmParameterSpec.tLen}\n"
+ return "$base64EncryptedPassword\n$$base64IV\n${gcmParameterSpec.tLen}\n"
}
}
--- a/app/src/main/java/com/geekorum/ttrss/debugtools/StrictMode.kt Mon May 20 15:08:22 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/debugtools/StrictMode.kt Mon May 20 16:35:57 2019 -0700
@@ -44,9 +44,7 @@
/**
* Configure StrictMode policies
*/
-class StrictModeInitializer @Inject constructor(
- contentResolver: ContentResolver
-) : AppInitializer {
+class StrictModeInitializer @Inject constructor() : AppInitializer {
private val listenerExecutor by lazy { Executors.newSingleThreadExecutor() }
private val shouldBeFatal: Boolean = (BuildConfig.DEBUG)
@@ -137,7 +135,7 @@
abstract class KotlinInitializerModule {
@Binds
@IntoSet
- abstract fun bindCoroutinesAsyncInitializer(oroutinesAsyncInitializer: KotlinInitializer): AppInitializer
+ abstract fun bindKotlinInitializer(kotlinInitializer: KotlinInitializer): AppInitializer
}
@@ -151,7 +149,10 @@
*
* ```
*/
-inline fun withStrictMode(originalThreadPolicy: StrictMode.ThreadPolicy, block: () -> Unit) {
- block()
- StrictMode.setThreadPolicy(originalThreadPolicy)
+inline fun <R> withStrictMode(originalThreadPolicy: StrictMode.ThreadPolicy, block: () -> R): R {
+ try {
+ return block()
+ } finally {
+ StrictMode.setThreadPolicy(originalThreadPolicy)
+ }
}