File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed
dev-app/src/main/java/com/uid2/dev
main/java/com/uid2/storage
test/java/com/uid2/storage Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 11package com.uid2.dev
22
33import android.app.Application
4+ import android.os.StrictMode
45import com.uid2.UID2Manager
56
67class DevApplication : Application () {
@@ -13,5 +14,20 @@ class DevApplication : Application() {
1314
1415 // Alternatively, we could initialise the UID2Manager with our own custom NetworkSession...
1516 // UID2Manager.init(this.applicationContext, OkNetworkSession())
17+
18+ // For the development app, we will enable a strict thread policy to ensure we have suitable visibility of any
19+ // issues within the SDK.
20+ enableStrictMode()
21+ }
22+
23+ private fun enableStrictMode () {
24+ StrictMode .setThreadPolicy(
25+ StrictMode .ThreadPolicy .Builder ().apply {
26+ detectDiskReads()
27+ detectDiskWrites()
28+ detectNetwork()
29+ penaltyLog()
30+ }.build(),
31+ )
1632 }
1733}
Original file line number Diff line number Diff line change @@ -14,11 +14,14 @@ import java.io.File
1414 * An implementation of the StorageManager that persists UID2Identity instances in clear-text via a File.
1515 */
1616internal class FileStorageManager (
17- private val identityFile : File ,
17+ val identityFileFactory : () -> File ,
1818 private val ioDispatcher : CoroutineDispatcher = Dispatchers .IO ,
1919) : StorageManager {
2020
21- constructor (context: Context ) : this (File (context.filesDir, FILE_IDENTITY ))
21+ constructor (context: Context ) : this ({ File (context.filesDir, FILE_IDENTITY ) })
22+
23+ // This lazy value *should* only be requested on the ioDispatcher.
24+ private val identityFile: File by lazy { identityFileFactory() }
2225
2326 override suspend fun saveIdentity (identity : UID2Identity , status : IdentityStatus ) = withContext(ioDispatcher) {
2427 runCatching {
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ class FileStorageManagerTest {
4545 " refresh response key" ,
4646 )
4747
48- val storageManager = FileStorageManager (identityFile, testDispatcher)
48+ val storageManager = FileStorageManager ({ identityFile } , testDispatcher)
4949 storageManager.saveIdentity(identity, ESTABLISHED )
5050 testDispatcher.scheduler.advanceUntilIdle()
5151
@@ -65,7 +65,7 @@ class FileStorageManagerTest {
6565 " refresh response key" ,
6666 )
6767
68- val storageManager = FileStorageManager (identityFile, testDispatcher)
68+ val storageManager = FileStorageManager ({ identityFile } , testDispatcher)
6969 storageManager.saveIdentity(identity, ESTABLISHED )
7070 testDispatcher.scheduler.advanceUntilIdle()
7171
You can’t perform that action at this time.
0 commit comments