commit | 597efc0ae6d1c0b9ba3d3f146c03ef5eb5f83c7c | [log] [tgz] |
---|---|---|
author | mlykotom <[email protected]> | Fri May 12 13:03:02 2023 +0200 |
committer | Android Build Coastguard Worker <[email protected]> | Fri May 12 23:00:10 2023 +0000 |
tree | 0b18dc640b50d38908ff440dca4652b285262932 | |
parent | 6c4fe79ee59d321dd0e29970e4702f6d6b4e41aa [diff] |
Fix ReportDrawn* crashing when navigating away from a screen Doesn't crash when removeReporter() is called multiple times, which is caused by onDismiss and observeReporter(). Relnote: Fix ReportDrawn crashing when navigating away from a screen before report is called. Fixes: 260506820 Test: testDisposingBeforeReporting (cherry picked from https://android-review.googlesource.com/q/commit:5713d41811d5a99c93b5d585cbac46bfaa9ed5a6) Merged-In: Ic46f17d4dfd9a0758398564dce72fbb5f637626e Change-Id: Ic46f17d4dfd9a0758398564dce72fbb5f637626e
diff --git a/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ReportDrawnTest.kt b/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ReportDrawnTest.kt index 75be5f1..db1fee8 100644 --- a/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ReportDrawnTest.kt +++ b/activity/activity-compose/src/androidTest/java/androidx/activity/compose/ReportDrawnTest.kt
@@ -265,4 +265,15 @@ } assertThat(localValue).isSameInstanceAs(fullyDrawnReporterOwner) } + + @Test + fun testDisposingBeforeReporting() { + rule.setContent { + // Reporting never finishes + ReportDrawnWhen { false } + // Report that finishes immediatelly + ReportDrawn() + } + // By going out of the scope, both reporters call onDismiss + } }
diff --git a/activity/activity/src/main/java/androidx/activity/FullyDrawnReporter.kt b/activity/activity/src/main/java/androidx/activity/FullyDrawnReporter.kt index 8c57628..dd87c18 100644 --- a/activity/activity/src/main/java/androidx/activity/FullyDrawnReporter.kt +++ b/activity/activity/src/main/java/androidx/activity/FullyDrawnReporter.kt
@@ -103,10 +103,7 @@ */ fun removeReporter() { synchronized(lock) { - if (!reportedFullyDrawn) { - check(reporterCount > 0) { - "removeReporter() called when all reporters have already been removed." - } + if (!reportedFullyDrawn && reporterCount > 0) { reporterCount-- postWhenReportersAreDone() } @@ -189,4 +186,4 @@ } finally { removeReporter() } -} \ No newline at end of file +}