Fixed
Status Update
Comments
du...@google.com <du...@google.com> #2
LegacyPagingSource compat path for DataSource depends on this for now.
yb...@google.com <yb...@google.com> #3
seems like we can do this since it can add observe itself ?
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit cfd1258a8911348898cd07d1b02b00d14917159d
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Dec 01 17:01:50 2020
Ensure legacy data source is always created on the fetcher
This CL fixes a bug where we could possibly create the legacy data
source on the main thread (more specifically, the thread where flow
collection happens).
We already tried to prevent it by making it lazy, assuming the first
call will be a loadInitial call but it is not the case for invalidations
where we end up calling dataSource.isInvalid which might create it
(lazy) and then call isInvalid. This issue became more appearant because
Room's limit offset data source implementations might run a database
query to check for invalidation, possibly causing ANR.
In this CL, I changed the paging source factory to be a suspend function
in Fetcher (it is internal class). Public API (Pager) still expects a
regular function. To workaround it, now asPagingSource returns a known
internal class (SuspendingPagingSourceFactory) which extends Function0
but also has another suspend function to create the paging source.
Pager, when initializing PageFetcher, checks the instance of the
function to unwrap it before creating the fetcher.
This WONT work if someone wraps that function but besides that, for the
common case, this should fix the issue until we can move everyone off of
Paging2 APIs, including Room.
I've also slightly changed the legacy paging source implementation not
to rely on overriding invalidate to be able to remove that method from
public API.
Bug: 173029013
Bug: 137971356
Test: LegacyPagingSourceTest
RelNote: "PagingSource.invalidate is no longer an open function. If you
need to get notified when invalidation happens, consider calling the
registerInvalidatedCallback method instead of overriding invalidate."
Change-Id: I628d9893a4ac55409aa24e49de1e2d2c35beda4f
M paging/common/api/current.txt
M paging/common/api/public_plus_experimental_current.txt
M paging/common/api/restricted_current.txt
M paging/common/src/main/kotlin/androidx/paging/DataSource.kt
M paging/common/src/main/kotlin/androidx/paging/LegacyPagingSource.kt
M paging/common/src/main/kotlin/androidx/paging/PageFetcher.kt
M paging/common/src/main/kotlin/androidx/paging/PagedList.kt
M paging/common/src/main/kotlin/androidx/paging/Pager.kt
M paging/common/src/main/kotlin/androidx/paging/PagingSource.kt
A paging/common/src/main/kotlin/androidx/paging/SuspendingPagingSourceFactory.kt
M paging/common/src/test/kotlin/androidx/paging/LegacyPagingSourceTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageKeyedDataSourceTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagedListTest.kt
M paging/runtime/src/androidTest/java/androidx/paging/AsyncPagedListDifferTest.kt
M testutils/testutils-common/src/main/java/androidx/testutils/TestExecutor.kt
https://android-review.googlesource.com/1515484
Branch: androidx-master-dev
commit cfd1258a8911348898cd07d1b02b00d14917159d
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Dec 01 17:01:50 2020
Ensure legacy data source is always created on the fetcher
This CL fixes a bug where we could possibly create the legacy data
source on the main thread (more specifically, the thread where flow
collection happens).
We already tried to prevent it by making it lazy, assuming the first
call will be a loadInitial call but it is not the case for invalidations
where we end up calling dataSource.isInvalid which might create it
(lazy) and then call isInvalid. This issue became more appearant because
Room's limit offset data source implementations might run a database
query to check for invalidation, possibly causing ANR.
In this CL, I changed the paging source factory to be a suspend function
in Fetcher (it is internal class). Public API (Pager) still expects a
regular function. To workaround it, now asPagingSource returns a known
internal class (SuspendingPagingSourceFactory) which extends Function0
but also has another suspend function to create the paging source.
Pager, when initializing PageFetcher, checks the instance of the
function to unwrap it before creating the fetcher.
This WONT work if someone wraps that function but besides that, for the
common case, this should fix the issue until we can move everyone off of
Paging2 APIs, including Room.
I've also slightly changed the legacy paging source implementation not
to rely on overriding invalidate to be able to remove that method from
public API.
Bug: 173029013
Bug: 137971356
Test: LegacyPagingSourceTest
RelNote: "PagingSource.invalidate is no longer an open function. If you
need to get notified when invalidation happens, consider calling the
registerInvalidatedCallback method instead of overriding invalidate."
Change-Id: I628d9893a4ac55409aa24e49de1e2d2c35beda4f
M paging/common/api/current.txt
M paging/common/api/public_plus_experimental_current.txt
M paging/common/api/restricted_current.txt
M paging/common/src/main/kotlin/androidx/paging/DataSource.kt
M paging/common/src/main/kotlin/androidx/paging/LegacyPagingSource.kt
M paging/common/src/main/kotlin/androidx/paging/PageFetcher.kt
M paging/common/src/main/kotlin/androidx/paging/PagedList.kt
M paging/common/src/main/kotlin/androidx/paging/Pager.kt
M paging/common/src/main/kotlin/androidx/paging/PagingSource.kt
A paging/common/src/main/kotlin/androidx/paging/SuspendingPagingSourceFactory.kt
M paging/common/src/test/kotlin/androidx/paging/LegacyPagingSourceTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageKeyedDataSourceTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagedListTest.kt
M paging/runtime/src/androidTest/java/androidx/paging/AsyncPagedListDifferTest.kt
M testutils/testutils-common/src/main/java/androidx/testutils/TestExecutor.kt
Description