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

Commit ae92b086 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

Include app compat resize overrides in task resizeability check

`FORCE_NON_RESIZE_APP` and `FORCE_RESIZE_APP` should be respected
when calculating the resizeability of a task.

FLAG: NONE(bug fix)
Fix: 319419057
Test: presubmit && atest WmTests:TaskTests
Change-Id: I94ae927b37c818c7da535118435f46eca295a0bc
parent eff4dad4
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
import static android.content.pm.ActivityInfo.FORCE_NON_RESIZE_APP;
import static android.content.pm.ActivityInfo.FORCE_RESIZE_APP;
import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
@@ -49,6 +51,7 @@ import static android.view.Display.INVALID_DISPLAY;
import static android.view.SurfaceControl.METADATA_TASK_ID;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_APP_CRASHED;
@@ -133,6 +136,7 @@ import android.app.IActivityController;
import android.app.PictureInPictureParams;
import android.app.TaskInfo;
import android.app.WindowConfiguration;
import android.app.compat.CompatChanges;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -503,6 +507,12 @@ class Task extends TaskFragment {
    int mOffsetXForInsets;
    int mOffsetYForInsets;

    /**
     * Whether the compatibility overrides that change the resizability of the app should be allowed
     * for the specific app.
     */
    boolean mAllowForceResizeOverride = true;

    private final AnimatingActivityRegistry mAnimatingActivityRegistry =
            new AnimatingActivityRegistry();

@@ -666,6 +676,7 @@ class Task extends TaskFragment {
            intent = _intent;
            mMinWidth = minWidth;
            mMinHeight = minHeight;
            updateAllowForceResizeOverride();
        }
        mAtmService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity);
        mHandler = new ActivityTaskHandler(mTaskSupervisor.mLooper);
@@ -1028,6 +1039,7 @@ class Task extends TaskFragment {
            mTaskSupervisor.mRecentTasks.remove(this);
            mTaskSupervisor.mRecentTasks.add(this);
        }
        updateAllowForceResizeOverride();
    }

    /** Sets the original minimal width and height. */
@@ -1823,6 +1835,17 @@ class Task extends TaskFragment {
                -1 /* don't check PID */, -1 /* don't check UID */, this);
    }

    private void updateAllowForceResizeOverride() {
        try {
            mAllowForceResizeOverride = mAtmService.mContext.getPackageManager().getProperty(
                    PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES,
                    getBasePackageName()).getBoolean();
        } catch (PackageManager.NameNotFoundException e) {
            // Package not found or property not defined, reset to default value.
            mAllowForceResizeOverride = true;
        }
    }

    /**
     * Check that a given bounds matches the application requested orientation.
     *
@@ -2812,7 +2835,18 @@ class Task extends TaskFragment {
    boolean isResizeable(boolean checkPictureInPictureSupport) {
        final boolean forceResizable = mAtmService.mForceResizableActivities
                && getActivityType() == ACTIVITY_TYPE_STANDARD;
        return forceResizable || ActivityInfo.isResizeableMode(mResizeMode)
        if (forceResizable) return true;

        final UserHandle userHandle = UserHandle.getUserHandleForUid(mUserId);
        final boolean forceResizableOverride = mAllowForceResizeOverride
                && CompatChanges.isChangeEnabled(
                        FORCE_RESIZE_APP, getBasePackageName(), userHandle);
        final boolean forceNonResizableOverride = mAllowForceResizeOverride
                && CompatChanges.isChangeEnabled(
                        FORCE_NON_RESIZE_APP, getBasePackageName(), userHandle);

        if (forceNonResizableOverride) return false;
        return forceResizableOverride || ActivityInfo.isResizeableMode(mResizeMode)
                || (mSupportsPictureInPicture && checkPictureInPictureSupport);
    }

+89 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
@@ -75,6 +77,7 @@ import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.TaskInfo;
import android.app.WindowConfiguration;
import android.compat.testing.PlatformCompatChangeRule;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -97,9 +100,13 @@ import androidx.test.filters.MediumTest;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;

import libcore.junit.util.compat.CoreCompatChangeRule;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.xmlpull.v1.XmlPullParser;
@@ -122,6 +129,9 @@ import java.io.Reader;
@RunWith(WindowTestRunner.class)
public class TaskTests extends WindowTestsBase {

    @Rule
    public TestRule compatChangeRule = new PlatformCompatChangeRule();

    private static final String TASK_TAG = "task";

    private Rect mParentBounds;
@@ -403,6 +413,85 @@ public class TaskTests extends WindowTestsBase {
        assertTrue(activity1.isVisibleRequested());
    }

    @Test
    @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_RESIZE_APP})
    public void testIsResizeable_nonResizeable_forceResize_overridesEnabled_Resizeable() {
        final Task task = new TaskBuilder(mSupervisor)
                .setCreateActivity(true)
                .setComponent(
                        ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
                .build();
        task.setResizeMode(RESIZE_MODE_UNRESIZEABLE);
        // Override should take effect and task should be resizeable.
        assertTrue(task.getTaskInfo().isResizeable);
    }

    @Test
    @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_RESIZE_APP})
    public void testIsResizeable_nonResizeable_forceResize_overridesDisabled_nonResizeable() {
        final Task task = new TaskBuilder(mSupervisor)
                .setCreateActivity(true)
                .setComponent(
                        ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
                .build();
        task.setResizeMode(RESIZE_MODE_UNRESIZEABLE);

        // Disallow resize overrides.
        task.mAllowForceResizeOverride = false;

        // Override should not take effect and task should be un-resizeable.
        assertFalse(task.getTaskInfo().isResizeable);
    }

    @Test
    @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_NON_RESIZE_APP})
    public void testIsResizeable_resizeable_forceNonResize_overridesEnabled_nonResizeable() {
        final Task task = new TaskBuilder(mSupervisor)
                .setCreateActivity(true)
                .setComponent(
                        ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
                .build();
        task.setResizeMode(RESIZE_MODE_RESIZEABLE);

        // Override should take effect and task should be un-resizeable.
        assertFalse(task.getTaskInfo().isResizeable);
    }

    @Test
    @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_NON_RESIZE_APP})
    public void testIsResizeable_resizeable_forceNonResize_overridesDisabled_Resizeable() {
        final Task task = new TaskBuilder(mSupervisor)
                .setCreateActivity(true)
                .setComponent(
                        ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
                .build();
        task.setResizeMode(RESIZE_MODE_RESIZEABLE);

        // Disallow resize overrides.
        task.mAllowForceResizeOverride = false;

        // Override should not take effect and task should be resizeable.
        assertTrue(task.getTaskInfo().isResizeable);
    }

    @Test
    @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_NON_RESIZE_APP})
    public void testIsResizeable_systemWideForceResize_compatForceNonResize__Resizeable() {
        final Task task = new TaskBuilder(mSupervisor)
                .setCreateActivity(true)
                .setComponent(
                        ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
                .build();
        task.setResizeMode(RESIZE_MODE_RESIZEABLE);

        // Set system-wide force resizeable override.
        task.mAtmService.mForceResizableActivities = true;

        // System wide override should tak priority over app compat override so the task should
        // remain resizeable.
        assertTrue(task.getTaskInfo().isResizeable);
    }

    @Test
    public void testResolveNonResizableTaskWindowingMode() {
        // Test with no support non-resizable in multi window regardless the screen size.