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

Commit f2e2532e authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Remove obsolete features" into main

parents 05084e2e 7a548377
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import com.android.internal.jank.Cuj;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.taskbar.LauncherTaskbarUIController;
import com.android.launcher3.uioverrides.QuickstepLauncher;
@@ -221,11 +220,6 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
            mCancelSplitRunnable.accept(animatorSet, duration);
            animatorSet.start();
        }
        if (FeatureFlags.ENABLE_PREMIUM_HAPTICS_ALL_APPS.get() &&
                ((mFromState == NORMAL && mToState == ALL_APPS)
                        || (mFromState == ALL_APPS && mToState == NORMAL)) && isFling) {
            mVibratorWrapper.vibrateForDragBump();
        }
    }

    private void onMotionPauseDetected() {
+1 −61
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import static com.android.launcher3.util.SystemUiController.UI_STATE_ALL_APPS;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.util.FloatProperty;
import android.view.HapticFeedbackConstants;
import android.view.View;
@@ -52,7 +51,6 @@ import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.anim.PropertySetter;
@@ -359,22 +357,6 @@ public class AllAppsTransitionController
            });
        }

        if (FeatureFlags.ENABLE_PREMIUM_HAPTICS_ALL_APPS.get() && config.isUserControlled()
                && Utilities.ATLEAST_S) {
            if (toState == ALL_APPS) {
                builder.addOnFrameListener(
                        new VibrationAnimatorUpdateListener(this, mVibratorWrapper,
                                SWIPE_DRAG_COMMIT_THRESHOLD, 1));
            } else {
                builder.addOnFrameListener(
                        new VibrationAnimatorUpdateListener(this, mVibratorWrapper,
                                0, SWIPE_DRAG_COMMIT_THRESHOLD));
            }
            builder.addEndListener((unused) -> {
                mVibratorWrapper.cancelVibrate();
            });
        }

        float targetProgress = toState.getVerticalProgress(mLauncher);
        if (Float.compare(mProgress, targetProgress) == 0) {
            setAlphas(toState, config, builder);
@@ -391,8 +373,7 @@ public class AllAppsTransitionController

        setAlphas(toState, config, builder);
        // This controls both haptics for tapping on QSB and going to all apps.
        if (ALL_APPS.equals(toState) && mLauncher.isInState(NORMAL) &&
                !FeatureFlags.ENABLE_PREMIUM_HAPTICS_ALL_APPS.get()) {
        if (ALL_APPS.equals(toState) && mLauncher.isInState(NORMAL)) {
            mLauncher.getAppsView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
        }
@@ -445,45 +426,4 @@ public class AllAppsTransitionController
    public void setShiftRange(float shiftRange) {
        mShiftRange = shiftRange;
    }

    /**
     * This VibrationAnimatorUpdateListener class takes in four parameters, a controller, start
     * threshold, end threshold, and a Vibrator wrapper. We use the progress given by the controller
     * as it gives an accurate progress that dictates where the vibrator should vibrate.
     * Note: once the user begins a gesture and does the commit haptic, there should not be anymore
     * haptics played for that gesture.
     */
    private static class VibrationAnimatorUpdateListener implements
            ValueAnimator.AnimatorUpdateListener {
        private final VibratorWrapper mVibratorWrapper;
        private final AllAppsTransitionController mController;
        private final float mStartThreshold;
        private final float mEndThreshold;
        private boolean mHasCommitted;

        VibrationAnimatorUpdateListener(AllAppsTransitionController controller,
                                        VibratorWrapper vibratorWrapper, float startThreshold,
                                        float endThreshold) {
            mController = controller;
            mVibratorWrapper = vibratorWrapper;
            mStartThreshold = startThreshold;
            mEndThreshold = endThreshold;
        }

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            if (mHasCommitted) {
                return;
            }
            float currentProgress =
                    AllAppsTransitionController.ALL_APPS_PROGRESS.get(mController);
            if (currentProgress > mStartThreshold && currentProgress < mEndThreshold) {
                mVibratorWrapper.vibrateForDragTexture();
            } else if (!(currentProgress == 0 || currentProgress == 1)) {
                // This check guards against committing at the location of the start of the gesture
                mVibratorWrapper.vibrateForDragCommit();
                mHasCommitted = true;
            }
        }
    }
}
+0 −12
Original line number Diff line number Diff line
@@ -93,18 +93,6 @@ public final class FeatureFlags {
            270394468, "ENABLE_SHOW_KEYBOARD_OPTION_IN_ALL_APPS", ENABLED,
            "Enable option to show keyboard when going to all-apps");

    // TODO(Block 5): Clean up flags
    public static final BooleanFlag ENABLE_TWOLINE_DEVICESEARCH = getDebugFlag(201388851,
            "ENABLE_TWOLINE_DEVICESEARCH", DISABLED,
            "Enable two line label for icons with labels on device search.");

    public static final BooleanFlag ENABLE_ICON_IN_TEXT_HEADER = getDebugFlag(270395143,
            "ENABLE_ICON_IN_TEXT_HEADER", DISABLED, "Show icon in textheader");

    public static final BooleanFlag ENABLE_PREMIUM_HAPTICS_ALL_APPS = getDebugFlag(270396358,
            "ENABLE_PREMIUM_HAPTICS_ALL_APPS", DISABLED,
            "Enables haptics opening/closing All apps");

    // TODO(Block 6): Clean up flags
    public static final BooleanFlag ENABLE_ALL_APPS_SEARCH_IN_TASKBAR = getDebugFlag(270393900,
            "ENABLE_ALL_APPS_SEARCH_IN_TASKBAR", ENABLED,
+0 −88
Original line number Diff line number Diff line
@@ -25,12 +25,10 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.SystemClock;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.launcher3.Utilities;
@@ -54,20 +52,6 @@ public class VibratorWrapper implements SafeCloseable {
    static final Uri HAPTIC_FEEDBACK_URI = Settings.System.getUriFor(HAPTIC_FEEDBACK_ENABLED);

    @VisibleForTesting static final float LOW_TICK_SCALE = 0.9f;
    @VisibleForTesting static final float DRAG_TEXTURE_SCALE = 0.03f;
    @VisibleForTesting static final float DRAG_COMMIT_SCALE = 0.5f;
    @VisibleForTesting static final float DRAG_BUMP_SCALE = 0.4f;
    @VisibleForTesting static final int DRAG_TEXTURE_EFFECT_SIZE = 200;

    @Nullable
    private final VibrationEffect mDragEffect;
    @Nullable
    private final VibrationEffect mCommitEffect;
    @Nullable
    private final VibrationEffect mBumpEffect;

    private long mLastDragTime;
    private final int mThresholdUntilNextDragCallMillis;

    /**
     * Haptic when entering overview.
@@ -100,28 +84,6 @@ public class VibratorWrapper implements SafeCloseable {
        } else {
            mIsHapticFeedbackEnabled = false;
        }

        if (Utilities.ATLEAST_S && mVibrator.areAllPrimitivesSupported(
                PRIMITIVE_LOW_TICK)) {

            // Drag texture, Commit, and Bump should only be used for premium phones.
            // Before using these haptics make sure check if the device can use it
            mDragEffect = getDragEffect();
            mCommitEffect = VibrationEffect.startComposition().addPrimitive(
                    VibrationEffect.Composition.PRIMITIVE_TICK, DRAG_COMMIT_SCALE).compose();
            mBumpEffect = VibrationEffect.startComposition().addPrimitive(
                    PRIMITIVE_LOW_TICK, DRAG_BUMP_SCALE).compose();
            int primitiveDuration = mVibrator.getPrimitiveDurations(
                    PRIMITIVE_LOW_TICK)[0];

            mThresholdUntilNextDragCallMillis =
                    DRAG_TEXTURE_EFFECT_SIZE * primitiveDuration + 100;
        } else {
            mDragEffect = null;
            mCommitEffect = null;
            mBumpEffect = null;
            mThresholdUntilNextDragCallMillis = 0;
        }
    }

    @Override
@@ -131,53 +93,12 @@ public class VibratorWrapper implements SafeCloseable {
        }
    }

    /**
     * This is called when the user swipes to/from all apps. This is meant to be used in between
     * long animation progresses so that it gives a dragging texture effect. For a better
     * experience, this should be used in combination with vibrateForDragCommit().
     */
    public void vibrateForDragTexture() {
        if (mDragEffect == null) {
            return;
        }
        long currentTime = SystemClock.elapsedRealtime();
        long elapsedTimeSinceDrag = currentTime - mLastDragTime;
        if (elapsedTimeSinceDrag >= mThresholdUntilNextDragCallMillis) {
            vibrate(mDragEffect);
            mLastDragTime = currentTime;
        }
    }

    /**
     * This is used when user reaches the commit threshold when swiping to/from from all apps.
     */
    public void vibrateForDragCommit() {
        if (mCommitEffect != null) {
            vibrate(mCommitEffect);
        }
        // resetting dragTexture timestamp to be able to play dragTexture again
        mLastDragTime = 0;
    }

    /**
     * The bump haptic is used to be called at the end of a swipe and only if it the gesture is a
     * FLING going to/from all apps. Client can just call this method elsewhere just for the
     * effect.
     */
    public void vibrateForDragBump() {
        if (mBumpEffect != null) {
            vibrate(mBumpEffect);
        }
    }

    /**
     * This should be used to cancel a haptic in case where the haptic shouldn't be vibrating. For
     * example, when no animation is happening but a vibrator happens to be vibrating still.
     */
    public void cancelVibrate() {
        UI_HELPER_EXECUTOR.execute(mVibrator::cancel);
        // reset dragTexture timestamp to be able to play dragTexture again whenever cancelled
        mLastDragTime = 0;
    }

    /** Vibrates with the given effect if haptic feedback is available and enabled. */
@@ -217,13 +138,4 @@ public class VibratorWrapper implements SafeCloseable {
            vibrate(primitiveLowTickEffect);
        }
    }

    static VibrationEffect getDragEffect() {
        VibrationEffect.Composition dragEffect = VibrationEffect.startComposition();
        for (int i = 0; i < DRAG_TEXTURE_EFFECT_SIZE; i++) {
            dragEffect.addPrimitive(
                    PRIMITIVE_LOW_TICK, DRAG_TEXTURE_SCALE);
        }
        return dragEffect.compose();
    }
}
+0 −52
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.launcher3.util

import android.media.AudioAttributes
import android.os.SystemClock
import android.os.VibrationEffect
import android.os.VibrationEffect.Composition.PRIMITIVE_LOW_TICK
import android.os.VibrationEffect.Composition.PRIMITIVE_TICK
@@ -35,13 +34,11 @@ import org.mockito.ArgumentCaptor
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mockito.any
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.never
import org.mockito.kotlin.same
import org.mockito.kotlin.verifyNoMoreInteractions

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -117,55 +114,6 @@ class VibratorWrapperTest {
        assertThat(vibrationEffectCaptor.value).isEqualTo(expectedEffect)
    }

    @Test
    fun vibrate_for_drag_bump() {
        underTest.vibrateForDragBump()

        awaitTasksCompleted()
        verify(vibrator).vibrate(vibrationEffectCaptor.capture(), same(VIBRATION_ATTRS))
        val expectedEffect =
            VibrationEffect.startComposition()
                .addPrimitive(PRIMITIVE_LOW_TICK, VibratorWrapper.DRAG_BUMP_SCALE)
                .compose()
        assertThat(vibrationEffectCaptor.value).isEqualTo(expectedEffect)
    }

    @Test
    fun vibrate_for_drag_commit() {
        underTest.vibrateForDragCommit()

        awaitTasksCompleted()
        verify(vibrator).vibrate(vibrationEffectCaptor.capture(), same(VIBRATION_ATTRS))
        val expectedEffect =
            VibrationEffect.startComposition()
                .addPrimitive(PRIMITIVE_TICK, VibratorWrapper.DRAG_COMMIT_SCALE)
                .compose()
        assertThat(vibrationEffectCaptor.value).isEqualTo(expectedEffect)
    }

    @Test
    fun vibrate_for_drag_texture() {
        SystemClock.setCurrentTimeMillis(40000)

        underTest.vibrateForDragTexture()

        awaitTasksCompleted()
        verify(vibrator).vibrate(vibrationEffectCaptor.capture(), same(VIBRATION_ATTRS))
        assertThat(vibrationEffectCaptor.value).isEqualTo(VibratorWrapper.getDragEffect())
    }

    @Test
    fun vibrate_for_drag_texture_within_time_window_noOp() {
        SystemClock.setCurrentTimeMillis(40000)
        underTest.vibrateForDragTexture()
        awaitTasksCompleted()
        reset(vibrator)

        underTest.vibrateForDragTexture()

        verifyNoMoreInteractions(vibrator)
    }

    @Test
    fun haptic_feedback_disabled_no_vibrate() {
        `when`(vibrator.hasVibrator()).thenReturn(false)