Fix issue 2203561: Sholes: audio playing out of earpiece.

Create a new IAudioTrack interface to AudioFlinger when start() fails due to a broken pipe error.
Do the same if start fails due to the same error after time out in obtainBuffer().
Do not indicate that the AudioTrack is started to AudioPolicyManager if IAudioTrack start fails.
This avoids that an AudioTrack keeps a dead IAudioTrack after a media server crash.

Same modifications for AudioRecord.

Add a flag to ToneGenerator indicating that the callback thread can call Java. Without it, when the media server crashes and restarts, the AudioSystem error callback will crash in JNI if the IAudiotrack is created from AudioTrack callback thread.
diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h
index c884c2c..1ad1f26 100644
--- a/include/media/ToneGenerator.h
+++ b/include/media/ToneGenerator.h
@@ -151,7 +151,7 @@
         NUM_SUP_TONES = LAST_SUP_TONE-FIRST_SUP_TONE+1
     };
 
-    ToneGenerator(int streamType, float volume);
+    ToneGenerator(int streamType, float volume, bool threadCanCallJava = false);
     ~ToneGenerator();
 
     bool startTone(int toneType, int durationMs = -1);
@@ -242,6 +242,7 @@
 
     static const ToneDescriptor sToneDescriptors[];
 
+    bool mThreadCanCallJava;
     unsigned int mTotalSmp;  // Total number of audio samples played (gives current time)
     unsigned int mNextSegSmp;  // Position of next segment transition expressed in samples
     // NOTE: because mTotalSmp, mNextSegSmp are stored on 32 bit, current design will operate properly