Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump min API to 19 #2883

Merged
merged 3 commits into from
Aug 16, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Breaking changes:
Breaking changes:
- Move enableNdk from SentryOptions to SentryAndroidOptions ([#2793](https://github.com/getsentry/sentry-java/pull/2793))
- Fix Coroutine Context Propagation using CopyableThreadContextElement, requires `kotlinx-coroutines-core` version `1.6.1` or higher ([#2838](https://github.com/getsentry/sentry-java/pull/2838))
- Bump min API to 19 ([#2883](https://github.com/getsentry/sentry-java/pull/2883))

## Unreleased

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ object Config {
object Android {
private val sdkVersion = 33

val minSdkVersion = 14
val minSdkVersion = 19
val minSdkVersionOkHttp = 21
val minSdkVersionNdk = 16
val minSdkVersionNdk = 19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minSdkVersionNdk can be removed since its the same now.

val minSdkVersionCompose = 21
val targetSdkVersion = sdkVersion
val compileSdkVersion = sdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static io.sentry.MeasurementUnit.Duration.MILLISECOND;
import static io.sentry.TypeCheckHint.ANDROID_ACTIVITY;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.os.Build;
Expand Down Expand Up @@ -396,15 +395,13 @@ public synchronized void onActivityStarted(final @NotNull Activity activity) {
addBreadcrumb(activity, "started");
}

@SuppressLint("NewApi")
@Override
public synchronized void onActivityResumed(final @NotNull Activity activity) {
if (performanceEnabled) {
final @Nullable ISpan ttidSpan = ttidSpanMap.get(activity);
final @Nullable ISpan ttfdSpan = ttfdSpanMap.get(activity);
final View rootView = activity.findViewById(android.R.id.content);
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN
&& rootView != null) {
if (rootView != null) {
FirstDrawDoneListener.registerForNextDraw(
rootView, () -> onFirstFrameDrawn(ttfdSpan, ttidSpan), buildInfoProvider);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import io.sentry.DeduplicateMultithreadedEventProcessor;
import io.sentry.DefaultTransactionPerformanceCollector;
import io.sentry.ILogger;
Expand Down Expand Up @@ -213,10 +212,7 @@ static void installDefaultIntegrations(

// Integrations are registered in the same order. NDK before adding Watch outbox,
// because sentry-native move files around and we don't want to watch that.
final Class<?> sentryNdkClass =
isNdkAvailable(buildInfoProvider)
? loadClass.loadClass(SENTRY_NDK_CLASS_NAME, options.getLogger())
: null;
final Class<?> sentryNdkClass = loadClass.loadClass(SENTRY_NDK_CLASS_NAME, options.getLogger());
options.addIntegration(new NdkIntegration(sentryNdkClass));

// this integration uses android.os.FileObserver, we can't move to sentry
Expand Down Expand Up @@ -325,8 +321,4 @@ private static void initializeCacheDirs(
final File cacheDir = new File(context.getCacheDir(), "sentry");
options.setCacheDirPath(cacheDir.getAbsolutePath());
}

private static boolean isNdkAvailable(final @NotNull BuildInfoProvider buildInfoProvider) {
return buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private void setDevice(final @NotNull SentryBaseEvent event) {
private @NotNull Device getDevice() {
Device device = new Device();
if (options.isSendDefaultPii()) {
device.setName(ContextUtils.getDeviceName(context, buildInfoProvider));
device.setName(ContextUtils.getDeviceName(context));
}
device.setManufacturer(Build.MANUFACTURER);
device.setBrand(Build.BRAND);
Expand Down Expand Up @@ -566,13 +566,8 @@ private void setDevice(final @NotNull SentryBaseEvent event) {
return device;
}

@SuppressLint("NewApi")
private @NotNull Long getMemorySize(final @NotNull ActivityManager.MemoryInfo memInfo) {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN) {
return memInfo.totalMem;
}
// using Runtime as a fallback
return java.lang.Runtime.getRuntime().totalMemory(); // JVM in bytes too
return memInfo.totalMem;
}

private void mergeOS(final @NotNull SentryBaseEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,8 @@ static boolean isForegroundImportance(final @NotNull Context context) {
}
}

@SuppressLint("NewApi") // we're wrapping into if-check with sdk version
static @Nullable String getDeviceName(
final @NotNull Context context, final @NotNull BuildInfoProvider buildInfoProvider) {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.Global.getString(context.getContentResolver(), "device_name");
} else {
return null;
}
static @Nullable String getDeviceName(final @NotNull Context context) {
return Settings.Global.getString(context.getContentResolver(), "device_name");
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -346,8 +340,6 @@ static boolean isForegroundImportance(final @NotNull Context context) {
}
}

// we perform an if-check for that, but lint fails to recognize
@SuppressLint("NewApi")
static void setAppPackageInfo(
final @NotNull PackageInfo packageInfo,
final @NotNull BuildInfoProvider buildInfoProvider,
Expand All @@ -356,26 +348,24 @@ static void setAppPackageInfo(
app.setAppVersion(packageInfo.versionName);
app.setAppBuild(ContextUtils.getVersionCode(packageInfo, buildInfoProvider));

if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN) {
final Map<String, String> permissions = new HashMap<>();
final String[] requestedPermissions = packageInfo.requestedPermissions;
final int[] requestedPermissionsFlags = packageInfo.requestedPermissionsFlags;

if (requestedPermissions != null
&& requestedPermissions.length > 0
&& requestedPermissionsFlags != null
&& requestedPermissionsFlags.length > 0) {
for (int i = 0; i < requestedPermissions.length; i++) {
String permission = requestedPermissions[i];
permission = permission.substring(permission.lastIndexOf('.') + 1);

final boolean granted =
(requestedPermissionsFlags[i] & REQUESTED_PERMISSION_GRANTED)
== REQUESTED_PERMISSION_GRANTED;
permissions.put(permission, granted ? "granted" : "not_granted");
}
final Map<String, String> permissions = new HashMap<>();
final String[] requestedPermissions = packageInfo.requestedPermissions;
final int[] requestedPermissionsFlags = packageInfo.requestedPermissionsFlags;

if (requestedPermissions != null
&& requestedPermissions.length > 0
&& requestedPermissionsFlags != null
&& requestedPermissionsFlags.length > 0) {
for (int i = 0; i < requestedPermissions.length; i++) {
String permission = requestedPermissions[i];
permission = permission.substring(permission.lastIndexOf('.') + 1);

final boolean granted =
(requestedPermissionsFlags[i] & REQUESTED_PERMISSION_GRANTED)
== REQUESTED_PERMISSION_GRANTED;
permissions.put(permission, granted ? "granted" : "not_granted");
}
app.setPermissions(permissions);
}
app.setPermissions(permissions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Device collectDeviceInformation(
final @NotNull Device device = new Device();

if (options.isSendDefaultPii()) {
device.setName(ContextUtils.getDeviceName(context, buildInfoProvider));
device.setName(ContextUtils.getDeviceName(context));
}
device.setManufacturer(Build.MANUFACTURER);
device.setBrand(Build.BRAND);
Expand Down Expand Up @@ -196,7 +196,7 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null) {
// in bytes
device.setMemorySize(getMemorySize(memInfo));
device.setMemorySize(memInfo.totalMem);
if (includeDynamicData) {
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
Expand Down Expand Up @@ -338,16 +338,6 @@ private Device.DeviceOrientation getOrientation() {
return deviceOrientation;
}

@SuppressWarnings({"ObsoleteSdkInt", "NewApi"})
@NotNull
private Long getMemorySize(final @NotNull ActivityManager.MemoryInfo memInfo) {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN) {
return memInfo.totalMem;
}
// using Runtime as a fallback
return java.lang.Runtime.getRuntime().totalMemory(); // JVM in bytes too
}

/**
* Get the total amount of internal storage, in bytes.
*
Expand All @@ -356,54 +346,15 @@ private Long getMemorySize(final @NotNull ActivityManager.MemoryInfo memInfo) {
@Nullable
private Long getTotalInternalStorage(final @NotNull StatFs stat) {
try {
long blockSize = getBlockSizeLong(stat);
long totalBlocks = getBlockCountLong(stat);
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
return totalBlocks * blockSize;
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error getting total internal storage amount.", e);
return null;
}
}

@SuppressWarnings({"ObsoleteSdkInt", "NewApi"})
private long getBlockSizeLong(final @NotNull StatFs stat) {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return stat.getBlockSizeLong();
}
return getBlockSizeDep(stat);
}

@SuppressWarnings({"deprecation"})
private int getBlockSizeDep(final @NotNull StatFs stat) {
return stat.getBlockSize();
}

@SuppressWarnings({"ObsoleteSdkInt", "NewApi"})
private long getBlockCountLong(final @NotNull StatFs stat) {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return stat.getBlockCountLong();
}
return getBlockCountDep(stat);
}

@SuppressWarnings({"deprecation"})
private int getBlockCountDep(final @NotNull StatFs stat) {
return stat.getBlockCount();
}

@SuppressWarnings({"ObsoleteSdkInt", "NewApi"})
private long getAvailableBlocksLong(final @NotNull StatFs stat) {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return stat.getAvailableBlocksLong();
}
return getAvailableBlocksDep(stat);
}

@SuppressWarnings({"deprecation"})
private int getAvailableBlocksDep(final @NotNull StatFs stat) {
return stat.getAvailableBlocks();
}

/**
* Get the unused amount of internal storage, in bytes.
*
Expand All @@ -412,8 +363,8 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
@Nullable
private Long getUnusedInternalStorage(final @NotNull StatFs stat) {
try {
long blockSize = getBlockSizeLong(stat);
long availableBlocks = getAvailableBlocksLong(stat);
long blockSize = stat.getBlockSizeLong();
long availableBlocks = stat.getAvailableBlocksLong();
return availableBlocks * blockSize;
} catch (Throwable e) {
options
Expand All @@ -437,23 +388,9 @@ private StatFs getExternalStorageStat(final @Nullable File internalStorage) {
return null;
}

@SuppressWarnings({"ObsoleteSdkInt", "NewApi"})
@Nullable
private File[] getExternalFilesDirs() {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.KITKAT) {
return context.getExternalFilesDirs(null);
} else {
File single = context.getExternalFilesDir(null);
if (single != null) {
return new File[] {single};
}
}
return null;
}

@Nullable
private File getExternalStorageDep(final @Nullable File internalStorage) {
final @Nullable File[] externalFilesDirs = getExternalFilesDirs();
final @Nullable File[] externalFilesDirs = context.getExternalFilesDirs(null);

if (externalFilesDirs != null) {
// return the 1st file which is not the emulated internal storage
Expand Down Expand Up @@ -490,8 +427,8 @@ private File getExternalStorageDep(final @Nullable File internalStorage) {
@Nullable
private Long getTotalExternalStorage(final @NotNull StatFs stat) {
try {
final long blockSize = getBlockSizeLong(stat);
final long totalBlocks = getBlockCountLong(stat);
final long blockSize = stat.getBlockSizeLong();
final long totalBlocks = stat.getBlockCountLong();
return totalBlocks * blockSize;
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error getting total external storage amount.", e);
Expand All @@ -515,8 +452,8 @@ private boolean isExternalStorageMounted() {
@Nullable
private Long getUnusedExternalStorage(final @NotNull StatFs stat) {
try {
final long blockSize = getBlockSizeLong(stat);
final long availableBlocks = getAvailableBlocksLong(stat);
final long blockSize = stat.getBlockSizeLong();
final long availableBlocks = stat.getAvailableBlocksLong();
return availableBlocks * blockSize;
} catch (Throwable e) {
options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.content.Context;
import android.content.pm.ProviderInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
Expand Down Expand Up @@ -126,8 +125,7 @@ public void onActivityResumed(@NotNull Activity activity) {
// sets App start as finished when the very first activity calls onResume
firstActivityResumed = true;
final View rootView = activity.findViewById(android.R.id.content);
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN
&& rootView != null) {
if (rootView != null) {
FirstDrawDoneListener.registerForNextDraw(
rootView, () -> AppStartState.getInstance().setAppStartEnd(), buildInfoProvider);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.sentry.android.core.internal.util;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.view.ViewTreeObserver;
import androidx.annotation.RequiresApi;
import io.sentry.android.core.BuildInfoProvider;
import java.util.concurrent.atomic.AtomicReference;
import org.jetbrains.annotations.NotNull;
Expand All @@ -19,8 +17,6 @@
* href="https://github.com/firebase/firebase-android-sdk/blob/master/firebase-perf/src/main/java/com/google/firebase/perf/util/FirstDrawDoneListener.java">Firebase</a>
* under the Apache License, Version 2.0.
*/
@SuppressLint("ObsoleteSdkInt")
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public class FirstDrawDoneListener implements ViewTreeObserver.OnDrawListener {
private final @NotNull Handler mainThreadHandler = new Handler(Looper.getMainLooper());
private final @NotNull AtomicReference<View> viewReference;
Expand All @@ -35,8 +31,8 @@ public static void registerForNextDraw(
// Handle bug prior to API 26 where OnDrawListener from the floating ViewTreeObserver is not
// merged into the real ViewTreeObserver.
// https://android.googlesource.com/platform/frameworks/base/+/9f8ec54244a5e0343b9748db3329733f259604f3
if (buildInfoProvider.getSdkInfoVersion() < 26
&& !isAliveAndAttached(view, buildInfoProvider)) {
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.O
&& !isAliveAndAttached(view)) {
view.addOnAttachStateChangeListener(
new View.OnAttachStateChangeListener() {
@Override
Expand Down Expand Up @@ -83,17 +79,7 @@ public void onDraw() {
* @return true if the View is already attached and the ViewTreeObserver is not a floating
* placeholder.
*/
private static boolean isAliveAndAttached(
final @NotNull View view, final @NotNull BuildInfoProvider buildInfoProvider) {
return view.getViewTreeObserver().isAlive() && isAttachedToWindow(view, buildInfoProvider);
}

@SuppressLint("NewApi")
private static boolean isAttachedToWindow(
final @NotNull View view, final @NotNull BuildInfoProvider buildInfoProvider) {
if (buildInfoProvider.getSdkInfoVersion() >= 19) {
return view.isAttachedToWindow();
}
return view.getWindowToken() != null;
private static boolean isAliveAndAttached(final @NotNull View view) {
return view.getViewTreeObserver().isAlive() && view.isAttachedToWindow();
}
}
Loading