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

Commit b68025b8 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

SoundEffectsHelper: Fix NPE when calling into SoundPool

The instance of SoundPool might get released as a result
of unloading sound effects. Required checks for the validity
of the SoundPool pointer were missing resulting in an NPE.

Bug: 159870337
Test: atest android.media.cts.AudioManagerTest#testSoundEffects
Change-Id: Ief4f7f0027a1f03f71d3db5af623df9ad3c37a1b
parent e4e478ed
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ class SoundEffectsHelper {
        }

        Resource res = mResources.get(mEffects[effect]);
        if (res.mSampleId != EFFECT_NOT_IN_SOUND_POOL && res.mLoaded) {
        if (mSoundPool != null && res.mSampleId != EFFECT_NOT_IN_SOUND_POOL && res.mLoaded) {
            mSoundPool.play(res.mSampleId, volFloat, volFloat, 0, 0, 1.0f);
        } else {
            MediaPlayer mediaPlayer = new MediaPlayer();
@@ -511,7 +511,9 @@ class SoundEffectsHelper {
        }

        void onComplete(boolean success) {
            if (mSoundPool != null) {
                mSoundPool.setOnLoadCompleteListener(null);
            }
            for (OnEffectsLoadCompleteHandler handler : mLoadCompleteHandlers) {
                handler.run(success);
            }