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

Commit 4264971f authored by Shawn Lee's avatar Shawn Lee Committed by Android (Google) Code Review
Browse files

Merge "Revert "Revert "Extract camera launch code from NPVC into Centra..."" into tm-qpr-dev

parents f668c059 404f12ff
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.shade;

import com.android.systemui.camera.CameraGestureHelper;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.statusbar.phone.KeyguardBypassController;

import javax.inject.Inject;

/** Handles launching camera from Shade. */
@SysUISingleton
public class CameraLauncher {
    private final CameraGestureHelper mCameraGestureHelper;
    private final KeyguardBypassController mKeyguardBypassController;

    private boolean mLaunchingAffordance;

    @Inject
    public CameraLauncher(
            CameraGestureHelper cameraGestureHelper,
            KeyguardBypassController keyguardBypassController
    ) {
        mCameraGestureHelper = cameraGestureHelper;
        mKeyguardBypassController = keyguardBypassController;
    }

    /** Launches the camera. */
    public void launchCamera(int source, boolean isShadeFullyCollapsed) {
        if (!isShadeFullyCollapsed) {
            setLaunchingAffordance(true);
        }

        mCameraGestureHelper.launchCamera(source);
    }

    /**
     * Set whether we are currently launching an affordance. This is currently only set when
     * launched via a camera gesture.
     */
    public void setLaunchingAffordance(boolean launchingAffordance) {
        mLaunchingAffordance = launchingAffordance;
        mKeyguardBypassController.setLaunchingAffordance(launchingAffordance);
    }

    /**
     * Return true when a bottom affordance is launching an occluded activity with a splash screen.
     */
    public boolean isLaunchingAffordance() {
        return mLaunchingAffordance;
    }

    /**
     * Whether the camera application can be launched for the camera launch gesture.
     */
    public boolean canCameraGestureBeLaunched(int barState) {
        return mCameraGestureHelper.canCameraGestureBeLaunched(barState);
    }
}
+4 −35
Original line number Diff line number Diff line
@@ -124,7 +124,6 @@ import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.animation.LaunchAnimator;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.camera.CameraGestureHelper;
import com.android.systemui.classifier.Classifier;
import com.android.systemui.classifier.FalsingCollector;
import com.android.systemui.dagger.qualifiers.DisplayId;
@@ -464,7 +463,6 @@ public final class NotificationPanelViewController implements Dumpable {
    private boolean mCollapsedOnDown;
    private boolean mClosingWithAlphaFadeOut;
    private boolean mHeadsUpAnimatingAway;
    private boolean mLaunchingAffordance;
    private final FalsingManager mFalsingManager;
    private final FalsingCollector mFalsingCollector;

@@ -615,7 +613,6 @@ public final class NotificationPanelViewController implements Dumpable {
    private final NotificationListContainer mNotificationListContainer;
    private final NotificationStackSizeCalculator mNotificationStackSizeCalculator;
    private final NPVCDownEventState.Buffer mLastDownEvents;
    private final CameraGestureHelper mCameraGestureHelper;
    private final KeyguardBottomAreaViewModel mKeyguardBottomAreaViewModel;
    private final KeyguardBottomAreaInteractor mKeyguardBottomAreaInteractor;
    private float mMinExpandHeight;
@@ -743,7 +740,6 @@ public final class NotificationPanelViewController implements Dumpable {
            UnlockedScreenOffAnimationController unlockedScreenOffAnimationController,
            ShadeTransitionController shadeTransitionController,
            SystemClock systemClock,
            CameraGestureHelper cameraGestureHelper,
            KeyguardBottomAreaViewModel keyguardBottomAreaViewModel,
            KeyguardBottomAreaInteractor keyguardBottomAreaInteractor,
            DumpManager dumpManager) {
@@ -924,7 +920,6 @@ public final class NotificationPanelViewController implements Dumpable {
                        unlockAnimationStarted(playingCannedAnimation, isWakeAndUnlock, startDelay);
                    }
                });
        mCameraGestureHelper = cameraGestureHelper;
        mKeyguardBottomAreaInteractor = keyguardBottomAreaInteractor;
        dumpManager.registerDumpable(this);
    }
@@ -3946,6 +3941,10 @@ public final class NotificationPanelViewController implements Dumpable {
        }
    }

    public int getBarState() {
        return mBarState;
    }

    private boolean isOnKeyguard() {
        return mBarState == KEYGUARD;
    }
@@ -3991,35 +3990,6 @@ public final class NotificationPanelViewController implements Dumpable {
                && mBarState == StatusBarState.SHADE;
    }

    /** Launches the camera. */
    public void launchCamera(int source) {
        if (!isFullyCollapsed()) {
            setLaunchingAffordance(true);
        }

        mCameraGestureHelper.launchCamera(source);
    }

    public void onAffordanceLaunchEnded() {
        setLaunchingAffordance(false);
    }

    /** Set whether we are currently launching an affordance (i.e. camera gesture). */
    private void setLaunchingAffordance(boolean launchingAffordance) {
        mLaunchingAffordance = launchingAffordance;
        mKeyguardBypassController.setLaunchingAffordance(launchingAffordance);
    }

    /** Returns whether a bottom affordance is launching an occluded activity with splash screen. */
    public boolean isLaunchingAffordanceWithPreview() {
        return mLaunchingAffordance;
    }

    /** Whether the camera application can be launched by the camera launch gesture. */
    public boolean canCameraGestureBeLaunched() {
        return mCameraGestureHelper.canCameraGestureBeLaunched(mBarState);
    }

    public boolean hideStatusBarIconsWhenExpanded() {
        if (mIsLaunchAnimationRunning) {
            return mHideIconsDuringLaunchAnimation;
@@ -4358,7 +4328,6 @@ public final class NotificationPanelViewController implements Dumpable {
        ipw.print("mCollapsedOnDown="); ipw.println(mCollapsedOnDown);
        ipw.print("mClosingWithAlphaFadeOut="); ipw.println(mClosingWithAlphaFadeOut);
        ipw.print("mHeadsUpAnimatingAway="); ipw.println(mHeadsUpAnimatingAway);
        ipw.print("mLaunchingAffordance="); ipw.println(mLaunchingAffordance);
        ipw.print("mShowIconsWhenExpanded="); ipw.println(mShowIconsWhenExpanded);
        ipw.print("mIndicationBottomPadding="); ipw.println(mIndicationBottomPadding);
        ipw.print("mAmbientIndicationBottomPadding="); ipw.println(mAmbientIndicationBottomPadding);
+11 −4
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import com.android.systemui.dagger.qualifiers.DisplayId;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.qs.QSPanelController;
import com.android.systemui.shade.CameraLauncher;
import com.android.systemui.shade.NotificationPanelViewController;
import com.android.systemui.shade.ShadeController;
import com.android.systemui.statusbar.CommandQueue;
@@ -71,6 +72,8 @@ import java.util.Optional;

import javax.inject.Inject;

import dagger.Lazy;

/** */
@CentralSurfacesComponent.CentralSurfacesScope
public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callbacks {
@@ -99,6 +102,7 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba
    private final boolean mVibrateOnOpening;
    private final VibrationEffect mCameraLaunchGestureVibrationEffect;
    private final SystemBarAttributesListener mSystemBarAttributesListener;
    private final Lazy<CameraLauncher> mCameraLauncherLazy;

    private static final VibrationAttributes HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES =
            VibrationAttributes.createForUsage(VibrationAttributes.USAGE_HARDWARE_FEEDBACK);
@@ -128,8 +132,8 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba
            Optional<Vibrator> vibratorOptional,
            DisableFlagsLogger disableFlagsLogger,
            @DisplayId int displayId,
            SystemBarAttributesListener systemBarAttributesListener) {

            SystemBarAttributesListener systemBarAttributesListener,
            Lazy<CameraLauncher> cameraLauncherLazy) {
        mCentralSurfaces = centralSurfaces;
        mContext = context;
        mShadeController = shadeController;
@@ -152,6 +156,7 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba
        mVibratorOptional = vibratorOptional;
        mDisableFlagsLogger = disableFlagsLogger;
        mDisplayId = displayId;
        mCameraLauncherLazy = cameraLauncherLazy;

        mVibrateOnOpening = resources.getBoolean(R.bool.config_vibrateOnIconAnimation);
        mCameraLaunchGestureVibrationEffect = getCameraGestureVibrationEffect(
@@ -346,7 +351,8 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba
            mCentralSurfaces.setLaunchCameraOnFinishedGoingToSleep(true);
            return;
        }
        if (!mNotificationPanelViewController.canCameraGestureBeLaunched()) {
        if (!mCameraLauncherLazy.get().canCameraGestureBeLaunched(
                mNotificationPanelViewController.getBarState())) {
            if (CentralSurfaces.DEBUG_CAMERA_LIFT) {
                Slog.d(CentralSurfaces.TAG, "Can't launch camera right now");
            }
@@ -383,7 +389,8 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba
                if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
                    mStatusBarKeyguardViewManager.reset(true /* hide */);
                }
                mNotificationPanelViewController.launchCamera(source);
                mCameraLauncherLazy.get().launchCamera(source,
                        mNotificationPanelViewController.isFullyCollapsed());
                mCentralSurfaces.updateScrimController();
            } else {
                // We need to defer the camera launch until the screen comes on, since otherwise
+14 −9
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@ import com.android.systemui.recents.ScreenPinningRequest;
import com.android.systemui.ripple.RippleShader.RippleShape;
import com.android.systemui.scrim.ScrimView;
import com.android.systemui.settings.brightness.BrightnessSliderController;
import com.android.systemui.shade.CameraLauncher;
import com.android.systemui.shade.NotificationPanelViewController;
import com.android.systemui.shade.NotificationShadeWindowView;
import com.android.systemui.shade.NotificationShadeWindowViewController;
@@ -485,6 +486,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
    private final PluginManager mPluginManager;
    private final ShadeController mShadeController;
    private final InitController mInitController;
    private final Lazy<CameraLauncher> mCameraLauncherLazy;

    private final PluginDependencyProvider mPluginDependencyProvider;
    private final KeyguardDismissUtil mKeyguardDismissUtil;
@@ -617,6 +619,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {

    private Runnable mLaunchTransitionEndRunnable;
    private Runnable mLaunchTransitionCancelRunnable;
    private boolean mLaunchingAffordance;
    private boolean mLaunchCameraWhenFinishedWaking;
    private boolean mLaunchCameraOnFinishedGoingToSleep;
    private boolean mLaunchEmergencyActionWhenFinishedWaking;
@@ -761,7 +764,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
            InteractionJankMonitor jankMonitor,
            DeviceStateManager deviceStateManager,
            WiredChargingRippleController wiredChargingRippleController,
            IDreamManager dreamManager) {
            IDreamManager dreamManager,
            Lazy<CameraLauncher> cameraLauncherLazy) {
        mContext = context;
        mNotificationsController = notificationsController;
        mFragmentService = fragmentService;
@@ -838,6 +842,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
        mMessageRouter = messageRouter;
        mWallpaperManager = wallpaperManager;
        mJankMonitor = jankMonitor;
        mCameraLauncherLazy = cameraLauncherLazy;

        mLockscreenShadeTransitionController = lockscreenShadeTransitionController;
        mStartingSurfaceOptional = startingSurfaceOptional;
@@ -2969,7 +2974,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {

    private void onLaunchTransitionFadingEnded() {
        mNotificationPanelViewController.resetAlpha();
        mNotificationPanelViewController.onAffordanceLaunchEnded();
        mCameraLauncherLazy.get().setLaunchingAffordance(false);
        releaseGestureWakeLock();
        runLaunchTransitionEndRunnable();
        mKeyguardStateController.setLaunchTransitionFadingAway(false);
@@ -3039,7 +3044,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {

    private void onLaunchTransitionTimeout() {
        Log.w(TAG, "Launch transition: Timeout!");
        mNotificationPanelViewController.onAffordanceLaunchEnded();
        mCameraLauncherLazy.get().setLaunchingAffordance(false);
        releaseGestureWakeLock();
        mNotificationPanelViewController.resetViews(false /* animate */);
    }
@@ -3092,7 +3097,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
        }
        mMessageRouter.cancelMessages(MSG_LAUNCH_TRANSITION_TIMEOUT);
        releaseGestureWakeLock();
        mNotificationPanelViewController.onAffordanceLaunchEnded();
        mCameraLauncherLazy.get().setLaunchingAffordance(false);
        mNotificationPanelViewController.resetAlpha();
        mNotificationPanelViewController.resetTranslation();
        mNotificationPanelViewController.resetViewGroupFade();
@@ -3250,7 +3255,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
    @Override
    public void endAffordanceLaunch() {
        releaseGestureWakeLock();
        mNotificationPanelViewController.onAffordanceLaunchEnded();
        mCameraLauncherLazy.get().setLaunchingAffordance(false);
    }

    /**
@@ -3522,7 +3527,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
    final WakefulnessLifecycle.Observer mWakefulnessObserver = new WakefulnessLifecycle.Observer() {
        @Override
        public void onFinishedGoingToSleep() {
            mNotificationPanelViewController.onAffordanceLaunchEnded();
            mCameraLauncherLazy.get().setLaunchingAffordance(false);
            releaseGestureWakeLock();
            mLaunchCameraWhenFinishedWaking = false;
            mDeviceInteractive = false;
@@ -3623,7 +3628,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
                        .updateSensitivenessForOccludedWakeup();
            }
            if (mLaunchCameraWhenFinishedWaking) {
                mNotificationPanelViewController.launchCamera(mLastCameraLaunchSource);
                mCameraLauncherLazy.get().launchCamera(mLastCameraLaunchSource,
                        mNotificationPanelViewController.isFullyCollapsed());
                mLaunchCameraWhenFinishedWaking = false;
            }
            if (mLaunchEmergencyActionWhenFinishedWaking) {
@@ -3814,8 +3820,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {

        mScrimController.setExpansionAffectsAlpha(!unlocking);

        boolean launchingAffordanceWithPreview =
                mNotificationPanelViewController.isLaunchingAffordanceWithPreview();
        boolean launchingAffordanceWithPreview = mLaunchingAffordance;
        mScrimController.setLaunchingAffordanceWithPreview(launchingAffordanceWithPreview);

        if (mStatusBarKeyguardViewManager.isShowingAlternateBouncer()) {
+0 −2
Original line number Diff line number Diff line
@@ -94,7 +94,6 @@ import com.android.systemui.DejankUtils;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.camera.CameraGestureHelper;
import com.android.systemui.classifier.FalsingCollectorFake;
import com.android.systemui.classifier.FalsingManagerFake;
import com.android.systemui.doze.DozeLog;
@@ -492,7 +491,6 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
                mUnlockedScreenOffAnimationController,
                mShadeTransitionController,
                systemClock,
                mock(CameraGestureHelper.class),
                mKeyguardBottomAreaViewModel,
                mKeyguardBottomAreaInteractor,
                mDumpManager);
Loading