From cf817a2330936947df94c11859f48771f5596a59 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Mon, 4 Aug 2014 20:36:31 -0700 Subject: [PATCH] audio: fix crashes upon USB device connection - Audio policy: Replace unknown device assertion by debug log in setDeviceConnectionState(). It is possible that some kernels indicate connection of a legacy device type when a USB audio device is connected. We should just ignore this device. - Audio flinger: Make sure FastMixer thread is idle before exiting the normal mixer thread and closing the output stream. Change-Id: Ia10a20176a60a8aa56765538093a555fc998508a --- services/audioflinger/Threads.cpp | 9 +++------ services/audiopolicy/AudioPolicyManager.cpp | 10 +++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp index 2e2f533587..2f65370df7 100644 --- a/services/audioflinger/Threads.cpp +++ b/services/audioflinger/Threads.cpp @@ -2639,12 +2639,9 @@ bool AudioFlinger::PlaybackThread::threadLoop() threadLoop_exit(); - // for DuplicatingThread, standby mode is handled by the outputTracks, otherwise ... - if (mType == MIXER || mType == DIRECT || mType == OFFLOAD) { - // put output stream into standby mode - if (!mStandby) { - mOutput->stream->common.standby(&mOutput->stream->common); - } + if (!mStandby) { + threadLoop_standby(); + mStandby = true; } releaseWakeLock(); diff --git a/services/audiopolicy/AudioPolicyManager.cpp b/services/audiopolicy/AudioPolicyManager.cpp index aa976b56a7..3a9c162914 100644 --- a/services/audiopolicy/AudioPolicyManager.cpp +++ b/services/audiopolicy/AudioPolicyManager.cpp @@ -239,10 +239,14 @@ status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, // register new device as available index = mAvailableOutputDevices.add(devDesc); if (index >= 0) { - mAvailableOutputDevices[index]->mId = nextUniqueId(); sp module = getModuleForDevice(device); - ALOG_ASSERT(module != NULL, "setDeviceConnectionState():" - "could not find HW module for device %08x", device); + if (module == 0) { + ALOGD("setDeviceConnectionState() could not find HW module for device %08x", + device); + mAvailableOutputDevices.remove(devDesc); + return INVALID_OPERATION; + } + mAvailableOutputDevices[index]->mId = nextUniqueId(); mAvailableOutputDevices[index]->mModule = module; } else { return NO_MEMORY; -- 2.11.0