Skip to content

Commit e4b8ddf

Browse files
committed
ref(macrobenchmark): Narrow the deprecation suppression to the deprecated call
@Suppress("DEPRECATION") covered the whole candidateDirs expression, including externalCacheDir, which is not deprecated -- so a future deprecation there would have been silently swallowed. Scope it to getExternalMediaDirs and record why it cannot be migrated: it is deprecated in favour of MediaStore, which returns content URIs rather than the filesystem path androidx.benchmark writes to.
1 parent c1cd5bd commit e4b8ddf

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • sentry-android-integration-tests/sentry-uitest-android-macrobenchmark/src/main/java/io/sentry/uitest/android/macrobenchmark

‎sentry-android-integration-tests/sentry-uitest-android-macrobenchmark/src/main/java/io/sentry/uitest/android/macrobenchmark/SentryStartupBenchmark.kt‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ class SentryStartupBenchmark {
102102

103103
private fun findBenchmarkData(): File? {
104104
val context = InstrumentationRegistry.getInstrumentation().targetContext
105-
@Suppress("DEPRECATION")
106-
val candidateDirs = context.externalMediaDirs.toList() + context.externalCacheDir
107-
return candidateDirs.filterNotNull().firstNotNullOfOrNull { dir ->
105+
// Deprecated since API 30 in favour of MediaStore, which hands back content URIs rather
106+
// than the filesystem path androidx.benchmark writes its File to -- so there is nothing to
107+
// migrate to. Suppressed on this call alone; externalCacheDir below is not deprecated.
108+
@Suppress("DEPRECATION") val mediaDirs = context.externalMediaDirs.toList()
109+
// Outputs uses the media dir from API 29 on, and externalCacheDir on API 24-28.
110+
return (mediaDirs + context.externalCacheDir).filterNotNull().firstNotNullOfOrNull { dir ->
108111
dir.listFiles()?.firstOrNull { it.name.endsWith(BENCHMARK_DATA_SUFFIX) }
109112
}
110113
}

0 commit comments

Comments
 (0)