diff --git a/core/java/android/os/IVibratorService.aidl b/core/java/android/os/IVibratorService.aidl index 1456ff7e6c5e8..6b881fecad569 100644 --- a/core/java/android/os/IVibratorService.aidl +++ b/core/java/android/os/IVibratorService.aidl @@ -24,6 +24,7 @@ interface IVibratorService { boolean hasVibrator(); boolean hasAmplitudeControl(); + boolean setAlwaysOnEffect(int id, in VibrationEffect effect, in AudioAttributes attributes); void vibrate(int uid, String opPkg, in VibrationEffect effect, in AudioAttributes attributes, String reason, IBinder token); void cancelVibrate(IBinder token); diff --git a/core/java/android/os/SystemVibrator.java b/core/java/android/os/SystemVibrator.java index a5188e7cd58d0..fbd11ca62a0ce 100644 --- a/core/java/android/os/SystemVibrator.java +++ b/core/java/android/os/SystemVibrator.java @@ -69,6 +69,20 @@ public class SystemVibrator extends Vibrator { return false; } + @Override + public boolean setAlwaysOnEffect(int id, VibrationEffect effect, AudioAttributes attributes) { + if (mService == null) { + Log.w(TAG, "Failed to set always-on effect; no vibrator service."); + return false; + } + try { + return mService.setAlwaysOnEffect(id, effect, attributes); + } catch (RemoteException e) { + Log.w(TAG, "Failed to set always-on effect.", e); + } + return false; + } + @Override public void vibrate(int uid, String opPkg, VibrationEffect effect, String reason, AudioAttributes attributes) { diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java index 28909c88a7340..6456d72a4a6fb 100644 --- a/core/java/android/os/Vibrator.java +++ b/core/java/android/os/Vibrator.java @@ -17,6 +17,7 @@ package android.os; import android.annotation.IntDef; +import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemService; import android.annotation.UnsupportedAppUsage; @@ -151,6 +152,24 @@ public abstract class Vibrator { */ public abstract boolean hasAmplitudeControl(); + /** + * Configure an always-on haptics effect. + * + * @param id The board-specific always-on ID to configure. + * @param effect Vibration effect to assign to always-on id. Passing null will disable it. + * @param attributes {@link AudioAttributes} corresponding to the vibration. For example, + * specify {@link AudioAttributes#USAGE_ALARM} for alarm vibrations or + * {@link AudioAttributes#USAGE_NOTIFICATION_RINGTONE} for + * vibrations associated with incoming calls. May only be null when effect is null. + * @hide + */ + @RequiresPermission(android.Manifest.permission.VIBRATE_ALWAYS_ON) + public boolean setAlwaysOnEffect(int id, @Nullable VibrationEffect effect, + @Nullable AudioAttributes attributes) { + Log.w(TAG, "Always-on effects aren't supported"); + return false; + } + /** * Vibrate constantly for the specified period of time. * diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 8dc84c804055f..082424fa4a4f6 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -1868,6 +1868,13 @@ android:description="@string/permdesc_vibrate" android:protectionLevel="normal|instant" /> + + +