Fix NPE on VibratorManagerService
The service fixes the VibrationAttributes extracted from the external vibration AudioAttributes to apply usage and flags, and thus need to check for permissions before applying them. The check had a NPE error for unknown external vibrations. Fix: 227677233 Test: VibratorManagerServiceTest Change-Id: I864a0538c90d65b96ec319ce75cb64f962138bb9
This commit is contained in:
@@ -989,12 +989,13 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
|
||||
*/
|
||||
@NonNull
|
||||
private VibrationAttributes fixupVibrationAttributes(@Nullable VibrationAttributes attrs,
|
||||
CombinedVibration effect) {
|
||||
@Nullable CombinedVibration effect) {
|
||||
if (attrs == null) {
|
||||
attrs = DEFAULT_ATTRIBUTES;
|
||||
}
|
||||
int usage = attrs.getUsage();
|
||||
if ((usage == VibrationAttributes.USAGE_UNKNOWN) && effect.isHapticFeedbackCandidate()) {
|
||||
if ((usage == VibrationAttributes.USAGE_UNKNOWN)
|
||||
&& (effect != null) && effect.isHapticFeedbackCandidate()) {
|
||||
usage = VibrationAttributes.USAGE_TOUCH;
|
||||
}
|
||||
int flags = attrs.getFlags();
|
||||
|
||||
@@ -1315,6 +1315,24 @@ public class VibratorManagerServiceTest {
|
||||
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) {
|
||||
return expectedPrebaked(effectId, VibrationEffect.EFFECT_STRENGTH_MEDIUM);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user