diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/os/IVibratorService.aidl | 1 | ||||
| -rw-r--r-- | core/java/android/os/SystemVibrator.java | 14 | ||||
| -rw-r--r-- | core/java/android/os/Vibrator.java | 19 |
3 files changed, 34 insertions, 0 deletions
diff --git a/core/java/android/os/IVibratorService.aidl b/core/java/android/os/IVibratorService.aidl index 1456ff7e6c5e..6b881fecad56 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 a5188e7cd58d..fbd11ca62a0c 100644 --- a/core/java/android/os/SystemVibrator.java +++ b/core/java/android/os/SystemVibrator.java @@ -70,6 +70,20 @@ public class SystemVibrator extends Vibrator { } @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) { if (mService == null) { diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java index 28909c88a734..6456d72a4a6f 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; @@ -152,6 +153,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. * * @param milliseconds The number of milliseconds to vibrate. |
