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

Commit 8a38f393 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Initialize RotationTouchHelper with RecentsAnimationDeviceState ctor" into sc-dev

parents 701947dd 3f6c3e13
Loading
Loading
Loading
Loading
+29 −9
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ class OrientationTouchTransformer {
    };

    private static final String TAG = "OrientationTouchTransformer";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = true;

    private static final int QUICKSTEP_ROTATION_UNINITIALIZED = -1;

@@ -163,6 +163,10 @@ class OrientationTouchTransformer {

    void setNavigationMode(SysUINavigationMode.Mode newMode, Info info,
            Resources newRes) {
        if (DEBUG) {
            Log.d(TestProtocol.NO_SWIPE_TO_HOME, "setNavigationMode new: " + newMode
                    + " oldMode: " + mMode + " " + this);
        }
        if (mMode == newMode) {
            return;
        }
@@ -254,10 +258,18 @@ class OrientationTouchTransformer {

        mCurrentDisplay = new CurrentDisplay(region.realSize, region.rotation);
        OrientationRectF regionToKeep = mSwipeTouchRegions.get(mCurrentDisplay);
        if (DEBUG) {
            Log.d(TestProtocol.NO_SWIPE_TO_HOME, "cached region: " + regionToKeep
                    + " mCurrentDisplay: " + mCurrentDisplay + " " + this);
        }
        if (regionToKeep == null) {
            regionToKeep = createRegionForDisplay(region);
        }
        mSwipeTouchRegions.clear();
        if (DEBUG) {
            Log.d(TestProtocol.NO_SWIPE_TO_HOME, "adding region: " + regionToKeep
                    + " mCurrentDisplay: " + mCurrentDisplay + " " + this);
        }
        mSwipeTouchRegions.put(mCurrentDisplay, regionToKeep);
        updateAssistantRegions(regionToKeep);
    }
@@ -273,7 +285,8 @@ class OrientationTouchTransformer {

    private OrientationRectF createRegionForDisplay(Info display) {
        if (DEBUG) {
            Log.d(TAG, "creating rotation region for: " + mCurrentDisplay.rotation);
            Log.d(TAG, "creating rotation region for: " + mCurrentDisplay.rotation
            + " with mode: " + mMode + " displayRotation: " + display.rotation);
        }

        Point size = display.realSize;
@@ -287,14 +300,19 @@ class OrientationTouchTransformer {
        } else {
            mAssistantLeftRegion.setEmpty();
            mAssistantRightRegion.setEmpty();
            int navbarSize = getNavbarSize(ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE);
            if (DEBUG) {
                Log.d(TestProtocol.NO_SWIPE_TO_HOME, "else case mode: " + mMode
                        + " getNavbarSize: " + navbarSize + " rotation: " + rotation + " " + this);
            }
            switch (rotation) {
                case Surface.ROTATION_90:
                    orientationRectF.left = orientationRectF.right
                            - getNavbarSize(ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE);
                            - navbarSize;
                    break;
                case Surface.ROTATION_270:
                    orientationRectF.right = orientationRectF.left
                            + getNavbarSize(ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE);
                            + navbarSize;
                    break;
                default:
                    orientationRectF.top = orientationRectF.bottom - touchHeight;
@@ -339,7 +357,7 @@ class OrientationTouchTransformer {
    boolean touchInValidSwipeRegions(float x, float y) {
        if (TestProtocol.sDebugTracing) {
            Log.d(TestProtocol.NO_SWIPE_TO_HOME, "touchInValidSwipeRegions " + x + "," + y + " in "
                    + mLastRectTouched);
                    + mLastRectTouched + " this: " + this);
        }
        if (mLastRectTouched != null) {
            return mLastRectTouched.contains(x, y);
@@ -462,7 +480,8 @@ class OrientationTouchTransformer {
                if (DEBUG) {
                    Log.d(TAG, "Transforming rotation due to forceTransform, "
                            + "mCurrentRotation: " + mCurrentDisplay.rotation
                            + "mRotation: " + mRotation);
                            + "mRotation: " + mRotation
                            + " this: " + this);
                }
                event.transform(mTmpMatrix);
                return true;
@@ -475,7 +494,8 @@ class OrientationTouchTransformer {
                Log.d(TAG, "original: " + event.getX() + ", " + event.getY()
                        + " new: " + mTmpPoint[0] + ", " + mTmpPoint[1]
                        + " rect: " + this + " forceTransform: " + forceTransform
                                + " contains: " + contains(mTmpPoint[0], mTmpPoint[1]));
                        + " contains: " + contains(mTmpPoint[0], mTmpPoint[1])
                        + " this: " + this);
            }

            if (contains(mTmpPoint[0], mTmpPoint[1])) {
+18 −2
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.Surface;

@@ -61,6 +62,7 @@ import androidx.annotation.BinderThread;

import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
@@ -127,14 +129,27 @@ public class RecentsAnimationDeviceState implements
    private boolean mIsUserSetupComplete;

    public RecentsAnimationDeviceState(Context context) {
        this(context, false);
    }

    /**
     * @param isInstanceForTouches {@code true} if this is the persistent instance being used for
     *                                   gesture touch handling
     */
    public RecentsAnimationDeviceState(Context context, boolean isInstanceForTouches) {
        mContext = context;
        mDisplayController = DisplayController.INSTANCE.get(context);
        mSysUiNavMode = SysUINavigationMode.INSTANCE.get(context);
        mDisplayId = mDisplayController.getInfo().id;
        mIsOneHandedModeSupported = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false);
        runOnDestroy(() -> mDisplayController.removeChangeListener(this));
        mRotationTouchHelper = new RotationTouchHelper(context, mDisplayController);
        mRotationTouchHelper = RotationTouchHelper.INSTANCE.get(context);
        if (isInstanceForTouches) {
            // rotationTouchHelper doesn't get initialized after being destroyed, so only destroy
            // if primary TouchInteractionService instance needs to be destroyed.
            mRotationTouchHelper.init();
            runOnDestroy(mRotationTouchHelper::destroy);
        }

        // Register for user unlocked if necessary
        mIsUserUnlocked = context.getSystemService(UserManager.class)
@@ -214,6 +229,7 @@ public class RecentsAnimationDeviceState implements
     * Cleans up all the registered listeners and receivers.
     */
    public void destroy() {
        Log.d(TestProtocol.NO_SWIPE_TO_HOME, "destroying RADS", new Throwable());
        for (Runnable r : mOnDestroyActions) {
            r.run();
        }
+45 −11
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.quickstep.SysUINavigationMode.Mode.THREE_BUTTONS;

import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
import android.view.MotionEvent;
import android.view.OrientationEventListener;

@@ -31,6 +32,7 @@ import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.quickstep.util.RecentsOrientedState;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.QuickStepContract;
@@ -43,10 +45,13 @@ public class RotationTouchHelper implements
        SysUINavigationMode.NavigationModeChangeListener,
        DisplayInfoChangeListener {

    private final OrientationTouchTransformer mOrientationTouchTransformer;
    private final DisplayController mDisplayController;
    private final SysUINavigationMode mSysUiNavMode;
    private final int mDisplayId;
    public static final MainThreadInitializedObject<RotationTouchHelper> INSTANCE =
            new MainThreadInitializedObject<>(RotationTouchHelper::new);

    private OrientationTouchTransformer mOrientationTouchTransformer;
    private DisplayController mDisplayController;
    private SysUINavigationMode mSysUiNavMode;
    private int mDisplayId;
    private int mDisplayRotation;

    private final ArrayList<Runnable> mOnDestroyActions = new ArrayList<>();
@@ -117,25 +122,46 @@ public class RotationTouchHelper implements
     */
    private boolean mInOverview;
    private boolean mTaskListFrozen;


    private final Context mContext;

    public RotationTouchHelper(Context context, DisplayController displayController) {
    /**
     * Keeps track of whether destroy has been called for this instance. Mainly used for TAPL tests
     * where multiple instances of RotationTouchHelper are being created. b/177316094
     */
    private boolean mNeedsInit = true;

    private RotationTouchHelper(Context context) {
        mContext = context;
        mDisplayController = displayController;
        Log.d(TestProtocol.NO_SWIPE_TO_HOME, "RotationTouchHelper ctor init? " + mNeedsInit
                + " " + this);
        if (mNeedsInit) {
            init();
        }
    }

    public void init() {
        if (!mNeedsInit) {
            Log.d(TestProtocol.NO_SWIPE_TO_HOME, "Did not need init? " + " " + this);
            return;
        }
        Log.d(TestProtocol.NO_SWIPE_TO_HOME, "RotationTouchHelper init() " + this,
                new Throwable());
        mDisplayController = DisplayController.INSTANCE.get(mContext);
        Resources resources = mContext.getResources();
        mSysUiNavMode = SysUINavigationMode.INSTANCE.get(context);
        mSysUiNavMode = SysUINavigationMode.INSTANCE.get(mContext);
        mDisplayId = mDisplayController.getInfo().id;

        mOrientationTouchTransformer = new OrientationTouchTransformer(resources, mMode,
                () -> QuickStepContract.getWindowCornerRadius(resources));

        // Register for navigation mode changes
        onNavigationModeChanged(mSysUiNavMode.addModeChangeListener(this));
        SysUINavigationMode.Mode newMode = mSysUiNavMode.addModeChangeListener(this);
        Log.d(TestProtocol.NO_SWIPE_TO_HOME, "AddedModeChangeListener: " + this +
                " currentMode: " + newMode);
        onNavigationModeChanged(newMode);
        runOnDestroy(() -> mSysUiNavMode.removeModeChangeListener(this));

        mOrientationListener = new OrientationEventListener(context) {
        mOrientationListener = new OrientationEventListener(mContext) {
            @Override
            public void onOrientationChanged(int degrees) {
                int newRotation = RecentsOrientedState.getRotationForUserDegreesRotated(degrees,
@@ -154,6 +180,7 @@ public class RotationTouchHelper implements
                }
            }
        };
        mNeedsInit = false;
    }

    private void setupOrientationSwipeHandler() {
@@ -176,9 +203,11 @@ public class RotationTouchHelper implements
     * Cleans up all the registered listeners and receivers.
     */
    public void destroy() {
        Log.d(TestProtocol.NO_SWIPE_TO_HOME, "destroying " + this);
        for (Runnable r : mOnDestroyActions) {
            r.run();
        }
        mNeedsInit = true;
    }

    public boolean isTaskListFrozen() {
@@ -223,6 +252,7 @@ public class RotationTouchHelper implements

    @Override
    public void onNavigationModeChanged(SysUINavigationMode.Mode newMode) {
        Log.d(TestProtocol.NO_SWIPE_TO_HOME, "nav mode changed: " + newMode);
        mDisplayController.removeChangeListener(this);
        mDisplayController.addChangeListener(this);
        onDisplayInfoChanged(mContext, mDisplayController.getInfo(), CHANGE_ALL);
@@ -374,4 +404,8 @@ public class RotationTouchHelper implements
        pw.println("  displayRotation=" + getDisplayRotation());
        mOrientationTouchTransformer.dump(pw);
    }

    public OrientationTouchTransformer getOrientationTouchTransformer() {
        return mOrientationTouchTransformer;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -300,7 +300,9 @@ public class TouchInteractionService extends Service implements PluginListener<O
        // Everything else should be initialized in onUserUnlocked() below.
        mMainChoreographer = Choreographer.getInstance();
        mAM = ActivityManagerWrapper.getInstance();
        mDeviceState = new RecentsAnimationDeviceState(this);
        mDeviceState = new RecentsAnimationDeviceState(this, true);
            Log.d(TestProtocol.NO_SWIPE_TO_HOME, "RADS OTT instance: " +
                    mDeviceState.getRotationTouchHelper().getOrientationTouchTransformer());
        mRotationTouchHelper = mDeviceState.getRotationTouchHelper();
        mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged);
        mDeviceState.addOneHandedModeChangedCallback(this::onOneHandedModeOverlayChanged);