Migrate DisplayFoldController fold state to be based on device state.
This modifies DisplayFoldController to base it's internal 'fold' state from being configured directly based on the lid switch (or the proximity sensor) to be based on the device state. Bug: 159401801 Test: Manual - fold/unfold and validate fold state Change-Id: Ib3ecc6326b1d73720d31fa94f33160cfaf1109cd
This commit is contained in:
@@ -654,10 +654,9 @@
|
||||
The default is false. -->
|
||||
<bool name="config_lidControlsSleep">false</bool>
|
||||
|
||||
<!-- Indicate whether closing the lid causes the device to enter the folded state which means
|
||||
to get a smaller screen and opening the lid causes the device to enter the unfolded state
|
||||
which means to get a larger screen. -->
|
||||
<bool name="config_lidControlsDisplayFold">false</bool>
|
||||
<!-- The device state (supplied by DeviceStateManager) that should be treated as folded by the
|
||||
display fold controller. Default is DeviceStateManager.INVALID_DEVICE_STATE. -->
|
||||
<integer name="config_foldedDeviceState">-1</integer>
|
||||
|
||||
<!-- Indicate the display area rect for foldable devices in folded state. -->
|
||||
<string name="config_foldedArea"></string>
|
||||
|
||||
@@ -3701,7 +3701,7 @@
|
||||
<java-symbol type="string" name="config_customCountryDetector" />
|
||||
|
||||
<!-- For Foldables -->
|
||||
<java-symbol type="bool" name="config_lidControlsDisplayFold" />
|
||||
<java-symbol type="integer" name="config_foldedDeviceState" />
|
||||
<java-symbol type="string" name="config_foldedArea" />
|
||||
|
||||
<java-symbol type="array" name="config_disableApksUnlessMatchedSku_apk_list" />
|
||||
|
||||
@@ -20,12 +20,10 @@ import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.ICameraService;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.hardware.devicestate.DeviceStateManager;
|
||||
import android.hardware.display.DisplayManagerInternal;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerExecutor;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Slog;
|
||||
@@ -63,7 +61,8 @@ class DisplayFoldController {
|
||||
private String mFocusedApp;
|
||||
private final DisplayFoldDurationLogger mDurationLogger = new DisplayFoldDurationLogger();
|
||||
|
||||
DisplayFoldController(WindowManagerInternal windowManagerInternal,
|
||||
DisplayFoldController(
|
||||
Context context, WindowManagerInternal windowManagerInternal,
|
||||
DisplayManagerInternal displayManagerInternal,
|
||||
@Nullable CameraServiceProxy cameraServiceProxy, int displayId, Rect foldedArea,
|
||||
Handler handler) {
|
||||
@@ -73,6 +72,10 @@ class DisplayFoldController {
|
||||
mDisplayId = displayId;
|
||||
mFoldedArea = new Rect(foldedArea);
|
||||
mHandler = handler;
|
||||
|
||||
DeviceStateManager deviceStateManager = context.getSystemService(DeviceStateManager.class);
|
||||
deviceStateManager.registerDeviceStateListener(new DeviceStateListener(context),
|
||||
new HandlerExecutor(handler));
|
||||
}
|
||||
|
||||
void finishedGoingToSleep() {
|
||||
@@ -83,11 +86,7 @@ class DisplayFoldController {
|
||||
mDurationLogger.onFinishedWakingUp(mFolded);
|
||||
}
|
||||
|
||||
void requestDeviceFolded(boolean folded) {
|
||||
mHandler.post(() -> setDeviceFolded(folded));
|
||||
}
|
||||
|
||||
void setDeviceFolded(boolean folded) {
|
||||
private void setDeviceFolded(boolean folded) {
|
||||
if (mFolded != null && mFolded == folded) {
|
||||
return;
|
||||
}
|
||||
@@ -179,33 +178,6 @@ class DisplayFoldController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only used for the case that persist.debug.force_foldable is set.
|
||||
* This is using proximity sensor to simulate the fold state switch.
|
||||
*/
|
||||
static DisplayFoldController createWithProxSensor(Context context, int displayId) {
|
||||
final SensorManager sensorManager = context.getSystemService(SensorManager.class);
|
||||
final Sensor proxSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||
if (proxSensor == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final DisplayFoldController result = create(context, displayId);
|
||||
sensorManager.registerListener(new SensorEventListener() {
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
result.requestDeviceFolded(event.values[0] < 1f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// Ignore.
|
||||
}
|
||||
}, proxSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void onDefaultDisplayFocusChanged(String pkg) {
|
||||
mFocusedApp = pkg;
|
||||
}
|
||||
@@ -227,7 +199,26 @@ class DisplayFoldController {
|
||||
foldedArea = Rect.unflattenFromString(configFoldedArea);
|
||||
}
|
||||
|
||||
return new DisplayFoldController(windowManagerService, displayService, cameraServiceProxy,
|
||||
displayId, foldedArea, DisplayThread.getHandler());
|
||||
return new DisplayFoldController(context, windowManagerService, displayService,
|
||||
cameraServiceProxy, displayId, foldedArea, DisplayThread.getHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to changes in device state and reports the state as folded if the device state
|
||||
* matches the value in the {@link com.android.internal.R.integer.config_foldedDeviceState}
|
||||
* resource.
|
||||
*/
|
||||
private class DeviceStateListener implements DeviceStateManager.DeviceStateListener {
|
||||
private final int mFoldedDeviceState;
|
||||
|
||||
DeviceStateListener(Context context) {
|
||||
mFoldedDeviceState = context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_foldedDeviceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceStateChanged(int deviceState) {
|
||||
setDeviceFolded(deviceState == mFoldedDeviceState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,7 +472,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
int mLidKeyboardAccessibility;
|
||||
int mLidNavigationAccessibility;
|
||||
private boolean mLidControlsDisplayFold;
|
||||
int mShortPressOnPowerBehavior;
|
||||
int mLongPressOnPowerBehavior;
|
||||
int mVeryLongPressOnPowerBehavior;
|
||||
@@ -1789,8 +1788,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
com.android.internal.R.integer.config_lidKeyboardAccessibility);
|
||||
mLidNavigationAccessibility = mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_lidNavigationAccessibility);
|
||||
mLidControlsDisplayFold = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_lidControlsDisplayFold);
|
||||
|
||||
mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
|
||||
@@ -1847,12 +1844,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
readConfigurationDependentBehaviors();
|
||||
|
||||
if (mLidControlsDisplayFold) {
|
||||
mDisplayFoldController = DisplayFoldController.create(context, DEFAULT_DISPLAY);
|
||||
} else if (SystemProperties.getBoolean("persist.debug.force_foldable", false)) {
|
||||
mDisplayFoldController = DisplayFoldController.createWithProxSensor(context,
|
||||
DEFAULT_DISPLAY);
|
||||
}
|
||||
mDisplayFoldController = DisplayFoldController.create(context, DEFAULT_DISPLAY);
|
||||
|
||||
mAccessibilityManager = (AccessibilityManager) context.getSystemService(
|
||||
Context.ACCESSIBILITY_SERVICE);
|
||||
@@ -4853,9 +4845,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
private void applyLidSwitchState() {
|
||||
final int lidState = mDefaultDisplayPolicy.getLidState();
|
||||
if (mLidControlsDisplayFold && mDisplayFoldController != null) {
|
||||
mDisplayFoldController.requestDeviceFolded(lidState == LID_CLOSED);
|
||||
} else if (lidState == LID_CLOSED) {
|
||||
if (lidState == LID_CLOSED) {
|
||||
int lidBehavior = getLidBehavior();
|
||||
switch (lidBehavior) {
|
||||
case LID_BEHAVIOR_LOCK:
|
||||
|
||||
@@ -1281,6 +1281,10 @@ public final class SystemServer implements Dumpable {
|
||||
inputManager = new InputManagerService(context);
|
||||
t.traceEnd();
|
||||
|
||||
t.traceBegin("DeviceStateManagerService");
|
||||
mSystemServiceManager.startService(DeviceStateManagerService.class);
|
||||
t.traceEnd();
|
||||
|
||||
if (!disableCameraService) {
|
||||
t.traceBegin("StartCameraServiceProxy");
|
||||
mSystemServiceManager.startService(CameraServiceProxy.class);
|
||||
@@ -1374,10 +1378,6 @@ public final class SystemServer implements Dumpable {
|
||||
mSystemServiceManager.startService(AppIntegrityManagerService.class);
|
||||
t.traceEnd();
|
||||
|
||||
t.traceBegin("DeviceStateManagerService");
|
||||
mSystemServiceManager.startService(DeviceStateManagerService.class);
|
||||
t.traceEnd();
|
||||
|
||||
} catch (Throwable e) {
|
||||
Slog.e("System", "******************************************");
|
||||
Slog.e("System", "************ Failure starting core service");
|
||||
|
||||
Reference in New Issue
Block a user