Skip to content

Commit 8c920a7

Browse files
authored
Merge 55df841 into 96eeafa
2 parents 96eeafa + 55df841 commit 8c920a7

File tree

6 files changed

+50
-13
lines changed

6 files changed

+50
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
# Unreleased
4+
5+
### Improvements
6+
7+
- Update Android targetSdk to API 36 (Android 16) ([#5016](https://github.com/getsentry/sentry-java/pull/5016))
8+
39
## 8.31.0
410

511
### Features

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ springboot2 = "2.7.18"
3434
springboot3 = "3.5.0"
3535
springboot4 = "4.0.0"
3636
# Android
37-
targetSdk = "34"
38-
compileSdk = "34"
37+
targetSdk = "36"
38+
compileSdk = "36"
3939
minSdk = "21"
4040
spotless = "7.0.4"
4141
gummyBears = "0.12.0"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) {
9898
executeInBackground(() -> captureConfigurationChangedBreadcrumb(now, newConfig));
9999
}
100100

101+
@SuppressWarnings("deprecation")
101102
@Override
102103
public void onLowMemory() {
103104
// we do this in onTrimMemory below already, this is legacy API (14 or below)

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.android.core.internal.util;
22

3+
import android.os.Build;
34
import android.os.Handler;
45
import android.os.Looper;
56
import android.os.Process;
@@ -24,14 +25,32 @@ private AndroidThreadChecker() {
2425
new Handler(Looper.getMainLooper()).post(() -> mainThreadSystemId = Process.myTid());
2526
}
2627

28+
/**
29+
* Gets the thread ID in a way that's compatible across Android versions.
30+
*
31+
* <p>Uses {@link Thread#threadId()} on Android 14 (API 34) and above, and falls back to {@link
32+
* Thread#getId()} on older versions.
33+
*
34+
* @param thread the thread to get the ID for
35+
* @return the thread ID
36+
*/
37+
@SuppressWarnings("deprecation")
38+
public static long getThreadId(final @NotNull Thread thread) {
39+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) {
40+
return thread.threadId();
41+
} else {
42+
return thread.getId();
43+
}
44+
}
45+
2746
@Override
2847
public boolean isMainThread(final long threadId) {
29-
return Looper.getMainLooper().getThread().getId() == threadId;
48+
return getThreadId(Looper.getMainLooper().getThread()) == threadId;
3049
}
3150

3251
@Override
3352
public boolean isMainThread(final @NotNull Thread thread) {
34-
return isMainThread(thread.getId());
53+
return isMainThread(getThreadId(thread));
3554
}
3655

3756
@Override

sentry-android-core/src/main/java/io/sentry/android/core/performance/ActivityLifecycleSpanHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.sentry.SpanDataConvention;
99
import io.sentry.SpanStatus;
1010
import io.sentry.android.core.AndroidDateUtils;
11+
import io.sentry.android.core.internal.util.AndroidThreadChecker;
1112
import java.util.concurrent.TimeUnit;
1213
import org.jetbrains.annotations.ApiStatus;
1314
import org.jetbrains.annotations.NotNull;
@@ -129,7 +130,9 @@ public void clear() {
129130
}
130131

131132
private void setDefaultStartSpanData(final @NotNull ISpan span) {
132-
span.setData(SpanDataConvention.THREAD_ID, Looper.getMainLooper().getThread().getId());
133+
span.setData(
134+
SpanDataConvention.THREAD_ID,
135+
AndroidThreadChecker.getThreadId(Looper.getMainLooper().getThread()));
133136
span.setData(SpanDataConvention.THREAD_NAME, "main");
134137
span.setData(SpanDataConvention.CONTRIBUTES_TTID, true);
135138
span.setData(SpanDataConvention.CONTRIBUTES_TTFD, true);

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/ProfilingActivity.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Bundle
44
import android.view.View
55
import android.widget.SeekBar
66
import android.widget.Toast
7+
import androidx.activity.OnBackPressedCallback
78
import androidx.appcompat.app.AppCompatActivity
89
import androidx.recyclerview.widget.LinearLayoutManager
910
import io.sentry.ITransaction
@@ -24,6 +25,21 @@ class ProfilingActivity : AppCompatActivity() {
2425

2526
override fun onCreate(savedInstanceState: Bundle?) {
2627
super.onCreate(savedInstanceState)
28+
29+
onBackPressedDispatcher.addCallback(
30+
this,
31+
object : OnBackPressedCallback(true) {
32+
override fun handleOnBackPressed() {
33+
if (profileFinished) {
34+
isEnabled = false
35+
onBackPressedDispatcher.onBackPressed()
36+
} else {
37+
Toast.makeText(this@ProfilingActivity, R.string.profiling_running, Toast.LENGTH_SHORT)
38+
.show()
39+
}
40+
}
41+
},
42+
)
2743
binding = ActivityProfilingBinding.inflate(layoutInflater)
2844

2945
binding.profilingDurationSeekbar.setOnSeekBarChangeListener(
@@ -156,14 +172,6 @@ class ProfilingActivity : AppCompatActivity() {
156172
else -> fibonacci(n - 1) + fibonacci(n - 2)
157173
}
158174

159-
override fun onBackPressed() {
160-
if (profileFinished) {
161-
super.onBackPressed()
162-
} else {
163-
Toast.makeText(this, R.string.profiling_running, Toast.LENGTH_SHORT).show()
164-
}
165-
}
166-
167175
private fun getProfileDuration(): Float {
168176
// Minimum duration of the profile is 100 milliseconds
169177
return binding.profilingDurationSeekbar.progress / 10.0F + 0.1F

0 commit comments

Comments
 (0)