getsentry / getsentry/sentry-dotnet

Support Android Direct Boot

Open
#2,057 0 comments 0 reactions 0 assignees View on GitHub
.NET Feature Framework: MAUI
Dominant language
C#
Stars
770
Forks
248
Avg merge
3d 4h
Merged PRs (30d)
49

Description

### Problem Statement

Reference: https://developer.android.com/training/articles/direct-boot

In Direct Boot mode, the Sentry cache path needs to be set to Device Encrypted (DE) storage (see #2052).

```csharp
.UseSentry(options =>
{
#if ANDROID
var deviceContext = Platform.AppContext.CreateDeviceProtectedStorageContext();
options.CacheDirectoryPath = deviceContext?.CacheDir?.AbsolutePath;
#endif
})
```

Direct Boot is an Android 7+ feature (API 24, "N"), so it also requires the app to either set:

```xml
24.0
```

... or check at runtime, such as with:

```csharp
#if ANDROID
#pragma warning disable CA1416
if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.N)
{
var deviceContext = Platform.AppContext.CreateDeviceProtectedStorageContext();
options.CacheDirectoryPath = deviceContext?.CacheDir?.AbsolutePath;
}
#pragma warning restore CA1416
#endif
```

### Solution Brainstorm

Since Direct Boot is only allowed when `android:directBootAware` is in the app manifest, it should be possible to detect it and automatically set the correct cache path as the default.

Stretch goal: It appears there's a way to detect [when the user unlocks the device](https://developer.android.com/training/articles/direct-boot#notification), at which time it would be possible to move the cache back to its regular location in CE storage. That would require a bit of coordination though, as we currently don't have a mechanism to change cache paths once the SDK is initialized. It would have to start writing to the new cache but continue to read from the old until drained.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.