Status Update
Comments
du...@google.com <du...@google.com> #2
Fixed with the following CL (missed tagging this bug):
There will be additional follow up work (handling new mainline versions that fix the issue), but we'll file separate bugs to improve that.
yb...@google.com <yb...@google.com> #3
How To Get Method Tracing Working in Microbench
Options:
1) Flash API 23 through 25
2) Flash API 31 through 33, and disable wifi/network on the device
Not connecting to the network prevents mainline updates. You can validate that your device hasn't taken a problematic mainline version with the following shell command:
adb shell cmd package list packages --show-versioncode --apex-only art
You should see e.g.:
package:com.google.android.art versionCode:320000000
If the first two digits of the version code are less than 34, you're good, method tracing will work and be on by default in microbench.
3) Force Mainline Update with Fix (will be documented later)
yb...@google.com <yb...@google.com> #4
i can reproduce this in the github sample app where LimitOffsetDataSource calls refreshVersionsSync
on the main thread, which is a problem :/
yb...@google.com <yb...@google.com> #5
sorry to clarify, it happens only on pull to refresh.
yb...@google.com <yb...@google.com> #7
and appearantly we already knew about this:
yb...@google.com <yb...@google.com> #8
btw, until we fix this, you can work around it by adding a flowOn(some background dispatcher)
your pagingData collector which will work around this issue by always calling the factory on a background thread.
ap...@google.com <ap...@google.com> #9
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
yb...@google.com <yb...@google.com>
sa...@gmail.com <sa...@gmail.com> #10
For the ones like me, an android dev working on a real project using the Paging 3, the suggested workaround flowOn(some background dispatcher)
was the only solution that fixed my need of creating a source in a suspendable fashion.
Why not allowing the pagingSourceFactory
to be suspendable? I didn't find a prettier solution than doing:
// viewModel
pagingSourceFactory = { runBlocking { createPagingSource() } }
// fragment
viewLifecycleOwner.lifecycleScope.launchWhenStarted {
successState.results
.flowOn(Dispatchers.IO)
.collect(searchResultsAdapter::submitData)
}
Which is not readable nor straightforward. At least, opening your internal SuspendingPagingSourceFactory<Key, Value>
would help, letting me extend my source factory to be cleaner and readable.
Description
Component used: paging3 Version used: androidx.paging:paging-runtime-ktx:3.0.0-alpha09 Devices/Android versions reproduced on: Pixel 4 xl
sometimes ANR happens, see BLOCKED threads