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

Commit bec98a28 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Android (Google) Code Review
Browse files

Merge changes I3b160921,Ic4d226f7 into main

* changes:
  Add shell command support for haptic feedback
  Create a hidden Vibrator API for haptic feedback.
parents 801c5b1e a45bee3c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ java_defaults {
    // Add java_aconfig_libraries to here to add them to the core framework
    srcs: [
        ":android.os.flags-aconfig-java{.generated_srcjars}",
        ":android.os.vibrator.flags-aconfig-java{.generated_srcjars}",
        ":android.security.flags-aconfig-java{.generated_srcjars}",
        ":camera_platform_flags_core_java_lib{.generated_srcjars}",
        ":com.android.window.flags.window-aconfig-java{.generated_srcjars}",
@@ -138,3 +139,16 @@ java_aconfig_library {
    aconfig_declarations: "android.view.inputmethod.flags-aconfig",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Vibrator
aconfig_declarations {
    name: "android.os.vibrator.flags-aconfig",
    package: "android.os.vibrator",
    srcs: ["core/java/android/os/vibrator/*.aconfig"],
}

java_aconfig_library {
    name: "android.os.vibrator.flags-aconfig-java",
    aconfig_declarations: "android.os.vibrator.flags-aconfig",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}
+6 −0
Original line number Diff line number Diff line
@@ -36,4 +36,10 @@ interface IVibratorManagerService {
    void vibrate(int uid, int displayId, String opPkg, in CombinedVibration vibration,
            in VibrationAttributes attributes, String reason, IBinder token);
    void cancelVibrate(int usageFilter, IBinder token);

    // Async oneway APIs.
    // There is no order guarantee with respect to the two-way APIs above like
    // vibrate/isVibrating/cancel.
    oneway void performHapticFeedback(int uid, int displayId, String opPkg, int constant,
            boolean always, String reason, IBinder token);
}
+9 −0
Original line number Diff line number Diff line
@@ -205,6 +205,15 @@ public class SystemVibrator extends Vibrator {
        mVibratorManager.vibrate(uid, opPkg, combinedEffect, reason, attributes);
    }

    @Override
    public void performHapticFeedback(int constant, boolean always, String reason) {
        if (mVibratorManager == null) {
            Log.w(TAG, "Failed to perform haptic feedback; no vibrator manager.");
            return;
        }
        mVibratorManager.performHapticFeedback(constant, always, reason);
    }

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

    @Override
    public void performHapticFeedback(int constant, boolean always, String reason) {
        if (mService == null) {
            Log.w(TAG, "Failed to perform haptic feedback; no vibrator manager service.");
            return;
        }
        try {
            mService.performHapticFeedback(
                    Process.myUid(), mContext.getAssociatedDisplayId(), mPackageName, constant,
                    always, reason, mToken);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to perform haptic feedback.", e);
        }
    }

    @Override
    public void cancel() {
        cancelVibration(VibrationAttributes.USAGE_FILTER_MATCH_ALL);
@@ -227,6 +242,11 @@ public class SystemVibratorManager extends VibratorManager {
            SystemVibratorManager.this.vibrate(uid, opPkg, combined, reason, attributes);
        }

        @Override
        public void performHapticFeedback(int effectId, boolean always, String reason) {
            SystemVibratorManager.this.performHapticFeedback(effectId, always, reason);
        }

        @Override
        public void cancel() {
            SystemVibratorManager.this.cancel();
+22 −0
Original line number Diff line number Diff line
@@ -509,6 +509,28 @@ public abstract class Vibrator {
    public abstract void vibrate(int uid, String opPkg, @NonNull VibrationEffect vibe,
            String reason, @NonNull VibrationAttributes attributes);

    /**
     * Performs a haptic feedback.
     *
     * <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 always {@code true} if the haptic feedback should be played regardless of the user
     *          vibration intensity settings applicable to the corresponding vibration.
     *          {@code false} if the vibration for the haptic feedback should respect the applicable
     *          vibration intensity settings.
     * @param reason the reason for this haptic feedback.
     *
     * @hide
     */
    public void performHapticFeedback(int constant, boolean always, String reason) {
        Log.w(TAG, "performHapticFeedback is not supported");
    }

    /**
     * Query whether the vibrator natively supports the given effects.
     *
Loading