Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8a9c66e5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix VibrationSettings to handle missing AudioManager" into aosp-main-future

parents 75efa8d8 a312bc1b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ final class VibrationSettings {
    @GuardedBy("mLock")
    private boolean mVibrateOn;
    @GuardedBy("mLock")
    private int mRingerMode;
    private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
    @GuardedBy("mLock")
    private boolean mOnWirelessCharger;

@@ -235,7 +235,7 @@ final class VibrationSettings {
    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;
@@ -615,10 +615,10 @@ final class VibrationSettings {

    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();
        }
    }
+10 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ public class VibrationSettingsTest {
        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);
@@ -463,6 +464,15 @@ public class VibrationSettingsTest {
        }
    }

    @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() {