You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 515e0d1
Browse filesBrowse the repository at this point in the historyBrowse files
fix(android): Treat an unpopulated connection cache as stale (JAVA-717) (#6029)
* test(android): Make the DISCONNECTED test mock a disconnected network
`When network is active but not connected with permission, return
DISCONNECTED` mocked an active network reporting isConnected=false
alongside NetworkCapabilities describing a validated WiFi link. Those
describe opposite worlds.
It passes today only because the empty connection cache reads as fresh
for the first two minutes of every boot (JAVA-717), which forces the
legacy activeNetworkInfo path where the capability mocks are never
consulted. buildInfo reports API 24, so once that bug is fixed the
provider reads capabilities and the test would fail for a reason that
has nothing to do with what it is named after.
Fixing the mocks first keeps that failure from being buried in the
commit that fixes the cache.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(android): Treat an unpopulated connection cache as stale (JAVA-717)
lastCacheUpdateTime used 0 for "never populated" while being compared
against SystemClock.uptimeMillis(), which starts at 0 at boot. For the
first two minutes of every boot the empty cache therefore read as fresh,
so getConnectionStatus() skipped updateCache() and fell through to the
legacy activeNetworkInfo path instead of reading NetworkCapabilities.
The window reopens after every unregisterNetworkCallback(), which reset
the field to 0.
Switching clocks does not fix this on its own: elapsedRealtimeNanos()
also starts at 0 at boot. Any 0-means-unset long compared against a
boot-relative clock has the same flaw; only epoch millis made it safe,
because there 0 is 1970.
The cache now holds a Deadline, so "never populated" is expired by
construction and has no numeric value to get wrong. The provider takes
an MonotonicClock in place of ICurrentDateProvider, which is what
a two-minute TTL wants: it must keep counting while the device sleeps.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Add changelog entry for JAVA-717
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@
7
7
- Update `SentryTraced` so that it now honors `options.setIgnoredSpanOrigins` ([#6058](https://github.com/getsentry/sentry-java/pull/6058))
8
8
- `SentryTraced` now checks for its owning transaction dynamically rather than once per app process. The latter caused `SentryTraced` spans to be dropped process-wide once the original transaction finished ([#6057](https://github.com/getsentry/sentry-java/pull/6057))
9
9
- Fix typos in Spring GraphQL integration names (`GrahQL` to `GraphQL`) ([#6061](https://github.com/getsentry/sentry-java/pull/6061))
10
+
- Populate the Android connection status cache during the first two minutes after boot, instead of treating the empty cache as up to date ([#6029](https://github.com/getsentry/sentry-java/pull/6029))
Copy file name to clipboardExpand all lines: sentry-android-core/src/main/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProvider.java
+18-15Lines changed: 18 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,12 @@
19
19
import io.sentry.android.core.AppState;
20
20
import io.sentry.android.core.BuildInfoProvider;
21
21
import io.sentry.android.core.ContextUtils;
22
-
import io.sentry.transport.ICurrentDateProvider;
22
+
import io.sentry.time.Deadline;
23
+
import io.sentry.time.MonotonicTicker;
23
24
import io.sentry.util.AutoClosableReentrantLock;
24
25
import java.util.ArrayList;
25
26
import java.util.List;
27
+
import java.util.concurrent.TimeUnit;
26
28
import java.util.concurrent.atomic.AtomicBoolean;
27
29
import org.jetbrains.annotations.ApiStatus;
28
30
import org.jetbrains.annotations.NotNull;
@@ -41,7 +43,7 @@ public final class AndroidConnectionStatusProvider
41
43
private final @NotNull Context context;
42
44
private final @NotNull SentryOptions options;
43
45
private final @NotNull BuildInfoProvider buildInfoProvider;
44
-
private final @NotNull ICurrentDateProvider timeProvider;
46
+
private final @NotNull MonotonicTicker ticker;
45
47
private final @NotNull List<IConnectionStatusObserver> connectionStatusObservers;
46
48
private final @Nullable Handler handler;
47
49
private final @NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock();
@@ -66,29 +68,30 @@ public final class AndroidConnectionStatusProvider
Copy file name to clipboardExpand all lines: sentry-android-core/src/test/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProviderTest.kt
0 commit comments