Skip to content

Commit 093d9bf

Browse files
committed
ref(time): Deprecate the legacy current-date providers (JAVA-571)
One interface carried two incompatible clocks: CurrentDateProvider is System.currentTimeMillis() and AndroidCurrentDateProvider is SystemClock.uptimeMillis(). Nothing in the name or the type said which, which is the defect JAVA-571 is about — a field declared ICurrentDateProvider accepts either, and the two disagree by however long the device has been suspended. MonotonicClock names the guarantee it gives, and SentryDateProvider covers wall time. The annotation goes on the members rather than the types: the Android modules compile at Java 8, where javac still warns on imports of a deprecated type, and an import declaration cannot carry a @SuppressWarnings. Deprecating getCurrentTimeMillis() and getInstance() warns any caller just the same, and every warning it produces lands somewhere that can be suppressed. Each suppression names the replacement the site should take at the next major. Several of these must stay on the wall clock: AnrV2Integration, TombstoneIntegration and ApplicationExitInfoHistoryDispatcher compare against epoch ApplicationExitInfo timestamps, and LifecycleWatcher against Session.getStarted().
1 parent a553260 commit 093d9bf

14 files changed

Lines changed: 75 additions & 1 deletion

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ private static void setupProfiler(
401401
}
402402
}
403403

404+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider or
405+
// MonotonicClock
406+
@SuppressWarnings("deprecation")
404407
static void installDefaultIntegrations(
405408
final @NotNull Context context,
406409
final @NotNull SentryAndroidOptions options,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class AnrV2Integration implements Integration, Closeable {
5050
private final @NotNull ICurrentDateProvider dateProvider;
5151
private @Nullable SentryAndroidOptions options;
5252

53+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
54+
// comparison it feeds must stay wall time
55+
@SuppressWarnings("deprecation")
5356
public AnrV2Integration(final @NotNull Context context) {
5457
// using CurrentDateProvider instead of AndroidCurrentDateProvider as AppExitInfo uses
5558
// System.currentTimeMillis

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public final class AppComponentsBreadcrumbsIntegration
3434
private @Nullable IScopes scopes;
3535
private @Nullable SentryAndroidOptions options;
3636

37+
// TODO [MAJOR]: replace AndroidCurrentDateProvider with MonotonicClock
38+
@SuppressWarnings("deprecation")
3739
private final @NotNull Debouncer trimMemoryDebouncer =
3840
new Debouncer(AndroidCurrentDateProvider.getInstance(), DEBOUNCE_WAIT_TIME_MS, 0);
3941

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ final class ApplicationExitInfoHistoryDispatcher implements Runnable {
3636
private final @NotNull ApplicationExitInfoPolicy policy;
3737
private final long threshold;
3838

39+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
40+
// comparison it feeds must stay wall time
41+
@SuppressWarnings("deprecation")
3942
ApplicationExitInfoHistoryDispatcher(
4043
final @NotNull Context context,
4144
final @NotNull IScopes scopes,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ final class LifecycleWatcher implements AppState.AppStateListener {
2828

2929
private final @NotNull ICurrentDateProvider currentDateProvider;
3030

31+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
32+
// comparison it feeds must stay wall time
33+
@SuppressWarnings("deprecation")
3134
LifecycleWatcher(
3235
final @NotNull IScopes scopes,
3336
final long sessionIntervalMillis,
@@ -60,6 +63,9 @@ public void onForeground() {
6063
addAppBreadcrumb("foreground");
6164
}
6265

66+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
67+
// comparison it feeds must stay wall time
68+
@SuppressWarnings("deprecation")
6369
private void startSession() {
6470
cancelTask();
6571

@@ -90,6 +96,9 @@ private void startSession() {
9096

9197
// App went to background and triggered this callback after 700ms
9298
// as no new screen was shown
99+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
100+
// comparison it feeds must stay wall time
101+
@SuppressWarnings("deprecation")
93102
@Override
94103
public void onBackground() {
95104
final long currentTimeMillis = currentDateProvider.getCurrentTimeMillis();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public final class ScreenshotEventProcessor implements EventProcessor {
4747
private final boolean isReplayAvailable;
4848
private final AtomicBoolean isReplayModuleAbsenceLogged = new AtomicBoolean(false);
4949

50+
// TODO [MAJOR]: replace AndroidCurrentDateProvider with MonotonicClock
51+
@SuppressWarnings("deprecation")
5052
public ScreenshotEventProcessor(
5153
final @NotNull SentryAndroidOptions options,
5254
final @NotNull BuildInfoProvider buildInfoProvider,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ final class SystemEventsBroadcastReceiver extends BroadcastReceiver {
298298
private static final long DEBOUNCE_WAIT_TIME_MS = 60 * 1000;
299299
private final @NotNull IScopes scopes;
300300
private final @NotNull SentryAndroidOptions options;
301+
302+
// TODO [MAJOR]: replace AndroidCurrentDateProvider with MonotonicClock
303+
@SuppressWarnings("deprecation")
301304
private final @NotNull Debouncer batteryChangedDebouncer =
302305
new Debouncer(AndroidCurrentDateProvider.getInstance(), DEBOUNCE_WAIT_TIME_MS, 0);
303306

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class TombstoneIntegration implements Integration, Closeable {
5454
private final @NotNull ICurrentDateProvider dateProvider;
5555
private @Nullable SentryAndroidOptions options;
5656

57+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
58+
// comparison it feeds must stay wall time
59+
@SuppressWarnings("deprecation")
5760
public TombstoneIntegration(final @NotNull Context context) {
5861
// using CurrentDateProvider instead of AndroidCurrentDateProvider as AppExitInfo uses
5962
// System.currentTimeMillis

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public final class ViewHierarchyEventProcessor implements EventProcessor {
4646
private static final long DEBOUNCE_WAIT_TIME_MS = 2000;
4747
private static final int DEBOUNCE_MAX_EXECUTIONS = 3;
4848

49+
// TODO [MAJOR]: replace AndroidCurrentDateProvider with MonotonicClock
50+
@SuppressWarnings("deprecation")
4951
public ViewHierarchyEventProcessor(final @NotNull SentryAndroidOptions options) {
5052
this.options = Objects.requireNonNull(options, "SentryAndroidOptions is required");
5153
this.debouncer =

‎sentry-android-core/src/main/java/io/sentry/android/core/cache/AndroidEnvelopeCache.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public final class AndroidEnvelopeCache extends EnvelopeCache {
3838

3939
private final @NotNull ICurrentDateProvider currentDateProvider;
4040

41+
// TODO [MAJOR]: replace AndroidCurrentDateProvider with MonotonicClock
42+
@SuppressWarnings("deprecation")
4143
public AndroidEnvelopeCache(final @NotNull SentryAndroidOptions options) {
4244
this(options, AndroidCurrentDateProvider.getInstance());
4345
}
@@ -63,6 +65,9 @@ public boolean storeEnvelope(@NotNull SentryEnvelope envelope, @NotNull Hint hin
6365
return storeInternalAndroid(envelope, hint);
6466
}
6567

68+
// TODO [MAJOR]: this reading must stay paired with AppStartMetrics.getStartUptimeMs(),
69+
// which is SystemClock.uptimeMillis(), so MonotonicClock is not a drop-in replacement
70+
@SuppressWarnings("deprecation")
6671
private boolean storeInternalAndroid(@NotNull SentryEnvelope envelope, @NotNull Hint hint) {
6772
final boolean didStore = super.storeEnvelope(envelope, hint);
6873

0 commit comments

Comments
 (0)