nils277
nils277

Reputation: 261

Android ANR in "android.app.ResourcesManager"

Recently i see a quite significant increase of ANRs in the Google Play Console for my app. There are reports for different types of causes but they have one thing in common:
Both the main thread and my worker thread are blocked and at least one of them is always blocked while accessing a method from "android.app.ResourcesManager"

Example 1:

"main" prio=5 tid=1 Blocked

at android.app.ResourcesManager.getAdjustedDisplay (ResourcesManager.java:353)
at android.app.ContextImpl.getDisplayNoVerify (ContextImpl.java:2559)
at android.view.WindowManagerImpl.getDefaultDisplay (WindowManagerImpl.java:164)
at org.n277.lynxlauncher.helper.DeviceUtilities.updateSystemHelper (DeviceUtilities.java:225)
at org.n277.lynxlauncher.views.DragContainerFrameLayout.onApplyWindowInsets (DragContainerFrameLayout.java:231)
at android.view.View.dispatchApplyWindowInsets (View.java:11399)
at android.view.ViewGroup.dispatchApplyWindowInsets (ViewGroup.java:7393)
at android.view.ViewGroup.newDispatchApplyWindowInsets (ViewGroup.java:7418)
at android.view.ViewGroup.dispatchApplyWindowInsets (ViewGroup.java:7400)
at android.view.ViewGroup.newDispatchApplyWindowInsets (ViewGroup.java:7418)
...

"Lynx-Worker" prio=5 tid=17 Blocked

at android.app.ResourcesManager.getOrCreateResources (ResourcesManager.java:865)
at android.app.ResourcesManager.getResources (ResourcesManager.java:982)
at android.app.ActivityThread.getTopLevelResources (ActivityThread.java:2411)
at android.app.ApplicationPackageManager.getResourcesForApplication (ApplicationPackageManager.java:1527)
at android.app.ApplicationPackageManager.getDrawable (ApplicationPackageManager.java:1277)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2684)
at android.app.ApplicationPackageManager.loadItemIcon (ApplicationPackageManager.java:2655)
at android.content.pm.PackageItemInfo.loadIcon (PackageItemInfo.java:516)
at android.content.pm.ComponentInfo.loadDefaultIcon (ComponentInfo.java:256)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2687)
at android.app.ApplicationPackageManager.loadItemIcon (ApplicationPackageManager.java:2655)
at android.content.pm.PackageItemInfo.loadIcon (PackageItemInfo.java:516)
at android.content.pm.LauncherActivityInfo.getIcon (LauncherActivityInfo.java:117)
at org.n277.lynxlauncher.visual.c.d.v (SourceFile:1)
at org.n277.lynxlauncher.visual.c.d.u (SourceFile:3)
...

The main thread tries to get the display size for measurement using the "windowManager.getDefaultDisplay().getSize()" method (for Pre Android R devices). The worker thread tries to get the Icon of an Application using a LauncherActivityInfo.

Example 2:

"main" prio=5 tid=1 Blocked

at android.view.WindowManagerImpl.getCurrentBounds (WindowManagerImpl.java:241)
at android.view.WindowManagerImpl.getCurrentWindowMetrics (WindowManagerImpl.java:235)
at org.n277.lynxlauncher.helper.DeviceUtilities.getUsableHeight (DeviceUtilities.java:190)
at org.n277.lynxlauncher.views.FullScreenFrameLayout.onMeasure (FullScreenFrameLayout.java:114)
at android.view.View.measure (View.java:25532)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
at android.view.View.measure (View.java:25532)
at android.widget.RelativeLayout.measureChildHorizontal (RelativeLayout.java:735)
...

"Lynx-Worker" prio=5 tid=17 Blocked

at android.app.ResourcesManager.createResources (ResourcesManager.java:846)
at android.app.ResourcesManager.getResources (ResourcesManager.java:947)
at android.app.ActivityThread.getTopLevelResources (ActivityThread.java:2296)
at android.app.ApplicationPackageManager.getResourcesForApplication (ApplicationPackageManager.java:1672)
at android.app.ApplicationPackageManager.getDrawable (ApplicationPackageManager.java:1437)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2950)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2953)
at android.app.ApplicationPackageManager.loadItemIcon (ApplicationPackageManager.java:2929)
at android.content.pm.PackageItemInfo.loadIcon (PackageItemInfo.java:271)
at android.content.pm.LauncherActivityInfo.getIcon (LauncherActivityInfo.java:119)
at org.n277.lynxlauncher.visual.c.d.v (SourceFile:1)
at org.n277.lynxlauncher.visual.c.d.u (SourceFile:3)
...

Again, the main thread tries to get the display size for measurement, but this time using windowManager.getCurrentWindowMetrics(). The worker thread again tries to get the Icon of an Application using a LauncherActivityInfo.

Example 3:

Exactly the same as example 2, but there is another generic thread stuck with the very same trace as the worker thread.

For me it really looks like there is some sort of deadlock when accessing the "android.app.ResourcesManager" class from multuple threads. I suspect that also "WindowManagerImpl.getCurrentBounds" is accessing the ResourcesManager although it is not shown explicidly. However, this did not happen before the last update and i have not changed anything regarding the threading. The only thing that comes into my mind is that i updated several dependencies:

buildToolsVersion from 30.0.0 to 30.0.2
com.android.billingclient:billing from 3.0.3 to 4.0.0
androidx.appcompat:appcompat from 1.2.0 to 1.3.0
androidx.recyclerview:recyclerview from 1.1.0 to 1.2.1

What i suspect is thas it is causing problems now when the Resources are accessed from multiple threads simultaneously. Moving the App Icon loading into the main thread however does not seem wise to me as this would clog this thread easily. For the "LauncherActivityInfo.getIcon" method it is clear that it has to access the resources to get the icon of the app (although not the resources of the app the method is called from but from the app from which the icon should be loaded). However many other tasks are also performed in the worker thread and many of the called API methods could also access the resources internally even though it is not obvious.

Has anyone else experiencef problems of this kind? (after an update of one of the above mentioned dependencies). Or has anyone found a workaround/solution to this specific ANR?

Upvotes: 4

Views: 582

Answers (0)

Related Questions