Merge "Fix NPE on VibratorManagerService" into tm-dev

This commit is contained in:
Lais Andrade
2022-04-04 10:51:20 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 2 deletions

View File

@@ -989,12 +989,13 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
*/ */
@NonNull @NonNull
private VibrationAttributes fixupVibrationAttributes(@Nullable VibrationAttributes attrs, private VibrationAttributes fixupVibrationAttributes(@Nullable VibrationAttributes attrs,
CombinedVibration effect) { @Nullable CombinedVibration effect) {
if (attrs == null) { if (attrs == null) {
attrs = DEFAULT_ATTRIBUTES; attrs = DEFAULT_ATTRIBUTES;
} }
int usage = attrs.getUsage(); int usage = attrs.getUsage();
if ((usage == VibrationAttributes.USAGE_UNKNOWN) && effect.isHapticFeedbackCandidate()) { if ((usage == VibrationAttributes.USAGE_UNKNOWN)
&& (effect != null) && effect.isHapticFeedbackCandidate()) {
usage = VibrationAttributes.USAGE_TOUCH; usage = VibrationAttributes.USAGE_TOUCH;
} }
int flags = attrs.getFlags(); int flags = attrs.getFlags();

View File

@@ -1315,6 +1315,24 @@ public class VibratorManagerServiceTest {
assertNotEquals(IExternalVibratorService.SCALE_MUTE, scale); assertNotEquals(IExternalVibratorService.SCALE_MUTE, scale);
} }
@Test
public void onExternalVibration_withUnknownUsage_appliesMediaSettings() {
mockVibrators(1);
mVibratorProviders.get(1).setCapabilities(IVibrator.CAP_EXTERNAL_CONTROL);
setUserSetting(Settings.System.MEDIA_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_OFF);
AudioAttributes flaggedAudioAttrs = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_UNKNOWN)
.setFlags(AudioAttributes.FLAG_BYPASS_MUTE)
.build();
createSystemReadyService();
int scale = mExternalVibratorService.onExternalVibrationStart(
new ExternalVibration(/* uid= */ 123, PACKAGE_NAME, flaggedAudioAttrs,
mock(IExternalVibrationController.class)));
assertEquals(IExternalVibratorService.SCALE_MUTE, scale);
}
private VibrationEffectSegment expectedPrebaked(int effectId) { private VibrationEffectSegment expectedPrebaked(int effectId) {
return expectedPrebaked(effectId, VibrationEffect.EFFECT_STRENGTH_MEDIUM); return expectedPrebaked(effectId, VibrationEffect.EFFECT_STRENGTH_MEDIUM);
} }