diff options
| author | Eric Laurent <elaurent@google.com> | 2011-01-19 10:41:57 -0800 |
|---|---|---|
| committer | Eric Laurent <elaurent@google.com> | 2011-01-19 12:16:19 -0800 |
| commit | 733a42b24b91ce2881e2e4457a1ee06f12bb127a (patch) | |
| tree | e121df86d79995ec7fe862ca8a01f554dfb9f1ab /core/java/android/view/VolumePanel.java | |
| parent | 54973710d769e4722dc21778f8fcb7b08d2872dd (diff) | |
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
Diffstat (limited to 'core/java/android/view/VolumePanel.java')
| -rw-r--r-- | core/java/android/view/VolumePanel.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java index e21824e0647d..e447dbb8a5f2 100644 --- a/core/java/android/view/VolumePanel.java +++ b/core/java/android/view/VolumePanel.java @@ -284,10 +284,11 @@ public class VolumePanel extends Handler synchronized (this) { ToneGenerator toneGen = getOrCreateToneGenerator(streamType); - toneGen.startTone(ToneGenerator.TONE_PROP_BEEP); + if (toneGen != null) { + toneGen.startTone(ToneGenerator.TONE_PROP_BEEP); + sendMessageDelayed(obtainMessage(MSG_STOP_SOUNDS), BEEP_DURATION); + } } - - sendMessageDelayed(obtainMessage(MSG_STOP_SOUNDS), BEEP_DURATION); } protected void onStopSounds() { @@ -319,10 +320,16 @@ 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]; } } |
