Don't ban background vibration with USAGE_ALARM

Test: manual, schedule a vibration-only alarm and see it vibrates
Bug: 129297051
Change-Id: I3e0b8551b47196964168731061630362b5b17558
This commit is contained in:
Alexey Kuzmin
2019-04-04 12:01:48 +01:00
parent 64b51f91ff
commit 082a59a1cc

View File

@@ -113,6 +113,7 @@ public class VibratorService extends IVibratorService.Stub
private final SparseArray<ScaleLevel> mScaleLevels;
private final LinkedList<VibrationInfo> mPreviousRingVibrations;
private final LinkedList<VibrationInfo> mPreviousNotificationVibrations;
private final LinkedList<VibrationInfo> mPreviousAlarmVibrations;
private final LinkedList<VibrationInfo> mPreviousVibrations;
private final int mPreviousVibrationsLimit;
private final boolean mAllowPriorityVibrationsInLowPowerMode;
@@ -258,6 +259,10 @@ public class VibratorService extends IVibratorService.Stub
return VibratorService.this.isRingtone(usageHint);
}
public boolean isAlarm() {
return VibratorService.this.isAlarm(usageHint);
}
public boolean isFromSystem() {
return uid == Process.SYSTEM_UID || uid == 0 || SYSTEM_UI_PACKAGE.equals(opPkg);
}
@@ -358,6 +363,7 @@ public class VibratorService extends IVibratorService.Stub
mPreviousRingVibrations = new LinkedList<>();
mPreviousNotificationVibrations = new LinkedList<>();
mPreviousAlarmVibrations = new LinkedList<>();
mPreviousVibrations = new LinkedList<>();
IntentFilter filter = new IntentFilter();
@@ -597,7 +603,7 @@ public class VibratorService extends IVibratorService.Stub
Vibration vib = new Vibration(token, effect, usageHint, uid, opPkg, reason);
if (mProcStatesCache.get(uid, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND)
> ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
&& !vib.isNotification() && !vib.isRingtone()) {
&& !vib.isNotification() && !vib.isRingtone() && !vib.isAlarm()) {
Slog.e(TAG, "Ignoring incoming vibration as process with"
+ " uid = " + uid + " is background,"
+ " usage = " + AudioAttributes.usageToString(vib.usageHint));
@@ -629,6 +635,8 @@ public class VibratorService extends IVibratorService.Stub
previousVibrations = mPreviousRingVibrations;
} else if (vib.isNotification()) {
previousVibrations = mPreviousNotificationVibrations;
} else if (vib.isAlarm()) {
previousVibrations = mPreviousAlarmVibrations;
} else {
previousVibrations = mPreviousVibrations;
}
@@ -793,6 +801,8 @@ public class VibratorService extends IVibratorService.Stub
return mNotificationIntensity;
} else if (vib.isHapticFeedback()) {
return mHapticFeedbackIntensity;
} else if (vib.isAlarm()) {
return Vibrator.VIBRATION_INTENSITY_HIGH;
} else {
return Vibrator.VIBRATION_INTENSITY_MEDIUM;
}
@@ -817,6 +827,8 @@ public class VibratorService extends IVibratorService.Stub
defaultIntensity = mVibrator.getDefaultNotificationVibrationIntensity();
} else if (vib.isHapticFeedback()) {
defaultIntensity = mVibrator.getDefaultHapticFeedbackIntensity();
} else if (vib.isAlarm()) {
defaultIntensity = Vibrator.VIBRATION_INTENSITY_HIGH;
} else {
// If we don't know what kind of vibration we're playing then just skip scaling for
// now.
@@ -1149,6 +1161,10 @@ public class VibratorService extends IVibratorService.Stub
return usageHint == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION;
}
private static boolean isAlarm(int usageHint) {
return usageHint == AudioAttributes.USAGE_ALARM;
}
private void noteVibratorOnLocked(int uid, long millis) {
try {
mBatteryStatsService.noteVibratorOn(uid, millis);
@@ -1380,6 +1396,12 @@ public class VibratorService extends IVibratorService.Stub
pw.println(info.toString());
}
pw.println(" Previous alarm vibrations:");
for (VibrationInfo info : mPreviousAlarmVibrations) {
pw.print(" ");
pw.println(info.toString());
}
pw.println(" Previous vibrations:");
for (VibrationInfo info : mPreviousVibrations) {
pw.print(" ");
@@ -1445,6 +1467,9 @@ public class VibratorService extends IVibratorService.Stub
} else if (isHapticFeedback(usage)) {
defaultIntensity = mVibrator.getDefaultHapticFeedbackIntensity();
currentIntensity = mHapticFeedbackIntensity;
} else if (isAlarm(usage)) {
defaultIntensity = Vibrator.VIBRATION_INTENSITY_HIGH;
currentIntensity = Vibrator.VIBRATION_INTENSITY_HIGH;
} else {
defaultIntensity = 0;
currentIntensity = 0;