Loading core/res/res/values/config.xml +3 −0 Original line number Diff line number Diff line Loading @@ -869,6 +869,9 @@ which means to get a larger screen. --> <bool name="config_lidControlsDisplayFold">false</bool> <!-- Indicate the display area rect for foldable devices in folded state. --> <string name="config_foldedArea"></string> <!-- Desk dock behavior --> <!-- The number of degrees to rotate the display when the device is in a desk dock. Loading core/res/res/values/symbols.xml +3 −0 Original line number Diff line number Diff line Loading @@ -3586,7 +3586,10 @@ <java-symbol type="integer" name="config_defaultRingVibrationIntensity" /> <java-symbol type="bool" name="config_maskMainBuiltInDisplayCutout" /> <!-- For Foldables --> <java-symbol type="bool" name="config_lidControlsDisplayFold" /> <java-symbol type="string" name="config_foldedArea" /> <java-symbol type="array" name="config_disableApksUnlessMatchedSku_apk_list" /> <java-symbol type="array" name="config_disableApkUnlessMatchedSku_skus_list" /> Loading services/core/java/com/android/server/policy/DisplayFoldController.java +40 −13 Original line number Diff line number Diff line Loading @@ -42,10 +42,12 @@ class DisplayFoldController { private final WindowManagerInternal mWindowManagerInternal; private final DisplayManagerInternal mDisplayManagerInternal; private final int mDisplayId; private final Handler mHandler; /** The display area while device is folded. */ private final Rect mFoldedArea; private final Handler mHandler; /** The display area to override the original folded area. */ private Rect mOverrideFoldedArea = new Rect(); private final DisplayInfo mNonOverrideDisplayInfo = new DisplayInfo(); private final RemoteCallbackList<IDisplayFoldListener> mListeners = new RemoteCallbackList<>(); Loading @@ -70,14 +72,23 @@ class DisplayFoldController { return; } if (folded) { Rect foldedArea; if (!mOverrideFoldedArea.isEmpty()) { foldedArea = mOverrideFoldedArea; } else if (!mFoldedArea.isEmpty()) { foldedArea = mFoldedArea; } else { return; } mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mNonOverrideDisplayInfo); final int dx = (mNonOverrideDisplayInfo.logicalWidth - mFoldedArea.width()) / 2 - mFoldedArea.left; final int dy = (mNonOverrideDisplayInfo.logicalHeight - mFoldedArea.height()) / 2 - mFoldedArea.top; final int dx = (mNonOverrideDisplayInfo.logicalWidth - foldedArea.width()) / 2 - foldedArea.left; final int dy = (mNonOverrideDisplayInfo.logicalHeight - foldedArea.height()) / 2 - foldedArea.top; mWindowManagerInternal.setForcedDisplaySize(mDisplayId, mFoldedArea.width(), mFoldedArea.height()); mWindowManagerInternal.setForcedDisplaySize(mDisplayId, foldedArea.width(), foldedArea.height()); mDisplayManagerInternal.setDisplayOffsets(mDisplayId, -dx, -dy); } else { mWindowManagerInternal.clearForcedDisplaySize(mDisplayId); Loading Loading @@ -114,6 +125,18 @@ class DisplayFoldController { mListeners.unregister(listener); } void setOverrideFoldedArea(Rect area) { mOverrideFoldedArea.set(area); } Rect getFoldedArea() { if (!mOverrideFoldedArea.isEmpty()) { return mOverrideFoldedArea; } else { return mFoldedArea; } } /** * Only used for the case that persist.debug.force_foldable is set. * This is using proximity sensor to simulate the fold state switch. Loading @@ -125,7 +148,7 @@ class DisplayFoldController { return null; } final DisplayFoldController result = create(displayId); final DisplayFoldController result = create(context, displayId); sensorManager.registerListener(new SensorEventListener() { @Override public void onSensorChanged(SensorEvent event) { Loading @@ -141,13 +164,17 @@ class DisplayFoldController { return result; } static DisplayFoldController create(int displayId) { static DisplayFoldController create(Context context, int displayId) { final DisplayManagerInternal displayService = LocalServices.getService(DisplayManagerInternal.class); final DisplayInfo displayInfo = new DisplayInfo(); displayService.getNonOverrideDisplayInfo(displayId, displayInfo); final Rect foldedArea = new Rect(0, displayInfo.logicalHeight / 2, displayInfo.logicalWidth, displayInfo.logicalHeight); final String configFoldedArea = context.getResources().getString( com.android.internal.R.string.config_foldedArea); final Rect foldedArea; if (configFoldedArea == null || configFoldedArea.isEmpty()) { foldedArea = new Rect(); } else { foldedArea = Rect.unflattenFromString(configFoldedArea); } return new DisplayFoldController(LocalServices.getService(WindowManagerInternal.class), displayService, displayId, foldedArea, DisplayThread.getHandler()); Loading services/core/java/com/android/server/policy/PhoneWindowManager.java +17 −1 Original line number Diff line number Diff line Loading @@ -125,6 +125,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.database.ContentObserver; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.hardware.display.DisplayManager; import android.hardware.hdmi.HdmiAudioSystemClient; Loading Loading @@ -1858,7 +1859,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { readConfigurationDependentBehaviors(); if (mLidControlsDisplayFold) { mDisplayFoldController = DisplayFoldController.create(DEFAULT_DISPLAY); mDisplayFoldController = DisplayFoldController.create(context, DEFAULT_DISPLAY); } else if (SystemProperties.getBoolean("persist.debug.force_foldable", false)) { mDisplayFoldController = DisplayFoldController.createWithProxSensor(context, DEFAULT_DISPLAY); Loading Loading @@ -3220,6 +3221,21 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } @Override public void setOverrideFoldedArea(Rect area) { if (mDisplayFoldController != null) { mDisplayFoldController.setOverrideFoldedArea(area); } } @Override public Rect getFoldedArea() { if (mDisplayFoldController != null) { return mDisplayFoldController.getFoldedArea(); } return new Rect(); } @Override public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService) throws RemoteException { Loading services/core/java/com/android/server/policy/WindowManagerPolicy.java +15 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; import static java.lang.annotation.RetentionPolicy.SOURCE; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.WindowConfiguration; import android.content.Context; Loading Loading @@ -1469,6 +1470,20 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants { */ default void unregisterDisplayFoldListener(IDisplayFoldListener listener) {} /** * Overrides the folded area. * * @param area the overriding folded area or an empty {@code Rect} to clear the override. */ default void setOverrideFoldedArea(@NonNull Rect area) {} /** * Get the display folded area. */ default @NonNull Rect getFoldedArea() { return new Rect(); } /** * Updates the flag about whether AOD is showing. * Loading Loading
core/res/res/values/config.xml +3 −0 Original line number Diff line number Diff line Loading @@ -869,6 +869,9 @@ which means to get a larger screen. --> <bool name="config_lidControlsDisplayFold">false</bool> <!-- Indicate the display area rect for foldable devices in folded state. --> <string name="config_foldedArea"></string> <!-- Desk dock behavior --> <!-- The number of degrees to rotate the display when the device is in a desk dock. Loading
core/res/res/values/symbols.xml +3 −0 Original line number Diff line number Diff line Loading @@ -3586,7 +3586,10 @@ <java-symbol type="integer" name="config_defaultRingVibrationIntensity" /> <java-symbol type="bool" name="config_maskMainBuiltInDisplayCutout" /> <!-- For Foldables --> <java-symbol type="bool" name="config_lidControlsDisplayFold" /> <java-symbol type="string" name="config_foldedArea" /> <java-symbol type="array" name="config_disableApksUnlessMatchedSku_apk_list" /> <java-symbol type="array" name="config_disableApkUnlessMatchedSku_skus_list" /> Loading
services/core/java/com/android/server/policy/DisplayFoldController.java +40 −13 Original line number Diff line number Diff line Loading @@ -42,10 +42,12 @@ class DisplayFoldController { private final WindowManagerInternal mWindowManagerInternal; private final DisplayManagerInternal mDisplayManagerInternal; private final int mDisplayId; private final Handler mHandler; /** The display area while device is folded. */ private final Rect mFoldedArea; private final Handler mHandler; /** The display area to override the original folded area. */ private Rect mOverrideFoldedArea = new Rect(); private final DisplayInfo mNonOverrideDisplayInfo = new DisplayInfo(); private final RemoteCallbackList<IDisplayFoldListener> mListeners = new RemoteCallbackList<>(); Loading @@ -70,14 +72,23 @@ class DisplayFoldController { return; } if (folded) { Rect foldedArea; if (!mOverrideFoldedArea.isEmpty()) { foldedArea = mOverrideFoldedArea; } else if (!mFoldedArea.isEmpty()) { foldedArea = mFoldedArea; } else { return; } mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mNonOverrideDisplayInfo); final int dx = (mNonOverrideDisplayInfo.logicalWidth - mFoldedArea.width()) / 2 - mFoldedArea.left; final int dy = (mNonOverrideDisplayInfo.logicalHeight - mFoldedArea.height()) / 2 - mFoldedArea.top; final int dx = (mNonOverrideDisplayInfo.logicalWidth - foldedArea.width()) / 2 - foldedArea.left; final int dy = (mNonOverrideDisplayInfo.logicalHeight - foldedArea.height()) / 2 - foldedArea.top; mWindowManagerInternal.setForcedDisplaySize(mDisplayId, mFoldedArea.width(), mFoldedArea.height()); mWindowManagerInternal.setForcedDisplaySize(mDisplayId, foldedArea.width(), foldedArea.height()); mDisplayManagerInternal.setDisplayOffsets(mDisplayId, -dx, -dy); } else { mWindowManagerInternal.clearForcedDisplaySize(mDisplayId); Loading Loading @@ -114,6 +125,18 @@ class DisplayFoldController { mListeners.unregister(listener); } void setOverrideFoldedArea(Rect area) { mOverrideFoldedArea.set(area); } Rect getFoldedArea() { if (!mOverrideFoldedArea.isEmpty()) { return mOverrideFoldedArea; } else { return mFoldedArea; } } /** * Only used for the case that persist.debug.force_foldable is set. * This is using proximity sensor to simulate the fold state switch. Loading @@ -125,7 +148,7 @@ class DisplayFoldController { return null; } final DisplayFoldController result = create(displayId); final DisplayFoldController result = create(context, displayId); sensorManager.registerListener(new SensorEventListener() { @Override public void onSensorChanged(SensorEvent event) { Loading @@ -141,13 +164,17 @@ class DisplayFoldController { return result; } static DisplayFoldController create(int displayId) { static DisplayFoldController create(Context context, int displayId) { final DisplayManagerInternal displayService = LocalServices.getService(DisplayManagerInternal.class); final DisplayInfo displayInfo = new DisplayInfo(); displayService.getNonOverrideDisplayInfo(displayId, displayInfo); final Rect foldedArea = new Rect(0, displayInfo.logicalHeight / 2, displayInfo.logicalWidth, displayInfo.logicalHeight); final String configFoldedArea = context.getResources().getString( com.android.internal.R.string.config_foldedArea); final Rect foldedArea; if (configFoldedArea == null || configFoldedArea.isEmpty()) { foldedArea = new Rect(); } else { foldedArea = Rect.unflattenFromString(configFoldedArea); } return new DisplayFoldController(LocalServices.getService(WindowManagerInternal.class), displayService, displayId, foldedArea, DisplayThread.getHandler()); Loading
services/core/java/com/android/server/policy/PhoneWindowManager.java +17 −1 Original line number Diff line number Diff line Loading @@ -125,6 +125,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.database.ContentObserver; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.hardware.display.DisplayManager; import android.hardware.hdmi.HdmiAudioSystemClient; Loading Loading @@ -1858,7 +1859,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { readConfigurationDependentBehaviors(); if (mLidControlsDisplayFold) { mDisplayFoldController = DisplayFoldController.create(DEFAULT_DISPLAY); mDisplayFoldController = DisplayFoldController.create(context, DEFAULT_DISPLAY); } else if (SystemProperties.getBoolean("persist.debug.force_foldable", false)) { mDisplayFoldController = DisplayFoldController.createWithProxSensor(context, DEFAULT_DISPLAY); Loading Loading @@ -3220,6 +3221,21 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } @Override public void setOverrideFoldedArea(Rect area) { if (mDisplayFoldController != null) { mDisplayFoldController.setOverrideFoldedArea(area); } } @Override public Rect getFoldedArea() { if (mDisplayFoldController != null) { return mDisplayFoldController.getFoldedArea(); } return new Rect(); } @Override public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService) throws RemoteException { Loading
services/core/java/com/android/server/policy/WindowManagerPolicy.java +15 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; import static java.lang.annotation.RetentionPolicy.SOURCE; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.WindowConfiguration; import android.content.Context; Loading Loading @@ -1469,6 +1470,20 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants { */ default void unregisterDisplayFoldListener(IDisplayFoldListener listener) {} /** * Overrides the folded area. * * @param area the overriding folded area or an empty {@code Rect} to clear the override. */ default void setOverrideFoldedArea(@NonNull Rect area) {} /** * Get the display folded area. */ default @NonNull Rect getFoldedArea() { return new Rect(); } /** * Updates the flag about whether AOD is showing. * Loading