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

Allow opting out of device info collection that requires Inter-Process Communication (IPC) #2100

Merged
merged 6 commits into from
Jun 17, 2022
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 @@ -5,6 +5,7 @@
### Features

- Replace `tracestate` header with `baggage` header ([#2078](https://github.com/getsentry/sentry-java/pull/2078))
- Allow opting out of device info collection that requires Inter-Process Communication (IPC) ([#2100](https://github.com/getsentry/sentry-java/pull/2100))

## 6.1.0

Expand Down
2 changes: 2 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun isAnrEnabled ()Z
public fun isAnrReportInDebug ()Z
public fun isAttachScreenshot ()Z
public fun isCollectAdditionalContext ()Z
public fun isEnableActivityLifecycleBreadcrumbs ()Z
public fun isEnableActivityLifecycleTracingAutoFinish ()Z
public fun isEnableAppComponentBreadcrumbs ()Z
Expand All @@ -141,6 +142,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun setAnrReportInDebug (Z)V
public fun setAnrTimeoutIntervalMillis (J)V
public fun setAttachScreenshot (Z)V
public fun setCollectAdditionalContext (Z)V
public fun setDebugImagesLoader (Lio/sentry/android/core/IDebugImagesLoader;)V
public fun setEnableActivityLifecycleBreadcrumbs (Z)V
public fun setEnableActivityLifecycleTracingAutoFinish (Z)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ static void init(

readDefaultOptionValues(options, context);

options.addEventProcessor(new DefaultAndroidEventProcessor(context, logger, buildInfoProvider));
options.addEventProcessor(
new DefaultAndroidEventProcessor(context, buildInfoProvider, options));
options.addEventProcessor(new PerformanceAndroidEventProcessor(options, activityFramesTracker));

options.setTransportGate(new AndroidTransportGate(context, options.getLogger()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.sentry.DateUtils;
import io.sentry.EventProcessor;
import io.sentry.Hint;
import io.sentry.ILogger;
import io.sentry.SentryBaseEvent;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
Expand Down Expand Up @@ -69,26 +68,29 @@ final class DefaultAndroidEventProcessor implements EventProcessor {

private final @NotNull BuildInfoProvider buildInfoProvider;
private final @NotNull RootChecker rootChecker;

private final @NotNull ILogger logger;
private final @NotNull SentryAndroidOptions options;

public DefaultAndroidEventProcessor(
final @NotNull Context context,
final @NotNull ILogger logger,
final @NotNull BuildInfoProvider buildInfoProvider) {
this(context, logger, buildInfoProvider, new RootChecker(context, buildInfoProvider, logger));
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull SentryAndroidOptions options) {
this(
context,
buildInfoProvider,
new RootChecker(context, buildInfoProvider, options.getLogger()),
options);
}

DefaultAndroidEventProcessor(
final @NotNull Context context,
final @NotNull ILogger logger,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull RootChecker rootChecker) {
final @NotNull RootChecker rootChecker,
final @NotNull SentryAndroidOptions options) {
this.context = Objects.requireNonNull(context, "The application context is required.");
this.logger = Objects.requireNonNull(logger, "The Logger is required.");
this.buildInfoProvider =
Objects.requireNonNull(buildInfoProvider, "The BuildInfoProvider is required.");
this.rootChecker = Objects.requireNonNull(rootChecker, "The RootChecker is required.");
this.options = Objects.requireNonNull(options, "The options object is required.");

ExecutorService executorService = Executors.newSingleThreadExecutor();
// dont ref. to method reference, theres a bug on it
Expand Down Expand Up @@ -149,10 +151,12 @@ private boolean shouldApplyScopeData(
if (HintUtils.shouldApplyScopeData(hint)) {
return true;
} else {
logger.log(
SentryLevel.DEBUG,
"Event was cached so not applying data relevant to the current app execution/version: %s",
event.getEventId());
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was cached so not applying data relevant to the current app execution/version: %s",
event.getEventId());
return false;
}
}
Expand Down Expand Up @@ -220,7 +224,7 @@ private void setThreads(final @NotNull SentryEvent event) {

private void setPackageInfo(final @NotNull SentryBaseEvent event, final @NotNull App app) {
final PackageInfo packageInfo =
ContextUtils.getPackageInfo(context, PackageManager.GET_PERMISSIONS, logger);
ContextUtils.getPackageInfo(context, PackageManager.GET_PERMISSIONS, options.getLogger());
if (packageInfo != null) {
String versionCode = ContextUtils.getVersionCode(packageInfo);

Expand Down Expand Up @@ -287,7 +291,9 @@ private void setArchitectures(final @NotNull Device device) {

// setting such values require IO hence we don't run for transactions
if (errorEvent) {
setDeviceIO(device, applyScopeData);
if (options.isCollectAdditionalContext()) {
setDeviceIO(device, applyScopeData);
}
}

device.setOrientation(getOrientation());
Expand All @@ -298,7 +304,7 @@ private void setArchitectures(final @NotNull Device device) {
device.setSimulator((Boolean) emulator);
}
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting emulator.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting emulator.", e);
}

DisplayMetrics displayMetrics = getDisplayMetrics();
Expand Down Expand Up @@ -336,7 +342,7 @@ private void setDeviceIO(final @NotNull Device device, final boolean applyScopeD
}

Boolean connected;
switch (ConnectivityChecker.getConnectionStatus(context, logger)) {
switch (ConnectivityChecker.getConnectionStatus(context, options.getLogger())) {
case NOT_CONNECTED:
connected = false;
break;
Expand All @@ -361,7 +367,8 @@ private void setDeviceIO(final @NotNull Device device, final boolean applyScopeD
}

// this way of getting the size of storage might be problematic for storages bigger than 2GB
// check the use of https://developer.android.com/reference/java/io/File.html#getFreeSpace%28%29
// check the use of
// https://developer.android.com/reference/java/io/File.html#getFreeSpace%28%29
final File internalStorageFile = context.getExternalFilesDir(null);
if (internalStorageFile != null) {
StatFs internalStorageStat = new StatFs(internalStorageFile.getPath());
Expand All @@ -378,7 +385,7 @@ private void setDeviceIO(final @NotNull Device device, final boolean applyScopeD
if (device.getConnectionType() == null) {
// wifi, ethernet or cellular, null if none
device.setConnectionType(
ConnectivityChecker.getConnectionType(context, logger, buildInfoProvider));
ConnectivityChecker.getConnectionType(context, options.getLogger(), buildInfoProvider));
}
}

Expand Down Expand Up @@ -409,7 +416,7 @@ private TimeZone getTimeZone() {
// currentTimeMillis returns UTC already
return DateUtils.getDateTime(System.currentTimeMillis() - SystemClock.elapsedRealtime());
} catch (IllegalArgumentException e) {
logger.log(SentryLevel.ERROR, e, "Error getting the device's boot time.");
options.getLogger().log(SentryLevel.ERROR, e, "Error getting the device's boot time.");
}
return null;
}
Expand All @@ -427,10 +434,10 @@ private TimeZone getTimeZone() {
actManager.getMemoryInfo(memInfo);
return memInfo;
}
logger.log(SentryLevel.INFO, "Error getting MemoryInfo.");
options.getLogger().log(SentryLevel.INFO, "Error getting MemoryInfo.");
return null;
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting MemoryInfo.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting MemoryInfo.", e);
return null;
}
}
Expand All @@ -449,7 +456,7 @@ private TimeZone getTimeZone() {
try {
return Build.MODEL.split(" ", -1)[0];
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting device family.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting device family.", e);
return null;
}
}
Expand All @@ -472,7 +479,7 @@ private TimeZone getTimeZone() {

return ((float) level / (float) scale) * percentMultiplier;
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting device battery level.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting device battery level.", e);
return null;
}
}
Expand All @@ -488,7 +495,7 @@ private TimeZone getTimeZone() {
return plugged == BatteryManager.BATTERY_PLUGGED_AC
|| plugged == BatteryManager.BATTERY_PLUGGED_USB;
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting device charging state.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting device charging state.", e);
return null;
}
}
Expand All @@ -500,7 +507,7 @@ private TimeZone getTimeZone() {
return ((float) temperature) / 10; // celsius
}
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting battery temperature.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting battery temperature.", e);
}
return null;
}
Expand All @@ -517,13 +524,15 @@ private TimeZone getTimeZone() {
deviceOrientation =
DeviceOrientations.getOrientation(context.getResources().getConfiguration().orientation);
if (deviceOrientation == null) {
logger.log(
SentryLevel.INFO,
"No device orientation available (ORIENTATION_SQUARE|ORIENTATION_UNDEFINED)");
options
.getLogger()
.log(
SentryLevel.INFO,
"No device orientation available (ORIENTATION_SQUARE|ORIENTATION_UNDEFINED)");
return null;
}
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting device orientation.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting device orientation.", e);
}
return deviceOrientation;
}
Expand All @@ -539,7 +548,7 @@ private TimeZone getTimeZone() {
long totalBlocks = getBlockCountLong(stat);
return totalBlocks * blockSize;
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting total internal storage amount.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting total internal storage amount.", e);
return null;
}
}
Expand Down Expand Up @@ -594,7 +603,9 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
long availableBlocks = getAvailableBlocksLong(stat);
return availableBlocks * blockSize;
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting unused internal storage amount.", e);
options
.getLogger()
.log(SentryLevel.ERROR, "Error getting unused internal storage amount.", e);
return null;
}
}
Expand All @@ -605,10 +616,10 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
if (path != null) { // && path.canRead()) { canRead() will read return false
return new StatFs(path.getPath());
}
logger.log(SentryLevel.INFO, "Not possible to read external files directory");
options.getLogger().log(SentryLevel.INFO, "Not possible to read external files directory");
return null;
}
logger.log(SentryLevel.INFO, "External storage is not mounted or emulated.");
options.getLogger().log(SentryLevel.INFO, "External storage is not mounted or emulated.");
return null;
}

Expand Down Expand Up @@ -649,7 +660,7 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
return file;
}
} else {
logger.log(SentryLevel.INFO, "Not possible to read getExternalFilesDirs");
options.getLogger().log(SentryLevel.INFO, "Not possible to read getExternalFilesDirs");
}
return null;
}
Expand All @@ -666,7 +677,7 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
long totalBlocks = getBlockCountLong(stat);
return totalBlocks * blockSize;
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting total external storage amount.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting total external storage amount.", e);
return null;
}
}
Expand All @@ -690,7 +701,9 @@ private boolean isExternalStorageMounted() {
long availableBlocks = getAvailableBlocksLong(stat);
return availableBlocks * blockSize;
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting unused external storage amount.", e);
options
.getLogger()
.log(SentryLevel.ERROR, "Error getting unused external storage amount.", e);
return null;
}
}
Expand All @@ -704,7 +717,7 @@ private boolean isExternalStorageMounted() {
try {
return context.getResources().getDisplayMetrics();
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting DisplayMetrics.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting DisplayMetrics.", e);
return null;
}
}
Expand All @@ -726,7 +739,7 @@ private boolean isExternalStorageMounted() {
os.setRooted((Boolean) rooted);
}
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting OperatingSystem.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting OperatingSystem.", e);
}

return os;
Expand Down Expand Up @@ -781,7 +794,7 @@ private void setAppPackageInfo(final @NotNull App app, final @NotNull PackageInf
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
return br.readLine();
} catch (IOException e) {
logger.log(SentryLevel.ERROR, errorMsg, e);
options.getLogger().log(SentryLevel.ERROR, errorMsg, e);
}

return defaultVersion;
Expand All @@ -805,7 +818,7 @@ private void setAppPackageInfo(final @NotNull App app, final @NotNull PackageInf
return context.getString(stringId);
}
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting application name.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting application name.", e);
}

return null;
Expand All @@ -827,7 +840,7 @@ private void setAppPackageInfo(final @NotNull App app, final @NotNull PackageInf
try {
return Installation.id(context);
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting installationId.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting installationId.", e);
}
return null;
}
Expand All @@ -836,7 +849,7 @@ private void setAppPackageInfo(final @NotNull App app, final @NotNull PackageInf
private @Nullable Map<String, String> getSideLoadedInfo() {
String packageName = null;
try {
final PackageInfo packageInfo = ContextUtils.getPackageInfo(context, logger);
final PackageInfo packageInfo = ContextUtils.getPackageInfo(context, options.getLogger());
final PackageManager packageManager = context.getPackageManager();

if (packageInfo != null && packageManager != null) {
Expand All @@ -861,7 +874,7 @@ private void setAppPackageInfo(final @NotNull App app, final @NotNull PackageInf
}
} catch (IllegalArgumentException e) {
// it'll never be thrown as we are querying its own App's package.
logger.log(SentryLevel.DEBUG, "%s package isn't installed.", packageName);
options.getLogger().log(SentryLevel.DEBUG, "%s package isn't installed.", packageName);
}

return null;
Expand All @@ -879,7 +892,7 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) {
}
}
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Error getting side loaded info.", e);
options.getLogger().log(SentryLevel.ERROR, "Error getting side loaded info.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ final class ManifestMetadataReader {

static final String ATTACH_SCREENSHOT = "io.sentry.attach-screenshot";
static final String CLIENT_REPORTS_ENABLE = "io.sentry.send-client-reports";
static final String COLLECT_ADDITIONAL_CONTEXT = "io.sentry.additional-context";

/** ManifestMetadataReader ctor */
private ManifestMetadataReader() {}
Expand Down Expand Up @@ -210,6 +211,13 @@ static void applyMetadata(
options.setSendClientReports(
readBool(metadata, logger, CLIENT_REPORTS_ENABLE, options.isSendClientReports()));

options.setCollectAdditionalContext(
readBool(
metadata,
logger,
COLLECT_ADDITIONAL_CONTEXT,
options.isCollectAdditionalContext()));

if (options.getTracesSampleRate() == null) {
final Double tracesSampleRate = readDouble(metadata, logger, TRACES_SAMPLE_RATE);
if (tracesSampleRate != -1) {
Expand Down
Loading