Merge "Update kotlinx.coroutines to version 1.5.0" into androidx-main
diff --git a/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ActivityResultRegistryTest.kt b/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ActivityResultRegistryTest.kt
index d9f957e..9da389c 100644
--- a/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ActivityResultRegistryTest.kt
+++ b/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ActivityResultRegistryTest.kt
@@ -208,7 +208,7 @@
         composeTestRule.runOnIdle {
             assertThat(counter).isEqualTo(0)
         }
-        launchChannel.offer(true)
+        launchChannel.trySend(true)
         composeTestRule.runOnIdle {
             registry.dispatchResult(code, RESULT_OK, Intent())
             assertThat(counter).isEqualTo(1)
diff --git a/activity/activity-ktx/src/main/java/androidx/activity/PipHintTracker.kt b/activity/activity-ktx/src/main/java/androidx/activity/PipHintTracker.kt
index 047b11d..1dbb51a 100644
--- a/activity/activity-ktx/src/main/java/androidx/activity/PipHintTracker.kt
+++ b/activity/activity-ktx/src/main/java/androidx/activity/PipHintTracker.kt
@@ -50,6 +50,7 @@
 
     // Create a cold flow that will emit the most updated position of the view in the form of a
     // rect as long as the view is attached to the window.
+    @Suppress("DEPRECATION")
     val flow = callbackFlow<Rect> {
         // Emit a new hint rect any time the view moves.
         val layoutChangeListener = View.OnLayoutChangeListener { v, l, t, r, b, oldLeft, oldTop,
diff --git a/camera/camera-camera2-pipe-testing/src/main/java/androidx/camera/camera2/pipe/testing/FakeRequestProcessor.kt b/camera/camera-camera2-pipe-testing/src/main/java/androidx/camera/camera2/pipe/testing/FakeRequestProcessor.kt
index 8b36e26..1873c41 100644
--- a/camera/camera-camera2-pipe-testing/src/main/java/androidx/camera/camera2/pipe/testing/FakeRequestProcessor.kt
+++ b/camera/camera-camera2-pipe-testing/src/main/java/androidx/camera/camera2/pipe/testing/FakeRequestProcessor.kt
@@ -85,7 +85,11 @@
             )
 
         if (rejectRequests) {
-            check(eventChannel.offer(Event(requestSequence = requestSequence, rejected = true)))
+            check(
+                eventChannel
+                    .trySend(Event(requestSequence = requestSequence, rejected = true))
+                    .isSuccess
+            )
             return false
         }
 
@@ -99,7 +103,11 @@
         requestSequence.invokeOnSequenceSubmitted()
         signal?.complete(requestSequence)
 
-        check(eventChannel.offer(Event(requestSequence = requestSequence, submit = true)))
+        check(
+            eventChannel
+                .trySend(Event(requestSequence = requestSequence, submit = true))
+                .isSuccess
+        )
 
         return true
     }
@@ -119,7 +127,11 @@
                 defaultListeners
             )
         if (rejectRequests) {
-            check(eventChannel.offer(Event(requestSequence = requestSequence, rejected = true)))
+            check(
+                eventChannel
+                    .trySend(Event(requestSequence = requestSequence, rejected = true))
+                    .isSuccess
+            )
             return false
         }
 
@@ -133,7 +145,11 @@
         requestSequence.invokeOnSequenceSubmitted()
         signal?.complete(requestSequence)
 
-        check(eventChannel.offer(Event(requestSequence = requestSequence, submit = true)))
+        check(
+            eventChannel
+                .trySend(Event(requestSequence = requestSequence, submit = true))
+                .isSuccess
+        )
 
         return true
     }
@@ -153,7 +169,11 @@
                 defaultListeners
             )
         if (rejectRequests) {
-            check(eventChannel.offer(Event(requestSequence = requestSequence, rejected = true)))
+            check(
+                eventChannel
+                    .trySend(Event(requestSequence = requestSequence, rejected = true))
+                    .isSuccess
+            )
             return false
         }
 
@@ -167,7 +187,11 @@
         requestSequence.invokeOnSequenceSubmitted()
         signal?.complete(requestSequence)
 
-        check(eventChannel.offer(Event(requestSequence = requestSequence, startRepeating = true)))
+        check(
+            eventChannel
+                .trySend(Event(requestSequence = requestSequence, startRepeating = true))
+                .isSuccess
+        )
         return true
     }
 
@@ -180,7 +204,7 @@
         for (sequence in requestSequencesToAbort) {
             sequence.invokeOnSequenceAborted()
         }
-        check(eventChannel.offer(Event(abort = true)))
+        check(eventChannel.trySend(Event(abort = true)).isSuccess)
     }
 
     override fun stopRepeating() {
@@ -190,14 +214,14 @@
             }
         }
         requestSequence?.invokeOnSequenceAborted()
-        check(eventChannel.offer(Event(stop = true)))
+        check(eventChannel.trySend(Event(stop = true)).isSuccess)
     }
 
     override fun close() {
         synchronized(lock) {
             rejectRequests = true
         }
-        check(eventChannel.offer(Event(close = true)))
+        check(eventChannel.trySend(Event(close = true)).isSuccess)
     }
 
     /**
diff --git a/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/VirtualCameraManager.kt b/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/VirtualCameraManager.kt
index aa1cf52..05bfaee3 100644
--- a/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/VirtualCameraManager.kt
+++ b/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/VirtualCameraManager.kt
@@ -82,7 +82,7 @@
     }
 
     private fun offerChecked(request: CameraRequest) {
-        check(requestQueue.offer(request)) {
+        check(requestQueue.trySend(request).isSuccess) {
             "There are more than $requestQueueDepth requests buffered!"
         }
     }
@@ -362,7 +362,7 @@
             scope,
             timeout = 1000,
             callback = {
-                channel.offer(RequestClose(this))
+                channel.trySend(RequestClose(this)).isSuccess
             }
         )
 
diff --git a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AForCaptureTest.kt b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AForCaptureTest.kt
index aae32a7..b886e3c 100644
--- a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AForCaptureTest.kt
+++ b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AForCaptureTest.kt
@@ -30,6 +30,7 @@
 import androidx.camera.camera2.pipe.testing.FakeRequestProcessor
 import androidx.camera.camera2.pipe.testing.RobolectricCameraPipeTestRunner
 import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.async
 import kotlinx.coroutines.launch
@@ -47,6 +48,7 @@
     private val listener3A = Listener3A()
     private val controller3A = Controller3A(graphProcessor, graphState3A, listener3A)
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testLock3AForCapture(): Unit = runBlocking {
         initGraphProcessor()
@@ -125,6 +127,7 @@
         }
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     private fun testUnlock3APostCaptureAndroidMAndAbove(): Unit = runBlocking {
         initGraphProcessor()
 
@@ -193,6 +196,7 @@
             .isEqualTo(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     private fun testUnlock3APostCaptureAndroidLAndBelow(): Unit = runBlocking {
         initGraphProcessor()
 
diff --git a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ALock3ATest.kt b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ALock3ATest.kt
index 89e5ebb..f7aadd1 100644
--- a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ALock3ATest.kt
+++ b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ALock3ATest.kt
@@ -32,6 +32,7 @@
 import androidx.camera.camera2.pipe.testing.FakeRequestProcessor
 import androidx.camera.camera2.pipe.testing.RobolectricCameraPipeTestRunner
 import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.async
 import kotlinx.coroutines.delay
@@ -50,6 +51,7 @@
     private val listener3A = Listener3A()
     private val controller3A = Controller3A(graphProcessor, graphState3A, listener3A)
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfImmediateAeImmediate(): Unit = runBlocking {
         initGraphProcessor()
@@ -130,6 +132,7 @@
         )
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfImmediateAeAfterCurrentScan(): Unit = runBlocking {
         initGraphProcessor()
@@ -210,6 +213,7 @@
         )
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfImmediateAeAfterNewScan(): Unit = runBlocking {
         initGraphProcessor()
@@ -295,6 +299,7 @@
         )
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfAfterCurrentScanAeImmediate(): Unit = runBlocking {
         initGraphProcessor()
@@ -375,6 +380,7 @@
         )
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfAfterNewScanScanAeImmediate(): Unit = runBlocking {
         initGraphProcessor()
@@ -461,6 +467,7 @@
         )
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfAfterCurrentScanAeAfterCurrentScan(): Unit = runBlocking {
         initGraphProcessor()
@@ -555,6 +562,7 @@
         )
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfAfterNewScanScanAeAfterNewScan(): Unit = runBlocking {
         initGraphProcessor()
@@ -644,6 +652,7 @@
         )
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testLock3AWithRegions(): Unit = runBlocking {
         initGraphProcessor()
diff --git a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASetTorchTest.kt b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASetTorchTest.kt
index df382c3..686e644 100644
--- a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASetTorchTest.kt
+++ b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASetTorchTest.kt
@@ -32,6 +32,7 @@
 import androidx.camera.camera2.pipe.testing.FakeRequestProcessor
 import androidx.camera.camera2.pipe.testing.RobolectricCameraPipeTestRunner
 import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.runBlocking
@@ -48,6 +49,7 @@
     private val listener3A = Listener3A()
     private val controller3A = Controller3A(graphProcessor, graphState3A, listener3A)
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testSetTorchOn() = runBlocking {
         initGraphProcessor()
@@ -80,6 +82,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testSetTorchOff() = runBlocking {
         initGraphProcessor()
@@ -112,6 +115,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testSetTorchDoesNotChangeAeModeIfNotNeeded() = runBlocking {
         initGraphProcessor()
diff --git a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASubmit3ATest.kt b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASubmit3ATest.kt
index 2a57464..ba1cee06 100644
--- a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASubmit3ATest.kt
+++ b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3ASubmit3ATest.kt
@@ -34,6 +34,7 @@
 import androidx.camera.camera2.pipe.testing.FakeRequestProcessor
 import androidx.camera.camera2.pipe.testing.RobolectricCameraPipeTestRunner
 import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.runBlocking
@@ -59,6 +60,7 @@
         assertThat(result.isCompleted).isFalse()
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfModeSubmit(): Unit = runBlocking {
         initGraphProcessor()
@@ -86,6 +88,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAeModeSubmit(): Unit = runBlocking {
         initGraphProcessor()
@@ -114,6 +117,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAwbModeSubmit(): Unit = runBlocking {
         initGraphProcessor()
@@ -142,6 +146,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfRegionsSubmit(): Unit = runBlocking {
         initGraphProcessor()
@@ -170,6 +175,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAeRegionsSubmit(): Unit = runBlocking {
         initGraphProcessor()
@@ -198,6 +204,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAwbRegionsSubmit(): Unit = runBlocking {
         initGraphProcessor()
diff --git a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUnlock3ATest.kt b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUnlock3ATest.kt
index 2e145aa..d5438e7 100644
--- a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUnlock3ATest.kt
+++ b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUnlock3ATest.kt
@@ -30,6 +30,7 @@
 import androidx.camera.camera2.pipe.testing.FakeRequestProcessor
 import androidx.camera.camera2.pipe.testing.RobolectricCameraPipeTestRunner
 import com.google.common.truth.Truth
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.async
 import kotlinx.coroutines.delay
@@ -48,6 +49,7 @@
     private val listener3A = Listener3A()
     private val controller3A = Controller3A(graphProcessor, graphState3A, listener3A)
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testUnlockAe(): Unit = runBlocking {
         initGraphProcessor()
@@ -111,6 +113,7 @@
         Truth.assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testUnlockAf(): Unit = runBlocking {
         initGraphProcessor()
@@ -172,6 +175,7 @@
         Truth.assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testUnlockAwb(): Unit = runBlocking {
         initGraphProcessor()
@@ -235,6 +239,7 @@
         Truth.assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testUnlockAeAf(): Unit = runBlocking {
         initGraphProcessor()
diff --git a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUpdate3ATest.kt b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUpdate3ATest.kt
index 54d025f..c21151c 100644
--- a/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUpdate3ATest.kt
+++ b/camera/camera-camera2-pipe/src/test/java/androidx/camera/camera2/pipe/graph/Controller3AUpdate3ATest.kt
@@ -35,6 +35,7 @@
 import androidx.camera.camera2.pipe.testing.RobolectricCameraPipeTestRunner
 import com.google.common.truth.Truth.assertThat
 import kotlinx.coroutines.CancellationException
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
@@ -73,6 +74,7 @@
         assertThat(result.getCompletionExceptionOrNull() is CancellationException)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfModeUpdate(): Unit = runBlocking {
         initGraphProcessor()
@@ -100,6 +102,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAeModeUpdate(): Unit = runBlocking {
         initGraphProcessor()
@@ -128,6 +131,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAwbModeUpdate(): Unit = runBlocking {
         initGraphProcessor()
@@ -156,6 +160,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAfRegionsUpdate(): Unit = runBlocking {
         initGraphProcessor()
@@ -184,6 +189,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAeRegionsUpdate(): Unit = runBlocking {
         initGraphProcessor()
@@ -212,6 +218,7 @@
         assertThat(result3A.status).isEqualTo(Result3A.Status.OK)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testAwbRegionsUpdate(): Unit = runBlocking {
         initGraphProcessor()
diff --git a/camera/camera-video/build.gradle b/camera/camera-video/build.gradle
index a3e03e9..60272a1 100644
--- a/camera/camera-video/build.gradle
+++ b/camera/camera-video/build.gradle
@@ -73,6 +73,8 @@
 
     // Use Robolectric 4.+
     testOptions.unitTests.includeAndroidResources = true
+
+    kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
 }
 
 androidx {
diff --git a/camera/camera-video/src/androidTest/java/androidx/camera/video/internal/encoder/AudioEncoderTest.kt b/camera/camera-video/src/androidTest/java/androidx/camera/video/internal/encoder/AudioEncoderTest.kt
index 019ce90..6c26f0c 100644
--- a/camera/camera-video/src/androidTest/java/androidx/camera/video/internal/encoder/AudioEncoderTest.kt
+++ b/camera/camera-video/src/androidTest/java/androidx/camera/video/internal/encoder/AudioEncoderTest.kt
@@ -24,6 +24,7 @@
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.LargeTest
 import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.asCoroutineDispatcher
@@ -372,6 +373,7 @@
         private val started = AtomicBoolean(false)
         private var job: Job? = null
 
+        @OptIn(DelicateCoroutinesApi::class)
         fun start() {
             if (started.getAndSet(true)) {
                 return
diff --git a/camera/integration-tests/timingtestapp/build.gradle b/camera/integration-tests/timingtestapp/build.gradle
index 73186e7..915df51 100644
--- a/camera/integration-tests/timingtestapp/build.gradle
+++ b/camera/integration-tests/timingtestapp/build.gradle
@@ -47,6 +47,9 @@
     buildFeatures {
         viewBinding true
     }
+    kotlinOptions {
+        freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
+    }
 }
 
 dependencies {
diff --git a/camera/integration-tests/timingtestapp/src/main/java/androidx/camera/integration/antelope/cameracontrollers/CameraXController.kt b/camera/integration-tests/timingtestapp/src/main/java/androidx/camera/integration/antelope/cameracontrollers/CameraXController.kt
index f86966c..5c393cc 100644
--- a/camera/integration-tests/timingtestapp/src/main/java/androidx/camera/integration/antelope/cameracontrollers/CameraXController.kt
+++ b/camera/integration-tests/timingtestapp/src/main/java/androidx/camera/integration/antelope/cameracontrollers/CameraXController.kt
@@ -42,6 +42,7 @@
 import androidx.concurrent.futures.await
 import androidx.core.util.Consumer
 import androidx.lifecycle.LifecycleOwner
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
@@ -57,6 +58,7 @@
  * All the needed Cmaera X use cases should be bound before starting the lifecycle. Depending on
  * the test, bind either the preview case, or both the preview and image capture case.
  */
+@kotlin.OptIn(DelicateCoroutinesApi::class)
 internal fun cameraXOpenCamera(
     activity: MainActivity,
     params: CameraParams,
@@ -194,6 +196,7 @@
 /**
  * End Camera X custom lifecycle, unbind use cases, and start timing the camera close.
  */
+@kotlin.OptIn(DelicateCoroutinesApi::class)
 internal fun closeCameraX(activity: MainActivity, params: CameraParams, testConfig: TestConfig) {
     logd("In closecameraX, camera: " + params.id + ",  test: " + testConfig.currentRunningTest)
 
diff --git a/compose/animation/animation-core/src/commonMain/kotlin/androidx/compose/animation/core/AnimateAsState.kt b/compose/animation/animation-core/src/commonMain/kotlin/androidx/compose/animation/core/AnimateAsState.kt
index 6199066..1b0b921 100644
--- a/compose/animation/animation-core/src/commonMain/kotlin/androidx/compose/animation/core/AnimateAsState.kt
+++ b/compose/animation/animation-core/src/commonMain/kotlin/androidx/compose/animation/core/AnimateAsState.kt
@@ -362,7 +362,7 @@
     val animSpec by rememberUpdatedState(animationSpec)
     val channel = remember { Channel<T>(Channel.CONFLATED) }
     SideEffect {
-        channel.offer(targetValue)
+        channel.trySend(targetValue)
     }
     LaunchedEffect(channel) {
         for (target in channel) {
@@ -371,7 +371,7 @@
             // will be received.
             // It may not be an issue elsewhere, but in animation we want to avoid being one
             // frame late.
-            val newTarget = channel.poll() ?: target
+            val newTarget = channel.tryReceive().getOrNull() ?: target
             launch {
                 if (newTarget != animatable.targetValue) {
                     animatable.animateTo(newTarget, animSpec)
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
index 74241b8..4e484f4 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
@@ -271,7 +271,7 @@
                             isDragSuccessful = false
                             if (!isActive) throw cancellation
                         } finally {
-                            channel.offer(if (isDragSuccessful) DragStopped else DragCancelled)
+                            channel.trySend(if (isDragSuccessful) DragStopped else DragCancelled)
                         }
                     }
                 }
@@ -318,9 +318,9 @@
     val overSlopOffset = initialDelta.toOffset(orientation)
     val adjustedStart = startEvent.position - overSlopOffset *
         sign(startEvent.position.toFloat(orientation))
-    channel.offer(DragStarted(adjustedStart))
+    channel.trySend(DragStarted(adjustedStart))
 
-    channel.offer(
+    channel.trySend(
         DragDelta(
             if (reverseDirection) initialDelta * -1 else initialDelta,
             startEvent.uptimeMillis
@@ -330,7 +330,7 @@
     val dragTick: (PointerInputChange) -> Unit = { event: PointerInputChange ->
         val delta = event.positionChange().toFloat(orientation)
         event.consumePositionChange()
-        channel.offer(DragDelta(if (reverseDirection) delta * -1 else delta, event.uptimeMillis))
+        channel.trySend(DragDelta(if (reverseDirection) delta * -1 else delta, event.uptimeMillis))
     }
     return if (orientation == Orientation.Vertical) {
         verticalDrag(startEvent.id, dragTick)
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/TapGestureDetector.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/TapGestureDetector.kt
index afbb6d1c..eef7db7 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/TapGestureDetector.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/TapGestureDetector.kt
@@ -321,28 +321,28 @@
                 // wait for the main pass of the initial event we already have eaten above
                 awaitPointerEvent()
             }
-            channel.offer(AllUp)
+            channel.trySend(AllUp)
             consumeAllUntilUp.value = false
         } else if (event.changes.fastAll { it.changedToDown() }) {
             val change = event.changes[0]
             change.consumeDownChange()
-            channel.offer(Down(change.position, change.uptimeMillis))
+            channel.trySend(Down(change.position, change.uptimeMillis))
         } else if (!detectDownsOnly.value) {
             if (event.changes.fastAll { it.changedToUp() }) {
                 // All pointers are up
                 val change = event.changes[0]
                 change.consumeDownChange()
-                channel.offer(Up(change.position, change.uptimeMillis))
+                channel.trySend(Up(change.position, change.uptimeMillis))
             } else if (
                 event.changes.fastAny { it.consumed.downChange || it.isOutOfBounds(size) }
             ) {
-                channel.offer(Cancel)
+                channel.trySend(Cancel)
             } else {
                 // Check for cancel by position consumption. We can look on the Final pass of the
                 // existing pointer event because it comes after the Main pass we checked above.
                 val consumeCheck = awaitPointerEvent(PointerEventPass.Final)
                 if (consumeCheck.changes.fastAny { it.positionChangeConsumed() }) {
-                    channel.offer(Cancel)
+                    channel.trySend(Cancel)
                 }
             }
         }
diff --git a/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/testing/CheatSheet.kt b/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/testing/CheatSheet.kt
index 14bfe86..35c82124 100644
--- a/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/testing/CheatSheet.kt
+++ b/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/testing/CheatSheet.kt
@@ -164,6 +164,7 @@
 import androidx.compose.ui.test.width
 import androidx.compose.ui.text.input.ImeAction
 import androidx.compose.ui.unit.dp
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import android.view.KeyEvent as AndroidKeyEvent
@@ -370,6 +371,7 @@
         .getUnclippedBoundsInRoot()
 }
 
+@OptIn(DelicateCoroutinesApi::class)
 @RequiresApi(Build.VERSION_CODES.O)
 private fun TestingCheatSheetOther() {
 
diff --git a/compose/material/material/samples/src/main/java/androidx/compose/material/samples/ScaffoldSamples.kt b/compose/material/material/samples/src/main/java/androidx/compose/material/samples/ScaffoldSamples.kt
index 3d6c1b2..370b121 100644
--- a/compose/material/material/samples/src/main/java/androidx/compose/material/samples/ScaffoldSamples.kt
+++ b/compose/material/material/samples/src/main/java/androidx/compose/material/samples/ScaffoldSamples.kt
@@ -289,7 +289,7 @@
                 text = { Text("Show snackbar") },
                 onClick = {
                     // offset snackbar data to the business logic
-                    channel.offer(++clickCount)
+                    channel.trySend(++clickCount)
                 }
             )
         },
diff --git a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/ProduceStateTests.kt b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/ProduceStateTests.kt
index cbc3a37..a550adb 100644
--- a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/ProduceStateTests.kt
+++ b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/ProduceStateTests.kt
@@ -51,7 +51,7 @@
 
         assertEquals(0, observedResult, "observedResult after initial composition")
 
-        emitter.offer(1)
+        emitter.trySend(1)
         rule.runOnIdle {
             assertEquals(1, observedResult, "observedResult after emitting new value")
         }
diff --git a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SideEffectTests.kt b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SideEffectTests.kt
index 68f2966..2d95d76 100644
--- a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SideEffectTests.kt
+++ b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SideEffectTests.kt
@@ -298,10 +298,10 @@
             }
         }.then {
             assertEquals(1, counter)
-            ch.offer(Unit)
+            ch.trySend(Unit)
         }.then {
             assertEquals(2, counter)
-            ch.offer(Unit)
+            ch.trySend(Unit)
         }.then {
             assertEquals(3, counter)
         }
@@ -405,10 +405,10 @@
         }.then {
             myComposableArg = "world"
         }.then {
-            val offerSucceeded = pleaseSend.offer(Unit)
+            val offerSucceeded = pleaseSend.trySend(Unit).isSuccess
             assertTrue(offerSucceeded, "task wasn't awaiting send signal")
         }.then {
-            val receivedResult = output.poll()
+            val receivedResult = output.tryReceive().getOrNull()
             assertEquals("world", receivedResult)
         }
     }
diff --git a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt
index 2f7677b..09cdb86 100644
--- a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt
+++ b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt
@@ -56,10 +56,10 @@
             }
         }.then {
             assertEquals(1, counter)
-            ch.offer(Unit)
+            ch.trySend(Unit)
         }.then {
             assertEquals(2, counter)
-            ch.offer(Unit)
+            ch.trySend(Unit)
         }.then {
             assertEquals(3, counter)
         }
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SnapshotState.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SnapshotState.kt
index dfee58f..4a47257 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SnapshotState.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SnapshotState.kt
@@ -831,13 +831,13 @@
     val readSet = mutableSetOf<Any>()
     val readObserver: (Any) -> Unit = { readSet.add(it) }
 
-    // This channel may not block or lose data on an offer call.
+    // This channel may not block or lose data on a trySend call.
     val appliedChanges = Channel<Set<Any>>(Channel.UNLIMITED)
 
     // Register the apply observer before running for the first time
     // so that we don't miss updates.
     val unregisterApplyObserver = Snapshot.registerApplyObserver { changed, _ ->
-        appliedChanges.offer(changed)
+        appliedChanges.trySend(changed)
     }
 
     try {
@@ -859,7 +859,7 @@
             while (true) {
                 // Assumption: readSet will typically be smaller than changed
                 found = found || readSet.intersects(changedObjects)
-                changedObjects = appliedChanges.poll() ?: break
+                changedObjects = appliedChanges.tryReceive().getOrNull() ?: break
             }
 
             if (found) {
diff --git a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/RecomposerTests.kt b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/RecomposerTests.kt
index 0dc4e9e..845e672 100644
--- a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/RecomposerTests.kt
+++ b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/RecomposerTests.kt
@@ -277,7 +277,7 @@
                 val threadLog = Channel<Thread>(Channel.BUFFERED)
                 lateinit var recomposeScope: RecomposeScope
                 composition.setContent {
-                    threadLog.offer(Thread.currentThread())
+                    threadLog.trySend(Thread.currentThread())
                     val scope = currentRecomposeScope
                     SideEffect {
                         recomposeScope = scope
@@ -356,7 +356,7 @@
             val recompositionThread = Channel<Thread>(1)
             composition.setContent {
                 if (recomposition) {
-                    recompositionThread.offer(Thread.currentThread())
+                    recompositionThread.trySend(Thread.currentThread())
                 }
             }
 
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilterTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilterTest.kt
index 49c2c27..9992c25 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilterTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilterTest.kt
@@ -103,7 +103,7 @@
             with(filter) {
                 awaitPointerEventScope {
                     repeat(3) {
-                        results.offer(awaitPointerEvent())
+                        results.trySend(awaitPointerEvent())
                     }
                     results.close()
                 }
@@ -138,7 +138,7 @@
             with(filter) {
                 awaitPointerEventScope {
                     repeat(3) {
-                        results.offer(awaitPointerEvent())
+                        results.trySend(awaitPointerEvent())
                     }
                     results.close()
                 }
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/WindowRecomposerTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/WindowRecomposerTest.kt
index 7efb51d..395b7a0 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/WindowRecomposerTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/WindowRecomposerTest.kt
@@ -34,6 +34,7 @@
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.LargeTest
 import androidx.test.filters.MediumTest
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.runBlocking
@@ -52,7 +53,7 @@
      * Test that a Recomposer that doesn't shut down with the activity doesn't inadvertently
      * keep a reference to the Activity
      */
-    @OptIn(InternalComposeUiApi::class)
+    @kotlin.OptIn(DelicateCoroutinesApi::class, InternalComposeUiApi::class)
     @Test
     @LargeTest
     fun activityGarbageCollected() {
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeViewAccessibilityDelegateCompat.android.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeViewAccessibilityDelegateCompat.android.kt
index 9d23df0..b441e23 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeViewAccessibilityDelegateCompat.android.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeViewAccessibilityDelegateCompat.android.kt
@@ -1517,7 +1517,7 @@
 
     private fun notifySubtreeAccessibilityStateChangedIfNeeded(layoutNode: LayoutNode) {
         if (subtreeChangedLayoutNodes.add(layoutNode)) {
-            boundsUpdateChannel.offer(Unit)
+            boundsUpdateChannel.trySend(Unit)
         }
     }
 
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.android.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.android.kt
index 3116d17..8663ca3 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.android.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.android.kt
@@ -47,7 +47,7 @@
                 }
             }
             Snapshot.registerGlobalWriteObserver {
-                channel.offer(Unit)
+                channel.trySend(Unit)
             }
         }
     }
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/WindowRecomposer.android.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/WindowRecomposer.android.kt
index f946d04..350c695 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/WindowRecomposer.android.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/WindowRecomposer.android.kt
@@ -30,6 +30,7 @@
 import androidx.lifecycle.ViewTreeLifecycleOwner
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.CoroutineStart
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.android.asCoroutineDispatcher
 import kotlinx.coroutines.launch
@@ -149,6 +150,7 @@
         }
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     internal fun createAndInstallWindowRecomposer(rootView: View): Recomposer {
         val newRecomposer = factory.get().createRecomposer(rootView)
         rootView.compositionContext = newRecomposer
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/text/input/TextInputServiceAndroid.android.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/text/input/TextInputServiceAndroid.android.kt
index f19e992..e61215c 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/text/input/TextInputServiceAndroid.android.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/text/input/TextInputServiceAndroid.android.kt
@@ -165,12 +165,12 @@
 
     override fun showSoftwareKeyboard() {
         if (DEBUG) { Log.d(TAG, "$DEBUG_CLASS.showSoftwareKeyboard") }
-        showKeyboardChannel.offer(true)
+        showKeyboardChannel.trySend(true)
     }
 
     override fun hideSoftwareKeyboard() {
         if (DEBUG) { Log.d(TAG, "$DEBUG_CLASS.hideSoftwareKeyboard") }
-        showKeyboardChannel.offer(false)
+        showKeyboardChannel.trySend(false)
     }
 
     suspend fun keyboardVisibilityEventLoop() {
@@ -180,7 +180,7 @@
             // on the same thread, there is a possibility that we have a stale value in the channel
             // because we start consuming from it before we finish producing all the values. We poll
             // to make sure that we use the most recent value.
-            if (showKeyboardChannel.poll() ?: showKeyboard) {
+            if (showKeyboardChannel.tryReceive().getOrNull() ?: showKeyboard) {
                 if (DEBUG) { Log.d(TAG, "$DEBUG_CLASS.keyboardVisibilityEventLoop.showSoftInput") }
                 inputMethodManager.showSoftInput(view)
             } else {
diff --git a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/desktop/AWTDebounceEventQueue.desktop.kt b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/desktop/AWTDebounceEventQueue.desktop.kt
index ea7a5df..5fdfb29 100644
--- a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/desktop/AWTDebounceEventQueue.desktop.kt
+++ b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/desktop/AWTDebounceEventQueue.desktop.kt
@@ -16,6 +16,7 @@
 
 package androidx.compose.desktop
 
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.channels.Channel
@@ -38,6 +39,7 @@
  * Without dispatching events we may have a situation
  * when 30 events of scroll block AWT Thread for 1 second, without rerendering content.
  */
+@OptIn(DelicateCoroutinesApi::class)
 internal class AWTDebounceEventQueue constructor(
     // 4 ms is enough for the user not to see the lags
     private val maxNanosToBlockThread: Long = 4_000_000, // 4 milliseconds
@@ -63,6 +65,6 @@
     }
 
     fun post(event: () -> Unit) {
-        queue.offer(event)
+        queue.trySend(event)
     }
 }
\ No newline at end of file
diff --git a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.desktop.kt b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.desktop.kt
index fd87f34..afd95d6 100644
--- a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.desktop.kt
+++ b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/GlobalSnapshotManager.desktop.kt
@@ -49,7 +49,7 @@
                 }
             }
             Snapshot.registerGlobalWriteObserver {
-                channel.offer(Unit)
+                channel.trySend(Unit)
             }
         }
     }
diff --git a/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt b/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt
index 562b8a0..27f7bcd 100644
--- a/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt
+++ b/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt
@@ -20,6 +20,7 @@
 
 import kotlinx.coroutines.CancellationException
 import kotlinx.coroutines.CoroutineStart
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.async
 import kotlinx.coroutines.launch
@@ -37,6 +38,7 @@
 import kotlin.test.assertFailsWith
 
 @RunWith(JUnit4::class)
+@OptIn(DelicateCoroutinesApi::class)
 class ListenableFutureTest {
     private var actionIndex = AtomicInteger()
     private var finished = AtomicBoolean()
diff --git a/datastore/datastore-core/src/main/java/androidx/datastore/core/SimpleActor.kt b/datastore/datastore-core/src/main/java/androidx/datastore/core/SimpleActor.kt
index 8f7d54a..4f1ed0b 100644
--- a/datastore/datastore-core/src/main/java/androidx/datastore/core/SimpleActor.kt
+++ b/datastore/datastore-core/src/main/java/androidx/datastore/core/SimpleActor.kt
@@ -20,6 +20,8 @@
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.channels.Channel
 import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
+import kotlinx.coroutines.channels.ClosedSendChannelException
+import kotlinx.coroutines.channels.onClosed
 import kotlinx.coroutines.ensureActive
 import kotlinx.coroutines.launch
 import java.util.concurrent.atomic.AtomicInteger
@@ -64,19 +66,10 @@
 
             messageQueue.close(ex)
 
-            var msg = try {
-                messageQueue.poll()
-            } catch (rethrownEx: Throwable) {
-                return@invokeOnCompletion
-            }
-
-            while (msg != null) {
-                onUndeliveredElement(msg, ex)
-                try {
-                    msg = messageQueue.poll()
-                } catch (rethrownEx: Throwable) {
-                    return@invokeOnCompletion
-                }
+            while (true) {
+                messageQueue.tryReceive().getOrNull()?.let { msg ->
+                    onUndeliveredElement(msg, ex)
+                } ?: break
             }
         }
     }
@@ -107,7 +100,11 @@
          */
 
         // should never return false bc the channel capacity is unlimited
-        check(messageQueue.offer(msg))
+        check(
+            messageQueue.trySend(msg)
+                .onClosed { throw it ?: ClosedSendChannelException("Channel was closed normally") }
+                .isSuccess
+        )
 
         // If the number of remaining messages was 0, there is no active consumer, since it quits
         // consuming once remaining messages hits 0. We must kick off a new consumer.
diff --git a/datastore/datastore-core/src/test/java/androidx/datastore/core/SingleProcessDataStoreStressTest.kt b/datastore/datastore-core/src/test/java/androidx/datastore/core/SingleProcessDataStoreStressTest.kt
index d8f25c3..dcefa82 100644
--- a/datastore/datastore-core/src/test/java/androidx/datastore/core/SingleProcessDataStoreStressTest.kt
+++ b/datastore/datastore-core/src/test/java/androidx/datastore/core/SingleProcessDataStoreStressTest.kt
@@ -44,6 +44,7 @@
 import java.util.concurrent.Executors
 import java.util.concurrent.TimeUnit
 import kotlin.time.ExperimentalTime
+import kotlin.time.seconds
 
 @RunWith(JUnit4::class)
 @ExperimentalTime
@@ -97,7 +98,8 @@
 
         // There's no reason this should take more than a few seconds once writers complete and
         // there's no reason writers won't complete.
-        withTimeout(10000L) {
+        @Suppress("DEPRECATION")
+        withTimeout(10.seconds) {
             readers.awaitAll()
         }
     }
@@ -161,7 +163,8 @@
 
         // There's no reason this should take more than a few seconds once writers complete and
         // there's no reason writers won't complete.
-        withTimeout(10000L) {
+        @Suppress("DEPRECATION")
+        withTimeout(10.seconds) {
             readers.awaitAll()
         }
     }
@@ -221,7 +224,8 @@
 
         // There's no reason this should take more than a few seconds once writers complete and
         // there's no reason writers won't complete.
-        withTimeout(10000L) {
+        @Suppress("DEPRECATION")
+        withTimeout(10.seconds) {
             readers.awaitAll()
         }
     }
diff --git a/datastore/datastore-rxjava2/src/test/java/androidx/datastore/rxjava2/RxDataStoreTest.java b/datastore/datastore-rxjava2/src/test/java/androidx/datastore/rxjava2/RxDataStoreTest.java
index 5a5c816..36471e8 100644
--- a/datastore/datastore-rxjava2/src/test/java/androidx/datastore/rxjava2/RxDataStoreTest.java
+++ b/datastore/datastore-rxjava2/src/test/java/androidx/datastore/rxjava2/RxDataStoreTest.java
@@ -160,11 +160,13 @@
 
         assertThat(testSubscriber.awaitTerminalEvent()).isTrue();
         testSubscriber.assertTerminated()
-                // Note(rohitsat): this is different from coroutines bc asFlowable converts the
-                // CancellationException to onComplete.
-                .assertNoErrors()
-                .assertComplete()
-                .assertValueCount(0);
+                // FIXME: This used to be different from coroutines bc asFlowable used to convert
+                //        the CancellationException to onComplete. This behavior changed with
+                //        kotlinx-coroutines-rx2:1.5.0
+                //        https://github.com/Kotlin/kotlinx.coroutines/issues/2173
+                //.assertNoErrors()
+                //.assertComplete()
+                .assertNoValues();
 
 
         // NOTE(rohitsat): this is different from data()
diff --git a/datastore/datastore-rxjava3/src/test/java/androidx/datastore/rxjava3/RxDataStoreTest.java b/datastore/datastore-rxjava3/src/test/java/androidx/datastore/rxjava3/RxDataStoreTest.java
index 9da1bfd..39da7e1 100644
--- a/datastore/datastore-rxjava3/src/test/java/androidx/datastore/rxjava3/RxDataStoreTest.java
+++ b/datastore/datastore-rxjava3/src/test/java/androidx/datastore/rxjava3/RxDataStoreTest.java
@@ -159,11 +159,12 @@
 
         assertThat(testSubscriber.await(5, TimeUnit.SECONDS)).isTrue();
 
-        // Note(rohitsat): this is different from coroutines bc asFlowable converts the
-        // CancellationException to onComplete
-        testSubscriber.assertNoErrors()
-                .assertComplete()
-                .assertValueCount(0);
+        // FIXME: This used to be different from coroutines bc asFlowable used to convert
+        //        the CancellationException to onComplete. This behavior changed with
+        //        kotlinx-coroutines-rx3:1.5.0
+        //        https://github.com/Kotlin/kotlinx.coroutines/issues/2173
+        // testSubscriber.assertNoErrors().assertComplete();
+        testSubscriber.assertNoValues();
 
 
         // NOTE(rohitsat): this is different from data()
diff --git a/development/build_log_simplifier/messages.ignore b/development/build_log_simplifier/messages.ignore
index 9a47b80..3b598ae 100644
--- a/development/build_log_simplifier/messages.ignore
+++ b/development/build_log_simplifier/messages.ignore
@@ -568,6 +568,8 @@
 # > Task :docs-public:dokkaKotlinDocs
 No documentation for .*
 Found an unresolved type in androidx\.compose\.animation\.AnimatedContentScope\$using\(androidx\.compose\.animation\.ContentTransform, androidx\.compose\.animation\.SizeTransform\) \(AnimatedContent\.kt:[0-9]+\)
+Found an unresolved type in androidx\.compose\.runtime\.BroadcastFrameClock\$cancel\(\) \(BroadcastFrameClock\.kt:[0-9]+\)
+Found an unresolved type in androidx\.datastore\.rxjava[0-9]+\.RxDataStore\$dispose\(\) \(RxDataStore\.kt:[0-9]+\)
 Found an unresolved type in androidx\.compose\.runtime\.Updater\$set\(kotlin\.Int, kotlin\.Function[0-9]+\(\(androidx\.compose\.runtime\.Updater\.T, kotlin\.Int, kotlin\.Unit\)\)\) \(Composer\.kt:[0-9]+\)
 Found an unresolved type in androidx\.compose\.runtime\.Updater\$set\(androidx\.compose\.runtime\.Updater\.set\.V, kotlin\.Function[0-9]+\(\(androidx\.compose\.runtime\.Updater\.T, androidx\.compose\.runtime\.Updater\.set\.V, kotlin\.Unit\)\)\) \(Composer\.kt:[0-9]+\)
 Found an unresolved type in androidx\.compose\.runtime\.Updater\$update\(kotlin\.Int, kotlin\.Function[0-9]+\(\(androidx\.compose\.runtime\.Updater\.T, kotlin\.Int, kotlin\.Unit\)\)\) \(Composer\.kt:[0-9]+\)
@@ -597,6 +599,9 @@
 # See b/180023439 for hiltNavGraphViewModel warning.
 Found an unresolved type in androidx\.hilt\.navigation\.compose\$hiltNavGraphViewModel\(androidx\.navigation\.NavController, kotlin\.String\) \(NavHostController\.kt:[0-9]+\)
 Unresolved link to .*
+Found an unresolved type in androidx\.compose\.foundation\.MutatorMutex\$mutate\(androidx\.compose\.foundation\.MutatePriority, kotlin\.coroutines\.SuspendFunction[0-9]+\(\(androidx\.compose\.foundation\.MutatorMutex\.mutate\.R\)\)\) \(MutatorMutex\.kt:[0-9]+\)
+Found an unresolved type in androidx\.compose\.foundation\.MutatorMutex\$mutateWith\(androidx\.compose\.foundation\.MutatorMutex\.mutateWith\.T, androidx\.compose\.foundation\.MutatePriority, kotlin\.coroutines\.SuspendFunction[0-9]+\(\(androidx\.compose\.foundation\.MutatorMutex\.mutateWith\.T, androidx\.compose\.foundation\.MutatorMutex\.mutateWith\.R\)\)\) \(MutatorMutex\.kt:[0-9]+\)
+Found an unresolved type in androidx\.compose\.foundation\.gestures\$detectTapGestures\(androidx\.compose\.ui\.input\.pointer\.PointerInputScope, kotlin\.Function[0-9]+\(\(androidx\.compose\.ui\.geometry\.Offset, kotlin\.Unit\)\), kotlin\.Function[0-9]+\(\(androidx\.compose\.ui\.geometry\.Offset, kotlin\.Unit\)\), kotlin\.coroutines\.SuspendFunction[0-9]+\(\(androidx\.compose\.foundation\.gestures\.PressGestureScope, androidx\.compose\.ui\.geometry\.Offset, kotlin\.Unit\)\), kotlin\.Function[0-9]+\(\(androidx\.compose\.ui\.geometry\.Offset, kotlin\.Unit\)\)\) \(TapGestureDetector\.kt:[0-9]+\)
 Found an unresolved type in androidx\.paging\.rxjava[0-9]+\.RxPagedListBuilder\$setInitialLoadKey\(androidx\.paging\.rxjava[0-9]+\.RxPagedListBuilder\.Key\) \(RxPagedListBuilder\.kt:[0-9]+\)
 Found an unresolved type in androidx\.paging\.rxjava[0-9]+\.RxPagedListBuilder\$setBoundaryCallback\(androidx\.paging\.PagedList\.BoundaryCallback\(\(androidx\.paging\.rxjava[0-9]+\.RxPagedListBuilder\.Value\)\)\) \(RxPagedListBuilder\.kt:[0-9]+\)
 Found an unresolved type in androidx\.paging\.rxjava[0-9]+\.RxPagedListBuilder\$setNotifyScheduler\(io\.reactivex\.rxjava[0-9]+\.core\.Scheduler\) \(RxPagedListBuilder\.kt:[0-9]+\)
@@ -1097,6 +1102,7 @@
 Info: Methods with invalid locals information:
 java\.lang\.Object androidx\.compose\.foundation\.gestures\.DraggableKt\$draggable\$[0-9]+\$[0-9]+\.invokeSuspend\(java\.lang\.Object\)
 Type information in locals\-table is inconsistent\. Cannot constrain type: @Nullable androidx\.compose\.foundation\.gestures\.DragLogic \{\} for value: v[0-9]+\(\$this\$invokeSuspend_u[0-9]+lambda_u[0-9]+d[0-9]+\) by constraint INT\.
+java\.lang\.Object androidx\.compose\.ui\.platform\.GlobalSnapshotManager\$ensureStarted\$[0-9]+\.invokeSuspend\(java\.lang\.Object\)
 java\.lang\.Object androidx\.wear\.watchface\.WatchFaceService\$EngineWrapper\.createWatchFaceImpl\(android\.icu\.util\.Calendar, androidx\.wear\.watchface\.ComplicationsManager, androidx\.wear\.watchface\.style\.CurrentUserStyleRepository, kotlinx\.coroutines\.CompletableDeferred, kotlinx\.coroutines\.CompletableDeferred, androidx\.wear\.watchface\.WatchState, kotlin\.coroutines\.Continuation\)
 java\.lang\.Object androidx\.wear\.watchface\.WatchFaceService\$EngineWrapper\.setUserStyle\$wear_watchface_release\(androidx\.wear\.watchface\.style\.data\.UserStyleWireFormat, kotlin\.coroutines\.Continuation\)
 java\.lang\.Object androidx\.wear\.watchface\.editor\.BaseEditorSession\$fetchComplicationsData\$[0-9]+\.invokeSuspend\(java\.lang\.Object\)
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 92ea9e4..1a467b5 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -22,7 +22,7 @@
 incap = "0.2"
 kotlin = "1.5.10"
 kotlinCompileTesting = "1.4.1"
-kotlinCoroutines = "1.4.3"
+kotlinCoroutines = "1.5.0"
 ksp = "1.5.10-1.0.0-beta01"
 leakcanary = "2.2"
 mockito = "2.25.0"
diff --git a/inspection/inspection-testing/src/androidTest/java/androidx/inspection/testing/echo/TickleManager.kt b/inspection/inspection-testing/src/androidTest/java/androidx/inspection/testing/echo/TickleManager.kt
index a5ed775..6d63471 100644
--- a/inspection/inspection-testing/src/androidTest/java/androidx/inspection/testing/echo/TickleManager.kt
+++ b/inspection/inspection-testing/src/androidTest/java/androidx/inspection/testing/echo/TickleManager.kt
@@ -33,6 +33,6 @@
     }
 
     fun tickle() {
-        channel.offer(Unit)
+        channel.trySend(Unit)
     }
 }
\ No newline at end of file
diff --git a/lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/FlowLiveData.kt b/lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/FlowLiveData.kt
index 0e3f903..538a417 100644
--- a/lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/FlowLiveData.kt
+++ b/lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/FlowLiveData.kt
@@ -20,6 +20,7 @@
 
 import android.os.Build
 import androidx.annotation.RequiresApi
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 
@@ -88,10 +89,11 @@
  * BackPressure: the returned flow is conflated. There is no mechanism to suspend an emission by
  * LiveData due to a slow collector, so collector always gets the most recent value emitted.
  */
+@OptIn(DelicateCoroutinesApi::class)
 public fun <T> LiveData<T>.asFlow(): Flow<T> = flow {
     val channel = Channel<T>(Channel.CONFLATED)
     val observer = Observer<T> {
-        channel.offer(it)
+        channel.trySend(it)
     }
     withContext(Dispatchers.Main.immediate) {
         observeForever(observer)
diff --git a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt
index 808c882..9ef1f3f 100644
--- a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt
+++ b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt
@@ -83,10 +83,10 @@
         var closeCalled = false
         val ld = callbackFlow {
             testScope.launch {
-                offer(1)
-                offer(2)
+                trySend(1)
+                trySend(2)
                 delay(1000)
-                offer(3)
+                trySend(3)
             }
             awaitClose {
                 closeCalled = true
diff --git a/paging/common/src/main/kotlin/androidx/paging/LegacyPagingSource.kt b/paging/common/src/main/kotlin/androidx/paging/LegacyPagingSource.kt
index cdf77c1..2dff161 100644
--- a/paging/common/src/main/kotlin/androidx/paging/LegacyPagingSource.kt
+++ b/paging/common/src/main/kotlin/androidx/paging/LegacyPagingSource.kt
@@ -25,6 +25,7 @@
 import androidx.paging.LoadType.PREPEND
 import androidx.paging.LoadType.REFRESH
 import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
@@ -34,6 +35,7 @@
  *
  * @hide
  */
+@OptIn(DelicateCoroutinesApi::class)
 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
 public class LegacyPagingSource<Key : Any, Value : Any>(
     private val fetchDispatcher: CoroutineDispatcher,
diff --git a/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshot.kt b/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshot.kt
index c849a44..6f942fc 100644
--- a/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshot.kt
+++ b/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshot.kt
@@ -100,7 +100,7 @@
         // Wrap collection behind a RendezvousChannel to prevent the RetryChannel from buffering
         // retry signals.
         val retryChannel = Channel<Unit>(Channel.RENDEZVOUS)
-        launch { retryFlow.collect { retryChannel.offer(it) } }
+        launch { retryFlow.collect { retryChannel.trySend(it) } }
 
         // Start collection on retry signals.
         launch {
diff --git a/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshotState.kt b/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshotState.kt
index b27e1b8..dcf138b 100644
--- a/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshotState.kt
+++ b/paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshotState.kt
@@ -110,12 +110,12 @@
 
     fun consumePrependGenerationIdAsFlow(): Flow<Int> {
         return prependGenerationIdCh.consumeAsFlow()
-            .onStart { prependGenerationIdCh.offer(prependGenerationId) }
+            .onStart { prependGenerationIdCh.trySend(prependGenerationId) }
     }
 
     fun consumeAppendGenerationIdAsFlow(): Flow<Int> {
         return appendGenerationIdCh.consumeAsFlow()
-            .onStart { appendGenerationIdCh.offer(appendGenerationId) }
+            .onStart { appendGenerationIdCh.trySend(appendGenerationId) }
     }
 
     fun setSourceLoadState(type: LoadType, newState: LoadState): Boolean {
@@ -251,7 +251,7 @@
                 placeholdersBefore = event.placeholdersRemaining
 
                 prependGenerationId++
-                prependGenerationIdCh.offer(prependGenerationId)
+                prependGenerationIdCh.trySend(prependGenerationId)
             }
             APPEND -> {
                 repeat(event.pageCount) { _pages.removeAt(pages.size - 1) }
@@ -259,7 +259,7 @@
                 placeholdersAfter = event.placeholdersRemaining
 
                 appendGenerationId++
-                appendGenerationIdCh.offer(appendGenerationId)
+                appendGenerationIdCh.trySend(appendGenerationId)
             }
             else -> throw IllegalArgumentException("cannot drop ${event.loadType}")
         }
diff --git a/paging/common/src/main/kotlin/androidx/paging/PagedList.kt b/paging/common/src/main/kotlin/androidx/paging/PagedList.kt
index 39b8e5c..149958d 100644
--- a/paging/common/src/main/kotlin/androidx/paging/PagedList.kt
+++ b/paging/common/src/main/kotlin/androidx/paging/PagedList.kt
@@ -21,6 +21,7 @@
 import androidx.annotation.RestrictTo
 import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.asCoroutineDispatcher
@@ -258,6 +259,7 @@
         private var dataSource: DataSource<Key, Value>?
         private val initialPage: PagingSource.LoadResult.Page<Key, Value>?
         private val config: Config
+        @OptIn(DelicateCoroutinesApi::class)
         private var coroutineScope: CoroutineScope = GlobalScope
         private var notifyDispatcher: CoroutineDispatcher? = null
         private var fetchDispatcher: CoroutineDispatcher? = null
diff --git a/paging/common/src/test/kotlin/androidx/paging/LegacyPageFetcherTest.kt b/paging/common/src/test/kotlin/androidx/paging/LegacyPageFetcherTest.kt
index 0334f4f..71166f4 100644
--- a/paging/common/src/test/kotlin/androidx/paging/LegacyPageFetcherTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/LegacyPageFetcherTest.kt
@@ -27,6 +27,7 @@
 import androidx.paging.PagingSource.LoadResult
 import androidx.paging.PagingSource.LoadResult.Page
 import androidx.testutils.TestDispatcher
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.runBlocking
 import org.junit.Assert.assertEquals
@@ -110,6 +111,7 @@
         }
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     private fun createPager(
         consumer: MockConsumer,
         start: Int = 0,
diff --git a/paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt b/paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
index 8320485..e1562f4 100644
--- a/paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
@@ -35,6 +35,7 @@
 import kotlinx.coroutines.CompletableDeferred
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.CoroutineStart
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.Job
@@ -3338,6 +3339,7 @@
         }
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun pageEventSentAfterChannelClosed() {
         val pager = PageFetcherSnapshot(
diff --git a/paging/common/src/test/kotlin/androidx/paging/PagingDataDifferTest.kt b/paging/common/src/test/kotlin/androidx/paging/PagingDataDifferTest.kt
index 883b4f2..2b02f56 100644
--- a/paging/common/src/test/kotlin/androidx/paging/PagingDataDifferTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/PagingDataDifferTest.kt
@@ -149,7 +149,7 @@
         val differ = SimpleDiffer(dummyDifferCallback)
 
         val pageEventCh = Channel<PageEvent<Int>>(Channel.UNLIMITED)
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Refresh(
                 pages = listOf(TransformablePage(0, listOf(0, 1))),
                 placeholdersBefore = 4,
@@ -157,14 +157,14 @@
                 combinedLoadStates = CombinedLoadStates.IDLE_SOURCE
             )
         )
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Prepend(
                 pages = listOf(TransformablePage(-1, listOf(-1, -2))),
                 placeholdersBefore = 2,
                 combinedLoadStates = CombinedLoadStates.IDLE_SOURCE
             )
         )
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Append(
                 pages = listOf(TransformablePage(1, listOf(2, 3))),
                 placeholdersAfter = 2,
@@ -205,7 +205,7 @@
         // Insert a new page, PagingDataDiffer should try to resend hint since index 0 still points
         // to a placeholder:
         // [null, null, [], [-1], [1], [3], null, null]
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Prepend(
                 pages = listOf(TransformablePage(-2, listOf())),
                 placeholdersBefore = 2,
@@ -227,7 +227,7 @@
 
         // Now index 0 has been loaded:
         // [[-3], [], [-1], [1], [3], null, null]
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Prepend(
                 pages = listOf(TransformablePage(-3, listOf(-3, -4))),
                 placeholdersBefore = 0,
@@ -257,7 +257,7 @@
 
         // Should only resend the hint for index 5, since index 0 has already been loaded:
         // [[-3], [], [-1], [1], [3], [], null, null]
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Append(
                 pages = listOf(TransformablePage(2, listOf())),
                 placeholdersAfter = 2,
@@ -283,7 +283,7 @@
 
         // Index 5 hasn't loaded, but we are at the end of the list:
         // [[-3], [], [-1], [1], [3], [], [5]]
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Append(
                 pages = listOf(TransformablePage(3, listOf(4, 5))),
                 placeholdersAfter = 0,
@@ -305,7 +305,7 @@
         val differ = SimpleDiffer(dummyDifferCallback)
 
         val pageEventCh = Channel<PageEvent<Int>>(Channel.UNLIMITED)
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Refresh(
                 pages = listOf(TransformablePage(0, listOf(0, 1))),
                 placeholdersBefore = 4,
@@ -313,14 +313,14 @@
                 combinedLoadStates = CombinedLoadStates.IDLE_SOURCE
             )
         )
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Prepend(
                 pages = listOf(TransformablePage(-1, listOf(-1, -2))),
                 placeholdersBefore = 2,
                 combinedLoadStates = CombinedLoadStates.IDLE_SOURCE
             )
         )
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Append(
                 pages = listOf(TransformablePage(1, listOf(2, 3))),
                 placeholdersAfter = 2,
@@ -361,7 +361,7 @@
         // Insert a new page, PagingDataDiffer should try to resend hint since index 0 still points
         // to a placeholder:
         // [null, null, [], [-1], [1], [3], null, null]
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Prepend(
                 pages = listOf(TransformablePage(-2, listOf())),
                 placeholdersBefore = 2,
@@ -383,7 +383,7 @@
 
         // Drop the previous page, which reset resendable index state in the PREPEND direction.
         // [null, null, [-1], [1], [3], null, null]
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Drop(
                 loadType = PREPEND,
                 minPageOffset = -2,
@@ -395,7 +395,7 @@
         // Re-insert the previous page, which should not trigger resending the index due to
         // previous page drop:
         // [[-3], [], [-1], [1], [3], null, null]
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Prepend(
                 pages = listOf(TransformablePage(-2, listOf())),
                 placeholdersBefore = 2,
@@ -410,7 +410,7 @@
     fun peek() = testScope.runBlockingTest {
         val differ = SimpleDiffer(dummyDifferCallback)
         val pageEventCh = Channel<PageEvent<Int>>(Channel.UNLIMITED)
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Refresh(
                 pages = listOf(TransformablePage(0, listOf(0, 1))),
                 placeholdersBefore = 4,
@@ -418,14 +418,14 @@
                 combinedLoadStates = CombinedLoadStates.IDLE_SOURCE
             )
         )
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Prepend(
                 pages = listOf(TransformablePage(-1, listOf(-1, -2))),
                 placeholdersBefore = 2,
                 combinedLoadStates = CombinedLoadStates.IDLE_SOURCE
             )
         )
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Append(
                 pages = listOf(TransformablePage(1, listOf(2, 3))),
                 placeholdersAfter = 2,
@@ -471,7 +471,7 @@
             differ.collectFrom(PagingData(pageEventCh.consumeAsFlow(), uiReceiver))
         }
 
-        pageEventCh.offer(
+        pageEventCh.trySend(
             Refresh(
                 pages = listOf(TransformablePage(emptyList())),
                 placeholdersBefore = 0,
diff --git a/paging/common/src/test/kotlin/androidx/paging/SingleRunnerTest.kt b/paging/common/src/test/kotlin/androidx/paging/SingleRunnerTest.kt
index 7e6ec72..fe0890e 100644
--- a/paging/common/src/test/kotlin/androidx/paging/SingleRunnerTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/SingleRunnerTest.kt
@@ -18,6 +18,7 @@
 
 import com.google.common.truth.Truth.assertThat
 import kotlinx.coroutines.CancellationException
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.GlobalScope
@@ -140,6 +141,7 @@
         assertThat(output.joinToString("")).isEqualTo("0a1b2c3d")
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun ensureIsolation_whenCancelationIsIgnoredByThePreviousBlock() {
         // make sure we wait for previous one if it ignores cancellation
diff --git a/paging/runtime/src/androidTest/java/androidx/paging/LivePagedListTest.kt b/paging/runtime/src/androidTest/java/androidx/paging/LivePagedListTest.kt
index 8a8be14..c3138ca 100644
--- a/paging/runtime/src/androidTest/java/androidx/paging/LivePagedListTest.kt
+++ b/paging/runtime/src/androidTest/java/androidx/paging/LivePagedListTest.kt
@@ -26,6 +26,7 @@
 import androidx.test.filters.SmallTest
 import androidx.testutils.TestDispatcher
 import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.asCoroutineDispatcher
@@ -44,6 +45,7 @@
     @Rule
     val instantTaskExecutorRule = InstantTaskExecutorRule()
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun instantiatesPagingSourceOnFetchDispatcher() {
         var pagingSourcesCreated = 0
diff --git a/paging/runtime/src/androidTest/java/androidx/paging/StringPagedList.kt b/paging/runtime/src/androidTest/java/androidx/paging/StringPagedList.kt
index 801ffb9..2f208b5 100644
--- a/paging/runtime/src/androidTest/java/androidx/paging/StringPagedList.kt
+++ b/paging/runtime/src/androidTest/java/androidx/paging/StringPagedList.kt
@@ -19,6 +19,7 @@
 import androidx.paging.PagingSource.LoadResult.Error
 import androidx.paging.PagingSource.LoadResult.Page
 import androidx.testutils.DirectDispatcher
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.runBlocking
 
@@ -46,6 +47,7 @@
     override fun getRefreshKey(state: PagingState<Any, Value>): Any? = null
 }
 
+@OptIn(DelicateCoroutinesApi::class)
 @Suppress("TestFunctionName", "DEPRECATION")
 fun StringPagedList(
     leadingNulls: Int,
diff --git a/paging/runtime/src/main/java/androidx/paging/LivePagedList.kt b/paging/runtime/src/main/java/androidx/paging/LivePagedList.kt
index e9b696a..4addf51 100644
--- a/paging/runtime/src/main/java/androidx/paging/LivePagedList.kt
+++ b/paging/runtime/src/main/java/androidx/paging/LivePagedList.kt
@@ -23,6 +23,7 @@
 import androidx.paging.LoadType.REFRESH
 import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.asCoroutineDispatcher
@@ -228,6 +229,7 @@
  *
  * @see LivePagedListBuilder
  */
+@OptIn(DelicateCoroutinesApi::class)
 @Suppress("DEPRECATION")
 @Deprecated(
     message = "PagedList is deprecated and has been replaced by PagingData",
@@ -286,6 +288,7 @@
  *
  * @see LivePagedListBuilder
  */
+@OptIn(DelicateCoroutinesApi::class)
 @Suppress("DEPRECATION")
 @Deprecated(
     message = "PagedList is deprecated and has been replaced by PagingData",
diff --git a/paging/runtime/src/main/java/androidx/paging/LivePagedListBuilder.kt b/paging/runtime/src/main/java/androidx/paging/LivePagedListBuilder.kt
index 907a45a..c770466 100644
--- a/paging/runtime/src/main/java/androidx/paging/LivePagedListBuilder.kt
+++ b/paging/runtime/src/main/java/androidx/paging/LivePagedListBuilder.kt
@@ -19,6 +19,7 @@
 import androidx.arch.core.executor.ArchTaskExecutor
 import androidx.lifecycle.LiveData
 import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.asCoroutineDispatcher
 import java.util.concurrent.Executor
@@ -43,6 +44,7 @@
 
     @Suppress("DEPRECATION")
     private val config: PagedList.Config
+    @OptIn(DelicateCoroutinesApi::class)
     private var coroutineScope: CoroutineScope = GlobalScope
     private var initialLoadKey: Key? = null
 
diff --git a/paging/rxjava2/src/main/java/androidx/paging/RxPagedListBuilder.kt b/paging/rxjava2/src/main/java/androidx/paging/RxPagedListBuilder.kt
index 9397d75..b3b7ad4 100644
--- a/paging/rxjava2/src/main/java/androidx/paging/RxPagedListBuilder.kt
+++ b/paging/rxjava2/src/main/java/androidx/paging/RxPagedListBuilder.kt
@@ -27,6 +27,7 @@
 import io.reactivex.Scheduler
 import io.reactivex.functions.Cancellable
 import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.launch
@@ -334,6 +335,7 @@
         return buildObservable().toFlowable(backpressureStrategy)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Suppress("DEPRECATION")
     internal class PagingObservableOnSubscribe<Key : Any, Value : Any>(
         initialLoadKey: Key?,
diff --git a/paging/rxjava2/src/main/java/androidx/paging/rxjava2/RxPagingData.kt b/paging/rxjava2/src/main/java/androidx/paging/rxjava2/RxPagingData.kt
index 1fac47a..35d63af 100644
--- a/paging/rxjava2/src/main/java/androidx/paging/rxjava2/RxPagingData.kt
+++ b/paging/rxjava2/src/main/java/androidx/paging/rxjava2/RxPagingData.kt
@@ -28,6 +28,7 @@
 import io.reactivex.Maybe
 import io.reactivex.Single
 import kotlinx.coroutines.rx2.await
+import kotlinx.coroutines.rx2.awaitSingleOrNull
 
 /**
  * Returns a [PagingData] containing the result of applying the given [transform] to each
@@ -72,4 +73,6 @@
 @CheckResult
 fun <T : R, R : Any> PagingData<T>.insertSeparatorsAsync(
     generator: (T?, T?) -> Maybe<R>
-): PagingData<R> = insertSeparators { before, after -> generator(before, after).await() }
+): PagingData<R> = insertSeparators { before, after ->
+    generator(before, after).awaitSingleOrNull()
+}
diff --git a/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagedListBuilder.kt b/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagedListBuilder.kt
index 0a48711..a183075 100644
--- a/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagedListBuilder.kt
+++ b/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagedListBuilder.kt
@@ -36,6 +36,7 @@
 import io.reactivex.rxjava3.core.Scheduler
 import io.reactivex.rxjava3.functions.Cancellable
 import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.launch
@@ -343,6 +344,7 @@
         return buildObservable().toFlowable(backpressureStrategy)
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Suppress("DEPRECATION")
     internal class PagingObservableOnSubscribe<Key : Any, Value : Any>(
         initialLoadKey: Key?,
diff --git a/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagingData.kt b/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagingData.kt
index c834f33..d5d9a2e 100644
--- a/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagingData.kt
+++ b/paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagingData.kt
@@ -28,6 +28,7 @@
 import io.reactivex.rxjava3.core.Maybe
 import io.reactivex.rxjava3.core.Single
 import kotlinx.coroutines.rx3.await
+import kotlinx.coroutines.rx3.awaitSingleOrNull
 
 /**
  * Returns a [PagingData] containing the result of applying the given [transform] to each
@@ -72,4 +73,6 @@
 @CheckResult
 fun <T : R, R : Any> PagingData<T>.insertSeparatorsAsync(
     generator: (T?, T?) -> Maybe<R>
-): PagingData<R> = insertSeparators { before, after -> generator(before, after).await() }
+): PagingData<R> = insertSeparators { before, after ->
+    generator(before, after).awaitSingleOrNull()
+}
diff --git a/room/room-ktx/src/androidTest/java/androidx/room/CoroutineRoomCancellationTest.kt b/room/room-ktx/src/androidTest/java/androidx/room/CoroutineRoomCancellationTest.kt
index 96c5369..252b1b1 100644
--- a/room/room-ktx/src/androidTest/java/androidx/room/CoroutineRoomCancellationTest.kt
+++ b/room/room-ktx/src/androidTest/java/androidx/room/CoroutineRoomCancellationTest.kt
@@ -22,6 +22,7 @@
 import androidx.test.filters.SdkSuppress
 import androidx.test.filters.SmallTest
 import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.GlobalScope
@@ -47,6 +48,7 @@
 
     private val database = TestDatabase()
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testSuspend_cancellable_duringLongQuery() = runBlocking {
         database.backingFieldMap["QueryDispatcher"] = Dispatchers.IO
@@ -80,7 +82,7 @@
         assertThat(cancellationSignal.isCanceled).isTrue()
     }
 
-    @OptIn(ExperimentalCoroutinesApi::class)
+    @OptIn(ExperimentalCoroutinesApi::class, DelicateCoroutinesApi::class)
     @Test
     fun testSuspend_cancellable_beforeQueryStarts() = runBlocking {
         database.backingFieldMap["QueryDispatcher"] = testDispatcher
@@ -118,6 +120,7 @@
         assertThat(cancellationSignal.isCanceled).isTrue()
     }
 
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testSuspend_exception_in_query() = runBlocking {
         database.backingFieldMap["QueryDispatcher"] = Dispatchers.IO
diff --git a/room/room-ktx/src/main/java/androidx/room/CoroutinesRoom.kt b/room/room-ktx/src/main/java/androidx/room/CoroutinesRoom.kt
index 8a71fe9..aee1d64 100644
--- a/room/room-ktx/src/main/java/androidx/room/CoroutinesRoom.kt
+++ b/room/room-ktx/src/main/java/androidx/room/CoroutinesRoom.kt
@@ -21,6 +21,7 @@
 import androidx.annotation.RestrictTo
 import androidx.sqlite.db.SupportSQLiteCompat
 import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.asCoroutineDispatcher
 import kotlinx.coroutines.channels.Channel
@@ -65,6 +66,7 @@
             }
         }
 
+        @OptIn(DelicateCoroutinesApi::class)
         @JvmStatic
         public suspend fun <R> execute(
             db: RoomDatabase,
@@ -110,10 +112,10 @@
                 val observerChannel = Channel<Unit>(Channel.CONFLATED)
                 val observer = object : InvalidationTracker.Observer(tableNames) {
                     override fun onInvalidated(tables: MutableSet<String>) {
-                        observerChannel.offer(Unit)
+                        observerChannel.trySend(Unit)
                     }
                 }
-                observerChannel.offer(Unit) // Initial signal to perform first query.
+                observerChannel.trySend(Unit) // Initial signal to perform first query.
                 val queryContext = coroutineContext[TransactionElement]?.transactionDispatcher
                     ?: if (inTransaction) db.transactionDispatcher else db.queryDispatcher
                 val resultChannel = Channel<R>()
diff --git a/sqlite/sqlite-inspection/src/androidTest/java/androidx/sqlite/inspection/test/CancellationQueryTest.kt b/sqlite/sqlite-inspection/src/androidTest/java/androidx/sqlite/inspection/test/CancellationQueryTest.kt
index 873ccbd..997730a 100644
--- a/sqlite/sqlite-inspection/src/androidTest/java/androidx/sqlite/inspection/test/CancellationQueryTest.kt
+++ b/sqlite/sqlite-inspection/src/androidTest/java/androidx/sqlite/inspection/test/CancellationQueryTest.kt
@@ -63,7 +63,7 @@
         assertThat(countingExecutorService.events.receive()).isEqualTo(STARTED)
         assertThat(countingExecutorService.events.receive()).isEqualTo(FINISHED)
         assertThat(result.rowsCount).isEqualTo(22)
-        assertThat(countingExecutorService.events.poll()).isNull()
+        assertThat(countingExecutorService.events.tryReceive().getOrNull()).isNull()
         job.cancelAndJoin()
         // check that task finished after cancellation
         assertThat(countingExecutorService.events.receive()).isEqualTo(FINISHED)
@@ -83,11 +83,11 @@
 
     override fun execute(command: Runnable) {
         executor.execute {
-            channel.offer(STARTED)
+            channel.trySend(STARTED)
             try {
                 command.run()
             } finally {
-                channel.offer(FINISHED)
+                channel.trySend(FINISHED)
             }
         }
     }
diff --git a/window/window-java/src/androidTest/java/androidx/window/java/WindowInfoRepoJavaAdapterTest.kt b/window/window-java/src/androidTest/java/androidx/window/java/WindowInfoRepoJavaAdapterTest.kt
index 688df0e..d87aed7 100644
--- a/window/window-java/src/androidTest/java/androidx/window/java/WindowInfoRepoJavaAdapterTest.kt
+++ b/window/window-java/src/androidTest/java/androidx/window/java/WindowInfoRepoJavaAdapterTest.kt
@@ -117,7 +117,7 @@
         unitUnderTest.addWindowLayoutInfoListener(Runnable::run, testConsumer)
         unitUnderTest.addWindowLayoutInfoListener(Runnable::run, mock())
         unitUnderTest.removeWindowLayoutInfoListener(testConsumer)
-        val accepted = channel.offer(info)
+        val accepted = channel.trySend(info).isSuccess
 
         assertTrue(accepted)
         testConsumer.assertEmpty()
diff --git a/window/window/src/main/java/androidx/window/WindowInfoRepoImp.kt b/window/window/src/main/java/androidx/window/WindowInfoRepoImp.kt
index f3f0105..206f2c0 100644
--- a/window/window/src/main/java/androidx/window/WindowInfoRepoImp.kt
+++ b/window/window/src/main/java/androidx/window/WindowInfoRepoImp.kt
@@ -100,7 +100,7 @@
      */
     override val windowLayoutInfo: Flow<WindowLayoutInfo>
         get() = callbackFlow {
-            val callback = Consumer<WindowLayoutInfo> { info -> offer(info) }
+            val callback = Consumer<WindowLayoutInfo> { info -> trySend(info) }
             windowBackend.registerLayoutChangeCallback(activity, Runnable::run, callback)
             awaitClose { windowBackend.unregisterLayoutChangeCallback(callback) }
         }.buffer(capacity = UNLIMITED)
diff --git a/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt b/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt
index 5f26e92..3774674 100644
--- a/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt
+++ b/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt
@@ -21,6 +21,7 @@
 import androidx.concurrent.futures.ResolvableFuture
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.SmallTest
+import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.runBlocking
@@ -33,6 +34,7 @@
 @RunWith(AndroidJUnit4::class)
 @SmallTest
 class ListenableFutureTest {
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testFutureWithResult() {
         val future: ResolvableFuture<Int> = ResolvableFuture.create()
@@ -45,6 +47,7 @@
             job.join()
         }
     }
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testFutureWithException() {
         val future: ResolvableFuture<Int> = ResolvableFuture.create()
@@ -62,6 +65,7 @@
             job.join()
         }
     }
+    @OptIn(DelicateCoroutinesApi::class)
     @Test
     fun testFutureCancellation() {
         val future: ResolvableFuture<Int> = ResolvableFuture.create()