Skip to content

Commit

Permalink
Merge branch 'main' into colin/fakes
Browse files Browse the repository at this point in the history
* main:
  Update the baseline files. (#1625)
  Always invoke mkdir when creating DiskCache. (#1626)
  Update dependency gradle to v8.0.1 (#1623)
  Fix DiskCache maxSize calculation (#1619) (#1620)
  Update plugin binaryCompatibility to v0.13.0 (#1621)
  Update dependency gradle to v8 (#1618)
  Update dependency androidx.profileinstaller:profileinstaller to v1.3.0-beta01 (#1613)
  Update Kotlin to 1.8.10. (#1614)
  Update dependency androidx.exifinterface:exifinterface to v1.3.6 (#1612)
  Update dependency androidx.appcompat:appcompat-resources to v1.6.1 (#1611)
  Migrate to collectStableBaselineProfile. (#1607)
  Update dependency com.android.tools.build:gradle to v7.4.1 (#1608)
  Fix file:// URI parsing (#1601)
  Update dependency com.vanniktech:gradle-maven-publish-plugin to v0.24.0 (#1603)
  Update dependency com.google.android.material:material to v1.8.0 (#1600)
  Update Kotlin to 1.8. (#1597)
  Update dependency com.vanniktech:gradle-maven-publish-plugin to v0.23.2 (#1596)
  Update dependency com.android.tools.build:gradle to v7.4.0 (#1594)
  • Loading branch information
colinrtwhite committed Feb 21, 2023
2 parents 921afa5 + f22720b commit 0f9135e
Show file tree
Hide file tree
Showing 12 changed files with 958 additions and 31 deletions.
41 changes: 41 additions & 0 deletions coil-base/src/androidTest/java/coil/disk/DiskCacheAndroidTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package coil.disk

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import java.io.File
import kotlin.test.assertEquals
import org.junit.After
import org.junit.Before
import org.junit.Test

class DiskCacheAndroidTest {

private lateinit var context: Context
private lateinit var directory: File

@Before
fun before() {
context = ApplicationProvider.getApplicationContext()
directory = context.filesDir.resolve("test_dir")
}

@After
fun after() {
directory.delete() // Ensure we start fresh.
}

@Test
fun checkMaxSize() {
val minimumMaxSizeBytes = 100L
val maximumMaxSizeBytes = 200L
val maxSizePercent = 0.5

val diskCache = DiskCache.Builder().directory(directory)
.maxSizePercent(maxSizePercent)
.minimumMaxSizeBytes(minimumMaxSizeBytes)
.maximumMaxSizeBytes(maximumMaxSizeBytes)
.build()

assertEquals(maximumMaxSizeBytes, diskCache.maxSize)
}
}
18 changes: 17 additions & 1 deletion coil-base/src/androidTest/java/coil/map/FileUriMapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package coil.map

import android.content.ContentResolver.SCHEME_FILE
import android.content.Context
import android.net.Uri
import androidx.core.net.toUri
import androidx.test.core.app.ApplicationProvider
import coil.request.Options
Expand Down Expand Up @@ -52,6 +53,21 @@ class FileUriMapperTest {
fun parsesPoundCharacterCorrectly() {
val path = "/sdcard/fi#le.jpg"
assertEquals(File(path), mapper.map(path.toUri(), Options(context)))
assertEquals(File(path), mapper.map("file://$path".toUri(), Options(context)))
}

/** Regression test: https://github.com/coil-kt/coil/issues/1513 */
@Test
fun ignoresAfterPathCorrectly() {
val expected = File("/sdcard/file.jpg")
val uri = Uri.parse("$SCHEME_FILE:///sdcard/file.jpg?query=value&query2=value#fragment")
assertEquals(expected, mapper.map(uri, Options(context)))
}

/** Regression test: https://github.com/coil-kt/coil/issues/1513 */
@Test
fun decodesEncodedPath() {
val expected = File("/sdcard/Some File.jpg")
val uri = Uri.parse("$SCHEME_FILE:///sdcard/Some%20File.jpg")
assertEquals(expected, mapper.map(uri, Options(context)))
}
}
735 changes: 724 additions & 11 deletions coil-base/src/main/baseline-prof.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion coil-base/src/main/java/coil/disk/DiskCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ interface DiskCache {
val directory = checkNotNull(directory) { "directory == null" }
val maxSize = if (maxSizePercent > 0) {
try {
val stats = StatFs(directory.toFile().absolutePath)
val stats = StatFs(directory.toFile().apply { mkdir() }.absolutePath)
val size = maxSizePercent * stats.blockCountLong * stats.blockSizeLong
size.toLong().coerceIn(minimumMaxSizeBytes, maximumMaxSizeBytes)
} catch (_: Exception) {
Expand Down
9 changes: 7 additions & 2 deletions coil-base/src/main/java/coil/map/FileUriMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ internal class FileUriMapper : Mapper<Uri, File> {

override fun map(data: Uri, options: Options): File? {
if (!isApplicable(data)) return null
val uri = if (data.scheme == null) data else data.buildUpon().scheme(null).build()
return File(uri.toString())
if (data.scheme == SCHEME_FILE) {
return data.path?.let(::File)
} else {
// If the scheme is not "file", it's null, representing a literal path on disk.
// Assume the entire input, regardless of any reserved characters, is valid.
return File(data.toString())
}
}

private fun isApplicable(data: Uri): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package coil.benchmark

import androidx.benchmark.macro.ExperimentalStableBaselineProfilesApi
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
Expand All @@ -19,9 +20,12 @@ class BaselineProfileGenerator {
val baselineProfileRule = BaselineProfileRule()

@Test
fun generate() = baselineProfileRule.collectBaselineProfile(
@OptIn(ExperimentalStableBaselineProfilesApi::class)
fun generate() = baselineProfileRule.collectStableBaselineProfile(
packageName = "sample.$PROJECT",
filterPredicate = newFilterPredicate(),
maxIterations = 15,
stableIterations = 3,
) {
pressHome()
startActivityAndWait()
Expand All @@ -40,6 +44,6 @@ class BaselineProfileGenerator {
private fun newFilterPredicate(): (String) -> Boolean {
// Only include Compose-specific rules in the coil-compose module.
val packageName = if (PROJECT == "compose") "coil/compose/" else "coil/"
return { line -> packageName in line && "sample/" !in line }
return { line -> "sample/" !in line && packageName in line }
}
}
1 change: 1 addition & 0 deletions coil-compose-base/api/coil-compose-base.api
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public final class coil/compose/AsyncImageKt {
}

public final class coil/compose/AsyncImagePainter : androidx/compose/ui/graphics/painter/Painter, androidx/compose/runtime/RememberObserver {
public static final field $stable I
public static final field Companion Lcoil/compose/AsyncImagePainter$Companion;
public final fun getImageLoader ()Lcoil/ImageLoader;
public fun getIntrinsicSize-NH-jbRc ()J
Expand Down
Loading

0 comments on commit 0f9135e

Please sign in to comment.