From 72e3f39146fce4686bd96f11057c051bea376dfb Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 20 May 2015 14:43:50 -0700 Subject: audio flinger: do not call JAVA services until system is ready Wait for system ready indication form AudioService before enabling calls to scheduling service or power manager. Bug: 11520969. Change-Id: I221927394f4a08fd86c9d457e55dd0e07949f0cf --- services/audioflinger/AudioFlinger.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'services/audioflinger/AudioFlinger.cpp') diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 93b1642..52fce34 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -181,7 +181,8 @@ AudioFlinger::AudioFlinger() mIsLowRamDevice(true), mIsDeviceTypeKnown(false), mGlobalEffectEnableTime(0), - mPrimaryOutputSampleRate(0) + mPrimaryOutputSampleRate(0), + mSystemReady(false) { getpid_cached = getpid(); char value[PROPERTY_VALUE_MAX]; @@ -1722,6 +1723,26 @@ audio_hw_sync_t AudioFlinger::getAudioHwSyncForSession(audio_session_t sessionId return (audio_hw_sync_t)value; } +status_t AudioFlinger::systemReady() +{ + Mutex::Autolock _l(mLock); + ALOGI("%s", __FUNCTION__); + if (mSystemReady) { + ALOGW("%s called twice", __FUNCTION__); + return NO_ERROR; + } + mSystemReady = true; + for (size_t i = 0; i < mPlaybackThreads.size(); i++) { + ThreadBase *thread = (ThreadBase *)mPlaybackThreads.valueAt(i).get(); + thread->systemReady(); + } + for (size_t i = 0; i < mRecordThreads.size(); i++) { + ThreadBase *thread = (ThreadBase *)mRecordThreads.valueAt(i).get(); + thread->systemReady(); + } + return NO_ERROR; +} + // setAudioHwSyncForSession_l() must be called with AudioFlinger::mLock held void AudioFlinger::setAudioHwSyncForSession_l(PlaybackThread *thread, audio_session_t sessionId) { @@ -1794,15 +1815,15 @@ sp AudioFlinger::openOutput_l(audio_module_handle_ PlaybackThread *thread; if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { - thread = new OffloadThread(this, outputStream, *output, devices); + thread = new OffloadThread(this, outputStream, *output, devices, mSystemReady); ALOGV("openOutput_l() created offload output: ID %d thread %p", *output, thread); } else if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) || !isValidPcmSinkFormat(config->format) || !isValidPcmSinkChannelMask(config->channel_mask)) { - thread = new DirectOutputThread(this, outputStream, *output, devices); + thread = new DirectOutputThread(this, outputStream, *output, devices, mSystemReady); ALOGV("openOutput_l() created direct output: ID %d thread %p", *output, thread); } else { - thread = new MixerThread(this, outputStream, *output, devices); + thread = new MixerThread(this, outputStream, *output, devices, mSystemReady); ALOGV("openOutput_l() created mixer output: ID %d thread %p", *output, thread); } mPlaybackThreads.add(*output, thread); @@ -1873,7 +1894,7 @@ audio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1, } audio_io_handle_t id = nextUniqueId(); - DuplicatingThread *thread = new DuplicatingThread(this, thread1, id); + DuplicatingThread *thread = new DuplicatingThread(this, thread1, id, mSystemReady); thread->addOutputTrack(thread2); mPlaybackThreads.add(id, thread); // notify client processes of the new output creation @@ -2120,7 +2141,8 @@ sp AudioFlinger::openInput_l(audio_module_handle_t m inputStream, *input, primaryOutputDevice_l(), - devices + devices, + mSystemReady #ifdef TEE_SINK , teeSink #endif -- cgit v1.1