Loading core/res/res/values/config.xml +3 −4 Original line number Diff line number Diff line Loading @@ -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> Loading core/res/res/values/symbols.xml +1 −1 Original line number Diff line number Diff line Loading @@ -3702,7 +3702,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" /> Loading services/core/java/com/android/server/policy/DisplayFoldController.java +30 −39 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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() { Loading @@ -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; } Loading Loading @@ -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; } Loading @@ -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); } } } services/core/java/com/android/server/policy/PhoneWindowManager.java +2 −12 Original line number Diff line number Diff line Loading @@ -472,7 +472,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { int mLidKeyboardAccessibility; int mLidNavigationAccessibility; private boolean mLidControlsDisplayFold; int mShortPressOnPowerBehavior; int mLongPressOnPowerBehavior; int mVeryLongPressOnPowerBehavior; Loading Loading @@ -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); Loading Loading @@ -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); } mAccessibilityManager = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); Loading Loading @@ -4860,9 +4852,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: Loading services/java/com/android/server/SystemServer.java +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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"); Loading Loading
core/res/res/values/config.xml +3 −4 Original line number Diff line number Diff line Loading @@ -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> Loading
core/res/res/values/symbols.xml +1 −1 Original line number Diff line number Diff line Loading @@ -3702,7 +3702,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" /> Loading
services/core/java/com/android/server/policy/DisplayFoldController.java +30 −39 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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() { Loading @@ -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; } Loading Loading @@ -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; } Loading @@ -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); } } }
services/core/java/com/android/server/policy/PhoneWindowManager.java +2 −12 Original line number Diff line number Diff line Loading @@ -472,7 +472,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { int mLidKeyboardAccessibility; int mLidNavigationAccessibility; private boolean mLidControlsDisplayFold; int mShortPressOnPowerBehavior; int mLongPressOnPowerBehavior; int mVeryLongPressOnPowerBehavior; Loading Loading @@ -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); Loading Loading @@ -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); } mAccessibilityManager = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); Loading Loading @@ -4860,9 +4852,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: Loading
services/java/com/android/server/SystemServer.java +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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"); Loading