Skip to content

Commit 81a532a

Browse files
authored
Merge pull request #5937 from getsentry/fix/data-collection-preserve-installation-id
fix(android): [Data Collection 19] Preserve installation ID
2 parents 93cca38 + 9f50ccb commit 81a532a

11 files changed

Lines changed: 17 additions & 39 deletions

File tree

‎sentry-android-core/src/main/java/io/sentry/android/core/ApplicationExitInfoEventProcessor.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ private void mergeUser(final @NotNull SentryBaseEvent event) {
678678
}
679679

680680
// userId should be set even if event is Cached as the userId is static and won't change anyway.
681-
if (user.getId() == null && options.getDataCollectionResolver().isUserInfoWithLegacyAlways()) {
681+
if (user.getId() == null) {
682682
user.setId(getDeviceId());
683683
}
684684
if (user.getIpAddress() == null && options.getDataCollectionResolver().isUserInfo()) {
@@ -745,8 +745,7 @@ private void setDevice(final @NotNull SentryBaseEvent event) {
745745
device.setScreenDpi(displayMetrics.densityDpi);
746746
}
747747

748-
if (device.getId() == null
749-
&& options.getDataCollectionResolver().isUserInfoWithLegacyAlways()) {
748+
if (device.getId() == null) {
750749
device.setId(getDeviceId());
751750
}
752751

‎sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private void mergeUser(final @NotNull SentryBaseEvent event) {
175175
}
176176

177177
// userId should be set even if event is Cached as the userId is static and won't change anyway.
178-
if (user.getId() == null && options.getDataCollectionResolver().isUserInfoWithLegacyAlways()) {
178+
if (user.getId() == null) {
179179
user.setId(Installation.id(context));
180180
}
181181
if (user.getIpAddress() == null && options.getDataCollectionResolver().isUserInfo()) {
@@ -374,9 +374,7 @@ private void setAppExtras(final @NotNull App app, final @NotNull Hint hint) {
374374
*/
375375
public @NotNull User getDefaultUser(final @NotNull Context context) {
376376
final @NotNull User user = new User();
377-
if (options.getDataCollectionResolver().isUserInfoWithLegacyAlways()) {
378-
user.setId(Installation.id(context));
379-
}
377+
user.setId(Installation.id(context));
380378
return user;
381379
}
382380

‎sentry-android-core/src/main/java/io/sentry/android/core/DeviceInfoUtil.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ public Device collectDeviceInformation(
109109
device.setBootTime(getBootTime());
110110
device.setTimezone(getTimeZone());
111111

112-
if (device.getId() == null
113-
&& options.getDataCollectionResolver().isUserInfoWithLegacyAlways()) {
112+
if (device.getId() == null) {
114113
device.setId(getDeviceId());
115114
}
116115

‎sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public static Map<String, Object> serializeScope(
100100
user = new User();
101101
scope.setUser(user);
102102
}
103-
if (user.getId() == null
104-
&& options.getDataCollectionResolver().isUserInfoWithLegacyAlways()) {
103+
if (user.getId() == null) {
105104
try {
106105
user.setId(Installation.id(context));
107106
} catch (RuntimeException e) {

‎sentry-android-core/src/test/java/io/sentry/android/core/ApplicationExitInfoEventProcessorTest.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ class ApplicationExitInfoEventProcessorTest {
232232
}
233233

234234
@Test
235-
fun `when user info is disabled, does not set device id`() {
235+
fun `when user info is disabled, sets device id`() {
236236
fixture.options.dataCollection.setUserInfo(false)
237237
val hint = HintUtils.createWithTypeCheckHint(AbnormalExitHint())
238238

239239
val processed = processEvent(hint)
240240

241-
assertNull(processed.contexts.device!!.id)
241+
assertNotNull(processed.contexts.device!!.id)
242242
}
243243

244244
@Test
@@ -681,7 +681,7 @@ class ApplicationExitInfoEventProcessorTest {
681681
}
682682

683683
@Test
684-
fun `when user info is disabled, does not set installation id for missing user id`() {
684+
fun `when user info is disabled, sets installation id for missing user id`() {
685685
fixture.options.dataCollection.setUserInfo(false)
686686
val hint = HintUtils.createWithTypeCheckHint(BackfillableHint())
687687
val original = SentryEvent()
@@ -690,7 +690,7 @@ class ApplicationExitInfoEventProcessorTest {
690690

691691
val processed = processor.process(original, hint)
692692

693-
assertNull(processed!!.user!!.id)
693+
assertEquals(Installation.deviceId, processed!!.user!!.id)
694694
}
695695

696696
@Test

‎sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ class DefaultAndroidEventProcessorTest {
285285
}
286286

287287
@Test
288-
fun `when user info is disabled, does not set automatic user data`() {
288+
fun `when user info is disabled, sets installation id but not automatic ip`() {
289289
fixture.options.dataCollection.setUserInfo(false)
290290
val sut = fixture.getSut(context, isSendDefaultPii = true)
291291
val event = SentryEvent().apply { user = User() }
292292

293293
sut.process(event, Hint())
294294

295295
assertNotNull(event.user) {
296-
assertNull(it.id)
296+
assertNotNull(it.id)
297297
assertNull(it.ipAddress)
298298
}
299299
}

‎sentry-android-core/src/test/java/io/sentry/android/core/DeviceInfoUtilTest.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class DeviceInfoUtilTest {
7070
assertNotNull(enabledDevice.id)
7171
assertNotNull(enabledDevice.storageSize)
7272
assertNotNull(enabled.operatingSystem.isRooted)
73-
assertNull(disabledDevice.id)
73+
assertNotNull(disabledDevice.id)
7474
assertNull(disabledDevice.storageSize)
7575
assertNull(disabled.operatingSystem.isRooted)
7676
}
@@ -94,12 +94,12 @@ class DeviceInfoUtilTest {
9494
}
9595

9696
@Test
97-
fun `does not set device id when user info is disabled`() {
97+
fun `sets device id when user info is disabled`() {
9898
val options = SentryAndroidOptions().apply { dataCollection.setUserInfo(false) }
9999
val deviceInfo =
100100
DeviceInfoUtil.getInstance(context, options).collectDeviceInformation(false, false)
101101

102-
assertNull(deviceInfo.id)
102+
assertNotNull(deviceInfo.id)
103103
}
104104

105105
@Test

‎sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import java.util.concurrent.atomic.AtomicReference
4040
import kotlin.test.BeforeTest
4141
import kotlin.test.Test
4242
import kotlin.test.assertEquals
43-
import kotlin.test.assertFalse
4443
import kotlin.test.assertNotEquals
4544
import kotlin.test.assertNotNull
4645
import kotlin.test.assertNull
@@ -355,14 +354,14 @@ class InternalSentrySdkTest {
355354
}
356355

357356
@Test
358-
fun `serializeScope does not provide fallback user id when user info is disabled`() {
357+
fun `serializeScope provides fallback user id when user info is disabled`() {
359358
val options = SentryAndroidOptions().apply { dataCollection.setUserInfo(false) }
360359
val scope = Scope(options)
361360
scope.user = null
362361

363362
val serializedScope = InternalSentrySdk.serializeScope(context, options, scope)
364363

365-
assertFalse((serializedScope["user"] as Map<*, *>).containsKey("id"))
364+
assertTrue((serializedScope["user"] as Map<*, *>).containsKey("id"))
366365
}
367366

368367
@Test

‎sentry/api/sentry.api‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ public final class io/sentry/DataCollectionResolver {
436436
public fun isOutgoingResponseBody ()Z
437437
public fun isOutgoingResponseBodyWithLegacyBodyGate ()Z
438438
public fun isUserInfo ()Z
439-
public fun isUserInfoWithLegacyAlways ()Z
440439
}
441440

442441
public final class io/sentry/DateUtils {

‎sentry/src/main/java/io/sentry/DataCollectionResolver.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public boolean isUserInfo() {
2323
return explicitOrSendDefaultPii(options.getDataCollection().getUserInfo(), true);
2424
}
2525

26-
public boolean isUserInfoWithLegacyAlways() {
27-
return explicitOrDefault(options.getDataCollection().getUserInfo(), true, true);
28-
}
29-
3026
public boolean isDatabaseQueryData() {
3127
return explicitOrSendDefaultPii(options.getDataCollection().getDatabaseQueryData(), true);
3228
}

0 commit comments

Comments
 (0)