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

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

Merge "haptic: add VibratorManager API to make haptic feedback based on input" into main

parents c5f265d7 dd141e0d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -42,4 +42,12 @@ interface IVibratorManagerService {
    // vibrate/isVibrating/cancel.
    oneway void performHapticFeedback(int uid, int deviceId, String opPkg, int constant,
            String reason, int flags, int privFlags);

    // Similar to performHapticFeedback but the effect is customized to the input device. The
    // customization for each constant is defined on a device basis, and the behavior will be the
    // same as performHapticFeedback when no customization is provided for a given constant and
    // device.
    oneway void performHapticFeedbackForInputDevice(int uid, int deviceId, String opPkg,
            int constant, int inputDeviceId, int inputSource, String reason, int flags,
            int privFlags);
}
+11 −0
Original line number Diff line number Diff line
@@ -214,6 +214,17 @@ public class SystemVibrator extends Vibrator {
        mVibratorManager.performHapticFeedback(constant, reason, flags, privFlags);
    }

    @Override
    public void performHapticFeedbackForInputDevice(int constant, int inputDeviceId,
            int inputSource, String reason, int flags, int privFlags) {
        if (mVibratorManager == null) {
            Log.w(TAG, "Failed to perform haptic feedback for input device; no vibrator manager.");
            return;
        }
        mVibratorManager.performHapticFeedbackForInputDevice(constant, inputDeviceId, inputSource,
                reason, flags, privFlags);
    }

    @Override
    public void cancel() {
        if (mVibratorManager == null) {
+16 −0
Original line number Diff line number Diff line
@@ -160,6 +160,22 @@ public class SystemVibratorManager extends VibratorManager {
        }
    }

    @Override
    public void performHapticFeedbackForInputDevice(int constant, int inputDeviceId,
            int inputSource, String reason, int flags, int privFlags) {
        if (mService == null) {
            Log.w(TAG, "Failed to perform haptic feedback for input device;"
                            + " no vibrator manager service.");
            return;
        }
        try {
            mService.performHapticFeedbackForInputDevice(mUid, mContext.getDeviceId(), mPackageName,
                    constant, inputDeviceId, inputSource, reason, flags, privFlags);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to perform haptic feedback for input device.", e);
        }
    }

    @Override
    public void cancel() {
        cancelVibration(VibrationAttributes.USAGE_FILTER_MATCH_ALL);
+25 −0
Original line number Diff line number Diff line
@@ -552,6 +552,31 @@ public abstract class Vibrator {
        Log.w(TAG, "performHapticFeedback is not supported");
    }

    /**
     * Performs a haptic feedback. Similar to {@link #performHapticFeedback} but also take into the
     * consideration the {@link InputDevice} that triggered the haptic
     *
     * <p>A haptic feedback is a short vibration feedback. The type of feedback is identified via
     * the {@code constant}, which should be one of the effect constants provided in
     * {@link HapticFeedbackConstants}. The haptic feedback provided for a given effect ID is
     * consistent across all usages on the same device.
     *
     * @param constant      the ID for the haptic feedback. This should be one of the constants
     *                      defined in {@link HapticFeedbackConstants}.
     * @param inputDeviceId the integer id of the input device that triggered the haptic feedback.
     * @param inputSource   the {@link InputDevice.Source} that triggered the haptic feedback.
     * @param reason        the reason for this haptic feedback.
     * @param flags         Additional flags as per {@link HapticFeedbackConstants}.
     * @param privFlags     Additional private flags as per {@link HapticFeedbackConstants}.
     * @hide
     */
    public void performHapticFeedbackForInputDevice(
            int constant, int inputDeviceId, int inputSource, String reason,
            @HapticFeedbackConstants.Flags int flags,
            @HapticFeedbackConstants.PrivateFlags int privFlags) {
        Log.w(TAG, "performHapticFeedbackForInputDevice is not supported");
    }

    /**
     * Query whether the vibrator natively supports the given effects.
     *
+21 −0
Original line number Diff line number Diff line
@@ -154,6 +154,27 @@ public abstract class VibratorManager {
        Log.w(TAG, "performHapticFeedback is not supported");
    }

    /**
     * Performs a haptic feedback. Similar to {@link #performHapticFeedback} but also take input
     * into consideration.
     *
     * @param constant      the ID of the requested haptic feedback. Should be one of the constants
     *                      defined in {@link HapticFeedbackConstants}.
     * @param inputDeviceId the integer id of the input device that customizes the haptic feedback
     *                      corresponding to the {@code constant}.
     * @param inputSource   the {@link InputDevice.Source} that customizes the haptic feedback
     *                      corresponding to the {@code constant}.
     * @param reason        the reason for this haptic feedback.
     * @param flags         Additional flags as per {@link HapticFeedbackConstants}.
     * @param privFlags     Additional private flags as per {@link HapticFeedbackConstants}.
     * @hide
     */
    public void performHapticFeedbackForInputDevice(int constant, int inputDeviceId,
            int inputSource, String reason, @HapticFeedbackConstants.Flags int flags,
            @HapticFeedbackConstants.PrivateFlags int privFlags) {
        Log.w(TAG, "performHapticFeedbackForInputDevice is not supported");
    }

    /**
     * Turn all the vibrators off.
     */
Loading