Reduce unnecessary operations in the setFocusedTask

- Eliminate an extra transition request when swipe-up gesture is
  active from RecentsTransitionHandler.RecentsController
  #setInputConsumerEnabled -> setFocusedTask. The invocation only
  needs to set focus without moving the task.
- Skip notifying unchanged state in
  setLastResumedActivityUncheckLocked.

Bug: 275508603
Test: CtsActivityManagerDeviceTestCases
Change-Id: I7560f98ade59f7e68de07e3cd027adafbc509598
This commit is contained in:
Riddle Hsu
2023-03-28 23:50:43 +08:00
parent 6d3448628d
commit 9e9bc72f94
2 changed files with 19 additions and 11 deletions

View File

@@ -2011,6 +2011,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
return;
}
if (r == mRootWindowContainer.getTopResumedActivity()) {
setLastResumedActivityUncheckLocked(r, "setFocusedTask-alreadyTop");
return;
}
final Transition transition = (getTransitionController().isCollecting()
|| !getTransitionController().isShellTransitionsEnabled()) ? null
: getTransitionController().createTransition(TRANSIT_TO_FRONT);
@@ -4788,11 +4792,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
// until we've committed to the gesture. The focus will be transferred at the end of
// the transition (if the transient launch is committed) or early if explicitly requested
// via `setFocused*`.
boolean focusedAppChanged = false;
if (!getTransitionController().isTransientCollect(r)) {
final Task prevFocusTask = r.mDisplayContent.mFocusedApp != null
? r.mDisplayContent.mFocusedApp.getTask() : null;
final boolean changed = r.mDisplayContent.setFocusedApp(r);
if (changed) {
focusedAppChanged = r.mDisplayContent.setFocusedApp(r);
if (focusedAppChanged) {
mWindowManager.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
true /*updateInputWindows*/);
}
@@ -4801,13 +4804,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
mTaskSupervisor.mRecentTasks.add(task);
}
applyUpdateLockStateLocked(r);
applyUpdateVrModeLocked(r);
if (focusedAppChanged) {
applyUpdateLockStateLocked(r);
}
if (mVrController.mVrService != null) {
applyUpdateVrModeLocked(r);
}
EventLogTags.writeWmSetResumedActivity(
r == null ? -1 : r.mUserId,
r == null ? "NULL" : r.shortComponentName,
reason);
EventLogTags.writeWmSetResumedActivity(r.mUserId, r.shortComponentName, reason);
}
final class SleepTokenAcquirerImpl implements ActivityTaskManagerInternal.SleepTokenAcquirer {

View File

@@ -126,6 +126,9 @@ final class VrController {
}
};
/** If it is null after system ready, then VR mode is not supported. */
VrManagerInternal mVrService;
/**
* Create new VrController instance.
*
@@ -141,6 +144,7 @@ final class VrController {
public void onSystemReady() {
VrManagerInternal vrManagerInternal = LocalServices.getService(VrManagerInternal.class);
if (vrManagerInternal != null) {
mVrService = vrManagerInternal;
vrManagerInternal.addPersistentVrModeStateListener(mPersistentVrModeListener);
}
}
@@ -181,7 +185,7 @@ final class VrController {
public boolean onVrModeChanged(ActivityRecord record) {
// This message means that the top focused activity enabled VR mode (or an activity
// that previously set this has become focused).
VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
final VrManagerInternal vrService = mVrService;
if (vrService == null) {
// VR mode isn't supported on this device.
return false;