Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

### Improvements

- Update Android targetSdk to API 36 (Android 16) ([#5016](https://github.com/getsentry/sentry-java/pull/5016))
- Expose `MAX_EVENT_SIZE_BYTES` constant in SentryOptions ([#4962](https://github.com/getsentry/sentry-java/pull/4962))
- Discard envelopes on `4xx` and `5xx` response ([#4950](https://github.com/getsentry/sentry-java/pull/4950))
- This aims to not overwhelm Sentry after an outage or load shedding (including HTTP 429) where too many events are sent at once
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ springboot2 = "2.7.18"
springboot3 = "3.5.0"
springboot4 = "4.0.0"
# Android
targetSdk = "34"
compileSdk = "34"
targetSdk = "36"
compileSdk = "36"
minSdk = "21"
spotless = "7.0.4"
gummyBears = "0.12.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) {
executeInBackground(() -> captureConfigurationChangedBreadcrumb(now, newConfig));
}

@SuppressWarnings("deprecation")
@Override
public void onLowMemory() {
// we do this in onTrimMemory below already, this is legacy API (14 or below)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.android.core.internal.util;

import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
Expand All @@ -24,14 +25,32 @@ private AndroidThreadChecker() {
new Handler(Looper.getMainLooper()).post(() -> mainThreadSystemId = Process.myTid());
}

/**
* Gets the thread ID in a way that's compatible across Android versions.
*
* <p>Uses {@link Thread#threadId()} on Android 14 (API 34) and above, and falls back to {@link
* Thread#getId()} on older versions.
*
* @param thread the thread to get the ID for
* @return the thread ID
*/
@SuppressWarnings("deprecation")
public static long getThreadId(final @NotNull Thread thread) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) {
return thread.threadId();
} else {
return thread.getId();
}
}

@Override
public boolean isMainThread(final long threadId) {
return Looper.getMainLooper().getThread().getId() == threadId;
return getThreadId(Looper.getMainLooper().getThread()) == threadId;
}

@Override
public boolean isMainThread(final @NotNull Thread thread) {
return isMainThread(thread.getId());
return isMainThread(getThreadId(thread));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.sentry.SpanDataConvention;
import io.sentry.SpanStatus;
import io.sentry.android.core.AndroidDateUtils;
import io.sentry.android.core.internal.util.AndroidThreadChecker;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -129,7 +130,9 @@ public void clear() {
}

private void setDefaultStartSpanData(final @NotNull ISpan span) {
span.setData(SpanDataConvention.THREAD_ID, Looper.getMainLooper().getThread().getId());
span.setData(
SpanDataConvention.THREAD_ID,
AndroidThreadChecker.getThreadId(Looper.getMainLooper().getThread()));
span.setData(SpanDataConvention.THREAD_NAME, "main");
span.setData(SpanDataConvention.CONTRIBUTES_TTID, true);
span.setData(SpanDataConvention.CONTRIBUTES_TTFD, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.View
import android.widget.SeekBar
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import io.sentry.ITransaction
Expand All @@ -24,6 +25,21 @@ class ProfilingActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (profileFinished) {
isEnabled = false
onBackPressedDispatcher.onBackPressed()
} else {
Toast.makeText(this@ProfilingActivity, R.string.profiling_running, Toast.LENGTH_SHORT)
.show()
}
}
},
)
binding = ActivityProfilingBinding.inflate(layoutInflater)

binding.profilingDurationSeekbar.setOnSeekBarChangeListener(
Expand Down Expand Up @@ -156,14 +172,6 @@ class ProfilingActivity : AppCompatActivity() {
else -> fibonacci(n - 1) + fibonacci(n - 2)
}

override fun onBackPressed() {
if (profileFinished) {
super.onBackPressed()
} else {
Toast.makeText(this, R.string.profiling_running, Toast.LENGTH_SHORT).show()
}
}

private fun getProfileDuration(): Float {
// Minimum duration of the profile is 100 milliseconds
return binding.profilingDurationSeekbar.progress / 10.0F + 0.1F
Expand Down
Loading