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: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ dependencies {
// Sentry Android SDK (core + replay for quality configuration)
implementation(libs.sentry.core)
implementation(libs.sentry.android.core)
implementation(libs.sentry.android.replay)
implementation(libs.sentry.logback)

// Firebase Analytics
implementation(platform(libs.firebase.bom))
Expand Down
18 changes: 1 addition & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,14 @@
<!-- enable the performance API by setting a sample-rate, adjust in production env -->
<meta-data
android:name="io.sentry.traces.sample-rate"
android:value="1.0" />
<!-- enable profiling when starting transactions, adjust in production env -->
<meta-data
android:name="io.sentry.traces.profiling.sample-rate"
android:value="1.0" />
android:value="0.0" />
<meta-data
android:name="io.sentry.send-default-pii"
android:value="true" />
<!-- Enable profiling on app start -->
<meta-data
android:name="io.sentry.traces.profiling.start-on-app-start"
android:value="true" />
<!-- Enable logs to be sent to Sentry -->
<meta-data
android:name="io.sentry.logs.enabled"
android:value="true" />
<!-- Record session replays for 100% of errors and 10% of sessions -->
<meta-data
android:name="io.sentry.session-replay.on-error-sample-rate"
android:value="1.0" />
<meta-data
android:name="io.sentry.session-replay.session-sample-rate"
android:value="0.1" />

<provider
android:name=".provider.IDEDocumentsProvider"
android:authorities="com.itsaky.androidide.documents"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.itsaky.androidide.utils.FeatureFlags
import com.termux.shared.reflection.ReflectionUtils
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
import io.sentry.Sentry
import io.sentry.SentryReplayOptions.SentryReplayQuality
import io.sentry.android.core.SentryAndroid
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -31,6 +30,13 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.slf4j.LoggerFactory
import kotlin.system.exitProcess
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.LoggerContext
import io.sentry.logback.SentryAppender
import io.sentry.protocol.User
import android.os.Build
import android.provider.Settings

/**
* @author Akash Yadav
Expand Down Expand Up @@ -67,14 +73,28 @@ internal object DeviceProtectedApplicationLoader :
)

SentryAndroid.init(app) { options ->
// Reduce replay quality to LOW to prevent OOM
// This reduces screenshot compression to 10 and bitrate to 50kbps
// (defaults to MEDIUM quality)
options.sessionReplay.quality = SentryReplayQuality.LOW
options.environment =
if (BuildConfig.DEBUG) IDEApplication.SENTRY_ENV_DEV else IDEApplication.SENTRY_ENV_PROD
}

val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext
val sentryLogAppender =
SentryAppender().apply {
context = loggerContext
setMinimumEventLevel(Level.OFF)
setMinimumBreadcrumbLevel(Level.INFO)
setMinimumLevel(Level.WARN)
start()
}
loggerContext.getLogger(Logger.ROOT_LOGGER_NAME).addAppender(sentryLogAppender)

Sentry.setUser(
User().apply {
id = Settings.Secure.getString(app.contentResolver, Settings.Secure.ANDROID_ID)
username = "${Build.MANUFACTURER} ${Build.MODEL}"
},
)

Comment on lines 75 to +97

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== File list =="
git ls-files app/src/main/java/com/itsaky/androidide/app/DeviceProtectedApplicationLoader.kt app/src/main/java/com/itsaky/androidide/app/IDEApplication.kt

echo
echo "== Outline: DeviceProtectedApplicationLoader.kt =="
ast-grep outline app/src/main/java/com/itsaky/androidide/app/DeviceProtectedApplicationLoader.kt --view expanded || true

echo
echo "== Outline: IDEApplication.kt =="
ast-grep outline app/src/main/java/com/itsaky/androidide/app/IDEApplication.kt --view expanded || true

echo
echo "== Relevant search: runCatching / direct boot / ANR / Sentry =="
rg -n "runCatching|direct boot|ANR|Sentry|LoggerContext|SentryAppender|Settings\.Secure\.ANDROID_ID" app/src/main/java/com/itsaky/androidide/app -S

Repository: appdevforall/CodeOnTheGo

Length of output: 6511


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== DeviceProtectedApplicationLoader.kt (lines 50-105) =="
sed -n '50,105p' app/src/main/java/com/itsaky/androidide/app/DeviceProtectedApplicationLoader.kt | cat -n

echo
echo "== IDEApplication.kt (lines 160-185) =="
sed -n '160,185p' app/src/main/java/com/itsaky/androidide/app/IDEApplication.kt | cat -n

echo
echo "== CredentialProtectedApplicationLoader.kt (selected runCatching/Sentry uses) =="
sed -n '130,205p' app/src/main/java/com/itsaky/androidide/app/CredentialProtectedApplicationLoader.kt | cat -n

Repository: appdevforall/CodeOnTheGo

Length of output: 6445


🌐 Web query:

Android direct boot Settings.Secure.ANDROID_ID ContentResolver availability

💡 Result:

In Android, Settings.Secure.ANDROID_ID is available to encryption-aware applications during Direct Boot mode [1][2]. Direct Boot mode allows an Android device to boot to a state where it is powered on but the user has not yet entered their credentials (such as a PIN, pattern, or password) [1][3]. To access system resources or perform operations during this phase, an application must be marked as encryption-aware by setting the android:directBootAware attribute to true in its manifest [2][4]. Regarding the specific availability of Settings.Secure.ANDROID_ID and ContentResolver: 1. Settings.Secure.ANDROID_ID: The Settings provider is generally available during Direct Boot, meaning applications can retrieve the ANDROID_ID via the standard ContentResolver interface [5][6]. 2. ContentResolver: While the ContentResolver class is available during Direct Boot, its utility is restricted by the encryption state of the underlying data [2][6]. An encryption-aware app can successfully use a ContentResolver to query data stored in device-encrypted storage [2]. However, attempts to access data in credential-encrypted storage (which is only decrypted after the user unlocks the device) will fail or be unavailable [2]. Developers should ensure that any components interacting with these APIs during the locked state are correctly registered and handle potential limitations regarding data access gracefully [2][4].

Citations:


Wrap the Sentry/Logback setup in runCatching.
DeviceProtectedApplicationLoader is startup-critical in direct boot, and any exception here can abort load() before ShizukuSettings.initialize() and EventBus setup. IDEApplication.kt already warns that failures in this loader can lead to ANRs after reboot.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/com/itsaky/androidide/app/DeviceProtectedApplicationLoader.kt`
around lines 75 - 97, Wrap the Sentry and Logback initialization in
DeviceProtectedApplicationLoader.load() in a runCatching block so
startup-critical failures do not abort direct-boot setup. Keep the existing
SentryAndroid.init, LoggerContext/SentryAppender configuration, and
Sentry.setUser logic inside the guarded block, and make sure any exception is
swallowed or logged without preventing the later ShizukuSettings.initialize()
and EventBus setup from running.

ShizukuSettings.initialize()

EventBus
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" }
# Sentry
sentry-core = { module = "io.sentry:sentry", version.ref = "sentry" }
sentry-android-core = { module = "io.sentry:sentry-android-core", version.ref = "sentry" }
sentry-android-replay = { module = "io.sentry:sentry-android-replay", version.ref = "sentry" }
sentry-logback = { module = "io.sentry:sentry-logback", version.ref = "sentry" }

# AndroidIDE
androidide-ts = { module = "com.itsaky.androidide.treesitter:android-tree-sitter", version.ref = "tree-sitter" }
Expand Down
Loading