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

Commit 5c65bf6b authored by Abdelrahman Daim's avatar Abdelrahman Daim Committed by Lais Andrade
Browse files

Add nullptr check for AudioManager Framework Component



Summary: Some framework components do not check
whether the system service being called is null or not
causing "FATAL EXCEPTION" in zygote system process.
Adding nullptr or NULL obj check before calling.

Test: m
flash the device
verify the zygote is running stable and not hitting
FATAL EXECEPTION.

Bug: 380022127
Merged-In: I5db3f6b99224c335109e83312fd6bc6252d23392
Change-Id: I866499d723c8630dbf1d711bd55b97cf6308300e
Signed-off-by: default avatarAbdelrahman Daim <adaim@meta.com>
parent f824197c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ final class VibrationSettings {
    @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 @@ 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;
@@ -616,10 +616,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();
        }
    }
+11 −0
Original line number Diff line number Diff line
@@ -202,6 +202,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);
@@ -461,6 +462,16 @@ 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() {