Protect volumepanel slider creation from race condition.

It is possible for 2 different threads to poke the mStreamControls at the same time,
causing the monkey bug mentioned in the bug report below.

Bug: 6411852

Couldn't think of any other reason Stream type 3 (MUSIC) wouldn't exist in the list.
It's possible that a programmatic call came in at the same time as the volume key press.

Synchronizing blocks where the mStreamControls are populated and accessed.

Change-Id: Ifedec6b0f8bad9634cb9e079fda785c433bdb7a7
diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java
index 78984e0..5ffc2c3 100644
--- a/core/java/android/view/VolumePanel.java
+++ b/core/java/android/view/VolumePanel.java
@@ -437,8 +437,10 @@
 
     public void postVolumeChanged(int streamType, int flags) {
         if (hasMessages(MSG_VOLUME_CHANGED)) return;
-        if (mStreamControls == null) {
-            createSliders();
+        synchronized (this) {
+            if (mStreamControls == null) {
+                createSliders();
+            }
         }
         removeMessages(MSG_FREE_RESOURCES);
         obtainMessage(MSG_VOLUME_CHANGED, streamType, flags).sendToTarget();
@@ -450,8 +452,10 @@
 
     public void postMuteChanged(int streamType, int flags) {
         if (hasMessages(MSG_VOLUME_CHANGED)) return;
-        if (mStreamControls == null) {
-            createSliders();
+        synchronized (this) {
+            if (mStreamControls == null) {
+                createSliders();
+            }
         }
         removeMessages(MSG_FREE_RESOURCES);
         obtainMessage(MSG_MUTE_CHANGED, streamType, flags).sendToTarget();
@@ -471,10 +475,12 @@
         if (LOGD) Log.d(TAG, "onVolumeChanged(streamType: " + streamType + ", flags: " + flags + ")");
 
         if ((flags & AudioManager.FLAG_SHOW_UI) != 0) {
-            if (mActiveStreamType != streamType) {
-                reorderSliders(streamType);
+            synchronized (this) {
+                if (mActiveStreamType != streamType) {
+                    reorderSliders(streamType);
+                }
+                onShowVolumeChanged(streamType, flags);
             }
-            onShowVolumeChanged(streamType, flags);
         }
 
         if ((flags & AudioManager.FLAG_PLAY_SOUND) != 0 && ! mRingIsSilent) {