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

Commit 5ef8b6f8 authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge "Allow swipe up on unlocked dream." into tm-qpr-dev

parents 7e9ff1ef fc12f29e
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -37,8 +37,10 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.complication.ComplicationHostViewController;
import com.android.systemui.dreams.dagger.DreamOverlayComponent;
import com.android.systemui.dreams.dagger.DreamOverlayModule;
import com.android.systemui.dreams.touch.scrim.BouncerlessScrimController;
import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor;
import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback;
import com.android.systemui.shade.ShadeExpansionChangeEvent;
import com.android.systemui.statusbar.BlurUtils;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.concurrency.DelayableExecutor;
@@ -82,6 +84,22 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve
    private long mJitterStartTimeMillis;

    private boolean mBouncerAnimating;
    private boolean mWakingUpFromSwipe;

    private final BouncerlessScrimController mBouncerlessScrimController;

    private final BouncerlessScrimController.Callback mBouncerlessExpansionCallback =
            new BouncerlessScrimController.Callback() {
        @Override
        public void onExpansion(ShadeExpansionChangeEvent event) {
            updateTransitionState(event.getFraction());
        }

        @Override
        public void onWakeup() {
            mWakingUpFromSwipe = true;
        }
    };

    private final PrimaryBouncerExpansionCallback
            mBouncerExpansionCallback =
@@ -156,7 +174,8 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve
            @Named(DreamOverlayModule.MILLIS_UNTIL_FULL_JITTER) long millisUntilFullJitter,
            PrimaryBouncerCallbackInteractor primaryBouncerCallbackInteractor,
            DreamOverlayAnimationsController animationsController,
            DreamOverlayStateController stateController) {
            DreamOverlayStateController stateController,
            BouncerlessScrimController bouncerlessScrimController) {
        super(containerView);
        mDreamOverlayContentView = contentView;
        mStatusBarViewController = statusBarViewController;
@@ -164,6 +183,9 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve
        mDreamOverlayAnimationsController = animationsController;
        mStateController = stateController;

        mBouncerlessScrimController = bouncerlessScrimController;
        mBouncerlessScrimController.addCallback(mBouncerlessExpansionCallback);

        mComplicationHostViewController = complicationHostViewController;
        mDreamOverlayMaxTranslationY = resources.getDimensionPixelSize(
                R.dimen.dream_overlay_y_offset);
@@ -190,6 +212,7 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve

    @Override
    protected void onViewAttached() {
        mWakingUpFromSwipe = false;
        mJitterStartTimeMillis = System.currentTimeMillis();
        mHandler.postDelayed(this::updateBurnInOffsets, mBurnInProtectionUpdateInterval);
        mPrimaryBouncerCallbackInteractor.addBouncerExpansionCallback(mBouncerExpansionCallback);
@@ -278,6 +301,13 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve
     */
    public void wakeUp(@NonNull Runnable onAnimationEnd,
            @NonNull DelayableExecutor callbackExecutor) {
        // When swiping causes wakeup, do not run any animations as the dream should exit as soon
        // as possible.
        if (mWakingUpFromSwipe) {
            onAnimationEnd.run();
            return;
        }

        mDreamOverlayAnimationsController.wakeUp(onAnimationEnd, callbackExecutor);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.DreamOverlayNotificationCountProvider;
import com.android.systemui.dreams.DreamOverlayService;
import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule;
import com.android.systemui.dreams.touch.scrim.dagger.ScrimModule;

import java.util.Optional;

@@ -42,6 +43,7 @@ import dagger.Provides;
@Module(includes = {
            RegisteredComplicationsModule.class,
            LowLightDreamModule.class,
            ScrimModule.class
        },
        subcomponents = {
            DreamOverlayComponent.class,
+31 −11
Original line number Diff line number Diff line
@@ -36,11 +36,12 @@ import androidx.annotation.VisibleForTesting;

import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.dreams.touch.scrim.ScrimController;
import com.android.systemui.dreams.touch.scrim.ScrimManager;
import com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants;
import com.android.systemui.shade.ShadeExpansionChangeEvent;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.wm.shell.animation.FlingAnimationUtils;

import java.util.Optional;
@@ -78,7 +79,8 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
    private final NotificationShadeWindowController mNotificationShadeWindowController;
    private final float mBouncerZoneScreenPercentage;

    private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
    private final ScrimManager mScrimManager;
    private ScrimController mCurrentScrimController;
    private float mCurrentExpansion;
    private final Optional<CentralSurfaces> mCentralSurfaces;

@@ -90,6 +92,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
    private final DisplayMetrics mDisplayMetrics;

    private Boolean mCapture;
    private Boolean mExpanded;

    private boolean mBouncerInitiallyShowing;

@@ -101,6 +104,17 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {

    private final UiEventLogger mUiEventLogger;

    private final ScrimManager.Callback mScrimManagerCallback = new ScrimManager.Callback() {
        @Override
        public void onScrimControllerChanged(ScrimController controller) {
            if (mCurrentScrimController != null) {
                mCurrentScrimController.reset();
            }

            mCurrentScrimController = controller;
        }
    };

    private final GestureDetector.OnGestureListener mOnGestureListener =
            new GestureDetector.SimpleOnGestureListener() {
                @Override
@@ -115,8 +129,10 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
                                .orElse(false);

                        if (mCapture) {
                            // reset expanding
                            mExpanded = false;
                            // Since the user is dragging the bouncer up, set scrimmed to false.
                            mStatusBarKeyguardViewManager.showPrimaryBouncer(false);
                            mCurrentScrimController.show();
                        }
                    }

@@ -157,10 +173,10 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
        ShadeExpansionChangeEvent event =
                new ShadeExpansionChangeEvent(
                        /* fraction= */ mCurrentExpansion,
                        /* expanded= */ false,
                        /* expanded= */ mExpanded,
                        /* tracking= */ true,
                        /* dragDownPxAmount= */ dragDownAmount);
        mStatusBarKeyguardViewManager.onPanelExpansionChanged(event);
        mCurrentScrimController.expand(event);
    }


@@ -187,7 +203,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
    @Inject
    public BouncerSwipeTouchHandler(
            DisplayMetrics displayMetrics,
            StatusBarKeyguardViewManager statusBarKeyguardViewManager,
            ScrimManager scrimManager,
            Optional<CentralSurfaces> centralSurfaces,
            NotificationShadeWindowController notificationShadeWindowController,
            ValueAnimatorCreator valueAnimatorCreator,
@@ -200,7 +216,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
            UiEventLogger uiEventLogger) {
        mDisplayMetrics = displayMetrics;
        mCentralSurfaces = centralSurfaces;
        mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
        mScrimManager = scrimManager;
        mNotificationShadeWindowController = notificationShadeWindowController;
        mBouncerZoneScreenPercentage = swipeRegionPercentage;
        mFlingAnimationUtils = flingAnimationUtils;
@@ -234,9 +250,12 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
        mTouchSession = session;
        mVelocityTracker.clear();
        mNotificationShadeWindowController.setForcePluginOpen(true, this);
        mScrimManager.addCallback(mScrimManagerCallback);
        mCurrentScrimController = mScrimManager.getCurrentController();

        session.registerCallback(() -> {
            mVelocityTracker.recycle();
            mScrimManager.removeCallback(mScrimManagerCallback);
            mCapture = null;
            mNotificationShadeWindowController.setForcePluginOpen(false, this);
        });
@@ -273,9 +292,10 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
                final float velocityVector =
                        (float) Math.hypot(horizontalVelocity, verticalVelocity);

                final float expansion = flingRevealsOverlay(verticalVelocity, velocityVector)
                        ? KeyguardBouncerConstants.EXPANSION_HIDDEN
                        : KeyguardBouncerConstants.EXPANSION_VISIBLE;
                mExpanded = !flingRevealsOverlay(verticalVelocity, velocityVector);
                final float expansion = mExpanded
                        ? KeyguardBouncerConstants.EXPANSION_VISIBLE
                        : KeyguardBouncerConstants.EXPANSION_HIDDEN;

                // Log the swiping up to show Bouncer event.
                if (!mBouncerInitiallyShowing
@@ -286,7 +306,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
                flingToExpansion(verticalVelocity, expansion);

                if (expansion == KeyguardBouncerConstants.EXPANSION_HIDDEN) {
                    mStatusBarKeyguardViewManager.reset(false);
                    mCurrentScrimController.reset();
                }
                break;
            default:
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.dreams.touch.scrim;

import com.android.systemui.shade.ShadeExpansionChangeEvent;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;

import javax.inject.Inject;

/**
 * Implementation for handling swipe movements on the overlay when the keyguard is present.
 */
public class BouncerScrimController implements ScrimController {
    private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;

    @Inject
    BouncerScrimController(StatusBarKeyguardViewManager statusBarKeyguardViewManager) {
        mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
    }

    @Override
    public void show() {
        mStatusBarKeyguardViewManager.showBouncer(false);
    }

    @Override
    public void expand(ShadeExpansionChangeEvent event) {
        mStatusBarKeyguardViewManager.onPanelExpansionChanged(event);
    }

    @Override
    public void reset() {
        mStatusBarKeyguardViewManager.reset(false);
    }
}
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.dreams.touch.scrim;

import android.os.PowerManager;
import android.os.SystemClock;

import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.shade.ShadeExpansionChangeEvent;
import com.android.systemui.unfold.util.CallbackController;

import java.util.HashSet;
import java.util.concurrent.Executor;

import javax.inject.Inject;

/**
 * {@link BouncerlessScrimController} handles scrim progression when no keyguard is set. When
 * fully expanded, the controller dismisses the dream.
 */
@SysUISingleton
public class BouncerlessScrimController implements ScrimController,
        CallbackController<BouncerlessScrimController.Callback> {
    private static final String TAG = "BLScrimController";

    /**
     * {@link Callback} allows {@link BouncerlessScrimController} clients to be informed of
     * expansion progression and wakeup
     */
    public interface Callback {
        /**
         * Invoked when there is a change to the scrim expansion.
         */
        void onExpansion(ShadeExpansionChangeEvent event);

        /**
         * Invoked after {@link BouncerlessScrimController} has started waking up the device.
         */
        void onWakeup();
    }

    private final Executor mExecutor;
    private final PowerManager mPowerManager;

    @Override
    public void addCallback(Callback listener) {
        mExecutor.execute(() -> mCallbacks.add(listener));
    }

    @Override
    public void removeCallback(Callback listener) {
        mExecutor.execute(() -> mCallbacks.remove(listener));
    }

    private final HashSet<Callback> mCallbacks;


    @Inject
    public BouncerlessScrimController(@Main Executor executor,
            PowerManager powerManager) {
        mExecutor = executor;
        mPowerManager = powerManager;
        mCallbacks = new HashSet<>();
    }

    @Override
    public void expand(ShadeExpansionChangeEvent event) {
        if (event.getExpanded())  {
            mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
                    "com.android.systemui:SwipeUp");
            mExecutor.execute(() -> mCallbacks.forEach(callback -> callback.onWakeup()));
        } else {
            mExecutor.execute(() -> mCallbacks.forEach(callback -> callback.onExpansion(event)));
        }
    }
}
Loading