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

Commit 35c7b19f authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Using WindowContext for listening to configuration changes

Pre-S: Continue to use config-changed broadcast for configuration changes
and display-changed event for rotation changes
S+: Use WindowContext#componentCallbacks for config and rotation changes, and
continue to use display listener for frame-rate changes

Bug: 179308296
Test: Manual and presubmit
Change-Id: I533e69068b5fa6c052a02759ef309dd075ee6a4b
parent b9649ede
Loading
Loading
Loading
Loading
+27 −3
Original line number Original line Diff line number Diff line
@@ -17,17 +17,26 @@


package com.android.quickstep;
package com.android.quickstep;


import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.util.DisplayMetrics;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.Surface;


@@ -35,11 +44,11 @@ import com.android.launcher3.ResourceUtils;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController;


import org.junit.Before;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;


@RunWith(RobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class OrientationTouchTransformerTest {
public class OrientationTouchTransformerTest {
@@ -284,11 +293,26 @@ public class OrientationTouchTransformerTest {
    }
    }


    private DisplayController.Info createDisplayInfo(ScreenSize screenSize, int rotation) {
    private DisplayController.Info createDisplayInfo(ScreenSize screenSize, int rotation) {
        Context context = RuntimeEnvironment.application;
        Display display = spy(context.getSystemService(DisplayManager.class)
                .getDisplay(DEFAULT_DISPLAY));

        Point p = new Point(screenSize.mWidth, screenSize.mHeight);
        Point p = new Point(screenSize.mWidth, screenSize.mHeight);
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
            p = new Point(screenSize.mHeight, screenSize.mWidth);
            p.set(screenSize.mHeight, screenSize.mWidth);
        }
        }
        return new DisplayController.Info(0, rotation, 0, p, p, p, null);

        doReturn(rotation).when(display).getRotation();
        doAnswer(i -> {
            ((Point) i.getArgument(0)).set(p.x, p.y);
            return null;
        }).when(display).getRealSize(any(Point.class));
        doAnswer(i -> {
            ((Point) i.getArgument(0)).set(p.x, p.y);
            ((Point) i.getArgument(1)).set(p.x, p.y);
            return null;
        }).when(display).getCurrentSizeRange(any(Point.class), any(Point.class));
        return new DisplayController.Info(context, display);
    }
    }


    private float generateTouchRegionHeight(ScreenSize screenSize, int rotation) {
    private float generateTouchRegionHeight(ScreenSize screenSize, int rotation) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -147,7 +147,7 @@ public class TaskViewSimulatorTest {
                    LauncherActivityInterface.INSTANCE);
                    LauncherActivityInterface.INSTANCE);
            tvs.setDp(mDeviceProfile);
            tvs.setDp(mDeviceProfile);


            int launcherRotation = DisplayController.getDefaultDisplay(mContext).getInfo().rotation;
            int launcherRotation = DisplayController.INSTANCE.get(mContext).getInfo().rotation;
            if (mAppRotation < 0) {
            if (mAppRotation < 0) {
                mAppRotation = launcherRotation;
                mAppRotation = launcherRotation;
            }
            }
+1 −1
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@ import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_HIDE_BACK_BUTTON;
import static com.android.launcher3.AbstractFloatingView.TYPE_HIDE_BACK_BUTTON;
import static com.android.launcher3.LauncherState.FLAG_HIDE_BACK_BUTTON;
import static com.android.launcher3.LauncherState.FLAG_HIDE_BACK_BUTTON;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.util.DisplayController.DisplayHolder.CHANGE_SIZE;
import static com.android.launcher3.util.DisplayController.CHANGE_SIZE;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.quickstep.SysUINavigationMode.Mode.TWO_BUTTONS;
import static com.android.quickstep.SysUINavigationMode.Mode.TWO_BUTTONS;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY;
+1 −1
Original line number Original line Diff line number Diff line
@@ -267,7 +267,7 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
    }
    }


    private float dpiFromPx(float pixels) {
    private float dpiFromPx(float pixels) {
        return Utilities.dpiFromPx(pixels, mLauncher.getResources().getDisplayMetrics());
        return Utilities.dpiFromPx(pixels, mLauncher.getResources().getDisplayMetrics().densityDpi);
    }
    }


    @Override
    @Override
+13 −18
Original line number Original line Diff line number Diff line
@@ -17,8 +17,8 @@ package com.android.quickstep;


import static android.content.Intent.ACTION_USER_UNLOCKED;
import static android.content.Intent.ACTION_USER_UNLOCKED;


import static com.android.launcher3.util.DisplayController.DisplayHolder.CHANGE_ALL;
import static com.android.launcher3.util.DisplayController.CHANGE_ALL;
import static com.android.launcher3.util.DisplayController.DisplayHolder.CHANGE_FRAME_DELAY;
import static com.android.launcher3.util.DisplayController.CHANGE_FRAME_DELAY;
import static com.android.launcher3.util.SettingsCache.ONE_HANDED_ENABLED;
import static com.android.launcher3.util.SettingsCache.ONE_HANDED_ENABLED;
import static com.android.launcher3.util.SettingsCache.ONE_HANDED_SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED;
import static com.android.launcher3.util.SettingsCache.ONE_HANDED_SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED;
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
@@ -62,7 +62,6 @@ import androidx.annotation.BinderThread;
import com.android.launcher3.R;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayHolder;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SettingsCache;
@@ -91,7 +90,7 @@ public class RecentsAnimationDeviceState implements


    private final Context mContext;
    private final Context mContext;
    private final SysUINavigationMode mSysUiNavMode;
    private final SysUINavigationMode mSysUiNavMode;
    private final DisplayHolder mDisplayHolder;
    private final DisplayController mDisplayController;
    private final int mDisplayId;
    private final int mDisplayId;
    private final RotationTouchHelper mRotationTouchHelper;
    private final RotationTouchHelper mRotationTouchHelper;


@@ -128,17 +127,13 @@ public class RecentsAnimationDeviceState implements
    private boolean mIsUserSetupComplete;
    private boolean mIsUserSetupComplete;


    public RecentsAnimationDeviceState(Context context) {
    public RecentsAnimationDeviceState(Context context) {
        this(context, DisplayController.getDefaultDisplay(context));
    }

    public RecentsAnimationDeviceState(Context context, DisplayHolder displayHolder) {
        mContext = context;
        mContext = context;
        mDisplayHolder = displayHolder;
        mDisplayController = DisplayController.INSTANCE.get(context);
        mSysUiNavMode = SysUINavigationMode.INSTANCE.get(context);
        mSysUiNavMode = SysUINavigationMode.INSTANCE.get(context);
        mDisplayId = mDisplayHolder.getInfo().id;
        mDisplayId = mDisplayController.getInfo().id;
        mIsOneHandedModeSupported = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false);
        mIsOneHandedModeSupported = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false);
        runOnDestroy(() -> mDisplayHolder.removeChangeListener(this));
        runOnDestroy(() -> mDisplayController.removeChangeListener(this));
        mRotationTouchHelper = new RotationTouchHelper(context, mDisplayHolder);
        mRotationTouchHelper = new RotationTouchHelper(context, mDisplayController);
        runOnDestroy(mRotationTouchHelper::destroy);
        runOnDestroy(mRotationTouchHelper::destroy);


        // Register for user unlocked if necessary
        // Register for user unlocked if necessary
@@ -244,9 +239,9 @@ public class RecentsAnimationDeviceState implements


    @Override
    @Override
    public void onNavigationModeChanged(SysUINavigationMode.Mode newMode) {
    public void onNavigationModeChanged(SysUINavigationMode.Mode newMode) {
        mDisplayHolder.removeChangeListener(this);
        mDisplayController.removeChangeListener(this);
        mDisplayHolder.addChangeListener(this);
        mDisplayController.addChangeListener(this);
        onDisplayInfoChanged(mDisplayHolder.getInfo(), CHANGE_ALL);
        onDisplayInfoChanged(mDisplayController.getInfo(), CHANGE_ALL);


        if (newMode == NO_BUTTON) {
        if (newMode == NO_BUTTON) {
            mExclusionListener.register();
            mExclusionListener.register();
@@ -254,7 +249,7 @@ public class RecentsAnimationDeviceState implements
            mExclusionListener.unregister();
            mExclusionListener.unregister();
        }
        }


        mNavBarPosition = new NavBarPosition(newMode, mDisplayHolder.getInfo());
        mNavBarPosition = new NavBarPosition(newMode, mDisplayController.getInfo());
        mMode = newMode;
        mMode = newMode;
    }
    }


@@ -556,11 +551,11 @@ public class RecentsAnimationDeviceState implements
        }
        }


        if (mIsOneHandedModeEnabled || mIsSwipeToNotificationEnabled) {
        if (mIsOneHandedModeEnabled || mIsSwipeToNotificationEnabled) {
            final Info displayInfo = mDisplayHolder.getInfo();
            final Info displayInfo = mDisplayController.getInfo();
            return (mRotationTouchHelper.touchInOneHandedModeRegion(ev)
            return (mRotationTouchHelper.touchInOneHandedModeRegion(ev)
                && displayInfo.rotation != Surface.ROTATION_90
                && displayInfo.rotation != Surface.ROTATION_90
                && displayInfo.rotation != Surface.ROTATION_270
                && displayInfo.rotation != Surface.ROTATION_270
                && displayInfo.metrics.densityDpi < DisplayMetrics.DENSITY_600);
                && displayInfo.densityDpi < DisplayMetrics.DENSITY_600);
        }
        }
        return false;
        return false;
    }
    }
Loading