summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/A2dpAudioInterface.cpp36
-rw-r--r--audio/Android.mk16
-rw-r--r--audio/AudioDumpInterface.cpp42
-rw-r--r--audio/AudioHardwareGeneric.cpp14
-rw-r--r--audio/AudioHardwareInterface.cpp11
-rw-r--r--audio/AudioPolicyCompatClient.cpp6
-rw-r--r--audio/AudioPolicyCompatClient.h2
-rw-r--r--audio/AudioPolicyManagerBase.cpp1178
-rw-r--r--audio/AudioPolicyManagerDefault.h4
-rw-r--r--audio/audio_hw_hal.cpp39
-rw-r--r--audio/audio_policy_hal.cpp56
-rw-r--r--include/hardware_legacy/AudioHardwareInterface.h5
-rw-r--r--include/hardware_legacy/AudioPolicyInterface.h31
-rw-r--r--include/hardware_legacy/AudioPolicyManagerBase.h144
-rw-r--r--include/hardware_legacy/AudioSystemLegacy.h4
-rw-r--r--include/hardware_legacy/power.h3
-rw-r--r--include/hardware_legacy/wifi.h74
-rw-r--r--power/Android.mk5
-rw-r--r--power/power.c53
-rw-r--r--power/power_qemu.c28
-rw-r--r--power/power_qemu.h24
-rw-r--r--qemu/qemu.c2
-rw-r--r--wifi/wifi.c346
23 files changed, 1142 insertions, 981 deletions
diff --git a/audio/A2dpAudioInterface.cpp b/audio/A2dpAudioInterface.cpp
index 2d78858..cc435bd 100644
--- a/audio/A2dpAudioInterface.cpp
+++ b/audio/A2dpAudioInterface.cpp
@@ -38,7 +38,7 @@ static const char *sA2dpWakeLock = "A2dpOutputStream";
// AudioHardwareInterface* hw = 0;
//
// hw = AudioHardwareInterface::create();
-// LOGD("new A2dpAudioInterface(hw: %p)", hw);
+// ALOGD("new A2dpAudioInterface(hw: %p)", hw);
// hw = new A2dpAudioInterface(hw);
// return hw;
//}
@@ -64,7 +64,7 @@ AudioStreamOut* A2dpAudioInterface::openOutputStream(
uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status)
{
if (!AudioSystem::isA2dpDevice((AudioSystem::audio_devices)devices)) {
- LOGV("A2dpAudioInterface::openOutputStream() open HW device: %x", devices);
+ ALOGV("A2dpAudioInterface::openOutputStream() open HW device: %x", devices);
return mHardwareInterface->openOutputStream(devices, format, channels, sampleRate, status);
}
@@ -137,7 +137,7 @@ status_t A2dpAudioInterface::setParameters(const String8& keyValuePairs)
String8 key;
status_t status = NO_ERROR;
- LOGV("setParameters() %s", keyValuePairs.string());
+ ALOGV("setParameters() %s", keyValuePairs.string());
key = "bluetooth_enabled";
if (param.get(key, value) == NO_ERROR) {
@@ -195,7 +195,7 @@ String8 A2dpAudioInterface::getParameters(const String8& keys)
keyValuePairs += mHardwareInterface->getParameters(param.toString());
}
- LOGV("getParameters() %s", keyValuePairs.string());
+ ALOGV("getParameters() %s", keyValuePairs.string());
return keyValuePairs;
}
@@ -239,7 +239,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::set(
uint32_t lChannels = pChannels ? *pChannels : 0;
uint32_t lRate = pRate ? *pRate : 0;
- LOGD("A2dpAudioStreamOut::set %x, %d, %d, %d\n", device, lFormat, lChannels, lRate);
+ ALOGD("A2dpAudioStreamOut::set %x, %d, %d, %d\n", device, lFormat, lChannels, lRate);
// fix up defaults
if (lFormat == 0) lFormat = format();
@@ -267,9 +267,9 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::set(
A2dpAudioInterface::A2dpAudioStreamOut::~A2dpAudioStreamOut()
{
- LOGV("A2dpAudioStreamOut destructor");
+ ALOGV("A2dpAudioStreamOut destructor");
close();
- LOGV("A2dpAudioStreamOut destructor returning from close()");
+ ALOGV("A2dpAudioStreamOut destructor returning from close()");
}
ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t bytes)
@@ -281,7 +281,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t
size_t remaining = bytes;
if (!mBluetoothEnabled || mClosing || mSuspended) {
- LOGV("A2dpAudioStreamOut::write(), but bluetooth disabled \
+ ALOGV("A2dpAudioStreamOut::write(), but bluetooth disabled \
mBluetoothEnabled %d, mClosing %d, mSuspended %d",
mBluetoothEnabled, mClosing, mSuspended);
goto Error;
@@ -301,7 +301,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t
while (remaining > 0 && retries) {
status = a2dp_write(mData, buffer, remaining);
if (status < 0) {
- LOGE("a2dp_write failed err: %d\n", status);
+ ALOGE("a2dp_write failed err: %d\n", status);
goto Error;
}
if (status == 0) {
@@ -316,7 +316,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t
// NOTE: It is likely that the A2DP headset is being disconnected
nsecs_t now = systemTime();
if ((uint32_t)ns2us(now - mLastWriteTime) < (mBufferDurationUs >> 2)) {
- LOGV("A2DP sink runs too fast");
+ ALOGV("A2DP sink runs too fast");
usleep(mBufferDurationUs - (uint32_t)ns2us(now - mLastWriteTime));
}
mLastWriteTime = now;
@@ -338,7 +338,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::init()
if (!mData) {
status_t status = a2dp_init(44100, 2, &mData);
if (status < 0) {
- LOGE("a2dp_init failed err: %d\n", status);
+ ALOGE("a2dp_init failed err: %d\n", status);
mData = NULL;
return status;
}
@@ -359,7 +359,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::standby_l()
int result = NO_ERROR;
if (!mStandby) {
- LOGV_IF(mClosing || !mBluetoothEnabled, "Standby skip stop: closing %d enabled %d",
+ ALOGV_IF(mClosing || !mBluetoothEnabled, "Standby skip stop: closing %d enabled %d",
mClosing, mBluetoothEnabled);
if (!mClosing && mBluetoothEnabled) {
result = a2dp_stop(mData);
@@ -378,7 +378,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setParameters(const String8& ke
String8 key = String8("a2dp_sink_address");
status_t status = NO_ERROR;
int device;
- LOGV("A2dpAudioStreamOut::setParameters() %s", keyValuePairs.string());
+ ALOGV("A2dpAudioStreamOut::setParameters() %s", keyValuePairs.string());
if (param.get(key, value) == NO_ERROR) {
if (value.length() != strlen("00:00:00:00:00:00")) {
@@ -428,7 +428,7 @@ String8 A2dpAudioInterface::A2dpAudioStreamOut::getParameters(const String8& key
param.addInt(key, (int)mDevice);
}
- LOGV("A2dpAudioStreamOut::getParameters() %s", param.toString().string());
+ ALOGV("A2dpAudioStreamOut::getParameters() %s", param.toString().string());
return param.toString();
}
@@ -448,7 +448,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setAddress(const char* address)
status_t A2dpAudioInterface::A2dpAudioStreamOut::setBluetoothEnabled(bool enabled)
{
- LOGD("setBluetoothEnabled %d", enabled);
+ ALOGD("setBluetoothEnabled %d", enabled);
Mutex::Autolock lock(mLock);
@@ -461,7 +461,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setBluetoothEnabled(bool enable
status_t A2dpAudioInterface::A2dpAudioStreamOut::setSuspended(bool onOff)
{
- LOGV("setSuspended %d", onOff);
+ ALOGV("setSuspended %d", onOff);
mSuspended = onOff;
standby();
return NO_ERROR;
@@ -470,7 +470,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setSuspended(bool onOff)
status_t A2dpAudioInterface::A2dpAudioStreamOut::close()
{
Mutex::Autolock lock(mLock);
- LOGV("A2dpAudioStreamOut::close() calling close_l()");
+ ALOGV("A2dpAudioStreamOut::close() calling close_l()");
return close_l();
}
@@ -478,7 +478,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::close_l()
{
standby_l();
if (mData) {
- LOGV("A2dpAudioStreamOut::close_l() calling a2dp_cleanup(mData)");
+ ALOGV("A2dpAudioStreamOut::close_l() calling a2dp_cleanup(mData)");
a2dp_cleanup(mData);
mData = NULL;
}
diff --git a/audio/Android.mk b/audio/Android.mk
index ef41374..a69b9cd 100644
--- a/audio/Android.mk
+++ b/audio/Android.mk
@@ -10,10 +10,6 @@ LOCAL_SRC_FILES := \
AudioHardwareInterface.cpp \
audio_hw_hal.cpp
-ifeq ($(BOARD_HAVE_BLUETOOTH),true)
- LOCAL_CFLAGS += -DWITH_A2DP
-endif
-
LOCAL_MODULE := libaudiohw_legacy
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES := libmedia_helper
@@ -31,10 +27,6 @@ ifeq ($(AUDIO_POLICY_TEST),true)
LOCAL_CFLAGS += -DAUDIO_POLICY_TEST
endif
-ifeq ($(BOARD_HAVE_BLUETOOTH),true)
- LOCAL_CFLAGS += -DWITH_A2DP
-endif
-
LOCAL_STATIC_LIBRARIES := libmedia_helper
LOCAL_MODULE := libaudiopolicy_legacy
LOCAL_MODULE_TAGS := optional
@@ -50,8 +42,7 @@ LOCAL_SRC_FILES := \
LOCAL_SHARED_LIBRARIES := \
libcutils \
- libutils \
- libmedia
+ libutils
LOCAL_STATIC_LIBRARIES := \
libmedia_helper
@@ -63,10 +54,6 @@ LOCAL_MODULE := audio_policy.default
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE_TAGS := optional
-ifeq ($(BOARD_HAVE_BLUETOOTH),true)
- LOCAL_CFLAGS += -DWITH_A2DP
-endif
-
include $(BUILD_SHARED_LIBRARY)
#ifeq ($(ENABLE_AUDIO_DUMP),true)
@@ -85,7 +72,6 @@ include $(BUILD_SHARED_LIBRARY)
#
# LOCAL_CFLAGS += \
# -DWITH_BLUETOOTH \
-# -DWITH_A2DP
#endif
#
#include $(BUILD_SHARED_LIBRARY)
diff --git a/audio/AudioDumpInterface.cpp b/audio/AudioDumpInterface.cpp
index 6c11114..62fdbd6 100644
--- a/audio/AudioDumpInterface.cpp
+++ b/audio/AudioDumpInterface.cpp
@@ -35,10 +35,10 @@ AudioDumpInterface::AudioDumpInterface(AudioHardwareInterface* hw)
: mPolicyCommands(String8("")), mFileName(String8(""))
{
if(hw == 0) {
- LOGE("Dump construct hw = 0");
+ ALOGE("Dump construct hw = 0");
}
mFinalInterface = hw;
- LOGV("Constructor %p, mFinalInterface %p", this, mFinalInterface);
+ ALOGV("Constructor %p, mFinalInterface %p", this, mFinalInterface);
}
@@ -94,7 +94,7 @@ AudioStreamOut* AudioDumpInterface::openOutputStream(
}
if (status) *status = NO_ERROR;
}
- LOGV("openOutputStream(), outFinal %p", outFinal);
+ ALOGV("openOutputStream(), outFinal %p", outFinal);
AudioStreamOutDump *dumOutput = new AudioStreamOutDump(this, mOutputs.size(), outFinal,
devices, lFormat, lChannels, lRate);
@@ -108,11 +108,11 @@ void AudioDumpInterface::closeOutputStream(AudioStreamOut* out)
AudioStreamOutDump *dumpOut = (AudioStreamOutDump *)out;
if (mOutputs.indexOf(dumpOut) < 0) {
- LOGW("Attempt to close invalid output stream");
+ ALOGW("Attempt to close invalid output stream");
return;
}
- LOGV("closeOutputStream() output %p", out);
+ ALOGV("closeOutputStream() output %p", out);
dumpOut->standby();
if (dumpOut->finalStream() != NULL) {
@@ -160,7 +160,7 @@ AudioStreamIn* AudioDumpInterface::openInputStream(uint32_t devices, int *format
}
if (status) *status = NO_ERROR;
}
- LOGV("openInputStream(), inFinal %p", inFinal);
+ ALOGV("openInputStream(), inFinal %p", inFinal);
AudioStreamInDump *dumInput = new AudioStreamInDump(this, mInputs.size(), inFinal,
devices, lFormat, lChannels, lRate);
@@ -173,7 +173,7 @@ void AudioDumpInterface::closeInputStream(AudioStreamIn* in)
AudioStreamInDump *dumpIn = (AudioStreamInDump *)in;
if (mInputs.indexOf(dumpIn) < 0) {
- LOGW("Attempt to close invalid input stream");
+ ALOGW("Attempt to close invalid input stream");
return;
}
dumpIn->standby();
@@ -191,7 +191,7 @@ status_t AudioDumpInterface::setParameters(const String8& keyValuePairs)
AudioParameter param = AudioParameter(keyValuePairs);
String8 value;
int valueInt;
- LOGV("setParameters %s", keyValuePairs.string());
+ ALOGV("setParameters %s", keyValuePairs.string());
if (param.get(String8("test_cmd_file_name"), value) == NO_ERROR) {
mFileName = value;
@@ -201,7 +201,7 @@ status_t AudioDumpInterface::setParameters(const String8& keyValuePairs)
Mutex::Autolock _l(mLock);
param.remove(String8("test_cmd_policy"));
mPolicyCommands = param.toString();
- LOGV("test_cmd_policy command %s written", mPolicyCommands.string());
+ ALOGV("test_cmd_policy command %s written", mPolicyCommands.string());
return NO_ERROR;
}
@@ -215,7 +215,7 @@ String8 AudioDumpInterface::getParameters(const String8& keys)
AudioParameter response;
String8 value;
-// LOGV("getParameters %s", keys.string());
+// ALOGV("getParameters %s", keys.string());
if (param.get(String8("test_cmd_policy"), value) == NO_ERROR) {
Mutex::Autolock _l(mLock);
if (mPolicyCommands.length() != 0) {
@@ -225,7 +225,7 @@ String8 AudioDumpInterface::getParameters(const String8& keys)
response.addInt(String8("test_cmd_policy"), 0);
}
param.remove(String8("test_cmd_policy"));
-// LOGV("test_cmd_policy command %s read", mPolicyCommands.string());
+// ALOGV("test_cmd_policy command %s read", mPolicyCommands.string());
}
if (param.get(String8("test_cmd_file_name"), value) == NO_ERROR) {
@@ -266,13 +266,13 @@ AudioStreamOutDump::AudioStreamOutDump(AudioDumpInterface *interface,
mSampleRate(sampleRate), mFormat(format), mChannels(channels), mLatency(0), mDevice(devices),
mBufferSize(1024), mFinalStream(finalStream), mFile(0), mFileCount(0)
{
- LOGV("AudioStreamOutDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
+ ALOGV("AudioStreamOutDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
}
AudioStreamOutDump::~AudioStreamOutDump()
{
- LOGV("AudioStreamOutDump destructor");
+ ALOGV("AudioStreamOutDump destructor");
Close();
}
@@ -291,7 +291,7 @@ ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes)
char name[255];
sprintf(name, "%s_out_%d_%d.pcm", mInterface->fileName().string(), mId, ++mFileCount);
mFile = fopen(name, "wb");
- LOGV("Opening dump file %s, fh %p", name, mFile);
+ ALOGV("Opening dump file %s, fh %p", name, mFile);
}
}
if (mFile) {
@@ -302,7 +302,7 @@ ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes)
status_t AudioStreamOutDump::standby()
{
- LOGV("AudioStreamOutDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
+ ALOGV("AudioStreamOutDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
Close();
if (mFinalStream != 0 ) return mFinalStream->standby();
@@ -343,7 +343,7 @@ status_t AudioStreamOutDump::setVolume(float left, float right)
}
status_t AudioStreamOutDump::setParameters(const String8& keyValuePairs)
{
- LOGV("AudioStreamOutDump::setParameters %s", keyValuePairs.string());
+ ALOGV("AudioStreamOutDump::setParameters %s", keyValuePairs.string());
if (mFinalStream != 0 ) {
return mFinalStream->setParameters(keyValuePairs);
@@ -427,7 +427,7 @@ AudioStreamInDump::AudioStreamInDump(AudioDumpInterface *interface,
mSampleRate(sampleRate), mFormat(format), mChannels(channels), mDevice(devices),
mBufferSize(1024), mFinalStream(finalStream), mFile(0), mFileCount(0)
{
- LOGV("AudioStreamInDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
+ ALOGV("AudioStreamInDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
}
@@ -447,7 +447,7 @@ ssize_t AudioStreamInDump::read(void* buffer, ssize_t bytes)
char name[255];
sprintf(name, "%s_in_%d_%d.pcm", mInterface->fileName().string(), mId, ++mFileCount);
mFile = fopen(name, "wb");
- LOGV("Opening input dump file %s, fh %p", name, mFile);
+ ALOGV("Opening input dump file %s, fh %p", name, mFile);
}
}
if (mFile) {
@@ -480,7 +480,7 @@ ssize_t AudioStreamInDump::read(void* buffer, ssize_t bytes)
}
strcat(name, ".wav");
mFile = fopen(name, "rb");
- LOGV("Opening input read file %s, fh %p", name, mFile);
+ ALOGV("Opening input read file %s, fh %p", name, mFile);
if (mFile) {
fseek(mFile, AUDIO_DUMP_WAVE_HDR_SIZE, SEEK_SET);
}
@@ -499,7 +499,7 @@ ssize_t AudioStreamInDump::read(void* buffer, ssize_t bytes)
status_t AudioStreamInDump::standby()
{
- LOGV("AudioStreamInDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
+ ALOGV("AudioStreamInDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
Close();
if (mFinalStream != 0 ) return mFinalStream->standby();
@@ -538,7 +538,7 @@ int AudioStreamInDump::format() const
status_t AudioStreamInDump::setParameters(const String8& keyValuePairs)
{
- LOGV("AudioStreamInDump::setParameters()");
+ ALOGV("AudioStreamInDump::setParameters()");
if (mFinalStream != 0 ) return mFinalStream->setParameters(keyValuePairs);
return NO_ERROR;
}
diff --git a/audio/AudioHardwareGeneric.cpp b/audio/AudioHardwareGeneric.cpp
index 61286e4..a2b00f8 100644
--- a/audio/AudioHardwareGeneric.cpp
+++ b/audio/AudioHardwareGeneric.cpp
@@ -273,7 +273,7 @@ status_t AudioStreamOutGeneric::setParameters(const String8& keyValuePairs)
String8 key = String8(AudioParameter::keyRouting);
status_t status = NO_ERROR;
int device;
- LOGV("setParameters() %s", keyValuePairs.string());
+ ALOGV("setParameters() %s", keyValuePairs.string());
if (param.getInt(key, device) == NO_ERROR) {
mDevice = device;
@@ -296,7 +296,7 @@ String8 AudioStreamOutGeneric::getParameters(const String8& keys)
param.addInt(key, (int)mDevice);
}
- LOGV("getParameters() %s", param.toString().string());
+ ALOGV("getParameters() %s", param.toString().string());
return param.toString();
}
@@ -318,12 +318,12 @@ status_t AudioStreamInGeneric::set(
AudioSystem::audio_in_acoustics acoustics)
{
if (pFormat == 0 || pChannels == 0 || pRate == 0) return BAD_VALUE;
- LOGV("AudioStreamInGeneric::set(%p, %d, %d, %d, %u)", hw, fd, *pFormat, *pChannels, *pRate);
+ ALOGV("AudioStreamInGeneric::set(%p, %d, %d, %d, %u)", hw, fd, *pFormat, *pChannels, *pRate);
// check values
if ((*pFormat != format()) ||
(*pChannels != channels()) ||
(*pRate != sampleRate())) {
- LOGE("Error opening input channel");
+ ALOGE("Error opening input channel");
*pFormat = format();
*pChannels = channels();
*pRate = sampleRate();
@@ -344,7 +344,7 @@ ssize_t AudioStreamInGeneric::read(void* buffer, ssize_t bytes)
{
AutoMutex lock(mLock);
if (mFd < 0) {
- LOGE("Attempt to read from unopened device");
+ ALOGE("Attempt to read from unopened device");
return NO_INIT;
}
return ::read(mFd, buffer, bytes);
@@ -381,7 +381,7 @@ status_t AudioStreamInGeneric::setParameters(const String8& keyValuePairs)
String8 key = String8(AudioParameter::keyRouting);
status_t status = NO_ERROR;
int device;
- LOGV("setParameters() %s", keyValuePairs.string());
+ ALOGV("setParameters() %s", keyValuePairs.string());
if (param.getInt(key, device) == NO_ERROR) {
mDevice = device;
@@ -404,7 +404,7 @@ String8 AudioStreamInGeneric::getParameters(const String8& keys)
param.addInt(key, (int)mDevice);
}
- LOGV("getParameters() %s", param.toString().string());
+ ALOGV("getParameters() %s", param.toString().string());
return param.toString();
}
diff --git a/audio/AudioHardwareInterface.cpp b/audio/AudioHardwareInterface.cpp
index c116669..60cce27 100644
--- a/audio/AudioHardwareInterface.cpp
+++ b/audio/AudioHardwareInterface.cpp
@@ -26,9 +26,6 @@
#include "AudioHardwareStub.h"
#include "AudioHardwareGeneric.h"
-#ifdef WITH_A2DP
-#include "A2dpAudioInterface.h"
-#endif
#ifdef ENABLE_AUDIO_DUMP
#include "AudioDumpInterface.h"
@@ -89,7 +86,7 @@ AudioHardwareBase::AudioHardwareBase()
status_t AudioHardwareBase::setMode(int mode)
{
#if LOG_ROUTING_CALLS
- LOGD("setMode(%s)", displayMode(mode));
+ ALOGD("setMode(%s)", displayMode(mode));
#endif
if ((mode < 0) || (mode >= AudioSystem::NUM_MODES))
return BAD_VALUE;
@@ -116,15 +113,15 @@ String8 AudioHardwareBase::getParameters(const String8& keys)
size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
{
if (sampleRate != 8000) {
- LOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
+ ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
return 0;
}
if (format != AudioSystem::PCM_16_BIT) {
- LOGW("getInputBufferSize bad format: %d", format);
+ ALOGW("getInputBufferSize bad format: %d", format);
return 0;
}
if (channelCount != 1) {
- LOGW("getInputBufferSize bad channel count: %d", channelCount);
+ ALOGW("getInputBufferSize bad channel count: %d", channelCount);
return 0;
}
diff --git a/audio/AudioPolicyCompatClient.cpp b/audio/AudioPolicyCompatClient.cpp
index 08c31c5..5231b41 100644
--- a/audio/AudioPolicyCompatClient.cpp
+++ b/audio/AudioPolicyCompatClient.cpp
@@ -37,7 +37,7 @@ audio_io_handle_t AudioPolicyCompatClient::openOutput(uint32_t *pDevices,
uint32_t *pLatencyMs,
AudioSystem::output_flags flags)
{
- return mServiceOps->open_output(mService, pDevices, pSamplingRate, pFormat,
+ return mServiceOps->open_output(mService, pDevices, pSamplingRate, (audio_format_t *) pFormat,
pChannels, pLatencyMs,
(audio_policy_output_flags_t)flags);
}
@@ -67,9 +67,9 @@ audio_io_handle_t AudioPolicyCompatClient::openInput(uint32_t *pDevices,
uint32_t *pSamplingRate,
uint32_t *pFormat,
uint32_t *pChannels,
- uint32_t acoustics)
+ audio_in_acoustics_t acoustics)
{
- return mServiceOps->open_input(mService, pDevices, pSamplingRate, pFormat,
+ return mServiceOps->open_input(mService, pDevices, pSamplingRate, (audio_format_t *) pFormat,
pChannels, acoustics);
}
diff --git a/audio/AudioPolicyCompatClient.h b/audio/AudioPolicyCompatClient.h
index 4feee37..99dd639 100644
--- a/audio/AudioPolicyCompatClient.h
+++ b/audio/AudioPolicyCompatClient.h
@@ -50,7 +50,7 @@ public:
uint32_t *pSamplingRate,
uint32_t *pFormat,
uint32_t *pChannels,
- uint32_t acoustics);
+ audio_in_acoustics_t acoustics);
virtual status_t closeInput(audio_io_handle_t input);
virtual status_t setStreamOutput(AudioSystem::stream_type stream, audio_io_handle_t output);
virtual status_t moveEffects(int session,
diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp
index e299db8..0e6a1cb 100644
--- a/audio/AudioPolicyManagerBase.cpp
+++ b/audio/AudioPolicyManagerBase.cpp
@@ -19,6 +19,7 @@
#include <utils/Log.h>
#include <hardware_legacy/AudioPolicyManagerBase.h>
#include <hardware/audio_effect.h>
+#include <hardware/audio.h>
#include <math.h>
namespace android_audio_legacy {
@@ -27,109 +28,152 @@ namespace android_audio_legacy {
// AudioPolicyInterface implementation
// ----------------------------------------------------------------------------
+////////////////////
+// TODO: the following static configuration will be read from a configuration file
+
+
+// sHasA2dp is true on platforms with support for bluetooth A2DP
+bool sHasA2dp = true;
+
+// devices that are always available on the platform
+audio_devices_t sAttachedOutputDevices =
+ (audio_devices_t)(AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER);
+
+// device selected by default at boot time must be in sAttachedOutputDevices
+audio_devices_t sDefaultOutputDevice = AUDIO_DEVICE_OUT_SPEAKER;
+
+uint32_t sSamplingRates[] = {44100, 0};
+audio_channel_mask_t sChannels[] = {AUDIO_CHANNEL_OUT_STEREO, (audio_channel_mask_t)0};
+audio_format_t sFormats[] = {AUDIO_FORMAT_PCM_16_BIT, (audio_format_t)0};
+
+// the primary output (identified by AUDIO_POLICY_OUTPUT_FLAG_PRIMARY in its profile) must exist and
+// is unique on a platform. It is the output receiving the routing and volume commands for telephony
+// use cases. It is normally exposed by the primary audio hw module and opened at boot time by
+// the audio policy manager.
+const output_profile_t sPrimaryOutput = {
+ sSamplingRates,
+ sChannels,
+ sFormats,
+ (audio_devices_t)(AUDIO_DEVICE_OUT_EARPIECE |
+ AUDIO_DEVICE_OUT_SPEAKER |
+ AUDIO_DEVICE_OUT_WIRED_HEADSET |
+ AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
+ AUDIO_DEVICE_OUT_ALL_SCO |
+ AUDIO_DEVICE_OUT_AUX_DIGITAL |
+ AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET),
+ AUDIO_POLICY_OUTPUT_FLAG_PRIMARY
+};
+
+const output_profile_t sA2dpOutput = {
+ sSamplingRates,
+ sChannels,
+ sFormats,
+ AUDIO_DEVICE_OUT_ALL_A2DP,
+ (audio_policy_output_flags_t)0
+};
+
+const output_profile_t *sAvailableOutputs[] = {
+ &sPrimaryOutput,
+ &sA2dpOutput,
+ NULL
+};
+
+///////////// end of temporary static configuration data
+
status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_devices device,
AudioSystem::device_connection_state state,
const char *device_address)
{
+ audio_io_handle_t output = 0;
- LOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
+ ALOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
// connect/disconnect only 1 device at a time
if (AudioSystem::popCount(device) != 1) return BAD_VALUE;
if (strlen(device_address) >= MAX_DEVICE_ADDRESS_LEN) {
- LOGE("setDeviceConnectionState() invalid address: %s", device_address);
+ ALOGE("setDeviceConnectionState() invalid address: %s", device_address);
return BAD_VALUE;
}
// handle output devices
if (AudioSystem::isOutputDevice(device)) {
-#ifndef WITH_A2DP
- if (AudioSystem::isA2dpDevice(device)) {
- LOGE("setDeviceConnectionState() invalid device: %x", device);
+ if (!sHasA2dp && AudioSystem::isA2dpDevice(device)) {
+ ALOGE("setDeviceConnectionState() invalid device: %x", device);
return BAD_VALUE;
}
-#endif
switch (state)
{
// handle output device connection
case AudioSystem::DEVICE_STATE_AVAILABLE:
if (mAvailableOutputDevices & device) {
- LOGW("setDeviceConnectionState() device already connected: %x", device);
+ ALOGW("setDeviceConnectionState() device already connected: %x", device);
return INVALID_OPERATION;
}
- LOGV("setDeviceConnectionState() connecting device %x", device);
+ ALOGV("setDeviceConnectionState() connecting device %x", device);
// register new device as available
- mAvailableOutputDevices |= device;
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | device);
-#ifdef WITH_A2DP
+ output = checkOutputForDevice((audio_devices_t)device, state);
+ if (output == 0) {
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device);
+ return INVALID_OPERATION;
+ }
// handle A2DP device connection
- if (AudioSystem::isA2dpDevice(device)) {
- status_t status = handleA2dpConnection(device, device_address);
- if (status != NO_ERROR) {
- mAvailableOutputDevices &= ~device;
- return status;
- }
- } else
-#endif
- {
- if (AudioSystem::isBluetoothScoDevice(device)) {
- LOGV("setDeviceConnectionState() BT SCO device, address %s", device_address);
- // keep track of SCO device address
- mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
- }
+ if (sHasA2dp && AudioSystem::isA2dpDevice(device)) {
+ AudioParameter param;
+ param.add(String8(AUDIO_PARAMETER_A2DP_SINK_ADDRESS), String8(device_address));
+ mpClientInterface->setParameters(output, param.toString());
+ mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
+ mA2dpSuspended = false;
+ } else if (AudioSystem::isBluetoothScoDevice(device)) {
+ ALOGV("setDeviceConnectionState() BT SCO device, address %s", device_address);
+ // keep track of SCO device address
+ mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
}
break;
// handle output device disconnection
case AudioSystem::DEVICE_STATE_UNAVAILABLE: {
if (!(mAvailableOutputDevices & device)) {
- LOGW("setDeviceConnectionState() device not connected: %x", device);
+ ALOGW("setDeviceConnectionState() device not connected: %x", device);
return INVALID_OPERATION;
}
- LOGV("setDeviceConnectionState() disconnecting device %x", device);
+ ALOGV("setDeviceConnectionState() disconnecting device %x", device);
// remove device from available output devices
- mAvailableOutputDevices &= ~device;
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device);
-#ifdef WITH_A2DP
+ output = checkOutputForDevice((audio_devices_t)device, state);
// handle A2DP device disconnection
- if (AudioSystem::isA2dpDevice(device)) {
- status_t status = handleA2dpDisconnection(device, device_address);
- if (status != NO_ERROR) {
- mAvailableOutputDevices |= device;
- return status;
- }
- } else
-#endif
- {
- if (AudioSystem::isBluetoothScoDevice(device)) {
- mScoDeviceAddress = "";
- }
+ if (sHasA2dp && AudioSystem::isA2dpDevice(device)) {
+ mA2dpDeviceAddress = "";
+ mA2dpSuspended = false;
+ } else if (AudioSystem::isBluetoothScoDevice(device)) {
+ mScoDeviceAddress = "";
}
} break;
default:
- LOGE("setDeviceConnectionState() invalid state: %x", state);
+ ALOGE("setDeviceConnectionState() invalid state: %x", state);
return BAD_VALUE;
}
// request routing change if necessary
- uint32_t newDevice = getNewDevice(mHardwareOutput, false);
-#ifdef WITH_A2DP
+ audio_devices_t newDevice = getNewDevice(mPrimaryOutput, false);
+
checkA2dpSuspend();
checkOutputForAllStrategies();
- // A2DP outputs must be closed after checkOutputForAllStrategies() is executed
- if (state == AudioSystem::DEVICE_STATE_UNAVAILABLE && AudioSystem::isA2dpDevice(device)) {
- closeA2dpOutputs();
+ // outputs must be closed after checkOutputForAllStrategies() is executed
+ if (state == AudioSystem::DEVICE_STATE_UNAVAILABLE && output != 0) {
+ closeOutput(output);
}
-#endif
updateDeviceForStrategy();
- setOutputDevice(mHardwareOutput, newDevice);
+ setOutputDevice(mPrimaryOutput, newDevice);
if (device == AudioSystem::DEVICE_OUT_WIRED_HEADSET) {
device = AudioSystem::DEVICE_IN_WIRED_HEADSET;
@@ -149,7 +193,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev
// handle input device connection
case AudioSystem::DEVICE_STATE_AVAILABLE: {
if (mAvailableInputDevices & device) {
- LOGW("setDeviceConnectionState() device already connected: %d", device);
+ ALOGW("setDeviceConnectionState() device already connected: %d", device);
return INVALID_OPERATION;
}
mAvailableInputDevices |= device;
@@ -159,23 +203,23 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev
// handle input device disconnection
case AudioSystem::DEVICE_STATE_UNAVAILABLE: {
if (!(mAvailableInputDevices & device)) {
- LOGW("setDeviceConnectionState() device not connected: %d", device);
+ ALOGW("setDeviceConnectionState() device not connected: %d", device);
return INVALID_OPERATION;
}
mAvailableInputDevices &= ~device;
} break;
default:
- LOGE("setDeviceConnectionState() invalid state: %x", state);
+ ALOGE("setDeviceConnectionState() invalid state: %x", state);
return BAD_VALUE;
}
audio_io_handle_t activeInput = getActiveInput();
if (activeInput != 0) {
AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput);
- uint32_t newDevice = getDeviceForInputSource(inputDesc->mInputSource);
+ audio_devices_t newDevice = getDeviceForInputSource(inputDesc->mInputSource);
if (newDevice != inputDesc->mDevice) {
- LOGV("setDeviceConnectionState() changing device from %x to %x for input %d",
+ ALOGV("setDeviceConnectionState() changing device from %x to %x for input %d",
inputDesc->mDevice, newDevice, activeInput);
inputDesc->mDevice = newDevice;
AudioParameter param = AudioParameter();
@@ -187,7 +231,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev
return NO_ERROR;
}
- LOGW("setDeviceConnectionState() invalid device: %x", device);
+ ALOGW("setDeviceConnectionState() invalid device: %x", device);
return BAD_VALUE;
}
@@ -198,12 +242,10 @@ AudioSystem::device_connection_state AudioPolicyManagerBase::getDeviceConnection
String8 address = String8(device_address);
if (AudioSystem::isOutputDevice(device)) {
if (device & mAvailableOutputDevices) {
-#ifdef WITH_A2DP
if (AudioSystem::isA2dpDevice(device) &&
- address != "" && mA2dpDeviceAddress != address) {
+ (!sHasA2dp || (address != "" && mA2dpDeviceAddress != address))) {
return state;
}
-#endif
if (AudioSystem::isBluetoothScoDevice(device) &&
address != "" && mScoDeviceAddress != address) {
return state;
@@ -221,22 +263,22 @@ AudioSystem::device_connection_state AudioPolicyManagerBase::getDeviceConnection
void AudioPolicyManagerBase::setPhoneState(int state)
{
- LOGV("setPhoneState() state %d", state);
- uint32_t newDevice = 0;
+ ALOGV("setPhoneState() state %d", state);
+ audio_devices_t newDevice = (audio_devices_t)0;
if (state < 0 || state >= AudioSystem::NUM_MODES) {
- LOGW("setPhoneState() invalid state %d", state);
+ ALOGW("setPhoneState() invalid state %d", state);
return;
}
if (state == mPhoneState ) {
- LOGW("setPhoneState() setting same state %d", state);
+ ALOGW("setPhoneState() setting same state %d", state);
return;
}
// if leaving call state, handle special case of active streams
// pertaining to sonification strategy see handleIncallSonification()
if (isInCall()) {
- LOGV("setPhoneState() in call state management: new state is %d", state);
+ ALOGV("setPhoneState() in call state management: new state is %d", state);
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
handleIncallSonification(stream, false, true);
}
@@ -249,31 +291,29 @@ void AudioPolicyManagerBase::setPhoneState(int state)
// are we entering or starting a call
if (!isStateInCall(oldState) && isStateInCall(state)) {
- LOGV(" Entering call in setPhoneState()");
+ ALOGV(" Entering call in setPhoneState()");
// force routing command to audio hardware when starting a call
// even if no device change is needed
force = true;
} else if (isStateInCall(oldState) && !isStateInCall(state)) {
- LOGV(" Exiting call in setPhoneState()");
+ ALOGV(" Exiting call in setPhoneState()");
// force routing command to audio hardware when exiting a call
// even if no device change is needed
force = true;
} else if (isStateInCall(state) && (state != oldState)) {
- LOGV(" Switching between telephony and VoIP in setPhoneState()");
+ ALOGV(" Switching between telephony and VoIP in setPhoneState()");
// force routing command to audio hardware when switching between telephony and VoIP
// even if no device change is needed
force = true;
}
// check for device and output changes triggered by new phone state
- newDevice = getNewDevice(mHardwareOutput, false);
-#ifdef WITH_A2DP
+ newDevice = getNewDevice(mPrimaryOutput, false);
checkA2dpSuspend();
checkOutputForAllStrategies();
-#endif
updateDeviceForStrategy();
- AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mHardwareOutput);
+ AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mPrimaryOutput);
// force routing command to audio hardware when ending call
// even if no device change is needed
@@ -290,20 +330,20 @@ void AudioPolicyManagerBase::setPhoneState(int state)
// and be sure that audio buffers not yet affected by the mute are out when
// we actually apply the route change
delayMs = hwOutputDesc->mLatency*2;
- setStreamMute(AudioSystem::RING, true, mHardwareOutput);
+ setStreamMute(AudioSystem::RING, true, mPrimaryOutput);
}
// change routing is necessary
- setOutputDevice(mHardwareOutput, newDevice, force, delayMs);
+ setOutputDevice(mPrimaryOutput, newDevice, force, delayMs);
// if entering in call state, handle special case of active streams
// pertaining to sonification strategy see handleIncallSonification()
if (isStateInCall(state)) {
- LOGV("setPhoneState() in call state management: new state is %d", state);
+ ALOGV("setPhoneState() in call state management: new state is %d", state);
// unmute the ringing tone after a sufficient delay if it was muted before
// setting output device above
if (oldState == AudioSystem::MODE_RINGTONE) {
- setStreamMute(AudioSystem::RING, false, mHardwareOutput, MUTE_TIME_MS);
+ setStreamMute(AudioSystem::RING, false, mPrimaryOutput, MUTE_TIME_MS);
}
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
handleIncallSonification(stream, true, true);
@@ -319,23 +359,16 @@ void AudioPolicyManagerBase::setPhoneState(int state)
}
}
-void AudioPolicyManagerBase::setRingerMode(uint32_t mode, uint32_t mask)
-{
- LOGV("setRingerMode() mode %x, mask %x", mode, mask);
-
- mRingerMode = mode;
-}
-
void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config)
{
- LOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mPhoneState);
+ ALOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mPhoneState);
bool forceVolumeReeval = false;
switch(usage) {
case AudioSystem::FOR_COMMUNICATION:
if (config != AudioSystem::FORCE_SPEAKER && config != AudioSystem::FORCE_BT_SCO &&
config != AudioSystem::FORCE_NONE) {
- LOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config);
+ ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config);
return;
}
forceVolumeReeval = true;
@@ -346,7 +379,7 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
config != AudioSystem::FORCE_WIRED_ACCESSORY &&
config != AudioSystem::FORCE_ANALOG_DOCK &&
config != AudioSystem::FORCE_DIGITAL_DOCK && config != AudioSystem::FORCE_NONE) {
- LOGW("setForceUse() invalid config %d for FOR_MEDIA", config);
+ ALOGW("setForceUse() invalid config %d for FOR_MEDIA", config);
return;
}
mForceUse[usage] = config;
@@ -354,7 +387,7 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
case AudioSystem::FOR_RECORD:
if (config != AudioSystem::FORCE_BT_SCO && config != AudioSystem::FORCE_WIRED_ACCESSORY &&
config != AudioSystem::FORCE_NONE) {
- LOGW("setForceUse() invalid config %d for FOR_RECORD", config);
+ ALOGW("setForceUse() invalid config %d for FOR_RECORD", config);
return;
}
mForceUse[usage] = config;
@@ -365,26 +398,24 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
config != AudioSystem::FORCE_WIRED_ACCESSORY &&
config != AudioSystem::FORCE_ANALOG_DOCK &&
config != AudioSystem::FORCE_DIGITAL_DOCK) {
- LOGW("setForceUse() invalid config %d for FOR_DOCK", config);
+ ALOGW("setForceUse() invalid config %d for FOR_DOCK", config);
}
forceVolumeReeval = true;
mForceUse[usage] = config;
break;
default:
- LOGW("setForceUse() invalid usage %d", usage);
+ ALOGW("setForceUse() invalid usage %d", usage);
break;
}
// check for device and output changes triggered by new phone state
- uint32_t newDevice = getNewDevice(mHardwareOutput, false);
-#ifdef WITH_A2DP
+ audio_devices_t newDevice = getNewDevice(mPrimaryOutput, false);
checkA2dpSuspend();
checkOutputForAllStrategies();
-#endif
updateDeviceForStrategy();
- setOutputDevice(mHardwareOutput, newDevice);
+ setOutputDevice(mPrimaryOutput, newDevice);
if (forceVolumeReeval) {
- applyStreamVolumes(mHardwareOutput, newDevice, 0, true);
+ applyStreamVolumes(mPrimaryOutput, newDevice, 0, true);
}
audio_io_handle_t activeInput = getActiveInput();
@@ -392,7 +423,7 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput);
newDevice = getDeviceForInputSource(inputDesc->mInputSource);
if (newDevice != inputDesc->mDevice) {
- LOGV("setForceUse() changing device from %x to %x for input %d",
+ ALOGV("setForceUse() changing device from %x to %x for input %d",
inputDesc->mDevice, newDevice, activeInput);
inputDesc->mDevice = newDevice;
AudioParameter param = AudioParameter();
@@ -410,13 +441,13 @@ AudioSystem::forced_config AudioPolicyManagerBase::getForceUse(AudioSystem::forc
void AudioPolicyManagerBase::setSystemProperty(const char* property, const char* value)
{
- LOGV("setSystemProperty() property %s, value %s", property, value);
+ ALOGV("setSystemProperty() property %s, value %s", property, value);
if (strcmp(property, "ro.camera.sound.forced") == 0) {
if (atoi(value)) {
- LOGV("ENFORCED_AUDIBLE cannot be muted");
+ ALOGV("ENFORCED_AUDIBLE cannot be muted");
mStreams[AudioSystem::ENFORCED_AUDIBLE].mCanBeMuted = false;
} else {
- LOGV("ENFORCED_AUDIBLE can be muted");
+ ALOGV("ENFORCED_AUDIBLE can be muted");
mStreams[AudioSystem::ENFORCED_AUDIBLE].mCanBeMuted = true;
}
}
@@ -431,16 +462,16 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
audio_io_handle_t output = 0;
uint32_t latency = 0;
routing_strategy strategy = getStrategy((AudioSystem::stream_type)stream);
- uint32_t device = getDeviceForStrategy(strategy);
- LOGV("getOutput() stream %d, samplingRate %d, format %d, channels %x, flags %x", stream, samplingRate, format, channels, flags);
+ audio_devices_t device = getDeviceForStrategy(strategy);
+ ALOGV("getOutput() stream %d, samplingRate %d, format %d, channels %x, flags %x", stream, samplingRate, format, channels, flags);
#ifdef AUDIO_POLICY_TEST
if (mCurOutput != 0) {
- LOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channels %x, mDirectOutput %d",
+ ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channels %x, mDirectOutput %d",
mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput);
if (mTestOutputs[mCurOutput] == 0) {
- LOGV("getOutput() opening test output");
+ ALOGV("getOutput() opening test output");
AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
outputDesc->mDevice = mTestDevice;
outputDesc->mSamplingRate = mTestSamplingRate;
@@ -469,8 +500,8 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
// open a direct output if required by specified parameters
if (needsDirectOuput(stream, samplingRate, format, channels, flags, device)) {
- LOGV("getOutput() opening direct output device %x", device);
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
+ ALOGV("getOutput() opening direct output device %x", device);
+ AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(NULL);
outputDesc->mDevice = device;
outputDesc->mSamplingRate = samplingRate;
outputDesc->mFormat = format;
@@ -479,7 +510,7 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
outputDesc->mFlags = (AudioSystem::output_flags)(flags | AudioSystem::OUTPUT_FLAG_DIRECT);
outputDesc->mRefCount[stream] = 0;
outputDesc->mStopTime[stream] = 0;
- output = mpClientInterface->openOutput(&outputDesc->mDevice,
+ output = mpClientInterface->openOutput((uint32_t *)&outputDesc->mDevice,
&outputDesc->mSamplingRate,
&outputDesc->mFormat,
&outputDesc->mChannels,
@@ -491,7 +522,7 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
(samplingRate != 0 && samplingRate != outputDesc->mSamplingRate) ||
(format != 0 && format != outputDesc->mFormat) ||
(channels != 0 && channels != outputDesc->mChannels)) {
- LOGV("getOutput() failed opening direct output: samplingRate %d, format %d, channels %d",
+ ALOGV("getOutput() failed opening direct output: samplingRate %d, format %d, channels %d",
samplingRate, format, channels);
if (output != 0) {
mpClientInterface->closeOutput(output);
@@ -511,37 +542,15 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
// get which output is suitable for the specified stream. The actual routing change will happen
// when startOutput() will be called
- uint32_t a2dpDevice = device & AudioSystem::DEVICE_OUT_ALL_A2DP;
- if (AudioSystem::popCount((AudioSystem::audio_devices)device) == 2) {
-#ifdef WITH_A2DP
- if (a2dpUsedForSonification() && a2dpDevice != 0) {
- // if playing on 2 devices among which one is A2DP, use duplicated output
- LOGV("getOutput() using duplicated output");
- LOGW_IF((mA2dpOutput == 0), "getOutput() A2DP device in multiple %x selected but A2DP output not opened", device);
- output = mDuplicatedOutput;
- } else
-#endif
- {
- // if playing on 2 devices among which none is A2DP, use hardware output
- output = mHardwareOutput;
- }
- LOGV("getOutput() using output %d for 2 devices %x", output, device);
- } else {
-#ifdef WITH_A2DP
- if (a2dpDevice != 0) {
- // if playing on A2DP device, use a2dp output
- LOGW_IF((mA2dpOutput == 0), "getOutput() A2DP device %x selected but A2DP output not opened", device);
- output = mA2dpOutput;
- } else
-#endif
- {
- // if playing on not A2DP device, use hardware output
- output = mHardwareOutput;
- }
- }
+ SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device);
+ // TODO: current implementation assumes that at most one output corresponds to a device.
+ // this will change when supporting low power, low latency or tunneled output streams
+ ALOG_ASSERT(outputs.size() < 2, "getOutput(): getOutputsForDevice() "
+ "returned %d outputs for device %04x", outputs.size(), device);
+ output = outputs[0];
- LOGW_IF((output ==0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
+ ALOGW_IF((output ==0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
stream, samplingRate, format, channels, flags);
return output;
@@ -551,28 +560,24 @@ status_t AudioPolicyManagerBase::startOutput(audio_io_handle_t output,
AudioSystem::stream_type stream,
int session)
{
- LOGV("startOutput() output %d, stream %d, session %d", output, stream, session);
+ ALOGV("startOutput() output %d, stream %d, session %d", output, stream, session);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- LOGW("startOutput() unknow output %d", output);
+ ALOGW("startOutput() unknow output %d", output);
return BAD_VALUE;
}
AudioOutputDescriptor *outputDesc = mOutputs.valueAt(index);
routing_strategy strategy = getStrategy((AudioSystem::stream_type)stream);
-#ifdef WITH_A2DP
- if (mA2dpOutput != 0 && !a2dpUsedForSonification() && strategy == STRATEGY_SONIFICATION) {
- setStrategyMute(STRATEGY_MEDIA, true, mA2dpOutput);
- }
-#endif
-
// incremenent usage count for this stream on the requested output:
// NOTE that the usage count is the same for duplicated output and hardware output which is
// necassary for a correct control of hardware output routing by startOutput() and stopOutput()
outputDesc->changeRefCount(stream, 1);
+ audio_devices_t prevDevice = outputDesc->device();
setOutputDevice(output, getNewDevice(output));
+ audio_devices_t newDevice = outputDesc->device();
// handle special case for sonification while in call
if (isInCall()) {
@@ -580,7 +585,17 @@ status_t AudioPolicyManagerBase::startOutput(audio_io_handle_t output,
}
// apply volume rules for current stream and device if necessary
- checkAndSetVolume(stream, mStreams[stream].mIndexCur, output, outputDesc->device());
+ checkAndSetVolume(stream,
+ mStreams[stream].getVolumeIndex((audio_devices_t)newDevice),
+ output,
+ newDevice);
+
+ // FIXME: need a delay to make sure that audio path switches to speaker before sound
+ // starts. Should be platform specific?
+ if (stream == AudioSystem::ENFORCED_AUDIBLE &&
+ prevDevice != newDevice) {
+ usleep(outputDesc->mLatency*4*1000);
+ }
return NO_ERROR;
}
@@ -589,10 +604,10 @@ status_t AudioPolicyManagerBase::stopOutput(audio_io_handle_t output,
AudioSystem::stream_type stream,
int session)
{
- LOGV("stopOutput() output %d, stream %d, session %d", output, stream, session);
+ ALOGV("stopOutput() output %d, stream %d, session %d", output, stream, session);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- LOGW("stopOutput() unknow output %d", output);
+ ALOGW("stopOutput() unknow output %d", output);
return BAD_VALUE;
}
@@ -612,31 +627,22 @@ status_t AudioPolicyManagerBase::stopOutput(audio_io_handle_t output,
setOutputDevice(output, getNewDevice(output), false, outputDesc->mLatency*2);
-#ifdef WITH_A2DP
- if (mA2dpOutput != 0 && !a2dpUsedForSonification() &&
- strategy == STRATEGY_SONIFICATION) {
- setStrategyMute(STRATEGY_MEDIA,
- false,
- mA2dpOutput,
- mOutputs.valueFor(mHardwareOutput)->mLatency*2);
- }
-#endif
- if (output != mHardwareOutput) {
- setOutputDevice(mHardwareOutput, getNewDevice(mHardwareOutput), true);
+ if (output != mPrimaryOutput) {
+ setOutputDevice(mPrimaryOutput, getNewDevice(mPrimaryOutput), true);
}
return NO_ERROR;
} else {
- LOGW("stopOutput() refcount is already 0 for output %d", output);
+ ALOGW("stopOutput() refcount is already 0 for output %d", output);
return INVALID_OPERATION;
}
}
void AudioPolicyManagerBase::releaseOutput(audio_io_handle_t output)
{
- LOGV("releaseOutput() %d", output);
+ ALOGV("releaseOutput() %d", output);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- LOGW("releaseOutput() releasing unknown output %d", output);
+ ALOGW("releaseOutput() releasing unknown output %d", output);
return;
}
@@ -668,9 +674,9 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,
AudioSystem::audio_in_acoustics acoustics)
{
audio_io_handle_t input = 0;
- uint32_t device = getDeviceForInputSource(inputSource);
+ audio_devices_t device = getDeviceForInputSource(inputSource);
- LOGV("getInput() inputSource %d, samplingRate %d, format %d, channels %x, acoustics %x", inputSource, samplingRate, format, channels, acoustics);
+ ALOGV("getInput() inputSource %d, samplingRate %d, format %d, channels %x, acoustics %x", inputSource, samplingRate, format, channels, acoustics);
if (device == 0) {
return 0;
@@ -700,18 +706,18 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,
inputDesc->mChannels = channels;
inputDesc->mAcoustics = acoustics;
inputDesc->mRefCount = 0;
- input = mpClientInterface->openInput(&inputDesc->mDevice,
+ input = mpClientInterface->openInput((uint32_t *)&inputDesc->mDevice,
&inputDesc->mSamplingRate,
&inputDesc->mFormat,
&inputDesc->mChannels,
- inputDesc->mAcoustics);
+ (audio_in_acoustics_t) inputDesc->mAcoustics);
// only accept input with the exact requested set of parameters
if (input == 0 ||
(samplingRate != inputDesc->mSamplingRate) ||
(format != inputDesc->mFormat) ||
(channels != inputDesc->mChannels)) {
- LOGV("getInput() failed opening input: samplingRate %d, format %d, channels %d",
+ ALOGV("getInput() failed opening input: samplingRate %d, format %d, channels %d",
samplingRate, format, channels);
if (input != 0) {
mpClientInterface->closeInput(input);
@@ -725,10 +731,10 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,
status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
{
- LOGV("startInput() input %d", input);
+ ALOGV("startInput() input %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- LOGW("startInput() unknow input %d", input);
+ ALOGW("startInput() unknow input %d", input);
return BAD_VALUE;
}
AudioInputDescriptor *inputDesc = mInputs.valueAt(index);
@@ -739,7 +745,7 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
{
// refuse 2 active AudioRecord clients at the same time
if (getActiveInput() != 0) {
- LOGW("startInput() input %d failed: other input already started", input);
+ ALOGW("startInput() input %d failed: other input already started", input);
return INVALID_OPERATION;
}
}
@@ -748,7 +754,7 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
param.addInt(String8(AudioParameter::keyRouting), (int)inputDesc->mDevice);
param.addInt(String8(AudioParameter::keyInputSource), (int)inputDesc->mInputSource);
- LOGV("AudioPolicyManager::startInput() input source = %d", inputDesc->mInputSource);
+ ALOGV("AudioPolicyManager::startInput() input source = %d", inputDesc->mInputSource);
mpClientInterface->setParameters(input, param.toString());
@@ -758,16 +764,16 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
status_t AudioPolicyManagerBase::stopInput(audio_io_handle_t input)
{
- LOGV("stopInput() input %d", input);
+ ALOGV("stopInput() input %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- LOGW("stopInput() unknow input %d", input);
+ ALOGW("stopInput() unknow input %d", input);
return BAD_VALUE;
}
AudioInputDescriptor *inputDesc = mInputs.valueAt(index);
if (inputDesc->mRefCount == 0) {
- LOGW("stopInput() input %d already stopped", input);
+ ALOGW("stopInput() input %d already stopped", input);
return INVALID_OPERATION;
} else {
AudioParameter param = AudioParameter();
@@ -780,68 +786,96 @@ status_t AudioPolicyManagerBase::stopInput(audio_io_handle_t input)
void AudioPolicyManagerBase::releaseInput(audio_io_handle_t input)
{
- LOGV("releaseInput() %d", input);
+ ALOGV("releaseInput() %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- LOGW("releaseInput() releasing unknown input %d", input);
+ ALOGW("releaseInput() releasing unknown input %d", input);
return;
}
mpClientInterface->closeInput(input);
delete mInputs.valueAt(index);
mInputs.removeItem(input);
- LOGV("releaseInput() exit");
+ ALOGV("releaseInput() exit");
}
void AudioPolicyManagerBase::initStreamVolume(AudioSystem::stream_type stream,
int indexMin,
int indexMax)
{
- LOGV("initStreamVolume() stream %d, min %d, max %d", stream , indexMin, indexMax);
+ ALOGV("initStreamVolume() stream %d, min %d, max %d", stream , indexMin, indexMax);
if (indexMin < 0 || indexMin >= indexMax) {
- LOGW("initStreamVolume() invalid index limits for stream %d, min %d, max %d", stream , indexMin, indexMax);
+ ALOGW("initStreamVolume() invalid index limits for stream %d, min %d, max %d", stream , indexMin, indexMax);
return;
}
mStreams[stream].mIndexMin = indexMin;
mStreams[stream].mIndexMax = indexMax;
}
-status_t AudioPolicyManagerBase::setStreamVolumeIndex(AudioSystem::stream_type stream, int index)
+status_t AudioPolicyManagerBase::setStreamVolumeIndex(AudioSystem::stream_type stream,
+ int index,
+ audio_devices_t device)
{
if ((index < mStreams[stream].mIndexMin) || (index > mStreams[stream].mIndexMax)) {
return BAD_VALUE;
}
+ if (!audio_is_output_device(device)) {
+ return BAD_VALUE;
+ }
// Force max volume if stream cannot be muted
if (!mStreams[stream].mCanBeMuted) index = mStreams[stream].mIndexMax;
- LOGV("setStreamVolumeIndex() stream %d, index %d", stream, index);
- mStreams[stream].mIndexCur = index;
+ ALOGV("setStreamVolumeIndex() stream %d, device %04x, index %d",
+ stream, device, index);
+
+ // if device is AUDIO_DEVICE_OUT_DEFAULT set default value and
+ // clear all device specific values
+ if (device == AUDIO_DEVICE_OUT_DEFAULT) {
+ mStreams[stream].mIndexCur.clear();
+ }
+ mStreams[stream].mIndexCur.add(device, index);
// compute and apply stream volume on all outputs according to connected device
status_t status = NO_ERROR;
for (size_t i = 0; i < mOutputs.size(); i++) {
- status_t volStatus = checkAndSetVolume(stream, index, mOutputs.keyAt(i), mOutputs.valueAt(i)->device());
- if (volStatus != NO_ERROR) {
- status = volStatus;
+ audio_devices_t curDevice =
+ getDeviceForVolume((audio_devices_t)mOutputs.valueAt(i)->device());
+ if (device == curDevice) {
+ status_t volStatus = checkAndSetVolume(stream, index, mOutputs.keyAt(i), curDevice);
+ if (volStatus != NO_ERROR) {
+ status = volStatus;
+ }
}
}
return status;
}
-status_t AudioPolicyManagerBase::getStreamVolumeIndex(AudioSystem::stream_type stream, int *index)
+status_t AudioPolicyManagerBase::getStreamVolumeIndex(AudioSystem::stream_type stream,
+ int *index,
+ audio_devices_t device)
{
- if (index == 0) {
+ if (index == NULL) {
return BAD_VALUE;
}
- LOGV("getStreamVolumeIndex() stream %d", stream);
- *index = mStreams[stream].mIndexCur;
+ if (!audio_is_output_device(device)) {
+ return BAD_VALUE;
+ }
+ // if device is AUDIO_DEVICE_OUT_DEFAULT, return volume for device corresponding to
+ // the strategy the stream belongs to.
+ if (device == AUDIO_DEVICE_OUT_DEFAULT) {
+ device = (audio_devices_t)getDeviceForStrategy(getStrategy(stream), true);
+ }
+ device = getDeviceForVolume(device);
+
+ *index = mStreams[stream].getVolumeIndex(device);
+ ALOGV("getStreamVolumeIndex() stream %d device %08x index %d", stream, device, *index);
return NO_ERROR;
}
audio_io_handle_t AudioPolicyManagerBase::getOutputForEffect(effect_descriptor_t *desc)
{
- LOGV("getOutputForEffect()");
+ ALOGV("getOutputForEffect()");
// apply simple rule where global effects are attached to the same output as MUSIC streams
return getOutput(AudioSystem::MUSIC);
}
@@ -856,20 +890,20 @@ status_t AudioPolicyManagerBase::registerEffect(effect_descriptor_t *desc,
if (index < 0) {
index = mInputs.indexOfKey(io);
if (index < 0) {
- LOGW("registerEffect() unknown io %d", io);
+ ALOGW("registerEffect() unknown io %d", io);
return INVALID_OPERATION;
}
}
if (mTotalEffectsMemory + desc->memoryUsage > getMaxEffectsMemory()) {
- LOGW("registerEffect() memory limit exceeded for Fx %s, Memory %d KB",
+ ALOGW("registerEffect() memory limit exceeded for Fx %s, Memory %d KB",
desc->name, desc->memoryUsage);
return INVALID_OPERATION;
}
mTotalEffectsMemory += desc->memoryUsage;
- LOGV("registerEffect() effect %s, io %d, strategy %d session %d id %d",
+ ALOGV("registerEffect() effect %s, io %d, strategy %d session %d id %d",
desc->name, io, strategy, session, id);
- LOGV("registerEffect() memory %d, total memory %d", desc->memoryUsage, mTotalEffectsMemory);
+ ALOGV("registerEffect() memory %d, total memory %d", desc->memoryUsage, mTotalEffectsMemory);
EffectDescriptor *pDesc = new EffectDescriptor();
memcpy (&pDesc->mDesc, desc, sizeof(effect_descriptor_t));
@@ -887,7 +921,7 @@ status_t AudioPolicyManagerBase::unregisterEffect(int id)
{
ssize_t index = mEffects.indexOfKey(id);
if (index < 0) {
- LOGW("unregisterEffect() unknown effect ID %d", id);
+ ALOGW("unregisterEffect() unknown effect ID %d", id);
return INVALID_OPERATION;
}
@@ -896,12 +930,12 @@ status_t AudioPolicyManagerBase::unregisterEffect(int id)
setEffectEnabled(pDesc, false);
if (mTotalEffectsMemory < pDesc->mDesc.memoryUsage) {
- LOGW("unregisterEffect() memory %d too big for total %d",
+ ALOGW("unregisterEffect() memory %d too big for total %d",
pDesc->mDesc.memoryUsage, mTotalEffectsMemory);
pDesc->mDesc.memoryUsage = mTotalEffectsMemory;
}
mTotalEffectsMemory -= pDesc->mDesc.memoryUsage;
- LOGV("unregisterEffect() effect %s, ID %d, memory %d total memory %d",
+ ALOGV("unregisterEffect() effect %s, ID %d, memory %d total memory %d",
pDesc->mDesc.name, id, pDesc->mDesc.memoryUsage, mTotalEffectsMemory);
mEffects.removeItem(id);
@@ -914,7 +948,7 @@ status_t AudioPolicyManagerBase::setEffectEnabled(int id, bool enabled)
{
ssize_t index = mEffects.indexOfKey(id);
if (index < 0) {
- LOGW("unregisterEffect() unknown effect ID %d", id);
+ ALOGW("unregisterEffect() unknown effect ID %d", id);
return INVALID_OPERATION;
}
@@ -924,27 +958,27 @@ status_t AudioPolicyManagerBase::setEffectEnabled(int id, bool enabled)
status_t AudioPolicyManagerBase::setEffectEnabled(EffectDescriptor *pDesc, bool enabled)
{
if (enabled == pDesc->mEnabled) {
- LOGV("setEffectEnabled(%s) effect already %s",
+ ALOGV("setEffectEnabled(%s) effect already %s",
enabled?"true":"false", enabled?"enabled":"disabled");
return INVALID_OPERATION;
}
if (enabled) {
if (mTotalEffectsCpuLoad + pDesc->mDesc.cpuLoad > getMaxEffectsCpuLoad()) {
- LOGW("setEffectEnabled(true) CPU Load limit exceeded for Fx %s, CPU %f MIPS",
+ ALOGW("setEffectEnabled(true) CPU Load limit exceeded for Fx %s, CPU %f MIPS",
pDesc->mDesc.name, (float)pDesc->mDesc.cpuLoad/10);
return INVALID_OPERATION;
}
mTotalEffectsCpuLoad += pDesc->mDesc.cpuLoad;
- LOGV("setEffectEnabled(true) total CPU %d", mTotalEffectsCpuLoad);
+ ALOGV("setEffectEnabled(true) total CPU %d", mTotalEffectsCpuLoad);
} else {
if (mTotalEffectsCpuLoad < pDesc->mDesc.cpuLoad) {
- LOGW("setEffectEnabled(false) CPU load %d too high for total %d",
+ ALOGW("setEffectEnabled(false) CPU load %d too high for total %d",
pDesc->mDesc.cpuLoad, mTotalEffectsCpuLoad);
pDesc->mDesc.cpuLoad = mTotalEffectsCpuLoad;
}
mTotalEffectsCpuLoad -= pDesc->mDesc.cpuLoad;
- LOGV("setEffectEnabled(false) total CPU %d", mTotalEffectsCpuLoad);
+ ALOGV("setEffectEnabled(false) total CPU %d", mTotalEffectsCpuLoad);
}
pDesc->mEnabled = enabled;
return NO_ERROR;
@@ -971,16 +1005,11 @@ status_t AudioPolicyManagerBase::dump(int fd)
snprintf(buffer, SIZE, "\nAudioPolicyManager Dump: %p\n", this);
result.append(buffer);
- snprintf(buffer, SIZE, " Hardware Output: %d\n", mHardwareOutput);
- result.append(buffer);
-#ifdef WITH_A2DP
- snprintf(buffer, SIZE, " A2DP Output: %d\n", mA2dpOutput);
- result.append(buffer);
- snprintf(buffer, SIZE, " Duplicated Output: %d\n", mDuplicatedOutput);
+
+ snprintf(buffer, SIZE, " Hardware Output: %d\n", mPrimaryOutput);
result.append(buffer);
snprintf(buffer, SIZE, " A2DP device address: %s\n", mA2dpDeviceAddress.string());
result.append(buffer);
-#endif
snprintf(buffer, SIZE, " SCO device address: %s\n", mScoDeviceAddress.string());
result.append(buffer);
snprintf(buffer, SIZE, " Output devices: %08x\n", mAvailableOutputDevices);
@@ -989,8 +1018,6 @@ status_t AudioPolicyManagerBase::dump(int fd)
result.append(buffer);
snprintf(buffer, SIZE, " Phone state: %d\n", mPhoneState);
result.append(buffer);
- snprintf(buffer, SIZE, " Ringer mode: %d\n", mRingerMode);
- result.append(buffer);
snprintf(buffer, SIZE, " Force use for communications %d\n", mForceUse[AudioSystem::FOR_COMMUNICATION]);
result.append(buffer);
snprintf(buffer, SIZE, " Force use for media %d\n", mForceUse[AudioSystem::FOR_MEDIA]);
@@ -1019,12 +1046,13 @@ status_t AudioPolicyManagerBase::dump(int fd)
snprintf(buffer, SIZE, "\nStreams dump:\n");
write(fd, buffer, strlen(buffer));
- snprintf(buffer, SIZE, " Stream Index Min Index Max Index Cur Can be muted\n");
+ snprintf(buffer, SIZE,
+ " Stream Can be muted Index Min Index Max Index Cur [device : index]...\n");
write(fd, buffer, strlen(buffer));
for (size_t i = 0; i < AudioSystem::NUM_STREAM_TYPES; i++) {
- snprintf(buffer, SIZE, " %02d", i);
- mStreams[i].dump(buffer + 3, SIZE);
+ snprintf(buffer, SIZE, " %02d ", i);
write(fd, buffer, strlen(buffer));
+ mStreams[i].dump(fd);
}
snprintf(buffer, SIZE, "\nTotal Effects CPU: %f MIPS, Total Effects memory: %d KB\n",
@@ -1052,7 +1080,8 @@ AudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clien
#ifdef AUDIO_POLICY_TEST
Thread(false),
#endif //AUDIO_POLICY_TEST
- mPhoneState(AudioSystem::MODE_NORMAL), mRingerMode(0),
+ mAvailableOutputDevices((audio_devices_t)0),
+ mPhoneState(AudioSystem::MODE_NORMAL),
mLimitRingtoneVolume(false), mLastVoiceVolume(-1.0f),
mTotalEffectsCpuLoad(0), mTotalEffectsMemory(0),
mA2dpSuspended(false)
@@ -1065,43 +1094,59 @@ AudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clien
initializeVolumeCurves();
- // devices available by default are speaker, ear piece and microphone
- mAvailableOutputDevices = AudioSystem::DEVICE_OUT_EARPIECE |
- AudioSystem::DEVICE_OUT_SPEAKER;
- mAvailableInputDevices = AudioSystem::DEVICE_IN_BUILTIN_MIC;
-
-#ifdef WITH_A2DP
- mA2dpOutput = 0;
- mDuplicatedOutput = 0;
mA2dpDeviceAddress = String8("");
-#endif
mScoDeviceAddress = String8("");
- // open hardware output
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
- outputDesc->mDevice = (uint32_t)AudioSystem::DEVICE_OUT_SPEAKER;
- mHardwareOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
- &outputDesc->mSamplingRate,
- &outputDesc->mFormat,
- &outputDesc->mChannels,
- &outputDesc->mLatency,
- outputDesc->mFlags);
-
- if (mHardwareOutput == 0) {
- LOGE("Failed to initialize hardware output stream, samplingRate: %d, format %d, channels %d",
- outputDesc->mSamplingRate, outputDesc->mFormat, outputDesc->mChannels);
- } else {
- addOutput(mHardwareOutput, outputDesc);
- setOutputDevice(mHardwareOutput, (uint32_t)AudioSystem::DEVICE_OUT_SPEAKER, true);
- //TODO: configure audio effect output stage here
+ // TODO read this from configuration file
+ sHasA2dp = true;
+ const output_profile_t **outProfile = sAvailableOutputs;
+ // open all output streams needed to access attached devices
+ while (*outProfile)
+ {
+ if ((*outProfile)->mSupportedDevices & sAttachedOutputDevices) {
+ AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(*outProfile);
+
+ outputDesc->mDevice = (audio_devices_t)(sDefaultOutputDevice & (*outProfile)->mSupportedDevices);
+ outputDesc->mSamplingRate = (*outProfile)->mSamplingRates[0];
+ outputDesc->mFormat = (*outProfile)->mFormats[0];
+ outputDesc->mChannels = (*outProfile)->mChannelMasks[0];
+ outputDesc->mFlags = (AudioSystem::output_flags)(*outProfile)->mFlags;
+ audio_io_handle_t output = mpClientInterface->openOutput((uint32_t *)&outputDesc->mDevice,
+ &outputDesc->mSamplingRate,
+ &outputDesc->mFormat,
+ &outputDesc->mChannels,
+ &outputDesc->mLatency,
+ outputDesc->mFlags);
+ if (output == 0) {
+ delete outputDesc;
+ } else {
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | ((*outProfile)->mSupportedDevices & sAttachedOutputDevices));
+ if ((*outProfile)->mFlags & AUDIO_POLICY_OUTPUT_FLAG_PRIMARY) {
+ mPrimaryOutput = output;
+ }
+ addOutput(output, outputDesc);
+ setOutputDevice(output,
+ (audio_devices_t)(sDefaultOutputDevice & (*outProfile)->mSupportedDevices),
+ true);
+ }
+ }
+ outProfile++;
}
+ ALOGE_IF((sAttachedOutputDevices & ~mAvailableOutputDevices),
+ "Not output found for attached devices %08x",
+ (sAttachedOutputDevices & ~mAvailableOutputDevices));
+
+ ALOGE_IF((mPrimaryOutput == 0), "Failed to open primary output");
+
+ mAvailableInputDevices = AudioSystem::DEVICE_IN_BUILTIN_MIC;
+
updateDeviceForStrategy();
#ifdef AUDIO_POLICY_TEST
- if (mHardwareOutput != 0) {
+ if (mPrimaryOutput != 0) {
AudioParameter outputCmd = AudioParameter();
outputCmd.addInt(String8("set_id"), 0);
- mpClientInterface->setParameters(mHardwareOutput, outputCmd.toString());
+ mpClientInterface->setParameters(mPrimaryOutput, outputCmd.toString());
mTestDevice = AudioSystem::DEVICE_OUT_SPEAKER;
mTestSamplingRate = 44100;
@@ -1141,13 +1186,13 @@ AudioPolicyManagerBase::~AudioPolicyManagerBase()
status_t AudioPolicyManagerBase::initCheck()
{
- return (mHardwareOutput == 0) ? NO_INIT : NO_ERROR;
+ return (mPrimaryOutput == 0) ? NO_INIT : NO_ERROR;
}
#ifdef AUDIO_POLICY_TEST
bool AudioPolicyManagerBase::threadLoop()
{
- LOGV("entering threadLoop()");
+ ALOGV("entering threadLoop()");
while (!exitPending())
{
String8 command;
@@ -1162,7 +1207,7 @@ bool AudioPolicyManagerBase::threadLoop()
if (param.getInt(String8("test_cmd_policy"), valueInt) == NO_ERROR &&
valueInt != 0) {
- LOGV("Test command %s received", command.string());
+ ALOGV("Test command %s received", command.string());
String8 target;
if (param.get(String8("target"), target) != NO_ERROR) {
target = "Manager";
@@ -1240,26 +1285,26 @@ bool AudioPolicyManagerBase::threadLoop()
if (param.get(String8("test_cmd_policy_reopen"), value) == NO_ERROR) {
param.remove(String8("test_cmd_policy_reopen"));
- mpClientInterface->closeOutput(mHardwareOutput);
- delete mOutputs.valueFor(mHardwareOutput);
- mOutputs.removeItem(mHardwareOutput);
+ mpClientInterface->closeOutput(mPrimaryOutput);
+ delete mOutputs.valueFor(mPrimaryOutput);
+ mOutputs.removeItem(mPrimaryOutput);
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
+ AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(NULL);
outputDesc->mDevice = (uint32_t)AudioSystem::DEVICE_OUT_SPEAKER;
- mHardwareOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
+ mPrimaryOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
&outputDesc->mSamplingRate,
&outputDesc->mFormat,
&outputDesc->mChannels,
&outputDesc->mLatency,
outputDesc->mFlags);
- if (mHardwareOutput == 0) {
- LOGE("Failed to reopen hardware output stream, samplingRate: %d, format %d, channels %d",
+ if (mPrimaryOutput == 0) {
+ ALOGE("Failed to reopen hardware output stream, samplingRate: %d, format %d, channels %d",
outputDesc->mSamplingRate, outputDesc->mFormat, outputDesc->mChannels);
} else {
AudioParameter outputCmd = AudioParameter();
outputCmd.addInt(String8("set_id"), 0);
- mpClientInterface->setParameters(mHardwareOutput, outputCmd.toString());
- addOutput(mHardwareOutput, outputDesc);
+ mpClientInterface->setParameters(mPrimaryOutput, outputCmd.toString());
+ addOutput(mPrimaryOutput, outputDesc);
}
}
@@ -1298,193 +1343,211 @@ void AudioPolicyManagerBase::addOutput(audio_io_handle_t id, AudioOutputDescript
}
-#ifdef WITH_A2DP
-status_t AudioPolicyManagerBase::handleA2dpConnection(AudioSystem::audio_devices device,
- const char *device_address)
+audio_io_handle_t AudioPolicyManagerBase::checkOutputForDevice(
+ audio_devices_t device,
+ AudioSystem::device_connection_state state)
{
- // when an A2DP device is connected, open an A2DP and a duplicated output
- LOGV("opening A2DP output for device %s", device_address);
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
- outputDesc->mDevice = device;
- mA2dpOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
- &outputDesc->mSamplingRate,
- &outputDesc->mFormat,
- &outputDesc->mChannels,
- &outputDesc->mLatency,
- outputDesc->mFlags);
- if (mA2dpOutput) {
- // add A2DP output descriptor
- addOutput(mA2dpOutput, outputDesc);
-
- //TODO: configure audio effect output stage here
-
- // set initial stream volume for A2DP device
- applyStreamVolumes(mA2dpOutput, device);
- if (a2dpUsedForSonification()) {
- mDuplicatedOutput = mpClientInterface->openDuplicateOutput(mA2dpOutput, mHardwareOutput);
- }
- if (mDuplicatedOutput != 0 ||
- !a2dpUsedForSonification()) {
- // If both A2DP and duplicated outputs are open, send device address to A2DP hardware
- // interface
- AudioParameter param;
- param.add(String8("a2dp_sink_address"), String8(device_address));
- mpClientInterface->setParameters(mA2dpOutput, param.toString());
- mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
-
- if (a2dpUsedForSonification()) {
+ audio_io_handle_t output = 0;
+ AudioOutputDescriptor *outputDesc;
+
+ // TODO handle multiple outputs supporting overlapping sets of devices.
+
+ if (state == AudioSystem::DEVICE_STATE_AVAILABLE) {
+ // first check if one output already open can be routed to this device
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ AudioOutputDescriptor *outputDesc = mOutputs.valueAt(i);
+ if (outputDesc->mProfile && outputDesc->mProfile->mSupportedDevices & device) {
+ return mOutputs.keyAt(i);
+ }
+ }
+ // then look for one available output that can be routed to this device
+ const output_profile_t **outProfile = sAvailableOutputs;
+ while (*outProfile)
+ {
+ if ((*outProfile)->mSupportedDevices & device) {
+ break;
+ }
+ outProfile++;
+ }
+ if (*outProfile == NULL) {
+ ALOGW("No output available for device %04x", device);
+ return output;
+ }
+
+ ALOGV("opening output for device %08x", device);
+ outputDesc = new AudioOutputDescriptor(*outProfile);
+ outputDesc->mDevice = device;
+ output = mpClientInterface->openOutput((uint32_t *)&outputDesc->mDevice,
+ &outputDesc->mSamplingRate,
+ &outputDesc->mFormat,
+ &outputDesc->mChannels,
+ &outputDesc->mLatency,
+ outputDesc->mFlags);
+
+ if (output != 0) {
+ audio_io_handle_t duplicatedOutput = 0;
+ // add output descriptor
+ addOutput(output, outputDesc);
+ // set initial stream volume for device
+ applyStreamVolumes(output, device);
+
+ //TODO: configure audio effect output stage here
+
+ // open a duplicating output thread for the new output and the primary output
+ duplicatedOutput = mpClientInterface->openDuplicateOutput(output, mPrimaryOutput);
+ if (duplicatedOutput != 0) {
// add duplicated output descriptor
- AudioOutputDescriptor *dupOutputDesc = new AudioOutputDescriptor();
- dupOutputDesc->mOutput1 = mOutputs.valueFor(mHardwareOutput);
- dupOutputDesc->mOutput2 = mOutputs.valueFor(mA2dpOutput);
+ AudioOutputDescriptor *dupOutputDesc = new AudioOutputDescriptor(NULL);
+ dupOutputDesc->mOutput1 = mOutputs.valueFor(mPrimaryOutput);
+ dupOutputDesc->mOutput2 = mOutputs.valueFor(output);
dupOutputDesc->mSamplingRate = outputDesc->mSamplingRate;
dupOutputDesc->mFormat = outputDesc->mFormat;
dupOutputDesc->mChannels = outputDesc->mChannels;
dupOutputDesc->mLatency = outputDesc->mLatency;
- addOutput(mDuplicatedOutput, dupOutputDesc);
- applyStreamVolumes(mDuplicatedOutput, device);
+ addOutput(duplicatedOutput, dupOutputDesc);
+ applyStreamVolumes(duplicatedOutput, device);
+ } else {
+ ALOGW("getOutput() could not open duplicated output for %d and %d",
+ mPrimaryOutput, output);
+ mpClientInterface->closeOutput(output);
+ mOutputs.removeItem(output);
+ delete outputDesc;
+ return 0;
}
} else {
- LOGW("getOutput() could not open duplicated output for %d and %d",
- mHardwareOutput, mA2dpOutput);
- mpClientInterface->closeOutput(mA2dpOutput);
- mOutputs.removeItem(mA2dpOutput);
- mA2dpOutput = 0;
+ ALOGW("setDeviceConnectionState() could not open A2DP output for device %x", device);
delete outputDesc;
- return NO_INIT;
+ return 0;
}
} else {
- LOGW("setDeviceConnectionState() could not open A2DP output for device %x", device);
- delete outputDesc;
- return NO_INIT;
- }
- AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mHardwareOutput);
-
- if (!a2dpUsedForSonification()) {
- // mute music on A2DP output if a notification or ringtone is playing
- uint32_t refCount = hwOutputDesc->strategyRefCount(STRATEGY_SONIFICATION);
- for (uint32_t i = 0; i < refCount; i++) {
- setStrategyMute(STRATEGY_MEDIA, true, mA2dpOutput);
+ // we assume that one given device is supported by zero or one output
+ // check if one opened output is not needed any more after disconnecting one device
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ outputDesc = mOutputs.valueAt(i);
+ if (outputDesc->mProfile &&
+ !(outputDesc->mProfile->mSupportedDevices & mAvailableOutputDevices)) {
+ output = mOutputs.keyAt(i);
+ break;
+ }
}
}
- mA2dpSuspended = false;
-
- return NO_ERROR;
+ return output;
}
-status_t AudioPolicyManagerBase::handleA2dpDisconnection(AudioSystem::audio_devices device,
- const char *device_address)
+void AudioPolicyManagerBase::closeOutput(audio_io_handle_t output)
{
- if (mA2dpOutput == 0) {
- LOGW("setDeviceConnectionState() disconnecting A2DP and no A2DP output!");
- return INVALID_OPERATION;
- }
+ ALOGV("closeOutput(%d)", output);
- if (mA2dpDeviceAddress != device_address) {
- LOGW("setDeviceConnectionState() disconnecting unknow A2DP sink address %s", device_address);
- return INVALID_OPERATION;
+ AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
+ if (outputDesc == NULL) {
+ ALOGW("closeOutput() unknown output %d", output);
+ return;
}
- // mute media strategy to avoid outputting sound on hardware output while music stream
- // is switched from A2DP output and before music is paused by music application
- setStrategyMute(STRATEGY_MEDIA, true, mHardwareOutput);
- setStrategyMute(STRATEGY_MEDIA, false, mHardwareOutput, MUTE_TIME_MS);
+ // look for duplicated outputs connected to the output being removed.
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ AudioOutputDescriptor *dupOutputDesc = mOutputs.valueAt(i);
+ if (dupOutputDesc->isDuplicated() &&
+ (dupOutputDesc->mOutput1 == outputDesc ||
+ dupOutputDesc->mOutput2 == outputDesc)) {
+ AudioOutputDescriptor *outputDesc2;
+ if (dupOutputDesc->mOutput1 == outputDesc) {
+ outputDesc2 = dupOutputDesc->mOutput2;
+ } else {
+ outputDesc2 = dupOutputDesc->mOutput1;
+ }
+ // As all active tracks on duplicated output will be deleted,
+ // and as they were also referenced on the other output, the reference
+ // count for their stream type must be adjusted accordingly on
+ // the other output.
+ for (int j = 0; j < (int)AudioSystem::NUM_STREAM_TYPES; j++) {
+ int refCount = dupOutputDesc->mRefCount[j];
+ outputDesc2->changeRefCount((AudioSystem::stream_type)j,-refCount);
+ }
+ audio_io_handle_t duplicatedOutput = mOutputs.keyAt(i);
+ ALOGV("closeOutput() closing also duplicated output %d", duplicatedOutput);
- if (!a2dpUsedForSonification()) {
- // unmute music on A2DP output if a notification or ringtone is playing
- uint32_t refCount = mOutputs.valueFor(mHardwareOutput)->strategyRefCount(STRATEGY_SONIFICATION);
- for (uint32_t i = 0; i < refCount; i++) {
- setStrategyMute(STRATEGY_MEDIA, false, mA2dpOutput);
+ mpClientInterface->closeOutput(duplicatedOutput);
+ delete mOutputs.valueFor(duplicatedOutput);
+ mOutputs.removeItem(duplicatedOutput);
}
}
- mA2dpDeviceAddress = "";
- mA2dpSuspended = false;
- return NO_ERROR;
+
+ AudioParameter param;
+ param.add(String8("closing"), String8("true"));
+ mpClientInterface->setParameters(output, param.toString());
+
+ mpClientInterface->closeOutput(output);
+ delete mOutputs.valueFor(output);
+ mOutputs.removeItem(output);
}
-void AudioPolicyManagerBase::closeA2dpOutputs()
+SortedVector<audio_io_handle_t> AudioPolicyManagerBase::getOutputsForDevice(audio_devices_t device)
{
+ SortedVector<audio_io_handle_t> outputs;
- LOGV("setDeviceConnectionState() closing A2DP and duplicated output!");
-
- if (mDuplicatedOutput != 0) {
- AudioOutputDescriptor *dupOutputDesc = mOutputs.valueFor(mDuplicatedOutput);
- AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mHardwareOutput);
- // As all active tracks on duplicated output will be deleted,
- // and as they were also referenced on hardware output, the reference
- // count for their stream type must be adjusted accordingly on
- // hardware output.
- for (int i = 0; i < (int)AudioSystem::NUM_STREAM_TYPES; i++) {
- int refCount = dupOutputDesc->mRefCount[i];
- hwOutputDesc->changeRefCount((AudioSystem::stream_type)i,-refCount);
+ ALOGV("getOutputsForDevice() device %04x", device);
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ if ((device & mOutputs.valueAt(i)->supportedDevices()) == device) {
+ ALOGV("getOutputsForDevice() found output %d", mOutputs.keyAt(i));
+ outputs.add(mOutputs.keyAt(i));
}
-
- mpClientInterface->closeOutput(mDuplicatedOutput);
- delete mOutputs.valueFor(mDuplicatedOutput);
- mOutputs.removeItem(mDuplicatedOutput);
- mDuplicatedOutput = 0;
- }
- if (mA2dpOutput != 0) {
- AudioParameter param;
- param.add(String8("closing"), String8("true"));
- mpClientInterface->setParameters(mA2dpOutput, param.toString());
-
- mpClientInterface->closeOutput(mA2dpOutput);
- delete mOutputs.valueFor(mA2dpOutput);
- mOutputs.removeItem(mA2dpOutput);
- mA2dpOutput = 0;
}
+ return outputs;
}
-void AudioPolicyManagerBase::checkOutputForStrategy(routing_strategy strategy)
+bool AudioPolicyManagerBase::vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
+ SortedVector<audio_io_handle_t>& outputs2)
{
- uint32_t prevDevice = getDeviceForStrategy(strategy);
- uint32_t curDevice = getDeviceForStrategy(strategy, false);
- bool a2dpWasUsed = AudioSystem::isA2dpDevice((AudioSystem::audio_devices)(prevDevice & ~AudioSystem::DEVICE_OUT_SPEAKER));
- bool a2dpIsUsed = AudioSystem::isA2dpDevice((AudioSystem::audio_devices)(curDevice & ~AudioSystem::DEVICE_OUT_SPEAKER));
- audio_io_handle_t srcOutput = 0;
- audio_io_handle_t dstOutput = 0;
-
- if (a2dpWasUsed && !a2dpIsUsed) {
- bool dupUsed = a2dpUsedForSonification() && a2dpWasUsed && (AudioSystem::popCount(prevDevice) == 2);
- dstOutput = mHardwareOutput;
- if (dupUsed) {
- LOGV("checkOutputForStrategy() moving strategy %d from duplicated", strategy);
- srcOutput = mDuplicatedOutput;
- } else {
- LOGV("checkOutputForStrategy() moving strategy %d from a2dp", strategy);
- srcOutput = mA2dpOutput;
- }
+ if (outputs1.size() != outputs2.size()) {
+ return false;
}
- if (a2dpIsUsed && !a2dpWasUsed) {
- bool dupUsed = a2dpUsedForSonification() && a2dpIsUsed && (AudioSystem::popCount(curDevice) == 2);
- srcOutput = mHardwareOutput;
- if (dupUsed) {
- LOGV("checkOutputForStrategy() moving strategy %d to duplicated", strategy);
- dstOutput = mDuplicatedOutput;
- } else {
- LOGV("checkOutputForStrategy() moving strategy %d to a2dp", strategy);
- dstOutput = mA2dpOutput;
+ for (size_t i = 0; i < outputs1.size(); i++) {
+ if (outputs1[i] != outputs2[i]) {
+ return false;
}
}
+ return true;
+}
+
+void AudioPolicyManagerBase::checkOutputForStrategy(routing_strategy strategy)
+{
+ SortedVector<audio_io_handle_t> srcOutputs =
+ getOutputsForDevice(getDeviceForStrategy(strategy));
+ SortedVector<audio_io_handle_t> dstOutputs =
+ getOutputsForDevice(getDeviceForStrategy(strategy, false));
+
+ // TODO: current implementation assumes that at most one output corresponds to a device.
+ // this will change when supporting low power, low latency or tunneled output streams
+ ALOG_ASSERT(srcOutputs.size() < 2, "checkOutputForStrategy(): "
+ "more than one (%d) source output for strategy %d", srcOutputs.size(), strategy);
+ ALOG_ASSERT(dstOutputs.size() < 2, "checkOutputForStrategy(): "
+ "more than one (%d) destination output for strategy %d", dstOutputs.size(), strategy);
+
+ if (!vectorsEqual(srcOutputs,dstOutputs)) {
+ ALOGV("checkOutputForStrategy() strategy %d, moving from output %d to output %d",
+ strategy, srcOutputs[0], dstOutputs[0]);
+ // mute media strategy while moving tracks from one output to another
+ setStrategyMute(strategy, true, srcOutputs[0]);
+ setStrategyMute(strategy, false, srcOutputs[0], MUTE_TIME_MS);
- if (srcOutput != 0 && dstOutput != 0) {
// Move effects associated to this strategy from previous output to new output
for (size_t i = 0; i < mEffects.size(); i++) {
EffectDescriptor *desc = mEffects.valueAt(i);
if (desc->mSession != AudioSystem::SESSION_OUTPUT_STAGE &&
desc->mStrategy == strategy &&
- desc->mIo == srcOutput) {
- LOGV("checkOutputForStrategy() moving effect %d to output %d", mEffects.keyAt(i), dstOutput);
- mpClientInterface->moveEffects(desc->mSession, srcOutput, dstOutput);
- desc->mIo = dstOutput;
+ desc->mIo == srcOutputs[0]) {
+ ALOGV("checkOutputForStrategy() moving effect %d to output %d",
+ mEffects.keyAt(i), dstOutputs[0]);
+ mpClientInterface->moveEffects(desc->mSession, srcOutputs[0], dstOutputs[0]);
+ desc->mIo = dstOutputs[0];
}
}
// Move tracks associated to this strategy from previous output to new output
for (int i = 0; i < (int)AudioSystem::NUM_STREAM_TYPES; i++) {
if (getStrategy((AudioSystem::stream_type)i) == strategy) {
- mpClientInterface->setStreamOutput((AudioSystem::stream_type)i, dstOutput);
+ mpClientInterface->setStreamOutput((AudioSystem::stream_type)i, dstOutputs[0]);
}
}
}
@@ -1492,14 +1555,39 @@ void AudioPolicyManagerBase::checkOutputForStrategy(routing_strategy strategy)
void AudioPolicyManagerBase::checkOutputForAllStrategies()
{
+ checkOutputForStrategy(STRATEGY_ENFORCED_AUDIBLE);
checkOutputForStrategy(STRATEGY_PHONE);
checkOutputForStrategy(STRATEGY_SONIFICATION);
checkOutputForStrategy(STRATEGY_MEDIA);
checkOutputForStrategy(STRATEGY_DTMF);
}
+audio_io_handle_t AudioPolicyManagerBase::getA2dpOutput()
+{
+ if (!sHasA2dp) {
+ return 0;
+ }
+
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ AudioOutputDescriptor *outputDesc = mOutputs.valueAt(i);
+ if (!outputDesc->isDuplicated() && outputDesc->device() & AUDIO_DEVICE_OUT_ALL_A2DP) {
+ return mOutputs.keyAt(i);
+ }
+ }
+
+ return 0;
+}
+
void AudioPolicyManagerBase::checkA2dpSuspend()
{
+ if (!sHasA2dp) {
+ return;
+ }
+ audio_io_handle_t a2dpOutput = getA2dpOutput();
+ if (a2dpOutput == 0) {
+ return;
+ }
+
// suspend A2DP output if:
// (NOT already suspended) &&
// ((SCO device is connected &&
@@ -1512,10 +1600,6 @@ void AudioPolicyManagerBase::checkA2dpSuspend()
// (forced usage NOT for communication && NOT for record is SCO))) &&
// (phone state is NOT ringing && NOT in call)
//
- if (mA2dpOutput == 0) {
- return;
- }
-
if (mA2dpSuspended) {
if (((mScoDeviceAddress == "") ||
((mForceUse[AudioSystem::FOR_COMMUNICATION] != AudioSystem::FORCE_BT_SCO) &&
@@ -1523,7 +1607,7 @@ void AudioPolicyManagerBase::checkA2dpSuspend()
((mPhoneState != AudioSystem::MODE_IN_CALL) &&
(mPhoneState != AudioSystem::MODE_RINGTONE))) {
- mpClientInterface->restoreOutput(mA2dpOutput);
+ mpClientInterface->restoreOutput(a2dpOutput);
mA2dpSuspended = false;
}
} else {
@@ -1533,31 +1617,32 @@ void AudioPolicyManagerBase::checkA2dpSuspend()
((mPhoneState == AudioSystem::MODE_IN_CALL) ||
(mPhoneState == AudioSystem::MODE_RINGTONE))) {
- mpClientInterface->suspendOutput(mA2dpOutput);
+ mpClientInterface->suspendOutput(a2dpOutput);
mA2dpSuspended = true;
}
}
}
-
-#endif
-
-uint32_t AudioPolicyManagerBase::getNewDevice(audio_io_handle_t output, bool fromCache)
+audio_devices_t AudioPolicyManagerBase::getNewDevice(audio_io_handle_t output, bool fromCache)
{
- uint32_t device = 0;
+ audio_devices_t device = (audio_devices_t)0;
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
// check the following by order of priority to request a routing change if necessary:
- // 1: we are in call or the strategy phone is active on the hardware output:
+ // 1: the strategy enforced audible is active on the output:
+ // use device for strategy enforced audible
+ // 2: we are in call or the strategy phone is active on the output:
// use device for strategy phone
- // 2: the strategy sonification is active on the hardware output:
+ // 3: the strategy sonification is active on the output:
// use device for strategy sonification
- // 3: the strategy media is active on the hardware output:
+ // 4: the strategy media is active on the output:
// use device for strategy media
- // 4: the strategy DTMF is active on the hardware output:
+ // 5: the strategy DTMF is active on the output:
// use device for strategy DTMF
- if (isInCall() ||
- outputDesc->isUsedByStrategy(STRATEGY_PHONE)) {
+ if (outputDesc->isUsedByStrategy(STRATEGY_ENFORCED_AUDIBLE)) {
+ device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache);
+ } else if (isInCall() ||
+ outputDesc->isUsedByStrategy(STRATEGY_PHONE)) {
device = getDeviceForStrategy(STRATEGY_PHONE, fromCache);
} else if (outputDesc->isUsedByStrategy(STRATEGY_SONIFICATION)) {
device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache);
@@ -1567,7 +1652,7 @@ uint32_t AudioPolicyManagerBase::getNewDevice(audio_io_handle_t output, bool fro
device = getDeviceForStrategy(STRATEGY_DTMF, fromCache);
}
- LOGV("getNewDevice() selected device %x", device);
+ ALOGV("getNewDevice() selected device %x", device);
return device;
}
@@ -1575,13 +1660,13 @@ uint32_t AudioPolicyManagerBase::getStrategyForStream(AudioSystem::stream_type s
return (uint32_t)getStrategy(stream);
}
-uint32_t AudioPolicyManagerBase::getDevicesForStream(AudioSystem::stream_type stream) {
- uint32_t devices;
+audio_devices_t AudioPolicyManagerBase::getDevicesForStream(AudioSystem::stream_type stream) {
+ audio_devices_t devices;
// By checking the range of stream before calling getStrategy, we avoid
- // getStrategy's behavior for invalid streams. getStrategy would do a LOGE
+ // getStrategy's behavior for invalid streams. getStrategy would do a ALOGE
// and then return STRATEGY_MEDIA, but we want to return the empty set.
if (stream < (AudioSystem::stream_type) 0 || stream >= AudioSystem::NUM_STREAM_TYPES) {
- devices = 0;
+ devices = (audio_devices_t)0;
} else {
AudioPolicyManagerBase::routing_strategy strategy = getStrategy(stream);
devices = getDeviceForStrategy(strategy, true);
@@ -1599,27 +1684,28 @@ AudioPolicyManagerBase::routing_strategy AudioPolicyManagerBase::getStrategy(
case AudioSystem::RING:
case AudioSystem::NOTIFICATION:
case AudioSystem::ALARM:
- case AudioSystem::ENFORCED_AUDIBLE:
return STRATEGY_SONIFICATION;
case AudioSystem::DTMF:
return STRATEGY_DTMF;
default:
- LOGE("unknown stream type");
+ ALOGE("unknown stream type");
case AudioSystem::SYSTEM:
// NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs
// while key clicks are played produces a poor result
case AudioSystem::TTS:
case AudioSystem::MUSIC:
return STRATEGY_MEDIA;
+ case AudioSystem::ENFORCED_AUDIBLE:
+ return STRATEGY_ENFORCED_AUDIBLE;
}
}
-uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy, bool fromCache)
+audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy, bool fromCache)
{
uint32_t device = 0;
if (fromCache) {
- LOGV("getDeviceForStrategy() from cache strategy %d, device %x", strategy, mDeviceForStrategy[strategy]);
+ ALOGV("getDeviceForStrategy() from cache strategy %d, device %x", strategy, mDeviceForStrategy[strategy]);
return mDeviceForStrategy[strategy];
}
@@ -1654,15 +1740,13 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
if (device) break;
-#ifdef WITH_A2DP
// when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP
- if (!isInCall() && !mA2dpSuspended) {
+ if (sHasA2dp && !isInCall() && !mA2dpSuspended) {
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP;
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
if (device) break;
}
-#endif
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_AUX_DIGITAL;
@@ -1671,19 +1755,17 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_EARPIECE;
if (device == 0) {
- LOGE("getDeviceForStrategy() earpiece device not found");
+ ALOGE("getDeviceForStrategy() earpiece device not found");
}
break;
case AudioSystem::FORCE_SPEAKER:
-#ifdef WITH_A2DP
// when not in a phone call, phone strategy should route STREAM_VOICE_CALL to
// A2DP speaker when forcing to speaker output
- if (!isInCall() && !mA2dpSuspended) {
+ if (sHasA2dp && !isInCall() && !mA2dpSuspended) {
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
if (device) break;
}
-#endif
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_AUX_DIGITAL;
@@ -1692,7 +1774,7 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
if (device == 0) {
- LOGE("getDeviceForStrategy() speaker device not found");
+ ALOGE("getDeviceForStrategy() speaker device not found");
}
break;
}
@@ -1706,9 +1788,15 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
device = getDeviceForStrategy(STRATEGY_PHONE, false);
break;
}
+ // FALL THROUGH
+
+ case STRATEGY_ENFORCED_AUDIBLE:
+ // strategy STRATEGY_ENFORCED_AUDIBLE uses same routing policy as STRATEGY_SONIFICATION
+ // except when in call where it doesn't default to STRATEGY_PHONE behavior
+
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
if (device == 0) {
- LOGE("getDeviceForStrategy() speaker device not found");
+ ALOGE("getDeviceForStrategy() speaker device not found");
}
// The second device used for sonification is the same as the device used by media strategy
// FALL THROUGH
@@ -1718,9 +1806,7 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device2 == 0) {
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
}
-#ifdef WITH_A2DP
- if ((mA2dpOutput != 0) && !mA2dpSuspended &&
- (strategy != STRATEGY_SONIFICATION || a2dpUsedForSonification())) {
+ if (sHasA2dp && (getA2dpOutput() != 0) && !mA2dpSuspended) {
if (device2 == 0) {
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP;
}
@@ -1731,7 +1817,6 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
}
}
-#endif
if (device2 == 0) {
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
}
@@ -1745,20 +1830,21 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
}
- // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION, 0 otherwise
+ // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or
+ // STRATEGY_ENFORCED_AUDIBLE, 0 otherwise
device |= device2;
if (device == 0) {
- LOGE("getDeviceForStrategy() speaker device not found");
+ ALOGE("getDeviceForStrategy() speaker device not found");
}
} break;
default:
- LOGW("getDeviceForStrategy() unknown strategy: %d", strategy);
+ ALOGW("getDeviceForStrategy() unknown strategy: %d", strategy);
break;
}
- LOGV("getDeviceForStrategy() strategy %d, device %x", strategy, device);
- return device;
+ ALOGV("getDeviceForStrategy() strategy %d, device %x", strategy, device);
+ return (audio_devices_t)device;
}
void AudioPolicyManagerBase::updateDeviceForStrategy()
@@ -1768,9 +1854,12 @@ void AudioPolicyManagerBase::updateDeviceForStrategy()
}
}
-void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t device, bool force, int delayMs)
+void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output,
+ audio_devices_t device,
+ bool force,
+ int delayMs)
{
- LOGV("setOutputDevice() output %d device %x delayMs %d", output, device, delayMs);
+ ALOGV("setOutputDevice() output %d device %x delayMs %d", output, device, delayMs);
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
@@ -1779,28 +1868,22 @@ void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t
setOutputDevice(outputDesc->mOutput2->mId, device, force, delayMs);
return;
}
-#ifdef WITH_A2DP
// filter devices according to output selected
- if (output == mA2dpOutput) {
- device &= AudioSystem::DEVICE_OUT_ALL_A2DP;
- } else {
- device &= ~AudioSystem::DEVICE_OUT_ALL_A2DP;
- }
-#endif
+ device = (audio_devices_t)(device & outputDesc->mProfile->mSupportedDevices);
- uint32_t prevDevice = (uint32_t)outputDesc->device();
+ audio_devices_t prevDevice = outputDesc->device();
// Do not change the routing if:
// - the requestede device is 0
// - the requested device is the same as current device and force is not specified.
// Doing this check here allows the caller to call setOutputDevice() without conditions
if ((device == 0 || device == prevDevice) && !force) {
- LOGV("setOutputDevice() setting same device %x or null device for output %d", device, output);
+ ALOGV("setOutputDevice() setting same device %x or null device for output %d", device, output);
return;
}
outputDesc->mDevice = device;
// mute media streams if both speaker and headset are selected
- if (output == mHardwareOutput && AudioSystem::popCount(device) == 2) {
+ if (output == mPrimaryOutput && AudioSystem::popCount(device) == 2) {
setStrategyMute(STRATEGY_MEDIA, true, output);
// wait for the PCM output buffers to empty before proceeding with the rest of the command
// FIXME: increased delay due to larger buffers used for low power audio mode.
@@ -1811,17 +1894,17 @@ void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t
// do the routing
AudioParameter param = AudioParameter();
param.addInt(String8(AudioParameter::keyRouting), (int)device);
- mpClientInterface->setParameters(mHardwareOutput, param.toString(), delayMs);
+ mpClientInterface->setParameters(mPrimaryOutput, param.toString(), delayMs);
// update stream volumes according to new device
applyStreamVolumes(output, device, delayMs);
// if changing from a combined headset + speaker route, unmute media streams
- if (output == mHardwareOutput && AudioSystem::popCount(prevDevice) == 2) {
+ if (output == mPrimaryOutput && AudioSystem::popCount((uint32_t)prevDevice) == 2) {
setStrategyMute(STRATEGY_MEDIA, false, output, delayMs);
}
}
-uint32_t AudioPolicyManagerBase::getDeviceForInputSource(int inputSource)
+audio_devices_t AudioPolicyManagerBase::getDeviceForInputSource(int inputSource)
{
uint32_t device;
@@ -1852,12 +1935,12 @@ uint32_t AudioPolicyManagerBase::getDeviceForInputSource(int inputSource)
device = AudioSystem::DEVICE_IN_VOICE_CALL;
break;
default:
- LOGW("getDeviceForInputSource() invalid input source %d", inputSource);
+ ALOGW("getDeviceForInputSource() invalid input source %d", inputSource);
device = 0;
break;
}
- LOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device);
- return device;
+ ALOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device);
+ return (audio_devices_t)device;
}
audio_io_handle_t AudioPolicyManagerBase::getActiveInput()
@@ -1871,31 +1954,35 @@ audio_io_handle_t AudioPolicyManagerBase::getActiveInput()
}
-AudioPolicyManagerBase::device_category AudioPolicyManagerBase::getDeviceCategory(uint32_t device)
+audio_devices_t AudioPolicyManagerBase::getDeviceForVolume(audio_devices_t device)
{
if (device == 0) {
// this happens when forcing a route update and no track is active on an output.
// In this case the returned category is not important.
- return DEVICE_CATEGORY_SPEAKER;
- }
-
- if (AudioSystem::popCount(device) > 1) {
+ device = AUDIO_DEVICE_OUT_SPEAKER;
+ } else if (AudioSystem::popCount(device) > 1) {
// Multiple device selection is either:
// - speaker + one other device: give priority to speaker in this case.
// - one A2DP device + another device: happens with duplicated output. In this case
// retain the device on the A2DP output as the other must not correspond to an active
// selection if not the speaker.
- if (device & AUDIO_DEVICE_OUT_SPEAKER)
- return DEVICE_CATEGORY_SPEAKER;
-
- device &= AUDIO_DEVICE_OUT_ALL_A2DP;
+ if (device & AUDIO_DEVICE_OUT_SPEAKER) {
+ device = AUDIO_DEVICE_OUT_SPEAKER;
+ } else {
+ device = (audio_devices_t)(device & AUDIO_DEVICE_OUT_ALL_A2DP);
+ }
}
- LOGW_IF(AudioSystem::popCount(device) != 1,
- "getDeviceCategory() invalid device combination: %08x",
+ ALOGW_IF(AudioSystem::popCount(device) != 1,
+ "getDeviceForVolume() invalid device combination: %08x",
device);
- switch(device) {
+ return device;
+}
+
+AudioPolicyManagerBase::device_category AudioPolicyManagerBase::getDeviceCategory(audio_devices_t device)
+{
+ switch(getDeviceForVolume(device)) {
case AUDIO_DEVICE_OUT_EARPIECE:
return DEVICE_CATEGORY_EARPIECE;
case AUDIO_DEVICE_OUT_WIRED_HEADSET:
@@ -1908,12 +1995,13 @@ AudioPolicyManagerBase::device_category AudioPolicyManagerBase::getDeviceCategor
case AUDIO_DEVICE_OUT_SPEAKER:
case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
+ case AUDIO_DEVICE_OUT_AUX_DIGITAL:
default:
return DEVICE_CATEGORY_SPEAKER;
}
}
-float AudioPolicyManagerBase::volIndexToAmpl(uint32_t device, const StreamDescriptor& streamDesc,
+float AudioPolicyManagerBase::volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
int indexInUi)
{
device_category deviceCategory = getDeviceCategory(device);
@@ -1949,7 +2037,7 @@ float AudioPolicyManagerBase::volIndexToAmpl(uint32_t device, const StreamDescri
float amplification = exp( decibels * 0.115129f); // exp( dB * ln(10) / 20 )
- LOGV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f",
+ ALOGV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f",
curve[segment].mIndex, volIdx,
curve[segment+1].mIndex,
curve[segment].mDBAttenuation,
@@ -2003,7 +2091,12 @@ const AudioPolicyManagerBase::VolumeCurvePoint
sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
sDefaultVolumeCurve, // DEVICE_CATEGORY_SPEAKER
sDefaultVolumeCurve // DEVICE_CATEGORY_EARPIECE
- }
+ },
+ { // STRATEGY_ENFORCED_AUDIBLE
+ sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
+ sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
+ sDefaultVolumeCurve // DEVICE_CATEGORY_EARPIECE
+ },
};
void AudioPolicyManagerBase::initializeVolumeCurves()
@@ -2016,7 +2109,10 @@ void AudioPolicyManagerBase::initializeVolumeCurves()
}
}
-float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device)
+float AudioPolicyManagerBase::computeVolume(int stream,
+ int index,
+ audio_io_handle_t output,
+ audio_devices_t device)
{
float volume = 1.0;
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
@@ -2029,8 +2125,8 @@ float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_hand
// if volume is not 0 (not muted), force media volume to max on digital output
if (stream == AudioSystem::MUSIC &&
index != mStreams[stream].mIndexMin &&
- (device == AudioSystem::DEVICE_OUT_AUX_DIGITAL ||
- device == AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) {
+ (device == AUDIO_DEVICE_OUT_AUX_DIGITAL ||
+ device == AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) {
return 1.0;
}
@@ -2054,11 +2150,15 @@ float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_hand
// by the music application and behave as if music was active if the last music track was
// just stopped
if (outputDesc->mRefCount[AudioSystem::MUSIC] || mLimitRingtoneVolume) {
- float musicVol = computeVolume(AudioSystem::MUSIC, mStreams[AudioSystem::MUSIC].mIndexCur, output, device);
- float minVol = (musicVol > SONIFICATION_HEADSET_VOLUME_MIN) ? musicVol : SONIFICATION_HEADSET_VOLUME_MIN;
+ float musicVol = computeVolume(AudioSystem::MUSIC,
+ mStreams[AudioSystem::MUSIC].getVolumeIndex(device),
+ output,
+ device);
+ float minVol = (musicVol > SONIFICATION_HEADSET_VOLUME_MIN) ?
+ musicVol : SONIFICATION_HEADSET_VOLUME_MIN;
if (volume > minVol) {
volume = minVol;
- LOGV("computeVolume limiting volume to %f musicVol %f", minVol, musicVol);
+ ALOGV("computeVolume limiting volume to %f musicVol %f", minVol, musicVol);
}
}
}
@@ -2066,19 +2166,24 @@ float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_hand
return volume;
}
-status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs, bool force)
+status_t AudioPolicyManagerBase::checkAndSetVolume(int stream,
+ int index,
+ audio_io_handle_t output,
+ audio_devices_t device,
+ int delayMs,
+ bool force)
{
// do not change actual stream volume if the stream is muted
if (mOutputs.valueFor(output)->mMuteCount[stream] != 0) {
- LOGV("checkAndSetVolume() stream %d muted count %d", stream, mOutputs.valueFor(output)->mMuteCount[stream]);
+ ALOGV("checkAndSetVolume() stream %d muted count %d", stream, mOutputs.valueFor(output)->mMuteCount[stream]);
return NO_ERROR;
}
// do not change in call volume if bluetooth is connected and vice versa
if ((stream == AudioSystem::VOICE_CALL && mForceUse[AudioSystem::FOR_COMMUNICATION] == AudioSystem::FORCE_BT_SCO) ||
(stream == AudioSystem::BLUETOOTH_SCO && mForceUse[AudioSystem::FOR_COMMUNICATION] != AudioSystem::FORCE_BT_SCO)) {
- LOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
+ ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
stream, mForceUse[AudioSystem::FOR_COMMUNICATION]);
return INVALID_OPERATION;
}
@@ -2090,7 +2195,7 @@ status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_
if (volume != mOutputs.valueFor(output)->mCurVolume[stream] ||
force) {
mOutputs.valueFor(output)->mCurVolume[stream] = volume;
- LOGV("setStreamVolume() for output %d stream %d, volume %f, delay %d", output, stream, volume, delayMs);
+ ALOGV("setStreamVolume() for output %d stream %d, volume %f, delay %d", output, stream, volume, delayMs);
if (stream == AudioSystem::VOICE_CALL ||
stream == AudioSystem::DTMF ||
stream == AudioSystem::BLUETOOTH_SCO) {
@@ -2117,7 +2222,7 @@ status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_
voiceVolume = 1.0;
}
- if (voiceVolume != mLastVoiceVolume && output == mHardwareOutput) {
+ if (voiceVolume != mLastVoiceVolume && output == mPrimaryOutput) {
mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
mLastVoiceVolume = voiceVolume;
}
@@ -2126,18 +2231,26 @@ status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_
return NO_ERROR;
}
-void AudioPolicyManagerBase::applyStreamVolumes(audio_io_handle_t output, uint32_t device, int delayMs, bool force)
+void AudioPolicyManagerBase::applyStreamVolumes(audio_io_handle_t output,
+ audio_devices_t device,
+ int delayMs,
+ bool force)
{
- LOGV("applyStreamVolumes() for output %d and device %x", output, device);
+ ALOGV("applyStreamVolumes() for output %d and device %x", output, device);
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
- checkAndSetVolume(stream, mStreams[stream].mIndexCur, output, device, delayMs, force);
+ checkAndSetVolume(stream,
+ mStreams[stream].getVolumeIndex(device),
+ output,
+ device,
+ delayMs,
+ force);
}
}
void AudioPolicyManagerBase::setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output, int delayMs)
{
- LOGV("setStrategyMute() strategy %d, mute %d, output %d", strategy, on, output);
+ ALOGV("setStrategyMute() strategy %d, mute %d, output %d", strategy, on, output);
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
if (getStrategy((AudioSystem::stream_type)stream) == strategy) {
setStreamMute(stream, on, output, delayMs);
@@ -2149,24 +2262,29 @@ void AudioPolicyManagerBase::setStreamMute(int stream, bool on, audio_io_handle_
{
StreamDescriptor &streamDesc = mStreams[stream];
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
+ audio_devices_t device = outputDesc->device();
- LOGV("setStreamMute() stream %d, mute %d, output %d, mMuteCount %d", stream, on, output, outputDesc->mMuteCount[stream]);
+ ALOGV("setStreamMute() stream %d, mute %d, output %d, mMuteCount %d", stream, on, output, outputDesc->mMuteCount[stream]);
if (on) {
if (outputDesc->mMuteCount[stream] == 0) {
if (streamDesc.mCanBeMuted) {
- checkAndSetVolume(stream, 0, output, outputDesc->device(), delayMs);
+ checkAndSetVolume(stream, 0, output, device, delayMs);
}
}
// increment mMuteCount after calling checkAndSetVolume() so that volume change is not ignored
outputDesc->mMuteCount[stream]++;
} else {
if (outputDesc->mMuteCount[stream] == 0) {
- LOGW("setStreamMute() unmuting non muted stream!");
+ ALOGW("setStreamMute() unmuting non muted stream!");
return;
}
if (--outputDesc->mMuteCount[stream] == 0) {
- checkAndSetVolume(stream, streamDesc.mIndexCur, output, outputDesc->device(), delayMs);
+ checkAndSetVolume(stream,
+ streamDesc.getVolumeIndex((audio_devices_t)device),
+ output,
+ device,
+ delayMs);
}
}
}
@@ -2181,8 +2299,8 @@ void AudioPolicyManagerBase::handleIncallSonification(int stream, bool starting,
// many times as there are active tracks on the output
if (getStrategy((AudioSystem::stream_type)stream) == STRATEGY_SONIFICATION) {
- AudioOutputDescriptor *outputDesc = mOutputs.valueFor(mHardwareOutput);
- LOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
+ AudioOutputDescriptor *outputDesc = mOutputs.valueFor(mPrimaryOutput);
+ ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
stream, starting, outputDesc->mDevice, stateChange);
if (outputDesc->mRefCount[stream]) {
int muteCount = 1;
@@ -2190,16 +2308,16 @@ void AudioPolicyManagerBase::handleIncallSonification(int stream, bool starting,
muteCount = outputDesc->mRefCount[stream];
}
if (AudioSystem::isLowVisibility((AudioSystem::stream_type)stream)) {
- LOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
+ ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
for (int i = 0; i < muteCount; i++) {
- setStreamMute(stream, starting, mHardwareOutput);
+ setStreamMute(stream, starting, mPrimaryOutput);
}
} else {
- LOGV("handleIncallSonification() high visibility");
+ ALOGV("handleIncallSonification() high visibility");
if (outputDesc->device() & getDeviceForStrategy(STRATEGY_PHONE)) {
- LOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
+ ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
for (int i = 0; i < muteCount; i++) {
- setStreamMute(stream, starting, mHardwareOutput);
+ setStreamMute(stream, starting, mPrimaryOutput);
}
}
if (starting) {
@@ -2230,7 +2348,7 @@ bool AudioPolicyManagerBase::needsDirectOuput(AudioSystem::stream_type stream,
uint32_t device)
{
return ((flags & AudioSystem::OUTPUT_FLAG_DIRECT) ||
- (format !=0 && !AudioSystem::isLinearPCM(format)));
+ (format != 0 && !AudioSystem::isLinearPCM(format)));
}
uint32_t AudioPolicyManagerBase::getMaxEffectsCpuLoad()
@@ -2245,9 +2363,11 @@ uint32_t AudioPolicyManagerBase::getMaxEffectsMemory()
// --- AudioOutputDescriptor class implementation
-AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor()
+AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor(
+ const output_profile_t *profile)
: mId(0), mSamplingRate(0), mFormat(0), mChannels(0), mLatency(0),
- mFlags((AudioSystem::output_flags)0), mDevice(0), mOutput1(0), mOutput2(0)
+ mFlags((AudioSystem::output_flags)0), mDevice((audio_devices_t)0),
+ mOutput1(0), mOutput2(0), mProfile(profile)
{
// clear usage count for all stream types
for (int i = 0; i < AudioSystem::NUM_STREAM_TYPES; i++) {
@@ -2258,15 +2378,13 @@ AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor()
}
}
-uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::device()
+audio_devices_t AudioPolicyManagerBase::AudioOutputDescriptor::device()
{
- uint32_t device = 0;
if (isDuplicated()) {
- device = mOutput1->mDevice | mOutput2->mDevice;
+ return (audio_devices_t)(mOutput1->mDevice | mOutput2->mDevice);
} else {
- device = mDevice;
+ return mDevice;
}
- return device;
}
void AudioPolicyManagerBase::AudioOutputDescriptor::changeRefCount(AudioSystem::stream_type stream, int delta)
@@ -2277,12 +2395,12 @@ void AudioPolicyManagerBase::AudioOutputDescriptor::changeRefCount(AudioSystem::
mOutput2->changeRefCount(stream, delta);
}
if ((delta + (int)mRefCount[stream]) < 0) {
- LOGW("changeRefCount() invalid delta %d for stream %d, refCount %d", delta, stream, mRefCount[stream]);
+ ALOGW("changeRefCount() invalid delta %d for stream %d, refCount %d", delta, stream, mRefCount[stream]);
mRefCount[stream] = 0;
return;
}
mRefCount[stream] += delta;
- LOGV("changeRefCount() stream %d, count %d", stream, mRefCount[stream]);
+ ALOGV("changeRefCount() stream %d, count %d", stream, mRefCount[stream]);
}
uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::refCount()
@@ -2305,6 +2423,15 @@ uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::strategyRefCount(routing
return refCount;
}
+audio_devices_t AudioPolicyManagerBase::AudioOutputDescriptor::supportedDevices()
+{
+ if (isDuplicated()) {
+ return (audio_devices_t)(mOutput1->supportedDevices() | mOutput2->supportedDevices());
+ } else {
+ return mProfile->mSupportedDevices ;
+ }
+}
+
status_t AudioPolicyManagerBase::AudioOutputDescriptor::dump(int fd)
{
const size_t SIZE = 256;
@@ -2338,7 +2465,7 @@ status_t AudioPolicyManagerBase::AudioOutputDescriptor::dump(int fd)
AudioPolicyManagerBase::AudioInputDescriptor::AudioInputDescriptor()
: mSamplingRate(0), mFormat(0), mChannels(0),
- mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice(0), mRefCount(0),
+ mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice((audio_devices_t)0), mRefCount(0),
mInputSource(0)
{
}
@@ -2368,13 +2495,40 @@ status_t AudioPolicyManagerBase::AudioInputDescriptor::dump(int fd)
// --- StreamDescriptor class implementation
-void AudioPolicyManagerBase::StreamDescriptor::dump(char* buffer, size_t size)
+AudioPolicyManagerBase::StreamDescriptor::StreamDescriptor()
+ : mIndexMin(0), mIndexMax(1), mCanBeMuted(true)
+{
+ mIndexCur.add(AUDIO_DEVICE_OUT_DEFAULT, 0);
+}
+
+int AudioPolicyManagerBase::StreamDescriptor::getVolumeIndex(audio_devices_t device)
+{
+ device = AudioPolicyManagerBase::getDeviceForVolume(device);
+ // there is always a valid entry for AUDIO_DEVICE_OUT_DEFAULT
+ if (mIndexCur.indexOfKey(device) < 0) {
+ device = AUDIO_DEVICE_OUT_DEFAULT;
+ }
+ return mIndexCur.valueFor(device);
+}
+
+void AudioPolicyManagerBase::StreamDescriptor::dump(int fd)
{
- snprintf(buffer, size, " %02d %02d %02d %d\n",
- mIndexMin,
- mIndexMax,
- mIndexCur,
- mCanBeMuted);
+ const size_t SIZE = 256;
+ char buffer[SIZE];
+ String8 result;
+
+ snprintf(buffer, SIZE, "%s %02d %02d ",
+ mCanBeMuted ? "true " : "false", mIndexMin, mIndexMax);
+ result.append(buffer);
+ for (size_t i = 0; i < mIndexCur.size(); i++) {
+ snprintf(buffer, SIZE, "%04x : %02d, ",
+ mIndexCur.keyAt(i),
+ mIndexCur.valueAt(i));
+ result.append(buffer);
+ }
+ result.append("\n");
+
+ write(fd, result.string(), result.size());
}
// --- EffectDescriptor class implementation
diff --git a/audio/AudioPolicyManagerDefault.h b/audio/AudioPolicyManagerDefault.h
index b2b2576..96dfee1 100644
--- a/audio/AudioPolicyManagerDefault.h
+++ b/audio/AudioPolicyManagerDefault.h
@@ -34,10 +34,6 @@ public:
protected:
// true is current platform implements a back microphone
virtual bool hasBackMicrophone() const { return false; }
-#ifdef WITH_A2DP
- // true is current platform supports suplication of notifications and ringtones over A2DP output
- virtual bool a2dpUsedForSonification() const { return true; }
-#endif
};
};
diff --git a/audio/audio_hw_hal.cpp b/audio/audio_hw_hal.cpp
index dd56c80..0fc4efa 100644
--- a/audio/audio_hw_hal.cpp
+++ b/audio/audio_hw_hal.cpp
@@ -65,7 +65,7 @@ static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
struct legacy_stream_out *out =
reinterpret_cast<struct legacy_stream_out *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement this */
return 0;
}
@@ -84,18 +84,19 @@ static uint32_t out_get_channels(const struct audio_stream *stream)
return out->legacy_out->channels();
}
-static int out_get_format(const struct audio_stream *stream)
+static audio_format_t out_get_format(const struct audio_stream *stream)
{
const struct legacy_stream_out *out =
reinterpret_cast<const struct legacy_stream_out *>(stream);
- return out->legacy_out->format();
+ // legacy API, don't change return type
+ return (audio_format_t) out->legacy_out->format();
}
-static int out_set_format(struct audio_stream *stream, int format)
+static int out_set_format(struct audio_stream *stream, audio_format_t format)
{
struct legacy_stream_out *out =
reinterpret_cast<struct legacy_stream_out *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement me */
return 0;
}
@@ -193,7 +194,7 @@ static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
struct legacy_stream_in *in =
reinterpret_cast<struct legacy_stream_in *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement this */
return 0;
}
@@ -212,18 +213,19 @@ static uint32_t in_get_channels(const struct audio_stream *stream)
return in->legacy_in->channels();
}
-static int in_get_format(const struct audio_stream *stream)
+static audio_format_t in_get_format(const struct audio_stream *stream)
{
const struct legacy_stream_in *in =
reinterpret_cast<const struct legacy_stream_in *>(stream);
- return in->legacy_in->format();
+ // legacy API, don't change return type
+ return (audio_format_t) in->legacy_in->format();
}
-static int in_set_format(struct audio_stream *stream, int format)
+static int in_set_format(struct audio_stream *stream, audio_format_t format)
{
struct legacy_stream_in *in =
reinterpret_cast<struct legacy_stream_in *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement me */
return 0;
}
@@ -360,10 +362,11 @@ static int adev_get_master_volume(struct audio_hw_device *dev, float* volume)
return ladev->hwif->getMasterVolume(volume);
}
-static int adev_set_mode(struct audio_hw_device *dev, int mode)
+static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
{
struct legacy_audio_device *ladev = to_ladev(dev);
- return ladev->hwif->setMode(mode);
+ // as this is the legacy API, don't change it to use audio_mode_t instead of int
+ return ladev->hwif->setMode((int) mode);
}
static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
@@ -395,16 +398,16 @@ static char * adev_get_parameters(const struct audio_hw_device *dev,
}
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
- uint32_t sample_rate, int format,
+ uint32_t sample_rate, audio_format_t format,
int channel_count)
{
const struct legacy_audio_device *ladev = to_cladev(dev);
- return ladev->hwif->getInputBufferSize(sample_rate, format, channel_count);
+ return ladev->hwif->getInputBufferSize(sample_rate, (int) format, channel_count);
}
static int adev_open_output_stream(struct audio_hw_device *dev,
uint32_t devices,
- int *format,
+ audio_format_t *format,
uint32_t *channels,
uint32_t *sample_rate,
struct audio_stream_out **stream_out)
@@ -418,7 +421,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
if (!out)
return -ENOMEM;
- out->legacy_out = ladev->hwif->openOutputStream(devices, format, channels,
+ out->legacy_out = ladev->hwif->openOutputStream(devices, (int *) format, channels,
sample_rate, &status);
if (!out->legacy_out) {
ret = status;
@@ -464,7 +467,7 @@ static void adev_close_output_stream(struct audio_hw_device *dev,
/** This method creates and opens the audio hardware input stream */
static int adev_open_input_stream(struct audio_hw_device *dev,
- uint32_t devices, int *format,
+ uint32_t devices, audio_format_t *format,
uint32_t *channels, uint32_t *sample_rate,
audio_in_acoustics_t acoustics,
struct audio_stream_in **stream_in)
@@ -478,7 +481,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
if (!in)
return -ENOMEM;
- in->legacy_in = ladev->hwif->openInputStream(devices, format, channels,
+ in->legacy_in = ladev->hwif->openInputStream(devices, (int *) format, channels,
sample_rate, &status,
(AudioSystem::audio_in_acoustics)acoustics);
if (!in->legacy_in) {
diff --git a/audio/audio_policy_hal.cpp b/audio/audio_policy_hal.cpp
index d5f2816..9a71d2f 100644
--- a/audio/audio_policy_hal.cpp
+++ b/audio/audio_policy_hal.cpp
@@ -84,18 +84,18 @@ static audio_policy_dev_state_t ap_get_device_connection_state(
device_address);
}
-static void ap_set_phone_state(struct audio_policy *pol, int state)
+static void ap_set_phone_state(struct audio_policy *pol, audio_mode_t state)
{
struct legacy_audio_policy *lap = to_lap(pol);
- lap->apm->setPhoneState(state);
+ // as this is the legacy API, don't change it to use audio_mode_t instead of int
+ lap->apm->setPhoneState((int) state);
}
/* indicate a change in ringer mode */
static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
uint32_t mask)
{
- struct legacy_audio_policy *lap = to_lap(pol);
- lap->apm->setRingerMode(mode, mask);
+ // deprecated, never called
}
/* force using a specific device category for the specified usage */
@@ -136,15 +136,15 @@ static int ap_init_check(const struct audio_policy *pol)
static audio_io_handle_t ap_get_output(struct audio_policy *pol,
audio_stream_type_t stream,
uint32_t sampling_rate,
- uint32_t format,
+ audio_format_t format,
uint32_t channels,
audio_policy_output_flags_t flags)
{
struct legacy_audio_policy *lap = to_lap(pol);
- LOGV("%s: tid %d", __func__, gettid());
+ ALOGV("%s: tid %d", __func__, gettid());
return lap->apm->getOutput((AudioSystem::stream_type)stream,
- sampling_rate, format, channels,
+ sampling_rate, (int) format, channels,
(AudioSystem::output_flags)flags);
}
@@ -171,14 +171,14 @@ static void ap_release_output(struct audio_policy *pol,
lap->apm->releaseOutput(output);
}
-static audio_io_handle_t ap_get_input(struct audio_policy *pol, int inputSource,
+static audio_io_handle_t ap_get_input(struct audio_policy *pol, audio_source_t inputSource,
uint32_t sampling_rate,
- uint32_t format,
+ audio_format_t format,
uint32_t channels,
audio_in_acoustics_t acoustics)
{
struct legacy_audio_policy *lap = to_lap(pol);
- return lap->apm->getInput(inputSource, sampling_rate, format, channels,
+ return lap->apm->getInput((int) inputSource, sampling_rate, (int) format, channels,
(AudioSystem::audio_in_acoustics)acoustics);
}
@@ -215,7 +215,8 @@ static int ap_set_stream_volume_index(struct audio_policy *pol,
{
struct legacy_audio_policy *lap = to_lap(pol);
return lap->apm->setStreamVolumeIndex((AudioSystem::stream_type)stream,
- index);
+ index,
+ AUDIO_DEVICE_OUT_DEFAULT);
}
static int ap_get_stream_volume_index(const struct audio_policy *pol,
@@ -224,7 +225,30 @@ static int ap_get_stream_volume_index(const struct audio_policy *pol,
{
const struct legacy_audio_policy *lap = to_clap(pol);
return lap->apm->getStreamVolumeIndex((AudioSystem::stream_type)stream,
- index);
+ index,
+ AUDIO_DEVICE_OUT_DEFAULT);
+}
+
+static int ap_set_stream_volume_index_for_device(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int index,
+ audio_devices_t device)
+{
+ struct legacy_audio_policy *lap = to_lap(pol);
+ return lap->apm->setStreamVolumeIndex((AudioSystem::stream_type)stream,
+ index,
+ device);
+}
+
+static int ap_get_stream_volume_index_for_device(const struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int *index,
+ audio_devices_t device)
+{
+ const struct legacy_audio_policy *lap = to_clap(pol);
+ return lap->apm->getStreamVolumeIndex((AudioSystem::stream_type)stream,
+ index,
+ device);
}
static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
@@ -234,7 +258,7 @@ static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
return lap->apm->getStrategyForStream((AudioSystem::stream_type)stream);
}
-static uint32_t ap_get_devices_for_stream(const struct audio_policy *pol,
+static audio_devices_t ap_get_devices_for_stream(const struct audio_policy *pol,
audio_stream_type_t stream)
{
const struct legacy_audio_policy *lap = to_clap(pol);
@@ -271,11 +295,11 @@ static int ap_set_effect_enabled(struct audio_policy *pol, int id, bool enabled)
return lap->apm->setEffectEnabled(id, enabled);
}
-static bool ap_is_stream_active(const struct audio_policy *pol, int stream,
+static bool ap_is_stream_active(const struct audio_policy *pol, audio_stream_type_t stream,
uint32_t in_past_ms)
{
const struct legacy_audio_policy *lap = to_clap(pol);
- return lap->apm->isStreamActive(stream, in_past_ms);
+ return lap->apm->isStreamActive((int) stream, in_past_ms);
}
static int ap_dump(const struct audio_policy *pol, int fd)
@@ -319,6 +343,8 @@ static int create_legacy_ap(const struct audio_policy_device *device,
lap->policy.init_stream_volume = ap_init_stream_volume;
lap->policy.set_stream_volume_index = ap_set_stream_volume_index;
lap->policy.get_stream_volume_index = ap_get_stream_volume_index;
+ lap->policy.set_stream_volume_index_for_device = ap_set_stream_volume_index_for_device;
+ lap->policy.get_stream_volume_index_for_device = ap_get_stream_volume_index_for_device;
lap->policy.get_strategy_for_stream = ap_get_strategy_for_stream;
lap->policy.get_devices_for_stream = ap_get_devices_for_stream;
lap->policy.get_output_for_effect = ap_get_output_for_effect;
diff --git a/include/hardware_legacy/AudioHardwareInterface.h b/include/hardware_legacy/AudioHardwareInterface.h
index 87f933c..b466000 100644
--- a/include/hardware_legacy/AudioHardwareInterface.h
+++ b/include/hardware_legacy/AudioHardwareInterface.h
@@ -56,7 +56,7 @@ public:
virtual size_t bufferSize() const = 0;
/**
- * returns the output channel nask
+ * returns the output channel mask
*/
virtual uint32_t channels() const = 0;
@@ -173,7 +173,7 @@ public:
virtual String8 getParameters(const String8& keys) = 0;
- // Return the amount of input frames lost in the audio driver since the last call of this function.
+ // Return the number of input frames lost in the audio driver since the last call of this function.
// Audio driver is expected to reset the value to 0 and restart counting upon returning the current value by this function call.
// Such loss typically occurs when the user space process is blocked longer than the capacity of audio driver buffers.
// Unit: the number of input audio frames
@@ -251,6 +251,7 @@ public:
uint32_t *sampleRate=0,
status_t *status=0) = 0;
virtual void closeOutputStream(AudioStreamOut* out) = 0;
+
/** This method creates and opens the audio hardware input stream */
virtual AudioStreamIn* openInputStream(
uint32_t devices,
diff --git a/include/hardware_legacy/AudioPolicyInterface.h b/include/hardware_legacy/AudioPolicyInterface.h
index 1ee0e20..d703485 100644
--- a/include/hardware_legacy/AudioPolicyInterface.h
+++ b/include/hardware_legacy/AudioPolicyInterface.h
@@ -69,16 +69,14 @@ public:
virtual status_t setDeviceConnectionState(AudioSystem::audio_devices device,
AudioSystem::device_connection_state state,
const char *device_address) = 0;
- // retreive a device connection status
+ // retrieve a device connection status
virtual AudioSystem::device_connection_state getDeviceConnectionState(AudioSystem::audio_devices device,
const char *device_address) = 0;
// indicate a change in phone state. Valid phones states are defined by AudioSystem::audio_mode
virtual void setPhoneState(int state) = 0;
- // indicate a change in ringer mode
- virtual void setRingerMode(uint32_t mode, uint32_t mask) = 0;
// force using a specific device category for the specified usage
virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config) = 0;
- // retreive current device category forced for a given usage
+ // retrieve current device category forced for a given usage
virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage) = 0;
// set a system property (e.g. camera sound always audible)
virtual void setSystemProperty(const char* property, const char* value) = 0;
@@ -89,7 +87,7 @@ public:
// Audio routing query functions
//
- // request an output appriate for playback of the supplied stream type and parameters
+ // request an output appropriate for playback of the supplied stream type and parameters
virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream,
uint32_t samplingRate = 0,
uint32_t format = AudioSystem::FORMAT_DEFAULT,
@@ -106,7 +104,7 @@ public:
// releases the output.
virtual void releaseOutput(audio_io_handle_t output) = 0;
- // request an input appriate for record from the supplied device with supplied parameters.
+ // request an input appropriate for record from the supplied device with supplied parameters.
virtual audio_io_handle_t getInput(int inputSource,
uint32_t samplingRate = 0,
uint32_t Format = AudioSystem::FORMAT_DEFAULT,
@@ -128,16 +126,25 @@ public:
int indexMin,
int indexMax) = 0;
- // sets the new stream volume at a level corresponding to the supplied index
- virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index) = 0;
- // retreive current volume index for the specified stream
- virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int *index) = 0;
+ // sets the new stream volume at a level corresponding to the supplied index for the
+ // supplied device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT means
+ // setting volume for all devices
+ virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream,
+ int index,
+ audio_devices_t device) = 0;
+
+ // retrieve current volume index for the specified stream and the
+ // specified device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT means
+ // querying the volume of the active device.
+ virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream,
+ int *index,
+ audio_devices_t device) = 0;
// return the strategy corresponding to a given stream type
virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream) = 0;
// return the enabled output devices for the given stream type
- virtual uint32_t getDevicesForStream(AudioSystem::stream_type stream) = 0;
+ virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream) = 0;
// Audio effect management
virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc) = 0;
@@ -196,7 +203,7 @@ public:
uint32_t *pSamplingRate,
uint32_t *pFormat,
uint32_t *pChannels,
- uint32_t acoustics) = 0;
+ audio_in_acoustics_t acoustics) = 0;
// closes an audio input
virtual status_t closeInput(audio_io_handle_t input) = 0;
//
diff --git a/include/hardware_legacy/AudioPolicyManagerBase.h b/include/hardware_legacy/AudioPolicyManagerBase.h
index d864b0a..1459e7e 100644
--- a/include/hardware_legacy/AudioPolicyManagerBase.h
+++ b/include/hardware_legacy/AudioPolicyManagerBase.h
@@ -20,11 +20,14 @@
#include <utils/Timers.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
+#include <utils/SortedVector.h>
#include <hardware_legacy/AudioPolicyInterface.h>
namespace android_audio_legacy {
using android::KeyedVector;
+ using android::DefaultKeyedVector;
+ using android::SortedVector;
// ----------------------------------------------------------------------------
@@ -53,6 +56,20 @@ namespace android_audio_legacy {
// and provided in a shared library libaudiopolicy.so.
// ----------------------------------------------------------------------------
+// the output_profile_s structure describes the capabilities of an output stream.
+// It is currently assumed that all combination of listed parameters are supported.
+// It is used by the policy manager to determine if an output is suitable for a given use case,
+// open/close it accordingly and connect/disconnect audio tracks to/from it.
+typedef struct output_profile_s {
+ uint32_t* mSamplingRates; // supported sampling rates (terminated by 0)
+ audio_channel_mask_t* mChannelMasks; // supported channel masks (terminated by 0)
+ audio_format_t* mFormats; // supported audio formats (terminated by 0)
+ audio_devices_t mSupportedDevices; // supported devices (devices this output can be
+ // routed to)
+ audio_policy_output_flags_t mFlags; // attribute flags (e.g primary output,
+ // direct output...)
+} output_profile_t;
+
class AudioPolicyManagerBase: public AudioPolicyInterface
#ifdef AUDIO_POLICY_TEST
, public Thread
@@ -70,7 +87,6 @@ public:
virtual AudioSystem::device_connection_state getDeviceConnectionState(AudioSystem::audio_devices device,
const char *device_address);
virtual void setPhoneState(int state);
- virtual void setRingerMode(uint32_t mode, uint32_t mask);
virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config);
virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage);
virtual void setSystemProperty(const char* property, const char* value);
@@ -93,22 +109,28 @@ public:
uint32_t format,
uint32_t channels,
AudioSystem::audio_in_acoustics acoustics);
+
// indicates to the audio policy manager that the input starts being used.
virtual status_t startInput(audio_io_handle_t input);
+
// indicates to the audio policy manager that the input stops being used.
virtual status_t stopInput(audio_io_handle_t input);
virtual void releaseInput(audio_io_handle_t input);
virtual void initStreamVolume(AudioSystem::stream_type stream,
int indexMin,
int indexMax);
- virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index);
- virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int *index);
+ virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream,
+ int index,
+ audio_devices_t device);
+ virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream,
+ int *index,
+ audio_devices_t device);
// return the strategy corresponding to a given stream type
virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream);
// return the enabled output devices for the given stream type
- virtual uint32_t getDevicesForStream(AudioSystem::stream_type stream);
+ virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream);
virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
virtual status_t registerEffect(effect_descriptor_t *desc,
@@ -130,6 +152,7 @@ protected:
STRATEGY_PHONE,
STRATEGY_SONIFICATION,
STRATEGY_DTMF,
+ STRATEGY_ENFORCED_AUDIBLE,
NUM_STRATEGIES
};
@@ -170,16 +193,17 @@ protected:
class AudioOutputDescriptor
{
public:
- AudioOutputDescriptor();
+ AudioOutputDescriptor(const output_profile_t *profile);
status_t dump(int fd);
- uint32_t device();
+ audio_devices_t device();
void changeRefCount(AudioSystem::stream_type, int delta);
uint32_t refCount();
uint32_t strategyRefCount(routing_strategy strategy);
bool isUsedByStrategy(routing_strategy strategy) { return (strategyRefCount(strategy) != 0);}
bool isDuplicated() { return (mOutput1 != NULL && mOutput2 != NULL); }
+ audio_devices_t supportedDevices();
audio_io_handle_t mId; // output handle
uint32_t mSamplingRate; //
@@ -187,13 +211,14 @@ protected:
uint32_t mChannels; // output configuration
uint32_t mLatency; //
AudioSystem::output_flags mFlags; //
- uint32_t mDevice; // current device this output is routed to
+ audio_devices_t mDevice; // current device this output is routed to
uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using this output
nsecs_t mStopTime[AudioSystem::NUM_STREAM_TYPES];
AudioOutputDescriptor *mOutput1; // used by duplicated outputs: first output
AudioOutputDescriptor *mOutput2; // used by duplicated outputs: second output
float mCurVolume[AudioSystem::NUM_STREAM_TYPES]; // current stream volume
int mMuteCount[AudioSystem::NUM_STREAM_TYPES]; // mute request counter
+ const output_profile_t *mProfile;
};
// descriptor for audio inputs. Used to maintain current configuration of each opened audio input
@@ -209,23 +234,23 @@ protected:
uint32_t mFormat; // input configuration
uint32_t mChannels; //
AudioSystem::audio_in_acoustics mAcoustics; //
- uint32_t mDevice; // current device this input is routed to
+ audio_devices_t mDevice; // current device this input is routed to
uint32_t mRefCount; // number of AudioRecord clients using this output
- int mInputSource; // input source selected by application (mediarecorder.h)
+ int mInputSource; // input source selected by application (mediarecorder.h)
};
// stream descriptor used for volume control
class StreamDescriptor
{
public:
- StreamDescriptor()
- : mIndexMin(0), mIndexMax(1), mIndexCur(1), mCanBeMuted(true) {}
+ StreamDescriptor();
- void dump(char* buffer, size_t size);
+ int getVolumeIndex(audio_devices_t device);
+ void dump(int fd);
int mIndexMin; // min volume index
int mIndexMax; // max volume index
- int mIndexCur; // current volume index
+ KeyedVector<audio_devices_t, int> mIndexCur; // current volume index per device
bool mCanBeMuted; // true is the stream can be muted
const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT];
@@ -249,6 +274,7 @@ protected:
// return the strategy corresponding to a given stream type
static routing_strategy getStrategy(AudioSystem::stream_type stream);
+
// return appropriate device for streams handled by the specified strategy according to current
// phone state, connected devices...
// if fromCache is true, the device is returned from mDeviceForStrategy[], otherwise it is determined
@@ -259,65 +285,93 @@ protected:
// "future" device selection (fromCache == false) when called from a context
// where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
// before updateDeviceForStrategy() is called.
- virtual uint32_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true);
+ virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true);
+
// change the route of the specified output
- void setOutputDevice(audio_io_handle_t output, uint32_t device, bool force = false, int delayMs = 0);
+ void setOutputDevice(audio_io_handle_t output,
+ audio_devices_t device,
+ bool force = false,
+ int delayMs = 0);
+
// select input device corresponding to requested audio source
- virtual uint32_t getDeviceForInputSource(int inputSource);
+ virtual audio_devices_t getDeviceForInputSource(int inputSource);
+
// return io handle of active input or 0 if no input is active
audio_io_handle_t getActiveInput();
+
// initialize volume curves for each strategy and device category
void initializeVolumeCurves();
+
// compute the actual volume for a given stream according to the requested index and a particular
// device
- virtual float computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device);
+ virtual float computeVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device);
+
// check that volume change is permitted, compute and send new volume to audio hardware
- status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs = 0, bool force = false);
+ status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
+
// apply all stream volumes to the specified output and device
- void applyStreamVolumes(audio_io_handle_t output, uint32_t device, int delayMs = 0, bool force = false);
+ void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
+
// Mute or unmute all streams handled by the specified strategy on the specified output
void setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output, int delayMs = 0);
+
// Mute or unmute the stream on the specified output
void setStreamMute(int stream, bool on, audio_io_handle_t output, int delayMs = 0);
+
// handle special cases for sonification strategy while in call: mute streams or replace by
// a special tone in the device used for communication
void handleIncallSonification(int stream, bool starting, bool stateChange);
+
// true is current platform implements a back microphone
virtual bool hasBackMicrophone() const { return false; }
+
// true if device is in a telephony or VoIP call
virtual bool isInCall();
+
// true if given state represents a device in a telephony or VoIP call
virtual bool isStateInCall(int state);
-#ifdef WITH_A2DP
- // true is current platform supports suplication of notifications and ringtones over A2DP output
- virtual bool a2dpUsedForSonification() const { return true; }
- status_t handleA2dpConnection(AudioSystem::audio_devices device,
- const char *device_address);
- status_t handleA2dpDisconnection(AudioSystem::audio_devices device,
- const char *device_address);
- void closeA2dpOutputs();
- // checks and if necessary changes output (a2dp, duplicated or hardware) used for all strategies.
- // must be called every time a condition that affects the output choice for a given strategy is
- // changed: connected device, phone state, force use...
+ // when a device is connected, checks if an open output can be routed
+ // to this device. If none is open, tries to open one of the available outputs.
+ // Returns an output suitable to this device or 0.
+ // when a device is disconnected, checks if an output is not used any more and
+ // returns its handle if any.
+ // transfers the audio tracks and effects from one output thread to another accordingly.
+ audio_io_handle_t checkOutputForDevice(audio_devices_t device,
+ AudioSystem::device_connection_state state);
+
+ // close an output and its companion duplicating output.
+ void closeOutput(audio_io_handle_t output);
+
+ // checks and if necessary changes outputs used for all strategies.
+ // must be called every time a condition that affects the output choice for a given strategy
+ // changes: connected device, phone state, force use...
// Must be called before updateDeviceForStrategy()
void checkOutputForStrategy(routing_strategy strategy);
+
// Same as checkOutputForStrategy() but for a all strategies in order of priority
void checkOutputForAllStrategies();
+
// manages A2DP output suspend/restore according to phone state and BT SCO usage
void checkA2dpSuspend();
-#endif
+
+ // returns the A2DP output handle if it is open or 0 otherwise
+ audio_io_handle_t getA2dpOutput();
+
// selects the most appropriate device on output for current state
// must be called every time a condition that affects the device choice for a given output is
// changed: connected device, phone state, force use, output start, output stop..
// see getDeviceForStrategy() for the use of fromCache parameter
- uint32_t getNewDevice(audio_io_handle_t output, bool fromCache = true);
+
+ audio_devices_t getNewDevice(audio_io_handle_t output, bool fromCache = true);
// updates cache of device used by all strategies (mDeviceForStrategy[])
// must be called every time a condition that affects the device choice for a given strategy is
// changed: connected device, phone state, force use...
// cached values are used by getDeviceForStrategy() if parameter fromCache is true.
// Must be called after checkOutputForAllStrategies()
+
void updateDeviceForStrategy();
+
// true if current platform requires a specific output to be opened for this particular
// set of parameters. This function is called by getOutput() and is implemented by platform
// specific audio policy manager.
@@ -327,6 +381,7 @@ protected:
uint32_t channels,
AudioSystem::output_flags flags,
uint32_t device);
+
virtual uint32_t getMaxEffectsCpuLoad();
virtual uint32_t getMaxEffectsMemory();
#ifdef AUDIO_POLICY_TEST
@@ -338,26 +393,29 @@ protected:
status_t setEffectEnabled(EffectDescriptor *pDesc, bool enabled);
// returns the category the device belongs to with regard to volume curve management
- static device_category getDeviceCategory(uint32_t device);
+ static device_category getDeviceCategory(audio_devices_t device);
- AudioPolicyClientInterface *mpClientInterface; // audio policy client interface
- audio_io_handle_t mHardwareOutput; // hardware output handler
- audio_io_handle_t mA2dpOutput; // A2DP output handler
- audio_io_handle_t mDuplicatedOutput; // duplicated output handler: outputs to hardware and A2DP.
+ // extract one device relevant for volume control from multiple device selection
+ static audio_devices_t getDeviceForVolume(audio_devices_t device);
+
+ SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device);
+ bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
+ SortedVector<audio_io_handle_t>& outputs2);
- KeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mOutputs; // list of output descriptors
- KeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs; // list of input descriptors
- uint32_t mAvailableOutputDevices; // bit field of all available output devices
+ AudioPolicyClientInterface *mpClientInterface; // audio policy client interface
+ audio_io_handle_t mPrimaryOutput; // primary output handle
+ DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mOutputs; // list of output descriptors
+ DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs; // list of input descriptors
+ audio_devices_t mAvailableOutputDevices; // bit field of all available output devices
uint32_t mAvailableInputDevices; // bit field of all available input devices
int mPhoneState; // current phone state
- uint32_t mRingerMode; // current ringer mode
AudioSystem::forced_config mForceUse[AudioSystem::NUM_FORCE_USE]; // current forced use configuration
StreamDescriptor mStreams[AudioSystem::NUM_STREAM_TYPES]; // stream descriptors for volume control
String8 mA2dpDeviceAddress; // A2DP device MAC address
String8 mScoDeviceAddress; // SCO device MAC address
bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected
- uint32_t mDeviceForStrategy[NUM_STRATEGIES];
+ audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
float mLastVoiceVolume; // last voice volume value sent to audio HAL
// Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
@@ -385,7 +443,7 @@ protected:
#endif //AUDIO_POLICY_TEST
private:
- static float volIndexToAmpl(uint32_t device, const StreamDescriptor& streamDesc,
+ static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
int indexInUi);
};
diff --git a/include/hardware_legacy/AudioSystemLegacy.h b/include/hardware_legacy/AudioSystemLegacy.h
index 4b78f58..6d90896 100644
--- a/include/hardware_legacy/AudioSystemLegacy.h
+++ b/include/hardware_legacy/AudioSystemLegacy.h
@@ -332,10 +332,10 @@ public:
return audio_is_low_visibility((audio_stream_type_t)stream);
}
static bool isValidFormat(uint32_t format) {
- return audio_is_valid_format(format);
+ return audio_is_valid_format((audio_format_t) format);
}
static bool isLinearPCM(uint32_t format) {
- return audio_is_linear_pcm(format);
+ return audio_is_linear_pcm((audio_format_t) format);
}
static bool isOutputChannel(uint32_t channel) {
return audio_is_output_channel(channel);
diff --git a/include/hardware_legacy/power.h b/include/hardware_legacy/power.h
index b7cee43..26d04b2 100644
--- a/include/hardware_legacy/power.h
+++ b/include/hardware_legacy/power.h
@@ -33,9 +33,6 @@ enum {
int acquire_wake_lock(int lock, const char* id);
int release_wake_lock(const char* id);
-// true if you want the screen on, false if you want it off
-int set_screen_state(int on);
-
// set how long to stay awake after the last user activity in seconds
int set_last_user_activity_timeout(int64_t delay);
diff --git a/include/hardware_legacy/wifi.h b/include/hardware_legacy/wifi.h
index 4166a6d..4d051e7 100644
--- a/include/hardware_legacy/wifi.h
+++ b/include/hardware_legacy/wifi.h
@@ -48,14 +48,7 @@ int is_wifi_driver_loaded();
*
* @return 0 on success, < 0 on failure.
*/
-int wifi_start_supplicant();
-
-/**
- * Start supplicant for p2p operation.
- *
- * @return 0 on success, < 0 on failure.
- */
-int wifi_start_p2p_supplicant();
+int wifi_start_supplicant(int p2pSupported);
/**
* Stop supplicant.
@@ -65,24 +58,25 @@ int wifi_start_p2p_supplicant();
int wifi_stop_supplicant();
/**
- * Open a connection to supplicant.
+ * Open a connection to supplicant on interface
*
* @return 0 on success, < 0 on failure.
*/
-int wifi_connect_to_supplicant();
+int wifi_connect_to_supplicant(const char *ifname);
/**
- * Close connection supplicant.
+ * Close connection to supplicant on interface
*
* @return 0 on success, < 0 on failure.
*/
-void wifi_close_supplicant_connection();
+void wifi_close_supplicant_connection(const char *ifname);
/**
* wifi_wait_for_event() performs a blocking call to
* get a Wi-Fi event and returns a string representing
* a Wi-Fi event when it occurs.
*
+ * @param iface is the interface on which event is received
* @param buf is the buffer that receives the event
* @param len is the maximum length of the buffer
*
@@ -90,61 +84,19 @@ void wifi_close_supplicant_connection();
* event (for instance, no connection), and less than 0
* if there is an error.
*/
-int wifi_wait_for_event(char *buf, size_t len);
+int wifi_wait_for_event(const char *iface, char *buf, size_t len);
/**
* wifi_command() issues a command to the Wi-Fi driver.
*
- * Android extends the standard commands listed at
- * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html
+ * Android extends the standard commands listed at
+ * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html
* to include support for sending commands to the driver:
*
- * <table border="2" cellspacing="2" cellpadding="2">
- * <tr>
- * <td><strong>Command / Command summary</strong></td>
- * <td><strong>Form of Response</strong></td>
- * <td><strong>Processing</strong></td>
- * </tr>
- * <tr>
- * <td>DRIVER START<BR>&nbsp;&nbsp;Turn on Wi-Fi Hardware</td>
- * <td>OK if successful</td>
- * <td>OK ? true : false</td>
- * </tr>
- * <tr>
- * <td>DRIVER STOP<BR>&nbsp;&nbsp;Turn off Wi-Fi hardware</td>
- * <td>OK if successful</td>
- * <td>OK ? true : false</td>
- * </tr>
- * <tr>
- * <td>DRIVER RSSI<BR>&nbsp;&nbsp;Return received signal strength indicator in -db for current AP</td>
- * <td>&lt;ssid&gt; Rssi xx</td>
- * <td>%*s %*s %d", &rssi</td>
- * </tr>
- * <tr>
- * <td>DRIVER LINKSPEED<BR>&nbsp;&nbsp;Return link speed in MBPS</td>
- * <td>LinkSpeed xx</td>
- * <td>%*s %d", &linkspd</td>
- * </tr>
- * <tr>
- * <td>DRIVER MACADDR<BR>&nbsp;&nbsp;Return mac address of the station</td>
- * <td>Macaddr = xx.xx.xx.xx.xx.xx</td>
- * <td>"%*s = %s", &macadr</td>
- * </tr>
- * <tr>
- * <td>DRIVER SCAN-ACTIVE<BR>&nbsp;&nbsp;Set scan type to active</td>
- * <td>"OK" if successful</td>
- * <td>"OK" ? true : false</td>
- * </tr>
- * <tr>
- * <td>DRIVER SCAN-PASSIVE<BR>&nbsp;&nbsp;Set scan type to passive</td>
- * <td>"OK" if successful</td>
- * <td>"OK" ? true : false</td>
- * </tr>
- * </table>
- *
- * See libs/android_runtime/android_net_wifi_Wifi.cpp for more information
- * describing how these and other commands are invoked.
+ * See wifi/java/android/net/wifi/WifiNative.java for the details of
+ * driver commands that are supported
*
+ * @param iface is the interface on which command is sent
* @param command is the string command
* @param reply is a buffer to receive a reply string
* @param reply_len on entry, this is the maximum length of
@@ -153,7 +105,7 @@ int wifi_wait_for_event(char *buf, size_t len);
*
* @return 0 if successful, < 0 if an error.
*/
-int wifi_command(const char *command, char *reply, size_t *reply_len);
+int wifi_command(const char *iface, const char *command, char *reply, size_t *reply_len);
/**
* do_dhcp_request() issues a dhcp request and returns the acquired
diff --git a/power/Android.mk b/power/Android.mk
index a524d0e..3e3ff5d 100644
--- a/power/Android.mk
+++ b/power/Android.mk
@@ -1,8 +1,3 @@
# Copyright 2006 The Android Open Source Project
LOCAL_SRC_FILES += power/power.c
-
-ifeq ($(QEMU_HARDWARE),true)
- LOCAL_SRC_FILES += power/power_qemu.c
- LOCAL_CFLAGS += -DQEMU_POWER=1
-endif
diff --git a/power/power.c b/power/power.c
index 927d75a..c4fa370 100644
--- a/power/power.c
+++ b/power/power.c
@@ -30,28 +30,20 @@
#define LOG_TAG "power"
#include <utils/Log.h>
-#include "qemu.h"
-#ifdef QEMU_POWER
-#include "power_qemu.h"
-#endif
-
enum {
ACQUIRE_PARTIAL_WAKE_LOCK = 0,
RELEASE_WAKE_LOCK,
- REQUEST_STATE,
OUR_FD_COUNT
};
const char * const OLD_PATHS[] = {
"/sys/android_power/acquire_partial_wake_lock",
"/sys/android_power/release_wake_lock",
- "/sys/android_power/request_state"
};
const char * const NEW_PATHS[] = {
"/sys/power/wake_lock",
"/sys/power/wake_unlock",
- "/sys/power/state"
};
const char * const AUTO_OFF_TIMEOUT_DEV = "/sys/android_power/auto_off_timeout";
@@ -61,9 +53,6 @@ static int g_initialized = 0;
static int g_fds[OUR_FD_COUNT];
static int g_error = 1;
-static const char *off_state = "mem";
-static const char *on_state = "on";
-
static int64_t systemTime()
{
struct timespec t;
@@ -97,11 +86,8 @@ initialize_fds(void)
//pthread_once(&g_initialized, open_file_descriptors);
// XXX: not this:
if (g_initialized == 0) {
- if(open_file_descriptors(NEW_PATHS) < 0) {
+ if(open_file_descriptors(NEW_PATHS) < 0)
open_file_descriptors(OLD_PATHS);
- on_state = "wake";
- off_state = "standby";
- }
g_initialized = 1;
}
}
@@ -111,7 +97,7 @@ acquire_wake_lock(int lock, const char* id)
{
initialize_fds();
-// LOGI("acquire_wake_lock lock=%d id='%s'\n", lock, id);
+// ALOGI("acquire_wake_lock lock=%d id='%s'\n", lock, id);
if (g_error) return g_error;
@@ -132,7 +118,7 @@ release_wake_lock(const char* id)
{
initialize_fds();
-// LOGI("release_wake_lock id='%s'\n", id);
+// ALOGI("release_wake_lock id='%s'\n", id);
if (g_error) return g_error;
@@ -143,7 +129,7 @@ release_wake_lock(const char* id)
int
set_last_user_activity_timeout(int64_t delay)
{
-// LOGI("set_last_user_activity_timeout delay=%d\n", ((int)(delay)));
+// ALOGI("set_last_user_activity_timeout delay=%d\n", ((int)(delay)));
int fd = open(AUTO_OFF_TIMEOUT_DEV, O_RDWR);
if (fd >= 0) {
@@ -158,34 +144,3 @@ set_last_user_activity_timeout(int64_t delay)
return errno;
}
}
-
-int
-set_screen_state(int on)
-{
- QEMU_FALLBACK(set_screen_state(on));
-
- LOGI("*** set_screen_state %d", on);
-
- initialize_fds();
-
- //LOGI("go_to_sleep eventTime=%lld now=%lld g_error=%s\n", eventTime,
- // systemTime(), strerror(g_error));
-
- if (g_error)
- goto failure;
-
- char buf[32];
- int len;
- if(on)
- len = snprintf(buf, sizeof(buf), "%s", on_state);
- else
- len = snprintf(buf, sizeof(buf), "%s", off_state);
-
- buf[sizeof(buf) - 1] = '\0';
- len = write(g_fds[REQUEST_STATE], buf, len);
- if(len < 0) {
- failure:
- LOGE("Failed setting last user activity: g_error=%d\n", g_error);
- }
- return 0;
-}
diff --git a/power/power_qemu.c b/power/power_qemu.c
deleted file mode 100644
index 742276f..0000000
--- a/power/power_qemu.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "qemu.h"
-#include "power_qemu.h"
-#include <fcntl.h>
-#include <errno.h>
-#include <hardware_legacy/power.h>
-
-int
-qemu_set_screen_state(int on)
-{
- qemu_control_command( "power:screen_state:%s", on ? "wake" : "standby" );
- return 0;
-}
-
diff --git a/power/power_qemu.h b/power/power_qemu.h
deleted file mode 100644
index c689da3..0000000
--- a/power/power_qemu.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef _power_qemu_h
-#define _power_qemu_h
-
-#include <stdint.h>
-
-extern int
-qemu_set_screen_state(int on);
-
-#endif /* _power_qemu_h */
diff --git a/qemu/qemu.c b/qemu/qemu.c
index 731df78..739976f 100644
--- a/qemu/qemu.c
+++ b/qemu/qemu.c
@@ -31,7 +31,7 @@
#define QEMU_DEBUG 0
#if QEMU_DEBUG
-# define D(...) LOGD(__VA_ARGS__)
+# define D(...) ALOGD(__VA_ARGS__)
#else
# define D(...) ((void)0)
#endif
diff --git a/wifi/wifi.c b/wifi/wifi.c
index 37cbb1e..5a42e2d 100644
--- a/wifi/wifi.c
+++ b/wifi/wifi.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <dirent.h>
#include <sys/socket.h>
+#include <unistd.h>
#include <poll.h>
#include "hardware_legacy/wifi.h"
@@ -36,10 +37,21 @@
#include <sys/_system_properties.h>
#endif
-static struct wpa_ctrl *ctrl_conn;
-static struct wpa_ctrl *monitor_conn;
+/* PRIMARY refers to the connection on the primary interface
+ * SECONDARY refers to an optional connection on a p2p interface
+ *
+ * For concurrency, we only support one active p2p connection and
+ * one active STA connection at a time
+ */
+#define PRIMARY 0
+#define SECONDARY 1
+#define MAX_CONNS 2
+
+static struct wpa_ctrl *ctrl_conn[MAX_CONNS];
+static struct wpa_ctrl *monitor_conn[MAX_CONNS];
+
/* socket pair used to exit from a blocking read */
-static int exit_sockets[2] = { -1, -1 };
+static int exit_sockets[MAX_CONNS][2];
extern int do_dhcp();
extern int ifc_init();
@@ -49,7 +61,7 @@ extern void get_dhcp_info();
extern int init_module(void *, unsigned long, const char *);
extern int delete_module(const char *, unsigned int);
-static char iface[PROPERTY_VALUE_MAX];
+static char primary_iface[PROPERTY_VALUE_MAX];
// TODO: use new ANDROID_SOCKET mechanism, once support for multiple
// sockets is in
@@ -88,10 +100,12 @@ static const char FIRMWARE_LOADER[] = WIFI_FIRMWARE_LOADER;
static const char DRIVER_PROP_NAME[] = "wlan.driver.status";
static const char SUPPLICANT_NAME[] = "wpa_supplicant";
static const char SUPP_PROP_NAME[] = "init.svc.wpa_supplicant";
+static const char P2P_SUPPLICANT_NAME[] = "p2p_supplicant";
+static const char P2P_PROP_NAME[] = "init.svc.p2p_supplicant";
static const char SUPP_CONFIG_TEMPLATE[]= "/system/etc/wifi/wpa_supplicant.conf";
static const char SUPP_CONFIG_FILE[] = "/data/misc/wifi/wpa_supplicant.conf";
static const char P2P_CONFIG_FILE[] = "/data/misc/wifi/p2p_supplicant.conf";
-static const char CONTROL_IFACE_PATH[] = "/data/misc/wifi";
+static const char CONTROL_IFACE_PATH[] = "/data/misc/wifi/sockets";
static const char MODULE_FILE[] = "/proc/modules";
static const char SUPP_ENTROPY_FILE[] = WIFI_ENTROPY_FILE;
@@ -100,6 +114,21 @@ static unsigned char dummy_key[21] = { 0x02, 0x11, 0xbe, 0x33, 0x43, 0x35,
0x1c, 0xd3, 0xee, 0xff, 0xf1, 0xe2,
0xf3, 0xf4, 0xf5 };
+/* Is either SUPPLICANT_NAME or P2P_SUPPLICANT_NAME */
+static char supplicant_name[PROPERTY_VALUE_MAX];
+/* Is either SUPP_PROP_NAME or P2P_PROP_NAME */
+static char supplicant_prop_name[PROPERTY_KEY_MAX];
+
+static int is_primary_interface(const char *ifname)
+{
+ //Treat NULL as primary interface to allow control
+ //on STA without an interface
+ if (ifname == NULL || !strncmp(ifname, primary_iface, strlen(primary_iface))) {
+ return 1;
+ }
+ return 0;
+}
+
static int insmod(const char *filename, const char *args)
{
void *module;
@@ -131,7 +160,7 @@ static int rmmod(const char *modname)
}
if (ret != 0)
- LOGD("Unable to unload driver module \"%s\": %s\n",
+ ALOGD("Unable to unload driver module \"%s\": %s\n",
modname, strerror(errno));
return ret;
}
@@ -139,13 +168,13 @@ static int rmmod(const char *modname)
int do_dhcp_request(int *ipaddr, int *gateway, int *mask,
int *dns1, int *dns2, int *server, int *lease) {
/* For test driver, always report success */
- if (strcmp(iface, WIFI_TEST_INTERFACE) == 0)
+ if (strcmp(primary_iface, WIFI_TEST_INTERFACE) == 0)
return 0;
if (ifc_init() < 0)
return -1;
- if (do_dhcp(iface) < 0) {
+ if (do_dhcp(primary_iface) < 0) {
ifc_close();
return -1;
}
@@ -177,7 +206,7 @@ int is_wifi_driver_loaded() {
* crash.
*/
if ((proc = fopen(MODULE_FILE, "r")) == NULL) {
- LOGW("Could not open %s: %s", MODULE_FILE, strerror(errno));
+ ALOGW("Could not open %s: %s", MODULE_FILE, strerror(errno));
property_set(DRIVER_PROP_NAME, "unloaded");
return 0;
}
@@ -269,19 +298,19 @@ int ensure_entropy_file_exists()
if ((ret == 0) || (errno == EACCES)) {
if ((ret != 0) &&
(chmod(SUPP_ENTROPY_FILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) {
- LOGE("Cannot set RW to \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
+ ALOGE("Cannot set RW to \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
return -1;
}
return 0;
}
- destfd = open(SUPP_ENTROPY_FILE, O_CREAT|O_RDWR, 0660);
+ destfd = TEMP_FAILURE_RETRY(open(SUPP_ENTROPY_FILE, O_CREAT|O_RDWR, 0660));
if (destfd < 0) {
- LOGE("Cannot create \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
+ ALOGE("Cannot create \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
return -1;
}
- if (write(destfd, dummy_key, sizeof(dummy_key)) != sizeof(dummy_key)) {
- LOGE("Error writing \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
+ if (TEMP_FAILURE_RETRY(write(destfd, dummy_key, sizeof(dummy_key))) != sizeof(dummy_key)) {
+ ALOGE("Error writing \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
close(destfd);
return -1;
}
@@ -289,14 +318,14 @@ int ensure_entropy_file_exists()
/* chmod is needed because open() didn't set permisions properly */
if (chmod(SUPP_ENTROPY_FILE, 0660) < 0) {
- LOGE("Error changing permissions of %s to 0660: %s",
+ ALOGE("Error changing permissions of %s to 0660: %s",
SUPP_ENTROPY_FILE, strerror(errno));
unlink(SUPP_ENTROPY_FILE);
return -1;
}
if (chown(SUPP_ENTROPY_FILE, AID_SYSTEM, AID_WIFI) < 0) {
- LOGE("Error changing group ownership of %s to %d: %s",
+ ALOGE("Error changing group ownership of %s to %d: %s",
SUPP_ENTROPY_FILE, AID_WIFI, strerror(errno));
unlink(SUPP_ENTROPY_FILE);
return -1;
@@ -319,16 +348,16 @@ int update_ctrl_interface(const char *config_file) {
pbuf = malloc(sb.st_size + PROPERTY_VALUE_MAX);
if (!pbuf)
return 0;
- srcfd = open(config_file, O_RDONLY);
+ srcfd = TEMP_FAILURE_RETRY(open(config_file, O_RDONLY));
if (srcfd < 0) {
- LOGE("Cannot open \"%s\": %s", config_file, strerror(errno));
+ ALOGE("Cannot open \"%s\": %s", config_file, strerror(errno));
free(pbuf);
return 0;
}
- nread = read(srcfd, pbuf, sb.st_size);
+ nread = TEMP_FAILURE_RETRY(read(srcfd, pbuf, sb.st_size));
close(srcfd);
if (nread < 0) {
- LOGE("Cannot read \"%s\": %s", config_file, strerror(errno));
+ ALOGE("Cannot read \"%s\": %s", config_file, strerror(errno));
free(pbuf);
return 0;
}
@@ -344,20 +373,20 @@ int update_ctrl_interface(const char *config_file) {
int mlen = strlen(ifc);
int nwrite;
if (strncmp(ifc, iptr, mlen) != 0) {
- LOGE("ctrl_interface != %s", ifc);
+ ALOGE("ctrl_interface != %s", ifc);
while (((ilen + (iptr - pbuf)) < nread) && (iptr[ilen] != '\n'))
ilen++;
mlen = ((ilen >= mlen) ? ilen : mlen) + 1;
memmove(iptr + mlen, iptr + ilen + 1, nread - (iptr + ilen + 1 - pbuf));
memset(iptr, '\n', mlen);
memcpy(iptr, ifc, strlen(ifc));
- destfd = open(config_file, O_RDWR, 0660);
+ destfd = TEMP_FAILURE_RETRY(open(config_file, O_RDWR, 0660));
if (destfd < 0) {
- LOGE("Cannot update \"%s\": %s", config_file, strerror(errno));
+ ALOGE("Cannot update \"%s\": %s", config_file, strerror(errno));
free(pbuf);
return -1;
}
- write(destfd, pbuf, nread + mlen - ilen -1);
+ TEMP_FAILURE_RETRY(write(destfd, pbuf, nread + mlen - ilen -1));
close(destfd);
}
}
@@ -377,7 +406,7 @@ int ensure_config_file_exists(const char *config_file)
if ((ret == 0) || (errno == EACCES)) {
if ((ret != 0) &&
(chmod(config_file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) {
- LOGE("Cannot set RW to \"%s\": %s", config_file, strerror(errno));
+ ALOGE("Cannot set RW to \"%s\": %s", config_file, strerror(errno));
return -1;
}
/* return if filesize is at least 10 bytes */
@@ -385,32 +414,32 @@ int ensure_config_file_exists(const char *config_file)
return update_ctrl_interface(config_file);
}
} else if (errno != ENOENT) {
- LOGE("Cannot access \"%s\": %s", config_file, strerror(errno));
+ ALOGE("Cannot access \"%s\": %s", config_file, strerror(errno));
return -1;
}
- srcfd = open(SUPP_CONFIG_TEMPLATE, O_RDONLY);
+ srcfd = TEMP_FAILURE_RETRY(open(SUPP_CONFIG_TEMPLATE, O_RDONLY));
if (srcfd < 0) {
- LOGE("Cannot open \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
+ ALOGE("Cannot open \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
return -1;
}
- destfd = open(config_file, O_CREAT|O_RDWR, 0660);
+ destfd = TEMP_FAILURE_RETRY(open(config_file, O_CREAT|O_RDWR, 0660));
if (destfd < 0) {
close(srcfd);
- LOGE("Cannot create \"%s\": %s", config_file, strerror(errno));
+ ALOGE("Cannot create \"%s\": %s", config_file, strerror(errno));
return -1;
}
- while ((nread = read(srcfd, buf, sizeof(buf))) != 0) {
+ while ((nread = TEMP_FAILURE_RETRY(read(srcfd, buf, sizeof(buf)))) != 0) {
if (nread < 0) {
- LOGE("Error reading \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
+ ALOGE("Error reading \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
close(srcfd);
close(destfd);
unlink(config_file);
return -1;
}
- write(destfd, buf, nread);
+ TEMP_FAILURE_RETRY(write(destfd, buf, nread));
}
close(destfd);
@@ -418,14 +447,14 @@ int ensure_config_file_exists(const char *config_file)
/* chmod is needed because open() didn't set permisions properly */
if (chmod(config_file, 0660) < 0) {
- LOGE("Error changing permissions of %s to 0660: %s",
+ ALOGE("Error changing permissions of %s to 0660: %s",
config_file, strerror(errno));
unlink(config_file);
return -1;
}
if (chown(config_file, AID_SYSTEM, AID_WIFI) < 0) {
- LOGE("Error changing group ownership of %s to %d: %s",
+ ALOGE("Error changing group ownership of %s to %d: %s",
config_file, AID_WIFI, strerror(errno));
unlink(config_file);
return -1;
@@ -472,35 +501,54 @@ void wifi_wpa_ctrl_cleanup(void)
closedir(dir);
}
-int wifi_start_supplicant_common(const char *config_file)
+int wifi_start_supplicant(int p2p_supported)
{
- char daemon_cmd[PROPERTY_VALUE_MAX];
char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
int count = 200; /* wait at most 20 seconds for completion */
#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
const prop_info *pi;
- unsigned serial = 0;
+ unsigned serial = 0, i;
#endif
+ if (p2p_supported) {
+ strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
+ strcpy(supplicant_prop_name, P2P_PROP_NAME);
+
+ /* Ensure p2p config file is created */
+ if (ensure_config_file_exists(P2P_CONFIG_FILE) < 0) {
+ ALOGE("Failed to create a p2p config file");
+ return -1;
+ }
+
+ } else {
+ strcpy(supplicant_name, SUPPLICANT_NAME);
+ strcpy(supplicant_prop_name, SUPP_PROP_NAME);
+ }
+
/* Check whether already running */
- if (property_get(SUPP_PROP_NAME, supp_status, NULL)
+ if (property_get(supplicant_name, supp_status, NULL)
&& strcmp(supp_status, "running") == 0) {
return 0;
}
/* Before starting the daemon, make sure its config file exists */
- if (ensure_config_file_exists(config_file) < 0) {
- LOGE("Wi-Fi will not be enabled");
+ if (ensure_config_file_exists(SUPP_CONFIG_FILE) < 0) {
+ ALOGE("Wi-Fi will not be enabled");
return -1;
}
if (ensure_entropy_file_exists() < 0) {
- LOGE("Wi-Fi entropy file was not created");
+ ALOGE("Wi-Fi entropy file was not created");
}
/* Clear out any stale socket files that might be left over. */
wifi_wpa_ctrl_cleanup();
+ /* Reset sockets used for exiting from hung state */
+ for (i=0; i<MAX_CONNS; i++) {
+ exit_sockets[i][0] = exit_sockets[i][1] = -1;
+ }
+
#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
/*
* Get a reference to the status property, so we can distinguish
@@ -509,20 +557,20 @@ int wifi_start_supplicant_common(const char *config_file)
* it starts in the stopped state and never manages to start
* running at all.
*/
- pi = __system_property_find(SUPP_PROP_NAME);
+ pi = __system_property_find(supplicant_prop_name);
if (pi != NULL) {
serial = pi->serial;
}
#endif
- property_get("wifi.interface", iface, WIFI_TEST_INTERFACE);
- snprintf(daemon_cmd, PROPERTY_VALUE_MAX, "%s:-i%s -c%s", SUPPLICANT_NAME, iface, config_file);
- property_set("ctl.start", daemon_cmd);
+ property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE);
+
+ property_set("ctl.start", supplicant_name);
sched_yield();
while (count-- > 0) {
#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
if (pi == NULL) {
- pi = __system_property_find(SUPP_PROP_NAME);
+ pi = __system_property_find(supplicant_prop_name);
}
if (pi != NULL) {
__system_property_read(pi, NULL, supp_status);
@@ -534,7 +582,7 @@ int wifi_start_supplicant_common(const char *config_file)
}
}
#else
- if (property_get(SUPP_PROP_NAME, supp_status, NULL)) {
+ if (property_get(supplicant_prop_name, supp_status, NULL)) {
if (strcmp(supp_status, "running") == 0)
return 0;
}
@@ -544,32 +592,22 @@ int wifi_start_supplicant_common(const char *config_file)
return -1;
}
-int wifi_start_supplicant()
-{
- return wifi_start_supplicant_common(SUPP_CONFIG_FILE);
-}
-
-int wifi_start_p2p_supplicant()
-{
- return wifi_start_supplicant_common(P2P_CONFIG_FILE);
-}
-
int wifi_stop_supplicant()
{
char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
int count = 50; /* wait at most 5 seconds for completion */
/* Check whether supplicant already stopped */
- if (property_get(SUPP_PROP_NAME, supp_status, NULL)
+ if (property_get(supplicant_prop_name, supp_status, NULL)
&& strcmp(supp_status, "stopped") == 0) {
return 0;
}
- property_set("ctl.stop", SUPPLICANT_NAME);
+ property_set("ctl.stop", supplicant_name);
sched_yield();
while (count-- > 0) {
- if (property_get(SUPP_PROP_NAME, supp_status, NULL)) {
+ if (property_get(supplicant_prop_name, supp_status, NULL)) {
if (strcmp(supp_status, "stopped") == 0)
return 0;
}
@@ -578,66 +616,77 @@ int wifi_stop_supplicant()
return -1;
}
-int wifi_connect_to_supplicant()
+int wifi_connect_on_socket_path(int index, const char *path)
{
- char ifname[256];
char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
/* Make sure supplicant is running */
- if (!property_get(SUPP_PROP_NAME, supp_status, NULL)
+ if (!property_get(supplicant_prop_name, supp_status, NULL)
|| strcmp(supp_status, "running") != 0) {
- LOGE("Supplicant not running, cannot connect");
+ ALOGE("Supplicant not running, cannot connect");
return -1;
}
- if (access(IFACE_DIR, F_OK) == 0) {
- snprintf(ifname, sizeof(ifname), "%s/%s", IFACE_DIR, iface);
- } else {
- strlcpy(ifname, iface, sizeof(ifname));
- }
-
- ctrl_conn = wpa_ctrl_open(ifname);
- if (ctrl_conn == NULL) {
- LOGE("Unable to open connection to supplicant on \"%s\": %s",
- ifname, strerror(errno));
+ ctrl_conn[index] = wpa_ctrl_open(path);
+ if (ctrl_conn[index] == NULL) {
+ ALOGE("Unable to open connection to supplicant on \"%s\": %s",
+ path, strerror(errno));
return -1;
}
- monitor_conn = wpa_ctrl_open(ifname);
- if (monitor_conn == NULL) {
- wpa_ctrl_close(ctrl_conn);
- ctrl_conn = NULL;
+ monitor_conn[index] = wpa_ctrl_open(path);
+ if (monitor_conn[index] == NULL) {
+ wpa_ctrl_close(ctrl_conn[index]);
+ ctrl_conn[index] = NULL;
return -1;
}
- if (wpa_ctrl_attach(monitor_conn) != 0) {
- wpa_ctrl_close(monitor_conn);
- wpa_ctrl_close(ctrl_conn);
- ctrl_conn = monitor_conn = NULL;
+ if (wpa_ctrl_attach(monitor_conn[index]) != 0) {
+ wpa_ctrl_close(monitor_conn[index]);
+ wpa_ctrl_close(ctrl_conn[index]);
+ ctrl_conn[index] = monitor_conn[index] = NULL;
return -1;
}
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, exit_sockets) == -1) {
- wpa_ctrl_close(monitor_conn);
- wpa_ctrl_close(ctrl_conn);
- ctrl_conn = monitor_conn = NULL;
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, exit_sockets[index]) == -1) {
+ wpa_ctrl_close(monitor_conn[index]);
+ wpa_ctrl_close(ctrl_conn[index]);
+ ctrl_conn[index] = monitor_conn[index] = NULL;
return -1;
}
return 0;
}
-int wifi_send_command(struct wpa_ctrl *ctrl, const char *cmd, char *reply, size_t *reply_len)
+/* Establishes the control and monitor socket connections on the interface */
+int wifi_connect_to_supplicant(const char *ifname)
+{
+ char path[256];
+
+ if (is_primary_interface(ifname)) {
+ if (access(IFACE_DIR, F_OK) == 0) {
+ snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
+ } else {
+ strlcpy(path, primary_iface, sizeof(path));
+ }
+ return wifi_connect_on_socket_path(PRIMARY, path);
+ } else {
+ sprintf(path, "%s/%s", CONTROL_IFACE_PATH, ifname);
+ return wifi_connect_on_socket_path(SECONDARY, path);
+ }
+}
+
+int wifi_send_command(int index, const char *cmd, char *reply, size_t *reply_len)
{
int ret;
- if (ctrl_conn == NULL) {
- LOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd);
+ if (ctrl_conn[index] == NULL) {
+ ALOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd);
return -1;
}
- ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), reply, reply_len, NULL);
+ ret = wpa_ctrl_request(ctrl_conn[index], cmd, strlen(cmd), reply, reply_len, NULL);
if (ret == -2) {
- LOGD("'%s' command timed out.\n", cmd);
+ ALOGD("'%s' command timed out.\n", cmd);
/* unblocks the monitor receive socket for termination */
- write(exit_sockets[0], "T", 1);
+ TEMP_FAILURE_RETRY(write(exit_sockets[index][0], "T", 1));
return -2;
} else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
return -1;
@@ -648,32 +697,31 @@ int wifi_send_command(struct wpa_ctrl *ctrl, const char *cmd, char *reply, size_
return 0;
}
-int wifi_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
+int wifi_ctrl_recv(int index, char *reply, size_t *reply_len)
{
int res;
- int ctrlfd = wpa_ctrl_get_fd(ctrl);
+ int ctrlfd = wpa_ctrl_get_fd(monitor_conn[index]);
struct pollfd rfds[2];
memset(rfds, 0, 2 * sizeof(struct pollfd));
rfds[0].fd = ctrlfd;
rfds[0].events |= POLLIN;
- rfds[1].fd = exit_sockets[1];
+ rfds[1].fd = exit_sockets[index][1];
rfds[1].events |= POLLIN;
- res = poll(rfds, 2, -1);
+ res = TEMP_FAILURE_RETRY(poll(rfds, 2, -1));
if (res < 0) {
- LOGE("Error poll = %d", res);
+ ALOGE("Error poll = %d", res);
return res;
}
if (rfds[0].revents & POLLIN) {
- return wpa_ctrl_recv(ctrl, reply, reply_len);
+ return wpa_ctrl_recv(monitor_conn[index], reply, reply_len);
} else {
- LOGD("Received on exit socket, terminate");
- return -1;
+ return -2;
}
return 0;
}
-int wifi_wait_for_event(char *buf, size_t buflen)
+int wifi_wait_on_socket(int index, char *buf, size_t buflen)
{
size_t nread = buflen - 1;
int fd;
@@ -682,26 +730,33 @@ int wifi_wait_for_event(char *buf, size_t buflen)
struct timeval tval;
struct timeval *tptr;
- if (monitor_conn == NULL) {
- LOGD("Connection closed\n");
+ if (monitor_conn[index] == NULL) {
+ ALOGD("Connection closed\n");
+ strncpy(buf, WPA_EVENT_TERMINATING " - connection closed", buflen-1);
+ buf[buflen-1] = '\0';
+ return strlen(buf);
+ }
+
+ result = wifi_ctrl_recv(index, buf, &nread);
+
+ /* Terminate reception on exit socket */
+ if (result == -2) {
strncpy(buf, WPA_EVENT_TERMINATING " - connection closed", buflen-1);
buf[buflen-1] = '\0';
return strlen(buf);
}
- result = wifi_ctrl_recv(monitor_conn, buf, &nread);
if (result < 0) {
- LOGD("wifi_ctrl_recv failed: %s\n", strerror(errno));
+ ALOGD("wifi_ctrl_recv failed: %s\n", strerror(errno));
strncpy(buf, WPA_EVENT_TERMINATING " - recv error", buflen-1);
buf[buflen-1] = '\0';
return strlen(buf);
}
buf[nread] = '\0';
- /* LOGD("wait_for_event: result=%d nread=%d string=\"%s\"\n", result, nread, buf); */
/* Check for EOF on the socket */
if (result == 0 && nread == 0) {
/* Fabricate an event to pass up */
- LOGD("Received EOF on supplicant socket\n");
+ ALOGD("Received EOF on supplicant socket\n");
strncpy(buf, WPA_EVENT_TERMINATING " - signal 0 received", buflen-1);
buf[buflen-1] = '\0';
return strlen(buf);
@@ -722,35 +777,62 @@ int wifi_wait_for_event(char *buf, size_t buflen)
memmove(buf, match+1, nread+1);
}
}
+
return nread;
}
-void wifi_close_supplicant_connection()
+int wifi_wait_for_event(const char *ifname, char *buf, size_t buflen)
{
- char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
- int count = 50; /* wait at most 5 seconds to ensure init has stopped stupplicant */
+ if (is_primary_interface(ifname)) {
+ return wifi_wait_on_socket(PRIMARY, buf, buflen);
+ } else {
+ return wifi_wait_on_socket(SECONDARY, buf, buflen);
+ }
+}
- if (ctrl_conn != NULL) {
- wpa_ctrl_close(ctrl_conn);
- ctrl_conn = NULL;
+void wifi_close_sockets(int index)
+{
+ if (ctrl_conn[index] != NULL) {
+ wpa_ctrl_close(ctrl_conn[index]);
+ ctrl_conn[index] = NULL;
}
- if (monitor_conn != NULL) {
- wpa_ctrl_close(monitor_conn);
- monitor_conn = NULL;
+
+ if (monitor_conn[index] != NULL) {
+ wpa_ctrl_close(monitor_conn[index]);
+ monitor_conn[index] = NULL;
}
- if (exit_sockets[0] >= 0) {
- close(exit_sockets[0]);
- exit_sockets[0] = -1;
+ if (exit_sockets[index][0] >= 0) {
+ close(exit_sockets[index][0]);
+ exit_sockets[index][0] = -1;
}
- if (exit_sockets[1] >= 0) {
- close(exit_sockets[1]);
- exit_sockets[1] = -1;
+ if (exit_sockets[index][1] >= 0) {
+ close(exit_sockets[index][1]);
+ exit_sockets[index][1] = -1;
+ }
+}
+
+void wifi_close_supplicant_connection(const char *ifname)
+{
+ char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
+ int count = 50; /* wait at most 5 seconds to ensure init has stopped stupplicant */
+
+ if (is_primary_interface(ifname)) {
+ wifi_close_sockets(PRIMARY);
+ } else {
+ /* p2p socket termination needs unblocking the monitor socket
+ * STA connection does not need it since supplicant gets shutdown
+ */
+ TEMP_FAILURE_RETRY(write(exit_sockets[SECONDARY][0], "T", 1));
+ wifi_close_sockets(SECONDARY);
+ //closing p2p connection does not need a wait on
+ //supplicant stop
+ return;
}
while (count-- > 0) {
- if (property_get(SUPP_PROP_NAME, supp_status, NULL)) {
+ if (property_get(supplicant_prop_name, supp_status, NULL)) {
if (strcmp(supp_status, "stopped") == 0)
return;
}
@@ -758,9 +840,13 @@ void wifi_close_supplicant_connection()
}
}
-int wifi_command(const char *command, char *reply, size_t *reply_len)
+int wifi_command(const char *ifname, const char *command, char *reply, size_t *reply_len)
{
- return wifi_send_command(ctrl_conn, command, reply, reply_len);
+ if (is_primary_interface(ifname)) {
+ return wifi_send_command(PRIMARY, command, reply, reply_len);
+ } else {
+ return wifi_send_command(SECONDARY, command, reply, reply_len);
+ }
}
const char *wifi_get_fw_path(int fw_type)
@@ -784,14 +870,14 @@ int wifi_change_fw_path(const char *fwpath)
if (!fwpath)
return ret;
- fd = open(WIFI_DRIVER_FW_PATH_PARAM, O_WRONLY);
+ fd = TEMP_FAILURE_RETRY(open(WIFI_DRIVER_FW_PATH_PARAM, O_WRONLY));
if (fd < 0) {
- LOGE("Failed to open wlan fw path param (%s)", strerror(errno));
+ ALOGE("Failed to open wlan fw path param (%s)", strerror(errno));
return -1;
}
len = strlen(fwpath) + 1;
- if (write(fd, fwpath, len) != len) {
- LOGE("Failed to write wlan fw path param (%s)", strerror(errno));
+ if (TEMP_FAILURE_RETRY(write(fd, fwpath, len)) != len) {
+ ALOGE("Failed to write wlan fw path param (%s)", strerror(errno));
ret = -1;
}
close(fd);