Merge "Add nullptr check for AudioManager Framework Component" into main
diff --git a/services/core/java/com/android/server/vibrator/VibrationSettings.java b/services/core/java/com/android/server/vibrator/VibrationSettings.java
index 2fc183d..227b6b4 100644
--- a/services/core/java/com/android/server/vibrator/VibrationSettings.java
+++ b/services/core/java/com/android/server/vibrator/VibrationSettings.java
@@ -193,7 +193,7 @@
@GuardedBy("mLock")
private boolean mKeyboardVibrationOn;
@GuardedBy("mLock")
- private int mRingerMode;
+ private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
@GuardedBy("mLock")
private boolean mOnWirelessCharger;
@@ -236,7 +236,7 @@
public void onSystemReady() {
PowerManagerInternal pm = LocalServices.getService(PowerManagerInternal.class);
AudioManager am = mContext.getSystemService(AudioManager.class);
- int ringerMode = am.getRingerModeInternal();
+ int ringerMode = (am == null) ? mRingerMode : am.getRingerModeInternal();
synchronized (mLock) {
mPowerManagerInternal = pm;
@@ -616,10 +616,10 @@
private void updateRingerMode() {
synchronized (mLock) {
- // If audio manager was not loaded yet then assume most restrictive mode.
+ // If audio manager was not loaded yet then assume normal mode.
// This will be loaded again as soon as the audio manager is loaded in onSystemReady.
mRingerMode = (mAudioManager == null)
- ? AudioManager.RINGER_MODE_SILENT
+ ? AudioManager.RINGER_MODE_NORMAL
: mAudioManager.getRingerModeInternal();
}
}
diff --git a/services/tests/vibrator/src/com/android/server/vibrator/VibrationSettingsTest.java b/services/tests/vibrator/src/com/android/server/vibrator/VibrationSettingsTest.java
index 88a9483..21604df 100644
--- a/services/tests/vibrator/src/com/android/server/vibrator/VibrationSettingsTest.java
+++ b/services/tests/vibrator/src/com/android/server/vibrator/VibrationSettingsTest.java
@@ -202,6 +202,7 @@
removeServicesForTest();
LocalServices.addService(PowerManagerInternal.class, mPowerManagerInternalMock);
LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternalMock);
+ when(mContextSpy.getSystemService(eq(Context.AUDIO_SERVICE))).thenReturn(null);
VibrationSettings minimalVibrationSettings = new VibrationSettings(mContextSpy,
new Handler(mTestLooper.getLooper()), mVibrationConfigMock);
@@ -461,6 +462,16 @@
}
}
+ @Test
+ public void shouldIgnoreVibration_withoutAudioManager_allowsAllVibrations() {
+ when(mContextSpy.getSystemService(eq(Context.AUDIO_SERVICE))).thenReturn(null);
+ createSystemReadyVibrationSettings();
+
+ for (int usage : ALL_USAGES) {
+ assertVibrationNotIgnoredForUsage(usage);
+ }
+ }
+
@Test
public void shouldIgnoreVibration_vibrateOnDisabled_ignoresUsagesNotAccessibility() {