Set audio attrs on volume + home button vibrations
System vibrations should not be turned off by dnd.
Previously, dnd would stop the vibrations on the ringer
volume dialog tri-state toggle and home buttons because
they didn't have the correct AudioAttributes. This CL gives
these vibrations the correct AudioAttributes so they don't
get muted by DND.
Test: manual
Bug: 74441602
Change-Id: Idbe52f94a35a5333d4c8f80ed374d0384ddb550d
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/VibratorHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/VibratorHelper.java
index 5c21fd1..6560f8f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/VibratorHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/VibratorHelper.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.database.ContentObserver;
+import android.media.AudioAttributes;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.UserHandle;
@@ -30,6 +31,11 @@
private final Vibrator mVibrator;
private final Context mContext;
private boolean mHapticFeedbackEnabled;
+ private static final AudioAttributes STATUS_BAR_VIBRATION_ATTRIBUTES =
+ new AudioAttributes.Builder()
+ .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+ .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
+ .build();
final private ContentObserver mVibrationObserver = new ContentObserver(Handler.getMain()) {
@Override
@@ -51,7 +57,8 @@
public void vibrate(final int effectId) {
if (mHapticFeedbackEnabled) {
AsyncTask.execute(() ->
- mVibrator.vibrate(VibrationEffect.get(effectId, false /* fallback */)));
+ mVibrator.vibrate(VibrationEffect.get(effectId, false /* fallback */),
+ STATUS_BAR_VIBRATION_ATTRIBUTES));
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java
index 89e7dd1..ee6748e 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java
@@ -26,8 +26,7 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.ContentObserver;
-import android.media.AudioDeviceCallback;
-import android.media.AudioDeviceInfo;
+import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.IVolumeController;
@@ -40,6 +39,7 @@
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
+import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings;
import android.service.notification.Condition;
@@ -59,9 +59,7 @@
import java.io.FileDescriptor;
import java.io.PrintWriter;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -77,6 +75,11 @@
private static final int DYNAMIC_STREAM_START_INDEX = 100;
private static final int VIBRATE_HINT_DURATION = 50;
+ private static final AudioAttributes SONFICIATION_VIBRATION_ATTRIBUTES =
+ new AudioAttributes.Builder()
+ .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+ .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
+ .build();
static final ArrayMap<Integer, Integer> STREAMS = new ArrayMap<>();
static {
@@ -299,7 +302,8 @@
public void vibrate() {
if (mHasVibrator) {
- mVibrator.vibrate(VIBRATE_HINT_DURATION);
+ mVibrator.vibrate(VibrationEffect.createOneShot(VIBRATE_HINT_DURATION,
+ VibrationEffect.DEFAULT_AMPLITUDE), SONFICIATION_VIBRATION_ATTRIBUTES);
}
}
@@ -308,7 +312,7 @@
}
private void onNotifyVisibleW(boolean visible) {
- if (mDestroyed) return;
+ if (mDestroyed) return;
mAudio.notifyVolumeControllerVisible(mVolumeController, visible);
if (!visible) {
if (updateActiveStreamW(-1)) {