From 45d53eee54b5d39f9c52e9ab03be74a00226b005 Mon Sep 17 00:00:00 2001 From: "Harpreet \\\"Eli\\\" Sangha" Date: Wed, 25 Sep 2019 17:43:24 +0900 Subject: vibrator: Support Always-On Effects Bug: 138909021 Test: Verify always-on haptics are configured on boot and settings change. Change-Id: I2c9458a55cb878b94dde88988ffa73d4b8cb7ac0 Signed-off-by: Harpreet \"Eli\" Sangha --- core/java/android/os/IVibratorService.aidl | 1 + core/java/android/os/SystemVibrator.java | 14 +++++ core/java/android/os/Vibrator.java | 19 +++++++ core/res/AndroidManifest.xml | 7 +++ .../java/com/android/server/VibratorService.java | 63 ++++++++++++++++++++++ .../jni/com_android_server_VibratorService.cpp | 17 ++++++ 6 files changed, 121 insertions(+) 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 @@ -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 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; @@ -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 a35c4dbdf383..5000fc073c72 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -1868,6 +1868,13 @@ android:description="@string/permdesc_vibrate" android:protectionLevel="normal|instant" /> + + +