Skip to content

Commit 582d8f6

Browse files
committed
fix(DeviceID): DeviceIdStore.load should be thread safe to avoid double device ID generation
1 parent 98d7d07 commit 582d8f6

5 files changed

Lines changed: 10 additions & 5 deletions

File tree

bugsnag-android-core/detekt-baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<ID>LongParameterList:AppWithState.kt$AppWithState$( binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, buildUuid: Provider&lt;String?>?, type: String?, versionCode: Number?, /** * The number of milliseconds the application was running before the event occurred */ var duration: Number?, /** * The number of milliseconds the application was running in the foreground before the * event occurred */ var durationInForeground: Number?, /** * Whether the application was in the foreground when the event occurred */ var inForeground: Boolean?, /** * Whether the application was launching when the event occurred */ var isLaunching: Boolean? )</ID>
1616
<ID>LongParameterList:AppWithState.kt$AppWithState$( binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, buildUuid: String?, type: String?, versionCode: Number?, /** * The number of milliseconds the application was running before the event occurred */ duration: Number?, /** * The number of milliseconds the application was running in the foreground before the * event occurred */ durationInForeground: Number?, /** * Whether the application was in the foreground when the event occurred */ inForeground: Boolean?, /** * Whether the application was launching when the event occurred */ isLaunching: Boolean? )</ID>
1717
<ID>LongParameterList:AppWithState.kt$AppWithState$( config: ImmutableConfig, binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, duration: Number?, durationInForeground: Number?, inForeground: Boolean?, isLaunching: Boolean? )</ID>
18-
<ID>LongParameterList:DataCollectionModule.kt$DataCollectionModule$( contextModule: ContextModule, configModule: ConfigModule, systemServiceModule: SystemServiceModule, trackerModule: TrackerModule, bgTaskService: BackgroundTaskService, connectivity: Connectivity, deviceIdStore: Provider&lt;DeviceIdStore>, memoryTrimState: MemoryTrimState, clientObservable: ClientObservable )</ID>
18+
<ID>LongParameterList:DataCollectionModule.kt$DataCollectionModule$( contextModule: ContextModule, configModule: ConfigModule, systemServiceModule: SystemServiceModule, trackerModule: TrackerModule, bgTaskService: BackgroundTaskService, connectivity: Connectivity, deviceId: Provider&lt;DeviceIdStore.DeviceIds?>, memoryTrimState: MemoryTrimState, clientObservable: ClientObservable )</ID>
1919
<ID>LongParameterList:Device.kt$Device$( buildInfo: DeviceBuildInfo, /** * The Application Binary Interface used */ var cpuAbi: Array&lt;String>?, /** * Whether the device has been jailbroken */ var jailbroken: Boolean?, /** * A UUID generated by Bugsnag and used for the individual application on a device */ var id: String?, /** * The IETF language tag of the locale used */ var locale: String?, /** * The total number of bytes of memory on the device */ var totalMemory: Long?, /** * A collection of names and their versions of the primary languages, frameworks or * runtimes that the application is running on */ runtimeVersions: MutableMap&lt;String, Any>? )</ID>
2020
<ID>LongParameterList:DeviceBuildInfo.kt$DeviceBuildInfo$( val manufacturer: String?, val model: String?, val osVersion: String?, val apiLevel: Int?, val osBuild: String?, val fingerprint: String?, val tags: String?, val brand: String?, val cpuAbis: Array&lt;String>? )</ID>
2121
<ID>LongParameterList:DeviceDataCollector.kt$DeviceDataCollector$( private val connectivity: Connectivity, private val appContext: Context, resources: Resources, private val deviceIdStore: Provider&lt;DeviceIdStore.DeviceIds?>, private val buildInfo: DeviceBuildInfo, private val dataDirectory: File, private val rootedFuture: Provider&lt;Boolean>?, private val bgTaskService: BackgroundTaskService, private val logger: Logger )</ID>

bugsnag-android-core/src/main/java/com/bugsnag/android/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public Unit invoke(Boolean hasConnection, String networkState) {
194194

195195
DataCollectionModule dataCollectionModule = new DataCollectionModule(contextModule,
196196
configModule, systemServiceModule, trackerModule,
197-
bgTaskService, connectivity, storageModule.getDeviceIdStore(),
197+
bgTaskService, connectivity, storageModule.getDeviceId(),
198198
memoryTrimState, clientObservable);
199199

200200
// load the device + user information

bugsnag-android-core/src/main/java/com/bugsnag/android/DataCollectionModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class DataCollectionModule(
2020
trackerModule: TrackerModule,
2121
bgTaskService: BackgroundTaskService,
2222
connectivity: Connectivity,
23-
deviceIdStore: Provider<DeviceIdStore>,
23+
deviceId: Provider<DeviceIdStore.DeviceIds?>,
2424
memoryTrimState: MemoryTrimState,
2525
clientObservable: ClientObservable
2626
) : BackgroundDependencyModule(bgTaskService) {
@@ -51,7 +51,7 @@ internal class DataCollectionModule(
5151
connectivity,
5252
ctx,
5353
ctx.resources,
54-
deviceIdStore.map { it.load() },
54+
deviceId,
5555
deviceBuildInfo,
5656
dataDir,
5757
rootDetection,

bugsnag-android-core/src/main/java/com/bugsnag/android/DeviceIdStore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ internal class DeviceIdStore @JvmOverloads @Suppress("LongParameterList") constr
6262
return internalPersistence.loadDeviceId(true)
6363
}
6464

65+
@Synchronized
6566
fun load(): DeviceIds? {
6667
if (deviceIds != null) {
6768
return deviceIds

bugsnag-android-core/src/main/java/com/bugsnag/android/StorageModule.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ internal class StorageModule(
3434
)
3535
}
3636

37+
val deviceId = deviceIdStore.map {
38+
it.load()
39+
}
40+
3741
val userStore = provider {
3842
UserStore(
3943
immutableConfig.persistUser,
4044
bugsnagDir,
41-
deviceIdStore.map { it.load() },
45+
deviceId,
4246
sharedPrefMigrator = sharedPrefMigrator,
4347
logger = immutableConfig.logger
4448
)

0 commit comments

Comments
 (0)