Skip to content

Commit 8354a65

Browse files
Ian BirdIanDBird
authored andcommitted
Enable StrictMode in Dev App
1 parent 79ce305 commit 8354a65

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

dev-app/src/main/java/com/uid2/dev/DevApplication.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.uid2.dev
22

33
import android.app.Application
4+
import android.os.StrictMode
45
import com.uid2.UID2Manager
56

67
class 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
}

sdk/src/main/java/com/uid2/storage/FileStorageManager.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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
*/
1616
internal 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 {

sdk/src/test/java/com/uid2/storage/FileStorageManagerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)