diff --git a/coil-core/src/androidInstrumentedTest/kotlin/coil3/util/SystemCallbacksTest.kt b/coil-core/src/androidInstrumentedTest/kotlin/coil3/util/SystemCallbacksTest.kt index 9139b5ef1a..1a0e874dfc 100644 --- a/coil-core/src/androidInstrumentedTest/kotlin/coil3/util/SystemCallbacksTest.kt +++ b/coil-core/src/androidInstrumentedTest/kotlin/coil3/util/SystemCallbacksTest.kt @@ -64,6 +64,7 @@ class SystemCallbacksTest { assertEquals(8_000_000, memoryCache.size) + @Suppress("DEPRECATION") systemCallbacks.onTrimMemory(TRIM_MEMORY_COMPLETE) assertEquals(0, memoryCache.size) diff --git a/coil-core/src/androidMain/kotlin/coil3/util/SystemCallbacks.kt b/coil-core/src/androidMain/kotlin/coil3/util/SystemCallbacks.kt index 7c6bece75e..d969f01a1c 100644 --- a/coil-core/src/androidMain/kotlin/coil3/util/SystemCallbacks.kt +++ b/coil-core/src/androidMain/kotlin/coil3/util/SystemCallbacks.kt @@ -4,7 +4,6 @@ import android.content.ComponentCallbacks2 import android.content.ComponentCallbacks2.TRIM_MEMORY_BACKGROUND import android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE import android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW -import android.content.ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN import android.content.Context import android.content.res.Configuration import coil3.RealImageLoader @@ -21,6 +20,7 @@ internal actual fun SystemCallbacks( * it be freed automatically by the garbage collector. If the [imageLoader] is freed, it unregisters * its callbacks. */ +@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") internal class AndroidSystemCallbacks( imageLoader: RealImageLoader, ) : SystemCallbacks, ComponentCallbacks2 { @@ -55,8 +55,10 @@ internal class AndroidSystemCallbacks( "trimMemory, level=$level" } if (level >= TRIM_MEMORY_BACKGROUND) { + // The app is in the background. imageLoader.memoryCache?.clear() - } else if (level in TRIM_MEMORY_RUNNING_LOW until TRIM_MEMORY_UI_HIDDEN) { + } else if (level >= TRIM_MEMORY_RUNNING_LOW) { + // The app is in the foreground, but is running low on memory. imageLoader.memoryCache?.apply { trimToSize(size / 2) } } } diff --git a/gradle.properties b/gradle.properties index 366289b857..a3c4e13e01 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,8 +23,8 @@ org.jetbrains.compose.experimental.wasm.enabled=true # Config minSdk=21 -targetSdk=34 -compileSdk=34 +targetSdk=35 +compileSdk=35 # Maven SONATYPE_HOST=DEFAULT diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt index f80eccaa34..48166affe9 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt @@ -8,22 +8,20 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onRoot -import androidx.test.ext.junit.runners.AndroidJUnit4 import coil3.ImageLoader import coil3.compose.AsyncImage import coil3.compose.rememberAsyncImagePainter import coil3.test.FakeImageLoaderEngine import coil3.test.intercept import coil3.test.utils.ComposeTestActivity +import coil3.test.utils.RobolectricTest import com.github.takahirom.roborazzi.RoborazziRule import org.junit.Rule import org.junit.Test -import org.junit.runner.RunWith import org.robolectric.annotation.GraphicsMode -@RunWith(AndroidJUnit4::class) @GraphicsMode(GraphicsMode.Mode.NATIVE) -class RoborazziComposeTestAndroid { +class RoborazziComposeTestAndroid : RobolectricTest() { @get:Rule val composeTestRule = createAndroidComposeRule() diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt index 31087ed770..79228f98b0 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt @@ -6,23 +6,21 @@ import android.widget.ImageView import androidx.test.espresso.Espresso.onView import androidx.test.espresso.matcher.ViewMatchers.isRoot import androidx.test.ext.junit.rules.activityScenarioRule -import androidx.test.ext.junit.runners.AndroidJUnit4 import coil3.ImageLoader import coil3.request.ImageRequest import coil3.request.target import coil3.test.FakeImageLoaderEngine import coil3.test.intercept +import coil3.test.utils.RobolectricTest import coil3.test.utils.ViewTestActivity import coil3.test.utils.activity import com.github.takahirom.roborazzi.RoborazziRule import org.junit.Rule import org.junit.Test -import org.junit.runner.RunWith import org.robolectric.annotation.GraphicsMode -@RunWith(AndroidJUnit4::class) @GraphicsMode(GraphicsMode.Mode.NATIVE) -class RoborazziViewTest { +class RoborazziViewTest : RobolectricTest() { @get:Rule val activityRule = activityScenarioRule() diff --git a/internal/test-utils/src/androidMain/kotlin/coil3/test/utils/utils.android.kt b/internal/test-utils/src/androidMain/kotlin/coil3/test/utils/utils.android.kt index 7b88ee4b23..3c6d0de46f 100644 --- a/internal/test-utils/src/androidMain/kotlin/coil3/test/utils/utils.android.kt +++ b/internal/test-utils/src/androidMain/kotlin/coil3/test/utils/utils.android.kt @@ -23,11 +23,13 @@ import okio.source import org.junit.Assume import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config @RunWith(AndroidJUnit4::class) actual abstract class AndroidJUnit4Test @RunWith(RobolectricTestRunner::class) +@Config(sdk = [34]) actual abstract class RobolectricTest actual val context: PlatformContext diff --git a/internal/test-utils/src/commonMain/kotlin/coil3/test/utils/AbstractNetworkFetcherTest.kt b/internal/test-utils/src/commonMain/kotlin/coil3/test/utils/AbstractNetworkFetcherTest.kt index c7d596ff59..5e0ec802be 100644 --- a/internal/test-utils/src/commonMain/kotlin/coil3/test/utils/AbstractNetworkFetcherTest.kt +++ b/internal/test-utils/src/commonMain/kotlin/coil3/test/utils/AbstractNetworkFetcherTest.kt @@ -18,7 +18,7 @@ import okio.ByteString.Companion.toByteString import okio.blackholeSink import okio.fakefilesystem.FakeFileSystem -abstract class AbstractNetworkFetcherTest : AndroidJUnit4Test() { +abstract class AbstractNetworkFetcherTest : RobolectricTest() { lateinit var fileSystem: FakeFileSystem lateinit var diskCache: DiskCache