Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void stopPreviousTransactions() {
}

private void startTracing(final @NotNull Activity activity) {
if (scopes != null && !isRunningTransactionOrTrace(activity)) {
if (scopes != null && options != null && !isRunningTransactionOrTrace(activity)) {
if (!performanceEnabled) {
activitiesWithOngoingTransactions.put(activity, NoOpTransaction.getInstance());
if (options.isEnableAutoTraceIdGeneration()) {
Expand Down Expand Up @@ -282,7 +282,7 @@ private void startTracing(final @NotNull Activity activity) {
// Continue either the foreground app.start above or an earlier headless app.start.
final @Nullable String continueSentryTrace;
final @Nullable String continueBaggage;
if (createStandaloneAppStart) {
if (createStandaloneAppStart && appStartTransaction != null) {
continueSentryTrace = appStartTransaction.toSentryTrace().getValue();
final @Nullable BaggageHeader baggageHeader = appStartTransaction.toBaggageHeader(null);
continueBaggage = baggageHeader == null ? null : baggageHeader.getValue();
Expand Down Expand Up @@ -332,7 +332,7 @@ private void startTracing(final @NotNull Activity activity) {
final SpanOptions spanOptions = new SpanOptions();
setSpanOrigin(spanOptions);

if (isAppStart) {
if (isAppStart && coldStart != null) {
if (!createStandaloneAppStart && !options.isEnableStandaloneAppStartTracing()) {
appStartSpan =
transaction.startChild(
Expand Down Expand Up @@ -980,7 +980,7 @@ private void onHeadlessAppStart() {
}

final @NotNull ITransaction transaction =
createStandaloneAppStartTransaction(startTime, null, false);
createStandaloneAppStartTransaction(scopes, options, startTime, null, false);
transaction.finish(SpanStatus.OK, endTime);
}

Expand All @@ -991,6 +991,8 @@ private void onHeadlessAppStart() {
* for its children and gets a deadline so it stays open until the extended span finishes.
*/
private @NotNull ITransaction createStandaloneAppStartTransaction(
final @NotNull IScopes scopes,
final @NotNull SentryAndroidOptions options,
final @NotNull SentryDate startTime,
final @Nullable TracesSamplingDecision samplingDecision,
final boolean holdOpenForExtension) {
Expand Down Expand Up @@ -1069,7 +1071,7 @@ private void onHeadlessAppStart() {
metrics.setAppStartSamplingDecision(null);

final @NotNull ITransaction transaction =
createStandaloneAppStartTransaction(startTime, samplingDecision, true);
createStandaloneAppStartTransaction(scopes, options, startTime, samplingDecision, true);

final SpanOptions spanOptions = new SpanOptions();
setSpanOrigin(spanOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public final class AppState implements Closeable {
private static @NotNull AppState instance = new AppState();
private final @NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock();
private volatile LifecycleObserver lifecycleObserver;
private volatile @Nullable LifecycleObserver lifecycleObserver;
private MainLooperHandler handler = new MainLooperHandler();

private AppState() {}
Expand All @@ -49,7 +49,7 @@ public void resetInstance() {

@ApiStatus.Internal
@TestOnly
public LifecycleObserver getLifecycleObserver() {
public @Nullable LifecycleObserver getLifecycleObserver() {
return lifecycleObserver;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
import io.sentry.util.HintUtils;
import io.sentry.util.LazyEvaluator;
import io.sentry.util.Objects;
import java.util.Collections;
import java.util.List;
Expand All @@ -40,8 +39,7 @@ final class DefaultAndroidEventProcessor implements SentryEventProcessor {
private final @NotNull BuildInfoProvider buildInfoProvider;
private final @NotNull SentryAndroidOptions options;
@TestOnly final @Nullable Future<DeviceInfoUtil> deviceInfoUtil;
private final @NotNull LazyEvaluator<String> deviceFamily =
new LazyEvaluator<>(() -> ContextUtils.getFamily(NoOpLogger.getInstance()));
private final @Nullable String deviceFamily = ContextUtils.getFamily(NoOpLogger.getInstance());

public DefaultAndroidEventProcessor(
final @NotNull Context context,
Expand Down Expand Up @@ -241,7 +239,7 @@ private void setDevice(final @NotNull SentryLogEvent event) {
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL));
event.setAttribute(
"device.family",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue()));
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e);
}
Expand Down Expand Up @@ -269,7 +267,7 @@ private void setDevice(final @NotNull SentryMetricsEvent event) {
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL));
event.setAttribute(
"device.family",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue()));
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private void startShakeDetection(final @NotNull Activity activity) {
final @Nullable WeakReference<Activity> ref = currentActivityRef;
final Activity active = ref != null ? ref.get() : null;
final Boolean inBackground = AppState.getInstance().isInBackground();
final @Nullable SentryAndroidOptions options = this.options;
if (active == null
|| options == null
|| !enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public final class SystemEventsBreadcrumbsIntegration
private final @NotNull String[] actions;
private volatile boolean isClosed = false;
private volatile boolean isStopped = false;
private volatile IntentFilter filter = null;
private volatile HandlerThread handlerThread = null;
private volatile @Nullable IntentFilter filter = null;
private volatile @Nullable HandlerThread handlerThread = null;
private final @NotNull AtomicBoolean isReceiverRegistered = new AtomicBoolean(false);
private final @NotNull AutoClosableReentrantLock receiverLock = new AutoClosableReentrantLock();
// Track previous battery state to avoid duplicate breadcrumbs when values haven't changed
Expand Down Expand Up @@ -152,12 +152,6 @@ private void registerReceiver(
filter.addAction(item);
}
}
if (customHandler == null && handlerThread == null) {
handlerThread =
new HandlerThread(
"SystemEventsReceiver", Process.THREAD_PRIORITY_BACKGROUND);
handlerThread.start();
}
try {
// registerReceiver can throw SecurityException but it's not documented in the
// official docs
Expand All @@ -167,6 +161,12 @@ private void registerReceiver(
if (customHandler != null) {
handler = customHandler;
} else {
if (handlerThread == null) {
handlerThread =
new HandlerThread(
"SystemEventsReceiver", Process.THREAD_PRIORITY_BACKGROUND);
handlerThread.start();
}
handler = new Handler(handlerThread.getLooper());
}
ContextUtils.registerReceiver(context, options, receiver, filter, handler);
Expand Down Expand Up @@ -198,6 +198,7 @@ private void registerReceiver(

@SuppressWarnings("Convert2MethodRef") // older AGP versions do not support method references
private void scheduleUnregisterReceiver() {
final @Nullable SentryAndroidOptions options = this.options;
if (options == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public ViewHierarchyEventProcessor(final @NotNull SentryAndroidOptions options)
return event;
}

public static byte[] snapshotViewHierarchyAsData(
public static @Nullable byte[] snapshotViewHierarchyAsData(
@Nullable Activity activity,
@NotNull IThreadChecker threadChecker,
@NotNull ISerializer serializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public AnrProfileManager(final @NotNull SentryOptions options, final @NotNull Fi
queueFile,
new ObjectQueue.Converter<AnrStackTrace>() {
@Override
public AnrStackTrace from(final byte[] source) throws IOException {
public @Nullable AnrStackTrace from(final byte[] source) throws IOException {
// no need to close the streams since they are backed by byte arrays and don't
// hold any resources
final @NotNull ByteArrayInputStream bis = new ByteArrayInputStream(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ && isViewScrollable(view, isAndroidXAvailable.getValue())) {
return null;
}

private UiElement createUiElement(final @NotNull View targetView) {
private @Nullable UiElement createUiElement(final @NotNull View targetView) {
final @Nullable String resourceName = ViewUtils.getResourceIdOrNull(targetView);
if (resourceName == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void parse(final @NotNull Lines lines) {
markThreads();
}

private SentryThread parseThread(final @NotNull Lines lines) {
private @Nullable SentryThread parseThread(final @NotNull Lines lines) {
final SentryThread sentryThread = new SentryThread();

final Matcher beginManagedThreadRe = BEGIN_MANAGED_THREAD_RE.matcher("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ void extendTo(final @NotNull MemoryMapping mapping) {
this.previousOffset = mapping.offset;
}

@Nullable
DebugImage toDebugImage() {
if (buildId.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,16 @@ private void updateCacheAndNotifyObservers(
private boolean isSignificantChange(@Nullable NetworkCapabilities newCapabilities) {
final NetworkCapabilities oldCapabilities = cachedNetworkCapabilities;

// Always significant if transitioning between null and non-null
if ((oldCapabilities == null) != (newCapabilities == null)) {
return true;
}

// If both null, no change
if (oldCapabilities == null && newCapabilities == null) {
return false;
}

// Always significant if transitioning between null and non-null
if (oldCapabilities == null || newCapabilities == null) {
return true;
}

// Check significant capability changes
if (hasSignificantCapabilityChanges(oldCapabilities, newCapabilities)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ class AndroidLoggerBatchProcessorTest {
val sut = fixture.getSut()
sut.close(false)

assertTrue(AppState.getInstance().lifecycleObserver.listeners.isEmpty())
assertTrue(AppState.getInstance().lifecycleObserver!!.listeners.isEmpty())
}

@Test
fun `close with isRestarting true still removes listener`() {
val sut = fixture.getSut()
sut.close(true)

assertTrue(AppState.getInstance().lifecycleObserver.listeners.isEmpty())
assertTrue(AppState.getInstance().lifecycleObserver!!.listeners.isEmpty())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ class AndroidMetricsBatchProcessorTest {
val sut = fixture.getSut()
sut.close(false)

assertTrue(AppState.getInstance().lifecycleObserver.listeners.isEmpty())
assertTrue(AppState.getInstance().lifecycleObserver!!.listeners.isEmpty())
}

@Test
fun `close with isRestarting true still removes listener`() {
val sut = fixture.getSut()
sut.close(true)

assertTrue(AppState.getInstance().lifecycleObserver.listeners.isEmpty())
assertTrue(AppState.getInstance().lifecycleObserver!!.listeners.isEmpty())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SessionTrackingIntegrationTest {

private fun setupLifecycle(): LifecycleRegistry {
val lifecycle = LifecycleRegistry(ProcessLifecycleOwner.get())
lifecycle.addObserver(AppState.getInstance().lifecycleObserver)
lifecycle.addObserver(AppState.getInstance().lifecycleObserver!!)
return lifecycle
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
sut.register(fixture.scopes, fixture.options)

assertTrue(
AppState.getInstance().lifecycleObserver.listeners.any {
AppState.getInstance().lifecycleObserver!!.listeners.any {
it is SystemEventsBreadcrumbsIntegration
}
)
Expand All @@ -401,7 +401,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
sut.register(fixture.scopes, fixture.options)

assertFalse(
AppState.getInstance().lifecycleObserver.listeners.any {
AppState.getInstance().lifecycleObserver!!.listeners.any {
it is SystemEventsBreadcrumbsIntegration
}
)
Expand All @@ -414,15 +414,15 @@ class SystemEventsBreadcrumbsIntegrationTest {
sut.register(fixture.scopes, fixture.options)

assertTrue(
AppState.getInstance().lifecycleObserver.listeners.any {
AppState.getInstance().lifecycleObserver!!.listeners.any {
it is SystemEventsBreadcrumbsIntegration
}
)

sut.close()

assertFalse(
AppState.getInstance().lifecycleObserver.listeners.any {
AppState.getInstance().lifecycleObserver!!.listeners.any {
it is SystemEventsBreadcrumbsIntegration
}
)
Expand All @@ -447,7 +447,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
shadowOf(Looper.getMainLooper()).idle()

assertFalse(
AppState.getInstance().lifecycleObserver.listeners.any {
AppState.getInstance().lifecycleObserver!!.listeners.any {
it is SystemEventsBreadcrumbsIntegration
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ class AnrProfilingIntegrationTest {
val thread = integration.getProperty<Thread?>("thread")
assertNotNull(thread)

assertTrue(AppState.getInstance().lifecycleObserver.listeners.isNotEmpty())
assertTrue(AppState.getInstance().lifecycleObserver!!.listeners.isNotEmpty())

integration.close()
thread.join(2000)

assertTrue(!thread.isAlive)
val enabled = integration.getProperty<java.util.concurrent.atomic.AtomicBoolean>("enabled")
assertTrue(!enabled.get())
assertTrue(AppState.getInstance().lifecycleObserver.listeners.isEmpty())
assertTrue(AppState.getInstance().lifecycleObserver!!.listeners.isEmpty())
}

@Test
Expand Down Expand Up @@ -334,7 +334,7 @@ class AnrProfilingIntegrationTest {
val integration = AnrProfilingIntegration()
integration.register(mockScopes, androidOptions)

assertFalse(AppState.getInstance().lifecycleObserver.listeners.isEmpty())
assertFalse(AppState.getInstance().lifecycleObserver!!.listeners.isEmpty())
assertTrue(SentryIntegrationPackageStorage.getInstance().integrations.contains("AnrProfiling"))

integration.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ class AndroidConnectionStatusProviderTest {
connectionStatusProvider.onBackground()

assertFalse(
AppState.getInstance().lifecycleObserver.listeners.any {
AppState.getInstance().lifecycleObserver!!.listeners.any {
it is SystemEventsBreadcrumbsIntegration
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public UiElement(
}

@Override
public boolean equals(Object o) {
public boolean equals(final @Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UiElement uiElement = (UiElement) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setRenderingSystem(String renderingSystem) {
this.renderingSystem = renderingSystem;
}

public void setType(String type) {
public void setType(final @Nullable String type) {
this.type = type;
}

Expand Down
Loading