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

Commit 8d99ed44 authored by Andrii Kulian's avatar Andrii Kulian Committed by android-build-merger
Browse files

Merge "Position app with short aspect ratio opposite of nav bar" into oc-dr1-dev

am: a40af83c

Change-Id: I08967a79847a0d42a0a5c67d2bb178d2717eae33
parents ae56a905 a40af83c
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -150,6 +150,11 @@ public interface WindowManagerPolicy {
    public final static int PRESENCE_INTERNAL = 1 << 0;
    public final static int PRESENCE_INTERNAL = 1 << 0;
    public final static int PRESENCE_EXTERNAL = 1 << 1;
    public final static int PRESENCE_EXTERNAL = 1 << 1;


    // Navigation bar position values
    int NAV_BAR_LEFT = 1 << 0;
    int NAV_BAR_RIGHT = 1 << 1;
    int NAV_BAR_BOTTOM = 1 << 2;

    public final static boolean WATCH_POINTER = false;
    public final static boolean WATCH_POINTER = false;


    /**
    /**
@@ -1675,6 +1680,14 @@ public interface WindowManagerPolicy {
     */
     */
    public boolean isNavBarForcedShownLw(WindowState win);
    public boolean isNavBarForcedShownLw(WindowState win);


    /**
     * @return The side of the screen where navigation bar is positioned.
     * @see #NAV_BAR_LEFT
     * @see #NAV_BAR_RIGHT
     * @see #NAV_BAR_BOTTOM
     */
    int getNavBarPosition();

    /**
    /**
     * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system
     * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system
     * bar or button bar. See {@link #getNonDecorDisplayWidth}.
     * bar or button bar. See {@link #getNonDecorDisplayWidth}.
+13 −0
Original line number Original line Diff line number Diff line
@@ -74,6 +74,7 @@ import static android.os.Build.VERSION_CODES.HONEYCOMB;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Process.SYSTEM_UID;
import static android.os.Process.SYSTEM_UID;
import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
import static android.view.WindowManagerPolicy.NAV_BAR_LEFT;


import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
@@ -154,6 +155,7 @@ import android.view.IAppTransitionAnimationSpecsFuture;
import android.view.IApplicationToken;
import android.view.IApplicationToken;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.ResolverActivity;
import com.android.internal.app.ResolverActivity;
import com.android.internal.content.ReferrerIntent;
import com.android.internal.content.ReferrerIntent;
import com.android.internal.util.XmlUtils;
import com.android.internal.util.XmlUtils;
@@ -2360,6 +2362,17 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo


        // Compute configuration based on max supported width and height.
        // Compute configuration based on max supported width and height.
        outBounds.set(0, 0, maxActivityWidth, maxActivityHeight);
        outBounds.set(0, 0, maxActivityWidth, maxActivityHeight);
        // Position the activity frame on the opposite side of the nav bar.
        final int navBarPosition = service.mWindowManager.getNavBarPosition();
        final int left = navBarPosition == NAV_BAR_LEFT
                ? configuration.appBounds.right - outBounds.width() : 0;
        outBounds.offsetTo(left, 0 /* top */);
    }

    /** Get bounds of the activity. */
    @VisibleForTesting
    Rect getBounds() {
        return new Rect(mBounds);
    }
    }


    /**
    /**
+6 −4
Original line number Original line Diff line number Diff line
@@ -358,10 +358,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER =
    private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER =
            "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";
            "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";


    private static final int NAV_BAR_BOTTOM = 0;
    private static final int NAV_BAR_RIGHT = 1;
    private static final int NAV_BAR_LEFT = 2;

    /**
    /**
     * Keyguard stuff
     * Keyguard stuff
     */
     */
@@ -6942,6 +6938,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return mForceShowSystemBars;
        return mForceShowSystemBars;
    }
    }


    @Override
    public int getNavBarPosition() {
        // TODO(multi-display): Support system decor on secondary displays.
        return mNavigationBarPosition;
    }

    @Override
    @Override
    public boolean isDockSideAllowed(int dockSide) {
    public boolean isDockSideAllowed(int dockSide) {


+16 −0
Original line number Original line Diff line number Diff line
@@ -6292,6 +6292,22 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        }
    }
    }


    /**
     * Used by ActivityManager to determine where to position an app with aspect ratio shorter then
     * the screen is.
     * @see WindowManagerPolicy#getNavBarPosition()
     */
    public int getNavBarPosition() {
        synchronized (mWindowMap) {
            // Perform layout if it was scheduled before to make sure that we get correct nav bar
            // position when doing rotations.
            final DisplayContent defaultDisplayContent = getDefaultDisplayContentLocked();
            defaultDisplayContent.performLayout(false /* initial */,
                    false /* updateInputWindows */);
            return mPolicy.getNavBarPosition();
        }
    }

    @Override
    @Override
    public WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
    public WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
            InputEventReceiver.Factory inputEventReceiverFactory) {
            InputEventReceiver.Factory inputEventReceiverFactory) {
+37 −0
Original line number Original line Diff line number Diff line
@@ -16,10 +16,15 @@


package com.android.server.am;
package com.android.server.am;


import static android.view.WindowManagerPolicy.NAV_BAR_BOTTOM;
import static android.view.WindowManagerPolicy.NAV_BAR_LEFT;
import static android.view.WindowManagerPolicy.NAV_BAR_RIGHT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;


import android.content.ComponentName;
import android.content.ComponentName;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.MediumTest;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.runner.AndroidJUnit4;
@@ -94,4 +99,36 @@ public class ActivityRecordTests extends ActivityTestsBase {


        return -1;
        return -1;
    }
    }

    @Test
    public void testPositionLimitedAspectRatioNavBarBottom() throws Exception {
        verifyPositionWithLimitedAspectRatio(NAV_BAR_BOTTOM, new Rect(0, 0, 1000, 2000), 1.5f,
                new Rect(0, 0, 1000, 1500));
    }

    @Test
    public void testPositionLimitedAspectRatioNavBarLeft() throws Exception {
        verifyPositionWithLimitedAspectRatio(NAV_BAR_LEFT, new Rect(0, 0, 2000, 1000), 1.5f,
                new Rect(500, 0, 2000, 1000));
    }

    @Test
    public void testPositionLimitedAspectRatioNavBarRight() throws Exception {
        verifyPositionWithLimitedAspectRatio(NAV_BAR_RIGHT, new Rect(0, 0, 2000, 1000), 1.5f,
                new Rect(0, 0, 1500, 1000));
    }

    private void verifyPositionWithLimitedAspectRatio(int navBarPosition, Rect taskBounds,
            float aspectRatio, Rect expectedActivityBounds) {
        final ActivityManagerService service = createActivityManagerService();
        final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
        final ActivityRecord record = createActivity(service, testActivityComponent, task);

        // Verify with nav bar on the right.
        when(service.mWindowManager.getNavBarPosition()).thenReturn(navBarPosition);
        task.getConfiguration().setAppBounds(taskBounds);
        record.info.maxAspectRatio = aspectRatio;
        record.ensureActivityConfigurationLocked(0 /* globalChanges */, false /* preserveWindow */);
        assertEquals(expectedActivityBounds, record.getBounds());
    }
}
}
Loading