diff options
author | Keith Mok <kmok@cyngn.com> | 2016-06-16 12:10:46 -0700 |
---|---|---|
committer | Keith Mok <kmok@cyngn.com> | 2016-06-16 16:21:28 -0700 |
commit | 4da63b534eecadab856bf4e39d74aa208798dca1 (patch) | |
tree | 573b1551212c4990e952803605fa4c2bca834504 | |
parent | 3f0054bd04310d8dbaf5f1d03ff7b14c481c912d (diff) | |
download | android_packages_apps_FMRadio-4da63b534eecadab856bf4e39d74aa208798dca1.tar.gz android_packages_apps_FMRadio-4da63b534eecadab856bf4e39d74aa208798dca1.tar.bz2 android_packages_apps_FMRadio-4da63b534eecadab856bf4e39d74aa208798dca1.zip |
FmService: Fix crash when plug-in/out headset
There is race condition between the RenderThread
and main thread using the object mAudioTrack and
mAudioRecord. Stop and re-create the RenderThread
when we need to create new instance of mAudioTrack
and mAudioRecord to avoid the race condition.
CYNGNOS-2775 FEIJ-1227
Change-Id: I919010fdcc8aad76f1fc5debe6729b4d2a6954dc
-rw-r--r-- | src/com/android/fmradio/FmService.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/com/android/fmradio/FmService.java b/src/com/android/fmradio/FmService.java index b3d7715..9638208 100644 --- a/src/com/android/fmradio/FmService.java +++ b/src/com/android/fmradio/FmService.java @@ -389,6 +389,8 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan private synchronized void startRender() { Log.d(TAG, "startRender " + AudioSystem.getForceUse(FOR_PROPRIETARY)); + exitRenderThread(); + // need to create new audio record and audio play back track, // because input/output device may be changed. if (mAudioRecord != null) { @@ -404,6 +406,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan initAudioRecordSink(); mIsRender = true; + createRenderThread(); synchronized (mRenderLock) { mRenderLock.notify(); } @@ -425,8 +428,12 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan } private synchronized void exitRenderThread() { - stopRender(); mRenderThread.interrupt(); + try { + mRenderThread.join(); + } catch (InterruptedException ie) { + Log.e(TAG, "Failed to join render thread"); + } mRenderThread = null; } @@ -1448,6 +1455,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan if (null != mFmRecorder) { mFmRecorder = null; } + stopRender(); exitRenderThread(); releaseAudioPatch(); unregisterAudioPortUpdateListener(); |