Skip to content
Open
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
2 changes: 0 additions & 2 deletions sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ android {
lint {
warningsAsErrors = true
checkDependencies = true
// TODO: Re-enable once the SDK_INT checks made obsolete by minSdk 24 are removed.
disable += "ObsoleteSdkInt"

// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
checkReleaseBuilds = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static io.sentry.IConnectionStatusProvider.ConnectionStatus.DISCONNECTED;
import static java.util.concurrent.TimeUnit.SECONDS;

import android.os.Build;
import io.sentry.CompositePerformanceCollector;
import io.sentry.DataCategory;
import io.sentry.IContinuousProfiler;
Expand Down Expand Up @@ -176,10 +175,6 @@ private void initScopes() {
private void start() {
initScopes();

// Debug.startMethodTracingSampling() is only available since Lollipop, but Android Profiler
// causes crashes on api 21 -> https://github.com/getsentry/sentry-java/issues/3392
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP_MR1) return;

// Let's initialize trace folder and profiling interval
init();
// init() didn't create profiler, should never happen
Expand Down Expand Up @@ -281,12 +276,6 @@ private void stop(final boolean restartProfiler) {
return;
}

// onTransactionStart() is only available since Lollipop_MR1
// and SystemClock.elapsedRealtimeNanos() since Jelly Bean
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP_MR1) {
return;
}

List<PerformanceCollectionData> performanceCollectionData = null;
if (performanceCollector != null) {
performanceCollectionData = performanceCollector.stop(chunkId.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ private void init() {

@Override
public void start() {
// Debug.startMethodTracingSampling() is only available since Lollipop, but Android Profiler
// causes crashes on api 21 -> https://github.com/getsentry/sentry-java/issues/3392
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP_MR1) return;

// When the first transaction is starting, we can start profiling
if (!isRunning.getAndSet(true)) {
// Let's initialize trace folder and profiling interval
Expand Down Expand Up @@ -234,11 +230,6 @@ public void bindTransaction(final @NotNull ITransaction transaction) {
final @Nullable List<PerformanceCollectionData> performanceCollectionData,
final @NotNull SentryOptions options) {

// onTransactionStart() is only available since Lollipop_MR1
// and SystemClock.elapsedRealtimeNanos() since Jelly Bean
// and SUPPORTED_ABIS since KITKAT
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP_MR1) return null;

// check if profiler was created
if (profiler == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions

if (androidOptions.isEnableNetworkEventBreadcrumbs()) {

// The specific error is logged in the ConnectivityChecker method
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.N) {
options.getLogger().log(SentryLevel.DEBUG, "NetworkCallbacks need Android N+.");
return;
}

try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
networkCallback =
new NetworkBreadcrumbsNetworkCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ public static void init(
// if SentryPerformanceProvider was disabled or removed,
// we set the app start / sdk init time here instead
final @NotNull AppStartMetrics appStartMetrics = AppStartMetrics.getInstance();
if (buildInfoProvider.getSdkInfoVersion() >= android.os.Build.VERSION_CODES.N) {
final @NotNull TimeSpan appStartTimeSpan = appStartMetrics.getAppStartTimeSpan();
if (appStartTimeSpan.hasNotStarted()) {
appStartTimeSpan.setStartedAt(Process.getStartUptimeMillis());
}
final @NotNull TimeSpan appStartTimeSpan = appStartMetrics.getAppStartTimeSpan();
if (appStartTimeSpan.hasNotStarted()) {
appStartTimeSpan.setStartedAt(Process.getStartUptimeMillis());
}
if (context.getApplicationContext() instanceof Application) {
appStartMetrics.registerLifecycleCallbacks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,8 @@ private void onAppLaunched(
final @NotNull TimeSpan sdkInitTimeSpan = appStartMetrics.getSdkInitTimeSpan();
sdkInitTimeSpan.setStartedAt(sdkInitMillis);

// performance v2: Uses Process.getStartUptimeMillis()
// requires API level 24+
if (buildInfoProvider.getSdkInfoVersion() >= android.os.Build.VERSION_CODES.N) {
final @NotNull TimeSpan appStartTimespan = appStartMetrics.getAppStartTimeSpan();
appStartTimespan.setStartedAt(Process.getStartUptimeMillis());
}
final @NotNull TimeSpan appStartTimespan = appStartMetrics.getAppStartTimeSpan();
appStartTimespan.setStartedAt(Process.getStartUptimeMillis());

if (context instanceof Application) {
app = (Application) context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ public AndroidConnectionStatusProvider(
new CellularNetworkTechnologyProvider(this.context, options.getLogger(), buildInfoProvider);

capabilities[0] = NetworkCapabilities.NET_CAPABILITY_INTERNET;
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.M) {
capabilities[1] = NetworkCapabilities.NET_CAPABILITY_VALIDATED;
}
capabilities[1] = NetworkCapabilities.NET_CAPABILITY_VALIDATED;

// Register network callback immediately for caching
//noinspection Convert2MethodRef
Expand All @@ -123,13 +121,9 @@ private boolean isNetworkEffectivelyConnected(
}

// Check for general internet capability AND validated status
boolean hasInternetAndValidated =
networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.M) {
hasInternetAndValidated =
hasInternetAndValidated
&& networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
}
final boolean hasInternetAndValidated =
networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
&& networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);

if (!hasInternetAndValidated) {
return false;
Expand Down Expand Up @@ -393,12 +387,6 @@ private void updateCache(@Nullable NetworkCapabilities networkCapabilities) {
return;
}

if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.M) {
cachedNetworkCapabilities = null;
cacheFreshUntil = Deadline.after(ticker, CACHE_TTL_MINUTES, TimeUnit.MINUTES);
return;
}

// Fallback: query current active network
final ConnectivityManager connectivityManager =
getConnectivityManager(context, options.getLogger());
Expand Down Expand Up @@ -630,65 +618,25 @@ public NetworkCapabilities getCachedNetworkCapabilities() {
boolean wifi = false;
boolean cellular = false;

if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.M) {

final Network activeNetwork = connectivityManager.getActiveNetwork();
if (activeNetwork == null) {
logger.log(SentryLevel.INFO, "Network is null and cannot check network status");
return null;
}
final NetworkCapabilities networkCapabilities =
connectivityManager.getNetworkCapabilities(activeNetwork);
if (networkCapabilities == null) {
logger.log(SentryLevel.INFO, "NetworkCapabilities is null and cannot check network type");
return null;
}
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
ethernet = true;
}
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
wifi = true;
}
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
cellular = true;
}
} else {
// ideally using connectivityManager.getAllNetworks(), but its >= Android L only

// for some reason linting didn't allow a single @SuppressWarnings("deprecation") on method
// signature
@SuppressWarnings("deprecation")
final android.net.NetworkInfo activeNetworkInfo =
connectivityManager.getActiveNetworkInfo();

if (activeNetworkInfo == null) {
logger.log(SentryLevel.INFO, "NetworkInfo is null, there's no active network.");
return null;
}

@SuppressWarnings("deprecation")
final int type = activeNetworkInfo.getType();

@SuppressWarnings("deprecation")
final int TYPE_ETHERNET = ConnectivityManager.TYPE_ETHERNET;

@SuppressWarnings("deprecation")
final int TYPE_WIFI = ConnectivityManager.TYPE_WIFI;

@SuppressWarnings("deprecation")
final int TYPE_MOBILE = ConnectivityManager.TYPE_MOBILE;

switch (type) {
case TYPE_ETHERNET:
ethernet = true;
break;
case TYPE_WIFI:
wifi = true;
break;
case TYPE_MOBILE:
cellular = true;
break;
}
final Network activeNetwork = connectivityManager.getActiveNetwork();
if (activeNetwork == null) {
logger.log(SentryLevel.INFO, "Network is null and cannot check network status");
return null;
}
final NetworkCapabilities networkCapabilities =
connectivityManager.getNetworkCapabilities(activeNetwork);
if (networkCapabilities == null) {
logger.log(SentryLevel.INFO, "NetworkCapabilities is null and cannot check network type");
return null;
}
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
ethernet = true;
}
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
wifi = true;
}
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
cellular = true;
}

// TODO: change the protocol to be a list of transports as a device may have the capability of
Expand Down Expand Up @@ -758,11 +706,6 @@ public static boolean addNetworkCallback(
final @NotNull ILogger logger,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull NetworkCallback networkCallback) {
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.N) {
logger.log(SentryLevel.DEBUG, "NetworkCallbacks need Android N+.");
return false;
}

if (!Permissions.hasPermission(context, Manifest.permission.ACCESS_NETWORK_STATE)) {
logger.log(SentryLevel.INFO, "No permission (ACCESS_NETWORK_STATE) to check network status.");
return false;
Expand All @@ -787,10 +730,6 @@ static boolean registerNetworkCallback(
final @NotNull BuildInfoProvider buildInfoProvider,
final @Nullable Handler handler,
final @NotNull NetworkCallback networkCallback) {
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.N) {
logger.log(SentryLevel.DEBUG, "NetworkCallbacks need Android N+.");
return false;
}
final ConnectivityManager connectivityManager = getConnectivityManager(context, logger);
if (connectivityManager == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ public void unregister() {

@SuppressLint({"MissingPermission", "InlinedApi", "NewApi"})
private @Nullable String getDataNetworkTechnology() {
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.N) {
// getDataNetworkType was added in API 24.
return null;
}
// The SDK doesn't declare these permissions, so the technology is only available to apps that
// already request one of them. READ_BASIC_PHONE_STATE only exists from API 31 on, where the
// display info listener is used instead, but checking it is harmless.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.view.Choreographer;
import android.view.FrameMetrics;
import android.view.Window;
import androidx.annotation.RequiresApi;
import io.sentry.ILogger;
import io.sentry.ISentryLifecycleToken;
import io.sentry.SentryLevel;
Expand Down Expand Up @@ -110,10 +109,6 @@ public SentryFrameMetricsCollector(
if (!(appContext instanceof Application)) {
return;
}
// FrameMetrics api is only available since sdk version N
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.N) {
return;
}
isAvailable = true;

// The frame metrics HandlerThread is started lazily on the first startCollection() call.
Expand Down Expand Up @@ -240,7 +235,6 @@ private long getFrameStartTimestamp(final @NotNull FrameMetrics frameMetrics) {
* Return time spent on the main thread (cpu) for frame creation. It doesn't consider time spent
* on the render thread (gpu).
*/
@RequiresApi(api = Build.VERSION_CODES.N)
private long getFrameCpuDuration(final @NotNull FrameMetrics frameMetrics) {
// Inspired by JankStats
// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:metrics/metrics-performance/src/main/java/androidx/metrics/performance/JankStatsApi24Impl.kt;l=74-79;drc=1de6215c6bd9e887e3d94556e9ac55cfb7b8c797
Expand Down Expand Up @@ -512,7 +506,6 @@ void onFrameMetricCollected(

@ApiStatus.Internal
public interface WindowFrameMetricsManager {
@RequiresApi(api = Build.VERSION_CODES.N)
default void addOnFrameMetricsAvailableListener(
final @NotNull Window window,
final @Nullable Window.OnFrameMetricsAvailableListener frameMetricsAvailableListener,
Expand All @@ -523,7 +516,6 @@ default void addOnFrameMetricsAvailableListener(
window.addOnFrameMetricsAvailableListener(frameMetricsAvailableListener, handler);
}

@RequiresApi(api = Build.VERSION_CODES.N)
default void removeOnFrameMetricsAvailableListener(
final @NotNull Window window,
final @Nullable Window.OnFrameMetricsAvailableListener frameMetricsAvailableListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,28 +550,15 @@ private void scheduleHeadlessAppStartCheckOnMain() {
if (!headlessAppStartCheckPending.compareAndSet(false, true)) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Looper.getMainLooper()
.getQueue()
.addIdleHandler(
() -> {
firstIdle = SystemClock.uptimeMillis();
headlessAppStartCheckPending.set(false);
handleHeadlessAppStartIfNeededOnMain();
return false;
});
} else {
final Handler handler = new Handler(Looper.getMainLooper());
handler.post(
() -> {
firstIdle = SystemClock.uptimeMillis();
handler.post(
() -> {
headlessAppStartCheckPending.set(false);
handleHeadlessAppStartIfNeededOnMain();
});
});
}
Looper.getMainLooper()
.getQueue()
.addIdleHandler(
() -> {
firstIdle = SystemClock.uptimeMillis();
headlessAppStartCheckPending.set(false);
handleHeadlessAppStartIfNeededOnMain();
return false;
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,6 @@ class AndroidContinuousProfilerTest {
assertEquals(0, profiler.rootSpanCounter)
}

@Test
fun `profiler works only on api 22+`() {
val buildInfo =
mock<BuildInfoProvider> {
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.LOLLIPOP)
}
val profiler = fixture.getSut(buildInfo)
profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
assertFalse(profiler.isRunning)
}

@Test
fun `profiler evaluates profilingTracesDirPath options only on first start`() {
val profiler = fixture.getSut { it.cacheDirPath = null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,6 @@ class AndroidTransactionProfilerTest {
assertEquals(profilingTraceData.transactionId, fixture.transaction1.eventId.toString())
}

@Test
fun `profiler works only on api 22+`() {
val buildInfo =
mock<BuildInfoProvider> {
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.LOLLIPOP)
}
val profiler = fixture.getSut(context, buildInfo)
profiler.start()
assertFalse(profiler.isRunning)
}

@Test
fun `profiler on profilesSampleRate=0 false`() {
fixture.options.apply { profilesSampleRate = 0.0 }
Expand Down
Loading
Loading