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

Commit 733a42b2 authored by Eric Laurent's avatar Eric Laurent
Browse files

Issue 3315999: catch ToneGenerator exceptions.

When the AudioFlinger runs out of available AudioTracks (max 32),
the ToneGenerator constructor throws a RuntimeException. Although this
denotes an abnormal situation, VolumePanel should catch this exception.

Change-Id: Ida1312fe4857e99a0ef38b4013cb03e819405689
parent 54973710
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -284,11 +284,12 @@ public class VolumePanel extends Handler

        synchronized (this) {
            ToneGenerator toneGen = getOrCreateToneGenerator(streamType);
            if (toneGen != null) {
                toneGen.startTone(ToneGenerator.TONE_PROP_BEEP);
        }

                sendMessageDelayed(obtainMessage(MSG_STOP_SOUNDS), BEEP_DURATION);
            }
        }
    }

    protected void onStopSounds() {

@@ -319,11 +320,17 @@ public class VolumePanel extends Handler
    private ToneGenerator getOrCreateToneGenerator(int streamType) {
        synchronized (this) {
            if (mToneGenerators[streamType] == null) {
                return mToneGenerators[streamType] = new ToneGenerator(streamType, MAX_VOLUME);
            } else {
                return mToneGenerators[streamType];
                try {
                    mToneGenerators[streamType] = new ToneGenerator(streamType, MAX_VOLUME);
                } catch (RuntimeException e) {
                    if (LOGD) {
                        Log.d(TAG, "ToneGenerator constructor failed with "
                                + "RuntimeException: " + e);
                    }
                }
            }
            return mToneGenerators[streamType];
        }
    }

    /**