Merge "Wake foldable device when device unfolds." into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d92c7d85d7
@@ -548,6 +548,7 @@ public final class PowerManager {
|
|||||||
WAKE_REASON_HDMI,
|
WAKE_REASON_HDMI,
|
||||||
WAKE_REASON_DISPLAY_GROUP_ADDED,
|
WAKE_REASON_DISPLAY_GROUP_ADDED,
|
||||||
WAKE_REASON_DISPLAY_GROUP_TURNED_ON,
|
WAKE_REASON_DISPLAY_GROUP_TURNED_ON,
|
||||||
|
WAKE_REASON_UNFOLD_DEVICE
|
||||||
})
|
})
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface WakeReason{}
|
public @interface WakeReason{}
|
||||||
@@ -646,6 +647,12 @@ public final class PowerManager {
|
|||||||
*/
|
*/
|
||||||
public static final int WAKE_REASON_DISPLAY_GROUP_TURNED_ON = 11;
|
public static final int WAKE_REASON_DISPLAY_GROUP_TURNED_ON = 11;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wake up reason code: Waking the device due to unfolding of a foldable device.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int WAKE_REASON_UNFOLD_DEVICE = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the wake reason to a string for debugging purposes.
|
* Convert the wake reason to a string for debugging purposes.
|
||||||
* @hide
|
* @hide
|
||||||
@@ -664,6 +671,7 @@ public final class PowerManager {
|
|||||||
case WAKE_REASON_LID: return "WAKE_REASON_LID";
|
case WAKE_REASON_LID: return "WAKE_REASON_LID";
|
||||||
case WAKE_REASON_DISPLAY_GROUP_ADDED: return "WAKE_REASON_DISPLAY_GROUP_ADDED";
|
case WAKE_REASON_DISPLAY_GROUP_ADDED: return "WAKE_REASON_DISPLAY_GROUP_ADDED";
|
||||||
case WAKE_REASON_DISPLAY_GROUP_TURNED_ON: return "WAKE_REASON_DISPLAY_GROUP_TURNED_ON";
|
case WAKE_REASON_DISPLAY_GROUP_TURNED_ON: return "WAKE_REASON_DISPLAY_GROUP_TURNED_ON";
|
||||||
|
case WAKE_REASON_UNFOLD_DEVICE: return "WAKE_REASON_UNFOLD_DEVICE";
|
||||||
default: return Integer.toString(wakeReason);
|
default: return Integer.toString(wakeReason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -654,6 +654,11 @@
|
|||||||
-->
|
-->
|
||||||
</integer-array>
|
</integer-array>
|
||||||
|
|
||||||
|
<!-- When entering this device state (defined in device_state_configuration.xml),
|
||||||
|
we should wake the device. -1 to disable the feature (do not wake on any device-state
|
||||||
|
transition). -->
|
||||||
|
<integer name="config_deviceStateOnWhichToWakeUp">-1</integer>
|
||||||
|
|
||||||
<!-- Indicate the display area rect for foldable devices in folded state. -->
|
<!-- Indicate the display area rect for foldable devices in folded state. -->
|
||||||
<string name="config_foldedArea"></string>
|
<string name="config_foldedArea"></string>
|
||||||
|
|
||||||
|
|||||||
@@ -3846,6 +3846,7 @@
|
|||||||
|
|
||||||
<!-- For Foldables -->
|
<!-- For Foldables -->
|
||||||
<java-symbol type="array" name="config_foldedDeviceStates" />
|
<java-symbol type="array" name="config_foldedDeviceStates" />
|
||||||
|
<java-symbol type="integer" name="config_deviceStateOnWhichToWakeUp" />
|
||||||
<java-symbol type="string" name="config_foldedArea" />
|
<java-symbol type="string" name="config_foldedArea" />
|
||||||
<java-symbol type="bool" name="config_supportsConcurrentInternalDisplays" />
|
<java-symbol type="bool" name="config_supportsConcurrentInternalDisplays" />
|
||||||
<java-symbol type="bool" name="config_unfoldTransitionEnabled" />
|
<java-symbol type="bool" name="config_unfoldTransitionEnabled" />
|
||||||
|
|||||||
@@ -721,13 +721,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
final IBinder token = device.getDisplayTokenLocked();
|
final IBinder token = device.getDisplayTokenLocked();
|
||||||
final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
|
final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
if (mDisplayDevice == device) {
|
if (mDisplayDevice != device) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
mDisplayDevice = device;
|
mDisplayDevice = device;
|
||||||
mUniqueDisplayId = uniqueId;
|
mUniqueDisplayId = uniqueId;
|
||||||
mDisplayDeviceConfig = config;
|
mDisplayDeviceConfig = config;
|
||||||
loadFromDisplayDeviceConfig(token, info);
|
loadFromDisplayDeviceConfig(token, info);
|
||||||
|
updatePowerState();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import android.hardware.devicestate.DeviceStateManager;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
@@ -69,7 +71,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
public static final int DISPLAY_GROUP_EVENT_CHANGED = 2;
|
public static final int DISPLAY_GROUP_EVENT_CHANGED = 2;
|
||||||
public static final int DISPLAY_GROUP_EVENT_REMOVED = 3;
|
public static final int DISPLAY_GROUP_EVENT_REMOVED = 3;
|
||||||
|
|
||||||
private static final int TIMEOUT_STATE_TRANSITION_MILLIS = 500;
|
private static final int TIMEOUT_STATE_TRANSITION_MILLIS = 300;
|
||||||
|
|
||||||
private static final int MSG_TRANSITION_TO_PENDING_DEVICE_STATE = 1;
|
private static final int MSG_TRANSITION_TO_PENDING_DEVICE_STATE = 1;
|
||||||
|
|
||||||
@@ -97,6 +99,11 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
*/
|
*/
|
||||||
private final boolean mSupportsConcurrentInternalDisplays;
|
private final boolean mSupportsConcurrentInternalDisplays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wake the device when transitioning into this device state.
|
||||||
|
*/
|
||||||
|
private final int mDeviceStateOnWhichToWakeUp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of all logical displays indexed by logical display id.
|
* Map of all logical displays indexed by logical display id.
|
||||||
* Any modification to mLogicalDisplays must invalidate the DisplayManagerGlobal cache.
|
* Any modification to mLogicalDisplays must invalidate the DisplayManagerGlobal cache.
|
||||||
@@ -113,6 +120,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
private final Listener mListener;
|
private final Listener mListener;
|
||||||
private final DisplayManagerService.SyncRoot mSyncRoot;
|
private final DisplayManagerService.SyncRoot mSyncRoot;
|
||||||
private final LogicalDisplayMapperHandler mHandler;
|
private final LogicalDisplayMapperHandler mHandler;
|
||||||
|
private final PowerManager mPowerManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has an entry for every logical display that the rest of the system has been notified about.
|
* Has an entry for every logical display that the rest of the system has been notified about.
|
||||||
@@ -150,12 +158,15 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
@NonNull Listener listener, @NonNull DisplayManagerService.SyncRoot syncRoot,
|
@NonNull Listener listener, @NonNull DisplayManagerService.SyncRoot syncRoot,
|
||||||
@NonNull Handler handler) {
|
@NonNull Handler handler) {
|
||||||
mSyncRoot = syncRoot;
|
mSyncRoot = syncRoot;
|
||||||
|
mPowerManager = context.getSystemService(PowerManager.class);
|
||||||
mHandler = new LogicalDisplayMapperHandler(handler.getLooper());
|
mHandler = new LogicalDisplayMapperHandler(handler.getLooper());
|
||||||
mDisplayDeviceRepo = repo;
|
mDisplayDeviceRepo = repo;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
|
mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
|
||||||
mSupportsConcurrentInternalDisplays = context.getResources().getBoolean(
|
mSupportsConcurrentInternalDisplays = context.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_supportsConcurrentInternalDisplays);
|
com.android.internal.R.bool.config_supportsConcurrentInternalDisplays);
|
||||||
|
mDeviceStateOnWhichToWakeUp = context.getResources().getInteger(
|
||||||
|
com.android.internal.R.integer.config_deviceStateOnWhichToWakeUp);
|
||||||
mDisplayDeviceRepo.addListener(this);
|
mDisplayDeviceRepo.addListener(this);
|
||||||
mDeviceStateToLayoutMap = new DeviceStateToLayoutMap();
|
mDeviceStateToLayoutMap = new DeviceStateToLayoutMap();
|
||||||
}
|
}
|
||||||
@@ -318,6 +329,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
|
|
||||||
ipw.println("mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
|
ipw.println("mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
|
||||||
ipw.println("mCurrentLayout=" + mCurrentLayout);
|
ipw.println("mCurrentLayout=" + mCurrentLayout);
|
||||||
|
ipw.println("mDeviceStateOnWhichToWakeUp=" + mDeviceStateOnWhichToWakeUp);
|
||||||
|
|
||||||
final int logicalDisplayCount = mLogicalDisplays.size();
|
final int logicalDisplayCount = mLogicalDisplays.size();
|
||||||
ipw.println();
|
ipw.println();
|
||||||
@@ -335,7 +347,9 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setDeviceStateLocked(int state) {
|
void setDeviceStateLocked(int state) {
|
||||||
Slog.i(TAG, "Requesting Transition to state: " + state);
|
final boolean isInteractive = mPowerManager.isInteractive();
|
||||||
|
Slog.i(TAG, "Requesting Transition to state: " + state + ", from state=" + mDeviceState
|
||||||
|
+ ", interactive=" + isInteractive);
|
||||||
// As part of a state transition, we may need to turn off some displays temporarily so that
|
// As part of a state transition, we may need to turn off some displays temporarily so that
|
||||||
// the transition is smooth. Plus, on some devices, only one internal displays can be
|
// the transition is smooth. Plus, on some devices, only one internal displays can be
|
||||||
// on at a time. We use DISPLAY_PHASE_LAYOUT_TRANSITION to mark a display that needs to be
|
// on at a time. We use DISPLAY_PHASE_LAYOUT_TRANSITION to mark a display that needs to be
|
||||||
@@ -344,8 +358,13 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
resetLayoutLocked(mDeviceState, state, LogicalDisplay.DISPLAY_PHASE_LAYOUT_TRANSITION);
|
resetLayoutLocked(mDeviceState, state, LogicalDisplay.DISPLAY_PHASE_LAYOUT_TRANSITION);
|
||||||
}
|
}
|
||||||
mPendingDeviceState = state;
|
mPendingDeviceState = state;
|
||||||
if (areAllTransitioningDisplaysOffLocked()) {
|
final boolean wakeDevice = mPendingDeviceState == mDeviceStateOnWhichToWakeUp
|
||||||
// Nothing to wait on, we're good to go
|
&& !isInteractive;
|
||||||
|
|
||||||
|
// If all displays are off already, we can just transition here, unless the device is asleep
|
||||||
|
// and we plan on waking it up. In that case, fall through to the call to wakeUp, and defer
|
||||||
|
// the final transition until later once the device is awake.
|
||||||
|
if (areAllTransitioningDisplaysOffLocked() && !wakeDevice) {
|
||||||
transitionToPendingStateLocked();
|
transitionToPendingStateLocked();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -356,6 +375,14 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
// Send the transitioning phase updates to DisplayManager so that the displays can
|
// Send the transitioning phase updates to DisplayManager so that the displays can
|
||||||
// start turning OFF in preparation for the new layout.
|
// start turning OFF in preparation for the new layout.
|
||||||
updateLogicalDisplaysLocked();
|
updateLogicalDisplaysLocked();
|
||||||
|
|
||||||
|
if (wakeDevice) {
|
||||||
|
// We already told the displays to turn off, now we need to wake the device as
|
||||||
|
// we transition to this new state. We do it here so that the waking happens between the
|
||||||
|
// transition from one layout to another.
|
||||||
|
mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_UNFOLD_DEVICE,
|
||||||
|
"server.display:unfold");
|
||||||
|
}
|
||||||
mHandler.sendEmptyMessageDelayed(MSG_TRANSITION_TO_PENDING_DEVICE_STATE,
|
mHandler.sendEmptyMessageDelayed(MSG_TRANSITION_TO_PENDING_DEVICE_STATE,
|
||||||
TIMEOUT_STATE_TRANSITION_MILLIS);
|
TIMEOUT_STATE_TRANSITION_MILLIS);
|
||||||
}
|
}
|
||||||
@@ -482,6 +509,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
assignDisplayGroupLocked(display);
|
assignDisplayGroupLocked(display);
|
||||||
mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_CHANGED);
|
mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_CHANGED);
|
||||||
|
|
||||||
|
// The display is involved in a display layout transition
|
||||||
} else if (updateState == UPDATE_STATE_TRANSITION) {
|
} else if (updateState == UPDATE_STATE_TRANSITION) {
|
||||||
mLogicalDisplaysToUpdate.put(displayId,
|
mLogicalDisplaysToUpdate.put(displayId,
|
||||||
LOGICAL_DISPLAY_EVENT_DEVICE_STATE_TRANSITION);
|
LOGICAL_DISPLAY_EVENT_DEVICE_STATE_TRANSITION);
|
||||||
@@ -672,14 +700,14 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
|||||||
|
|
||||||
// We consider a display-device as changing/transition if
|
// We consider a display-device as changing/transition if
|
||||||
// 1) It's already marked as transitioning
|
// 1) It's already marked as transitioning
|
||||||
// 2) It's going from enabled to disabled
|
// 2) It's going from enabled to disabled, or vice versa
|
||||||
// 3) It's enabled, but it's mapped to a new logical display ID. To the user this
|
// 3) It's enabled, but it's mapped to a new logical display ID. To the user this
|
||||||
// would look like apps moving from one screen to another since task-stacks stay
|
// would look like apps moving from one screen to another since task-stacks stay
|
||||||
// with the logical display [ID].
|
// with the logical display [ID].
|
||||||
final boolean isTransitioning =
|
final boolean isTransitioning =
|
||||||
(logicalDisplay.getPhase() == LogicalDisplay.DISPLAY_PHASE_LAYOUT_TRANSITION)
|
(logicalDisplay.getPhase() == LogicalDisplay.DISPLAY_PHASE_LAYOUT_TRANSITION)
|
||||||
|| (wasEnabled && !willBeEnabled)
|
|| (wasEnabled != willBeEnabled)
|
||||||
|| (wasEnabled && deviceHasNewLogicalDisplayId);
|
|| deviceHasNewLogicalDisplayId;
|
||||||
|
|
||||||
if (isTransitioning) {
|
if (isTransitioning) {
|
||||||
setDisplayPhase(logicalDisplay, phase);
|
setDisplayPhase(logicalDisplay, phase);
|
||||||
|
|||||||
Reference in New Issue
Block a user