Use display awake signal to replace screen-off signal for sleep token.

For sleep token, device goingToSleep/awake might be more reliable than
screen on/off since it can be affected by AOD, we can consider this as
a signal to sleep device.
And move the SleepTokenAcquirer to DisplayPolicy, we don't need the
SleepTokenAcquirer interface on ActivityTaskManagerInternal anymore.
Also reuse the acquirer on RootWindowContainer for default display
so there does not need to create another one.

Bug: 199633495
Test: atest KeyguardTests KeyguardTransitionTests
Change-Id: I676cd5855f31d31d7acba9f161d27bdaf58844f1
(cherry picked from commit 0760ca28ea)
This commit is contained in:
wilsonshih
2021-10-04 18:12:30 +08:00
committed by Wei Sheng Shih
parent 7a937c356e
commit 357fe2f190
7 changed files with 38 additions and 65 deletions

View File

@@ -519,7 +519,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private boolean mPendingKeyguardOccluded;
private boolean mKeyguardOccludedChanged;
private ActivityTaskManagerInternal.SleepTokenAcquirer mScreenOffSleepTokenAcquirer;
Intent mHomeIntent;
Intent mCarDockIntent;
Intent mDeskDockIntent;
@@ -1817,9 +1816,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
new AccessibilityShortcutController(mContext, new Handler(), mCurrentUserId);
mLogger = new MetricsLogger();
mScreenOffSleepTokenAcquirer = mActivityTaskManagerInternal
.createSleepTokenAcquirer("ScreenOff");
Resources res = mContext.getResources();
mWakeOnDpadKeyPress =
res.getBoolean(com.android.internal.R.bool.config_wakeOnDpadKeyPress);
@@ -4485,7 +4481,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (DEBUG_WAKEUP) Slog.i(TAG, "Display" + displayId + " turned off...");
if (displayId == DEFAULT_DISPLAY) {
updateScreenOffSleepToken(true);
mRequestedOrSleepingDefaultDisplay = false;
mDefaultDisplayPolicy.screenTurnedOff();
synchronized (mLock) {
@@ -4518,7 +4513,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (displayId == DEFAULT_DISPLAY) {
Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenTurningOn",
0 /* cookie */);
updateScreenOffSleepToken(false);
mDefaultDisplayPolicy.screenTurnedOn(screenOnListener);
mBootAnimationDismissable = false;
@@ -5039,15 +5033,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
// TODO (multidisplay): Support multiple displays in WindowManagerPolicy.
private void updateScreenOffSleepToken(boolean acquire) {
if (acquire) {
mScreenOffSleepTokenAcquirer.acquire(DEFAULT_DISPLAY);
} else {
mScreenOffSleepTokenAcquirer.release(DEFAULT_DISPLAY);
}
}
/** {@inheritDoc} */
@Override
public void enableScreenAfterBoot() {

View File

@@ -125,35 +125,6 @@ public abstract class ActivityTaskManagerInternal {
void onKeyguardStateChanged(boolean isShowing);
}
/**
* Sleep tokens cause the activity manager to put the top activity to sleep.
* They are used by components such as dreams that may hide and block interaction
* with underlying activities.
* The Acquirer provides an interface that encapsulates the underlying work, so the user does
* not need to handle the token by him/herself.
*/
public interface SleepTokenAcquirer {
/**
* Acquires a sleep token.
* @param displayId The display to apply to.
*/
void acquire(int displayId);
/**
* Releases the sleep token.
* @param displayId The display to apply to.
*/
void release(int displayId);
}
/**
* Creates a sleep token acquirer for the specified display with the specified tag.
*
* @param tag A string identifying the purpose (eg. "Dream").
*/
public abstract SleepTokenAcquirer createSleepTokenAcquirer(@NonNull String tag);
/**
* Returns home activity for the specified user.
*

View File

@@ -4544,17 +4544,25 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
reason);
}
final class SleepTokenAcquirerImpl implements ActivityTaskManagerInternal.SleepTokenAcquirer {
/**
* Sleep tokens cause the activity manager to put the top activity to sleep.
* They are used by components such as dreams that may hide and block interaction
* with underlying activities.
*/
final class SleepTokenAcquirer {
private final String mTag;
private final SparseArray<RootWindowContainer.SleepToken> mSleepTokens =
new SparseArray<>();
SleepTokenAcquirerImpl(@NonNull String tag) {
SleepTokenAcquirer(@NonNull String tag) {
mTag = tag;
}
@Override
public void acquire(int displayId) {
/**
* Acquires a sleep token.
* @param displayId The display to apply to.
*/
void acquire(int displayId) {
synchronized (mGlobalLock) {
if (!mSleepTokens.contains(displayId)) {
mSleepTokens.append(displayId,
@@ -4564,8 +4572,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
}
@Override
public void release(int displayId) {
/**
* Releases the sleep token.
* @param displayId The display to apply to.
*/
void release(int displayId) {
synchronized (mGlobalLock) {
final RootWindowContainer.SleepToken token = mSleepTokens.get(displayId);
if (token != null) {
@@ -5254,12 +5265,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
final class LocalService extends ActivityTaskManagerInternal {
@Override
public SleepTokenAcquirer createSleepTokenAcquirer(@NonNull String tag) {
Objects.requireNonNull(tag);
return new SleepTokenAcquirerImpl(tag);
}
@Override
public ComponentName getHomeActivityForUser(int userId) {
synchronized (mGlobalLock) {

View File

@@ -662,7 +662,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
/** All tokens used to put activities on this root task to sleep (including mOffToken) */
final ArrayList<RootWindowContainer.SleepToken> mAllSleepTokens = new ArrayList<>();
/** The token acquirer to put root tasks on the display to sleep */
private final ActivityTaskManagerInternal.SleepTokenAcquirer mOffTokenAcquirer;
private final ActivityTaskManagerService.SleepTokenAcquirer mOffTokenAcquirer;
private boolean mSleeping;
@@ -5424,6 +5424,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
return mMetricsLogger;
}
void acquireScreenOffToken(boolean acquire) {
if (acquire) {
mOffTokenAcquirer.acquire(mDisplayId);
} else {
mOffTokenAcquirer.release(mDisplayId);
}
}
void onDisplayChanged() {
mDisplay.getRealSize(mTmpDisplaySize);
setBounds(0, 0, mTmpDisplaySize.x, mTmpDisplaySize.y);
@@ -5434,9 +5442,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
if (displayId != DEFAULT_DISPLAY) {
final int displayState = mDisplay.getState();
if (displayState == Display.STATE_OFF) {
mOffTokenAcquirer.acquire(mDisplayId);
acquireScreenOffToken(true /* acquire */);
} else if (displayState == Display.STATE_ON) {
mOffTokenAcquirer.release(mDisplayId);
acquireScreenOffToken(false /* acquire */);
}
ProtoLog.v(WM_DEBUG_LAYER_MIRRORING,
"Display %d state is now (%d), so update layer mirroring?",

View File

@@ -752,6 +752,10 @@ public class DisplayPolicy {
public void setAwake(boolean awake) {
mAwake = awake;
// The screen off token for non-default display is controlled by DisplayContent.
if (mDisplayContent.isDefaultDisplay) {
mDisplayContent.acquireScreenOffToken(!awake);
}
}
public boolean isAwake() {

View File

@@ -75,14 +75,14 @@ class KeyguardController {
private final SparseArray<KeyguardDisplayState> mDisplayStates = new SparseArray<>();
private final ActivityTaskManagerService mService;
private RootWindowContainer mRootWindowContainer;
private final ActivityTaskManagerInternal.SleepTokenAcquirer mSleepTokenAcquirer;
private final ActivityTaskManagerService.SleepTokenAcquirer mSleepTokenAcquirer;
KeyguardController(ActivityTaskManagerService service,
ActivityTaskSupervisor taskSupervisor) {
mService = service;
mTaskSupervisor = taskSupervisor;
mSleepTokenAcquirer = mService.new SleepTokenAcquirerImpl(KEYGUARD_SLEEP_TOKEN_TAG);
mSleepTokenAcquirer = mService.new SleepTokenAcquirer(KEYGUARD_SLEEP_TOKEN_TAG);
}
void setWindowManager(WindowManagerService windowManager) {
@@ -513,10 +513,10 @@ class KeyguardController {
private boolean mRequestDismissKeyguard;
private final ActivityTaskManagerService mService;
private final ActivityTaskManagerInternal.SleepTokenAcquirer mSleepTokenAcquirer;
private final ActivityTaskManagerService.SleepTokenAcquirer mSleepTokenAcquirer;
KeyguardDisplayState(ActivityTaskManagerService service, int displayId,
ActivityTaskManagerInternal.SleepTokenAcquirer acquirer) {
ActivityTaskManagerService.SleepTokenAcquirer acquirer) {
mService = service;
mDisplayId = displayId;
mSleepTokenAcquirer = acquirer;

View File

@@ -225,7 +225,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
private static final String DISPLAY_OFF_SLEEP_TOKEN_TAG = "Display-off";
/** The token acquirer to put root tasks on the displays to sleep */
final ActivityTaskManagerInternal.SleepTokenAcquirer mDisplayOffTokenAcquirer;
final ActivityTaskManagerService.SleepTokenAcquirer mDisplayOffTokenAcquirer;
/**
* The modes which affect which tasks are returned when calling
@@ -470,7 +470,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
mService = service.mAtmService;
mTaskSupervisor = mService.mTaskSupervisor;
mTaskSupervisor.mRootWindowContainer = this;
mDisplayOffTokenAcquirer = mService.new SleepTokenAcquirerImpl(DISPLAY_OFF_SLEEP_TOKEN_TAG);
mDisplayOffTokenAcquirer = mService.new SleepTokenAcquirer(DISPLAY_OFF_SLEEP_TOKEN_TAG);
}
boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {