Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70a9ab9e authored by Chilun's avatar Chilun
Browse files

Foldables: Customize folded area

Customize folded area by config and command.

Bug: 123245311
Bug: 123243587
Test: adb shell wm folded-area
Test: atest WmTests
Change-Id: Iff1c104bef8b7e5f9c5d14d1117080e62610f55a
parent 9c6db23f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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.
+3 −0
Original line number Diff line number Diff line
@@ -3584,7 +3584,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" />
+40 −13
Original line number Diff line number Diff line
@@ -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<>();
@@ -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);
@@ -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.
@@ -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) {
@@ -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());
+17 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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);
@@ -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 {
+15 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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