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

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

Merge changes from topic "haptic-mapping"

* changes:
  Fallback added for HEAVY_CLICK effect
  Mapping of haptic constants updated
  Add haptic constants
parents c05f8294 17cab654
Loading
Loading
Loading
Loading
+49 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,55 @@ public class HapticFeedbackConstants {
     */
     */
    public static final int TEXT_HANDLE_MOVE = 9;
    public static final int TEXT_HANDLE_MOVE = 9;


    /**
     * The user unlocked the device
     * @hide
     */
    public static final int ENTRY_BUMP = 10;

    /**
     * The user has moved the dragged object within a droppable area.
     * @hide
     */
    public static final int DRAG_CROSSING = 11;

    /**
     * The user has started a gesture (e.g. on the soft keyboard).
     * @hide
     */
    public static final int GESTURE_START = 12;

    /**
     * The user has finished a gesture (e.g. on the soft keyboard).
     * @hide
     */
    public static final int GESTURE_END = 13;

    /**
     * The user's squeeze crossed the gesture's initiation threshold.
     * @hide
     */
    public static final int EDGE_SQUEEZE = 14;

    /**
     * The user's squeeze crossed the gesture's release threshold.
     * @hide
     */
    public static final int EDGE_RELEASE = 15;

    /**
     * A haptic effect to signal the confirmation or successful completion of a user
     * interaction.
     * @hide
     */
    public static final int CONFIRM = 16;

    /**
     * A haptic effect to signal the rejection or failure of a user interaction.
     * @hide
     */
    public static final int REJECT = 17;

    /**
    /**
     * The phone has booted with safe mode enabled.
     * The phone has booted with safe mode enabled.
     * This is a private constant.  Feel free to renumber as desired.
     * This is a private constant.  Feel free to renumber as desired.
+9 −6
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.SettingNotFoundException;
import android.util.DebugUtils;
import android.util.DebugUtils;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.view.InputDevice;
import android.view.InputDevice;
import android.media.AudioAttributes;
import android.media.AudioAttributes;


@@ -91,7 +92,7 @@ public class VibratorService extends IVibratorService.Stub
    private final boolean mAllowPriorityVibrationsInLowPowerMode;
    private final boolean mAllowPriorityVibrationsInLowPowerMode;
    private final boolean mSupportsAmplitudeControl;
    private final boolean mSupportsAmplitudeControl;
    private final int mDefaultVibrationAmplitude;
    private final int mDefaultVibrationAmplitude;
    private final VibrationEffect[] mFallbackEffects;
    private final SparseArray<VibrationEffect> mFallbackEffects;
    private final WorkSource mTmpWorkSource = new WorkSource();
    private final WorkSource mTmpWorkSource = new WorkSource();
    private final Handler mH = new Handler();
    private final Handler mH = new Handler();
    private final Object mLock = new Object();
    private final Object mLock = new Object();
@@ -177,6 +178,7 @@ public class VibratorService extends IVibratorService.Stub
                switch (prebaked.getId()) {
                switch (prebaked.getId()) {
                    case VibrationEffect.EFFECT_CLICK:
                    case VibrationEffect.EFFECT_CLICK:
                    case VibrationEffect.EFFECT_DOUBLE_CLICK:
                    case VibrationEffect.EFFECT_DOUBLE_CLICK:
                    case VibrationEffect.EFFECT_HEAVY_CLICK:
                    case VibrationEffect.EFFECT_TICK:
                    case VibrationEffect.EFFECT_TICK:
                        return true;
                        return true;
                    default:
                    default:
@@ -293,7 +295,11 @@ public class VibratorService extends IVibratorService.Stub
                com.android.internal.R.array.config_clockTickVibePattern);
                com.android.internal.R.array.config_clockTickVibePattern);
        VibrationEffect tickEffect = createEffect(tickEffectTimings);
        VibrationEffect tickEffect = createEffect(tickEffectTimings);


        mFallbackEffects = new VibrationEffect[] { clickEffect, doubleClickEffect, tickEffect };
        mFallbackEffects = new SparseArray<VibrationEffect>();
        mFallbackEffects.put(VibrationEffect.EFFECT_CLICK, clickEffect);
        mFallbackEffects.put(VibrationEffect.EFFECT_DOUBLE_CLICK, doubleClickEffect);
        mFallbackEffects.put(VibrationEffect.EFFECT_TICK, tickEffect);
        mFallbackEffects.put(VibrationEffect.EFFECT_HEAVY_CLICK, clickEffect);
    }
    }


    private static VibrationEffect createEffect(long[] timings) {
    private static VibrationEffect createEffect(long[] timings) {
@@ -960,10 +966,7 @@ public class VibratorService extends IVibratorService.Stub
    }
    }


    private VibrationEffect getFallbackEffect(int effectId) {
    private VibrationEffect getFallbackEffect(int effectId) {
        if (effectId < 0 || effectId >= mFallbackEffects.length) {
        return mFallbackEffects.get(effectId);
            return null;
        }
        return mFallbackEffects[effectId];
    }
    }


    /**
    /**
+21 −15
Original line number Original line Diff line number Diff line
@@ -8013,29 +8013,35 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private VibrationEffect getVibrationEffect(int effectId) {
    private VibrationEffect getVibrationEffect(int effectId) {
        long[] pattern;
        long[] pattern;
        switch (effectId) {
        switch (effectId) {
            case HapticFeedbackConstants.LONG_PRESS:
                pattern = mLongPressVibePattern;
                break;
            case HapticFeedbackConstants.CLOCK_TICK:
            case HapticFeedbackConstants.CLOCK_TICK:
            case HapticFeedbackConstants.CONTEXT_CLICK:
                return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
                return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
            case HapticFeedbackConstants.KEYBOARD_RELEASE:
            case HapticFeedbackConstants.TEXT_HANDLE_MOVE:
            case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE:
            case HapticFeedbackConstants.ENTRY_BUMP:
            case HapticFeedbackConstants.DRAG_CROSSING:
            case HapticFeedbackConstants.GESTURE_END:
                return VibrationEffect.get(VibrationEffect.EFFECT_TICK, false);
            case HapticFeedbackConstants.KEYBOARD_TAP: // == KEYBOARD_PRESS
            case HapticFeedbackConstants.VIRTUAL_KEY:
            case HapticFeedbackConstants.EDGE_RELEASE:
            case HapticFeedbackConstants.CONFIRM:
            case HapticFeedbackConstants.GESTURE_START:
                return VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
            case HapticFeedbackConstants.LONG_PRESS:
            case HapticFeedbackConstants.EDGE_SQUEEZE:
                return VibrationEffect.get(VibrationEffect.EFFECT_HEAVY_CLICK);
            case HapticFeedbackConstants.REJECT:
                return VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK);

            case HapticFeedbackConstants.CALENDAR_DATE:
            case HapticFeedbackConstants.CALENDAR_DATE:
                pattern = mCalendarDateVibePattern;
                pattern = mCalendarDateVibePattern;
                break;
                break;
            case HapticFeedbackConstants.SAFE_MODE_ENABLED:
            case HapticFeedbackConstants.SAFE_MODE_ENABLED:
                pattern = mSafeModeEnabledVibePattern;
                pattern = mSafeModeEnabledVibePattern;
                break;
                break;
            case HapticFeedbackConstants.CONTEXT_CLICK:

                return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
            case HapticFeedbackConstants.VIRTUAL_KEY:
                return VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
            case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE:
                return VibrationEffect.get(VibrationEffect.EFFECT_TICK, false);
            case HapticFeedbackConstants.KEYBOARD_PRESS:  // == HapticFeedbackConstants.KEYBOARD_TAP
                return VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
            case HapticFeedbackConstants.KEYBOARD_RELEASE:
                return VibrationEffect.get(VibrationEffect.EFFECT_TICK, false);
            case HapticFeedbackConstants.TEXT_HANDLE_MOVE:
                return VibrationEffect.get(VibrationEffect.EFFECT_TICK, false);
            default:
            default:
                return null;
                return null;
        }
        }