Provide window visibility of uid without WM lock
The problems:
- ActivityTaskManagerInternal#isUidForeground is called frequently
from request of bind/start service. It is too heavy to acquire
WM lock each time.
- The isUidForeground calls isAnyNonToastWindowVisibleForUid. It is
inefficient to iterate entire window hierarchy. Especially the
calling uid usually doesn't have a window.
This change:
- Replace isAnyNonToastWindowVisibleForUid with hasActiveVisibleWindow
that queries VisibleActivityProcessTracker for activity, and
MirrorActiveUids for non-app (exclude toast) window. The separation
also makes it simpler to apply special rule to activity window for
background activity launch restriction in the future.
- Both the container have their own lock so WM lock is not needed for
ActivityTaskManagerService#hasActiveVisibleWindow.
- To reflect the latest state, if ActivityRecord#mVisibleRequested or
mVisible is changed, the process and uid state also need be updated.
- Launch a dozen activities after booting. With the same total
invocation count of isUidForegound, the total time becomes 20~30x
faster. While the state update time is negligible because the
structure is very simple and the frequency of change is not high.
- Remove a legacy workaround in WPC#computeProcessActivityState
that checks whether the activity belongs to the process. Because
it was fixed by ActivityRecord#detachFromProcess that ensures
the two-way relation.
Bug: 171490517
Test: WindowStateTests#testHasActiveVisibleWindow
ActivityStarterTests#testBackgroundActivityStarts*
ActivityManagerFgsBgStartTest
BackgroundActivityLaunchTest
Change-Id: Iadca2b79e8971c1a8633e2557f2e8a4184857650
Loading
Please register or sign in to comment