Skip to content

Commit 67f3913

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 dc2ac71 commit 67f3913

12 files changed

Lines changed: 58 additions & 1 deletion

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ final class ANRWatchDog extends Thread {
8585
debugManager);
8686
}
8787

88+
// TODO [MAJOR]: measure the stall on a MonotonicTicker instead of an injected wall clock
89+
@SuppressWarnings("deprecation")
8890
@TestOnly
8991
ANRWatchDog(
9092
@NotNull final ICurrentDateProvider timeProvider,
@@ -122,6 +124,7 @@ final class ANRWatchDog extends Thread {
122124
}
123125
}
124126

127+
@SuppressWarnings("deprecation")
125128
@Override
126129
public void run() {
127130
// right when the watchdog gets started, let's assume there's no ANR

‎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
@@ -412,6 +412,9 @@ private static void setupProfiler(
412412
}
413413
}
414414

415+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider or
416+
// MonotonicTicker
417+
@SuppressWarnings("deprecation")
415418
static void installDefaultIntegrations(
416419
final @NotNull Context context,
417420
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/ApplicationExitInfoHistoryDispatcher.java‎

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

56+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
57+
// comparison it feeds must stay wall time
58+
@SuppressWarnings("deprecation")
5659
ApplicationExitInfoHistoryDispatcher(
5760
final @NotNull Context context,
5861
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/MemoryLimiterIntegration.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public final class MemoryLimiterIntegration implements Integration, Closeable {
8989
private final @NotNull BuildInfoProvider buildInfoProvider;
9090
private @Nullable SentryAndroidOptions androidOptions;
9191

92+
// TODO [MAJOR]: replace CurrentDateProvider (wall clock) with SentryDateProvider; the epoch
93+
// comparison it feeds must stay wall time
94+
@SuppressWarnings("deprecation")
9295
public MemoryLimiterIntegration(
9396
final @NotNull Context context, final @NotNull BuildInfoProvider buildInfoProvider) {
9497
// Use CurrentDateProvider instead of AndroidCurrentDateProvider as ApplicationExitInfo uses

‎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/cache/AndroidEnvelopeCache.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public boolean storeEnvelope(@NotNull SentryEnvelope envelope, @NotNull Hint hin
6767
return storeInternalAndroid(envelope, hint);
6868
}
6969

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

‎sentry-android-core/src/main/java/io/sentry/android/core/internal/util/AndroidCurrentDateProvider.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@ApiStatus.Internal
2020
public final class AndroidCurrentDateProvider implements ICurrentDateProvider {
2121

22+
@SuppressWarnings("deprecation")
2223
private static final ICurrentDateProvider instance = new AndroidCurrentDateProvider();
2324

2425
/**
@@ -32,6 +33,7 @@ public static ICurrentDateProvider getInstance() {
3233
private AndroidCurrentDateProvider() {}
3334

3435
@Override
36+
@SuppressWarnings("deprecation")
3537
public long getCurrentTimeMillis() {
3638
return SystemClock.uptimeMillis();
3739
}

‎sentry-android-core/src/main/java/io/sentry/android/core/internal/util/Debouncer.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public Debouncer(
3030
* @return true if the execution should be debounced due to maxExecutions executions being made
3131
* within waitTimeMs, otherwise false.
3232
*/
33+
// TODO [MAJOR]: replace AndroidCurrentDateProvider with MonotonicTicker
34+
@SuppressWarnings("deprecation")
3335
public boolean checkForDebounce() {
3436
final long now = timeProvider.getCurrentTimeMillis();
3537
if (lastExecutionTime.get() == 0 || (lastExecutionTime.get() + waitTimeMs) <= now) {

0 commit comments

Comments
 (0)