Policy config parser: migrate to BP and drop legacy format
Migrate to android.bp as test need to use the library.
As bp do not support conditional statement, and this format has been
deprecated for 3 years, drop the pre-treble .conf parser.
AUDIOSERVER_MULTILIB is no longer use as it does not make sense for a
static lib.
Bug: 114303641
Bug: 111681420
Test: compile, boots
Change-Id: I9f429b306ecfbb80116445ba6297a4b3d6dc57f6
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/services/audiopolicy/Android.mk b/services/audiopolicy/Android.mk
index f23e426..02ab8ad 100644
--- a/services/audiopolicy/Android.mk
+++ b/services/audiopolicy/Android.mk
@@ -81,9 +81,9 @@
LOCAL_SHARED_LIBRARIES += libmedia_helper
LOCAL_SHARED_LIBRARIES += libmediametrics
-ifeq ($(USE_XML_AUDIO_POLICY_CONF), 1)
LOCAL_SHARED_LIBRARIES += libhidlbase libicuuc libxml2
+ifeq ($(USE_XML_AUDIO_POLICY_CONF), 1)
LOCAL_CFLAGS += -DUSE_XML_AUDIO_POLICY_CONF
endif #ifeq ($(USE_XML_AUDIO_POLICY_CONF), 1)
diff --git a/services/audiopolicy/common/Android.bp b/services/audiopolicy/common/Android.bp
new file mode 100644
index 0000000..a925b9a
--- /dev/null
+++ b/services/audiopolicy/common/Android.bp
@@ -0,0 +1,4 @@
+cc_library_headers {
+ name: "libaudiopolicycommon",
+ export_include_dirs: ["include"],
+}
diff --git a/services/audiopolicy/common/Android.mk b/services/audiopolicy/common/Android.mk
deleted file mode 100644
index dcce8e3..0000000
--- a/services/audiopolicy/common/Android.mk
+++ /dev/null
@@ -1,9 +0,0 @@
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-#######################################################################
-# Recursive call sub-folder Android.mk
-#
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
diff --git a/services/audiopolicy/common/managerdefinitions/Android.bp b/services/audiopolicy/common/managerdefinitions/Android.bp
new file mode 100644
index 0000000..d0b4973
--- /dev/null
+++ b/services/audiopolicy/common/managerdefinitions/Android.bp
@@ -0,0 +1,53 @@
+cc_library_static {
+ name: "libaudiopolicycomponents",
+
+ srcs: [
+ "src/AudioCollections.cpp",
+ "src/AudioGain.cpp",
+ "src/AudioInputDescriptor.cpp",
+ "src/AudioOutputDescriptor.cpp",
+ "src/AudioPatch.cpp",
+ "src/AudioPolicyMix.cpp",
+ "src/AudioPort.cpp",
+ "src/AudioProfile.cpp",
+ "src/AudioRoute.cpp",
+ "src/ClientDescriptor.cpp",
+ "src/DeviceDescriptor.cpp",
+ "src/EffectDescriptor.cpp",
+ "src/HwModule.cpp",
+ "src/IOProfile.cpp",
+ "src/Serializer.cpp",
+ "src/SoundTriggerSession.cpp",
+ "src/TypeConverter.cpp",
+ "src/VolumeCurve.cpp",
+ ],
+ shared_libs: [
+ "libcutils",
+ "libhidlbase",
+ "libicuuc",
+ "liblog",
+ "libmedia",
+ "libutils",
+ "libxml2",
+ ],
+ export_shared_lib_headers: ["libmedia"],
+ static_libs: [
+ "libaudioutils",
+ ],
+ header_libs: [
+ "libaudiopolicycommon",
+ ],
+ export_header_lib_headers: ["libaudiopolicycommon"],
+
+ include_dirs: [
+ "frameworks/av/services/audiopolicy",
+ ],
+
+ export_include_dirs: ["include"],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
+}
diff --git a/services/audiopolicy/common/managerdefinitions/Android.mk b/services/audiopolicy/common/managerdefinitions/Android.mk
deleted file mode 100644
index 3336b79..0000000
--- a/services/audiopolicy/common/managerdefinitions/Android.mk
+++ /dev/null
@@ -1,66 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- src/DeviceDescriptor.cpp \
- src/AudioGain.cpp \
- src/HwModule.cpp \
- src/IOProfile.cpp \
- src/AudioPort.cpp \
- src/AudioProfile.cpp \
- src/AudioRoute.cpp \
- src/AudioPolicyMix.cpp \
- src/AudioPatch.cpp \
- src/AudioInputDescriptor.cpp \
- src/AudioOutputDescriptor.cpp \
- src/AudioCollections.cpp \
- src/EffectDescriptor.cpp \
- src/SoundTriggerSession.cpp \
- src/VolumeCurve.cpp \
- src/TypeConverter.cpp \
- src/ClientDescriptor.cpp
-
-LOCAL_SHARED_LIBRARIES := \
- libcutils \
- libmedia \
- libutils \
- liblog \
-
-LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libmedia
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/include \
- frameworks/av/services/audiopolicy/common/include \
- frameworks/av/services/audiopolicy \
- $(call include-path-for, audio-utils) \
-
-ifeq ($(USE_XML_AUDIO_POLICY_CONF), 1)
-
-LOCAL_SRC_FILES += src/Serializer.cpp
-
-LOCAL_SHARED_LIBRARIES += libhidlbase libicuuc libxml2
-
-LOCAL_C_INCLUDES += \
- external/libxml2/include \
- external/icu/icu4c/source/common
-
-else
-
-LOCAL_SRC_FILES += \
- src/ConfigParsingUtils.cpp \
- src/StreamDescriptor.cpp \
- src/Gains.cpp
-
-endif #ifeq ($(USE_XML_AUDIO_POLICY_CONF), 1)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
- $(LOCAL_PATH)/include
-
-LOCAL_MULTILIB := $(AUDIOSERVER_MULTILIB)
-
-LOCAL_CFLAGS := -Wall -Werror
-
-LOCAL_MODULE := libaudiopolicycomponents
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/services/audiopolicy/common/managerdefinitions/include/ConfigParsingUtils.h b/services/audiopolicy/common/managerdefinitions/include/ConfigParsingUtils.h
deleted file mode 100644
index a007854..0000000
--- a/services/audiopolicy/common/managerdefinitions/include/ConfigParsingUtils.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#pragma once
-
-#include "AudioPolicyConfig.h"
-#include "DeviceDescriptor.h"
-#include "HwModule.h"
-#include "audio_policy_conf.h"
-#include <system/audio.h>
-#include <utils/Log.h>
-#include <utils/Vector.h>
-#include <utils/SortedVector.h>
-#include <cutils/config_utils.h>
-#include <utils/RefBase.h>
-#include <system/audio_policy.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-// Definitions for audio_policy.conf file parsing
-// ----------------------------------------------------------------------------
-
-class ConfigParsingUtils
-{
-public:
- static status_t loadConfig(const char *path, AudioPolicyConfig &config);
-
-private:
- static void loadAudioPortGain(cnode *root, AudioPort &audioPort, int index);
- static void loadAudioPortGains(cnode *root, AudioPort &audioPort);
- static void loadDeviceDescriptorGains(cnode *root, sp<DeviceDescriptor> &deviceDesc);
- static status_t loadHwModuleDevice(cnode *root, DeviceVector &devices);
- static status_t loadHwModuleProfile(cnode *root, sp<HwModule> &module, audio_port_role_t role);
- static void loadDevicesFromTag(const char *tag, DeviceVector &devices,
- const DeviceVector &declaredDevices);
- static void loadHwModules(cnode *root, HwModuleCollection &hwModules,
- AudioPolicyConfig &config);
- static void loadGlobalConfig(cnode *root, AudioPolicyConfig &config,
- const sp<HwModule> &primaryModule);
- static void loadModuleGlobalConfig(cnode *root, const sp<HwModule> &module,
- AudioPolicyConfig &config);
- static status_t loadHwModule(cnode *root, sp<HwModule> &module, AudioPolicyConfig &config);
-};
-
-} // namespace android
diff --git a/services/audiopolicy/common/managerdefinitions/include/Gains.h b/services/audiopolicy/common/managerdefinitions/include/Gains.h
deleted file mode 100644
index cb229a4..0000000
--- a/services/audiopolicy/common/managerdefinitions/include/Gains.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#pragma once
-
-#include <StreamDescriptor.h>
-#include <utils/KeyedVector.h>
-#include <system/audio.h>
-#include <utils/Errors.h>
-#include <utils/RefBase.h>
-
-namespace android {
-
-class StreamDescriptor;
-
-class Gains
-{
-public :
- static float volIndexToDb(const VolumeCurvePoint *point, int indexMin, int indexMax,
- int indexInUi);
-
- // default volume curve
- static const VolumeCurvePoint sDefaultVolumeCurve[Volume::VOLCNT];
- // default volume curve for media strategy
- static const VolumeCurvePoint sDefaultMediaVolumeCurve[Volume::VOLCNT];
- // volume curve for non-media audio on ext media outputs (HDMI, Line, etc)
- static const VolumeCurvePoint sExtMediaSystemVolumeCurve[Volume::VOLCNT];
- // volume curve for media strategy on speakers
- static const VolumeCurvePoint sSpeakerMediaVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sSpeakerMediaVolumeCurveDrc[Volume::VOLCNT];
- // volume curve for sonification strategy on speakers
- static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sSpeakerSonificationVolumeCurveDrc[Volume::VOLCNT];
- static const VolumeCurvePoint sDefaultSystemVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sDefaultSystemVolumeCurveDrc[Volume::VOLCNT];
- static const VolumeCurvePoint sHeadsetSystemVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sDefaultVoiceVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sSpeakerVoiceVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sLinearVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sSilentVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sFullScaleVolumeCurve[Volume::VOLCNT];
- static const VolumeCurvePoint sHearingAidVolumeCurve[Volume::VOLCNT];
- // default volume curves per stream and device category. See initializeVolumeCurves()
- static const VolumeCurvePoint *sVolumeProfiles[AUDIO_STREAM_CNT][DEVICE_CATEGORY_CNT];
-};
-
-} // namespace android
diff --git a/services/audiopolicy/common/managerdefinitions/include/StreamDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/StreamDescriptor.h
deleted file mode 100644
index 6266313..0000000
--- a/services/audiopolicy/common/managerdefinitions/include/StreamDescriptor.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#pragma once
-
-#include "IVolumeCurvesCollection.h"
-#include <utils/KeyedVector.h>
-#include <utils/StrongPointer.h>
-#include <utils/SortedVector.h>
-#include <system/audio.h>
-
-namespace android {
-
-// stream descriptor used for volume control
-class StreamDescriptor
-{
-public:
- StreamDescriptor();
-
- int getVolumeIndex(audio_devices_t device) const;
- bool canBeMuted() const { return mCanBeMuted; }
- void clearCurrentVolumeIndex();
- void addCurrentVolumeIndex(audio_devices_t device, int index);
- int getVolumeIndexMin() const { return mIndexMin; }
- int getVolumeIndexMax() const { return mIndexMax; }
- void setVolumeIndexMin(int volIndexMin);
- void setVolumeIndexMax(int volIndexMax);
- bool hasVolumeIndexForDevice(audio_devices_t device) const
- {
- device = Volume::getDeviceForVolume(device);
- return mIndexCur.indexOfKey(device) >= 0;
- }
-
- void dump(String8 *dst) const;
-
- void setVolumeCurvePoint(device_category deviceCategory, const VolumeCurvePoint *point);
- const VolumeCurvePoint *getVolumeCurvePoint(device_category deviceCategory) const
- {
- return mVolumeCurve[deviceCategory];
- }
-
-private:
- const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT];
- KeyedVector<audio_devices_t, int> mIndexCur; /**< current volume index per device. */
- int mIndexMin; /**< min volume index. */
- int mIndexMax; /**< max volume index. */
- bool mCanBeMuted; /**< true is the stream can be muted. */
-};
-
-/**
- * stream descriptors collection for volume control
- */
-class StreamDescriptorCollection : public DefaultKeyedVector<audio_stream_type_t, StreamDescriptor>,
- public IVolumeCurvesCollection
-{
-public:
- StreamDescriptorCollection();
-
- virtual void clearCurrentVolumeIndex(audio_stream_type_t stream);
- virtual void addCurrentVolumeIndex(audio_stream_type_t stream, audio_devices_t device,
- int index);
- virtual bool canBeMuted(audio_stream_type_t stream);
- virtual int getVolumeIndexMin(audio_stream_type_t stream) const
- {
- return valueFor(stream).getVolumeIndexMin();
- }
- virtual int getVolumeIndex(audio_stream_type_t stream, audio_devices_t device)
- {
- return valueFor(stream).getVolumeIndex(device);
- }
- virtual int getVolumeIndexMax(audio_stream_type_t stream) const
- {
- return valueFor(stream).getVolumeIndexMax();
- }
- virtual float volIndexToDb(audio_stream_type_t stream, device_category device,
- int indexInUi) const;
- virtual status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax);
- virtual void initializeVolumeCurves(bool isSpeakerDrcEnabled);
- virtual void switchVolumeCurve(audio_stream_type_t streamSrc, audio_stream_type_t streamDst);
- virtual bool hasVolumeIndexForDevice(audio_stream_type_t stream,
- audio_devices_t device) const
- {
- return valueFor(stream).hasVolumeIndexForDevice(device);
- }
-
- void dump(String8 *dst) const override;
-
-private:
- void setVolumeCurvePoint(audio_stream_type_t stream, device_category deviceCategory,
- const VolumeCurvePoint *point);
- const VolumeCurvePoint *getVolumeCurvePoint(audio_stream_type_t stream,
- device_category deviceCategory) const;
- void setVolumeIndexMin(audio_stream_type_t stream,int volIndexMin);
- void setVolumeIndexMax(audio_stream_type_t stream,int volIndexMax);
-};
-
-} // namespace android
diff --git a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp b/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
deleted file mode 100644
index 59db81c..0000000
--- a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#define LOG_TAG "APM::ConfigParsingUtils"
-//#define LOG_NDEBUG 0
-
-#include "ConfigParsingUtils.h"
-#include "AudioGain.h"
-#include "IOProfile.h"
-#include <system/audio.h>
-#include <media/AudioParameter.h>
-#include <media/TypeConverter.h>
-#include <utils/Log.h>
-#include <cutils/misc.h>
-
-namespace android {
-
-// --- audio_policy.conf file parsing
-
-//static
-void ConfigParsingUtils::loadAudioPortGain(cnode *root, AudioPort &audioPort, int index)
-{
- cnode *node = root->first_child;
-
- sp<AudioGain> gain = new AudioGain(index, audioPort.useInputChannelMask());
-
- while (node) {
- if (strcmp(node->name, GAIN_MODE) == 0) {
- gain->setMode(GainModeConverter::maskFromString(node->value));
- } else if (strcmp(node->name, GAIN_CHANNELS) == 0) {
- audio_channel_mask_t mask;
- if (audioPort.useInputChannelMask()) {
- if (InputChannelConverter::fromString(node->value, mask)) {
- gain->setChannelMask(mask);
- }
- } else {
- if (OutputChannelConverter::fromString(node->value, mask)) {
- gain->setChannelMask(mask);
- }
- }
- } else if (strcmp(node->name, GAIN_MIN_VALUE) == 0) {
- gain->setMinValueInMb(atoi(node->value));
- } else if (strcmp(node->name, GAIN_MAX_VALUE) == 0) {
- gain->setMaxValueInMb(atoi(node->value));
- } else if (strcmp(node->name, GAIN_DEFAULT_VALUE) == 0) {
- gain->setDefaultValueInMb(atoi(node->value));
- } else if (strcmp(node->name, GAIN_STEP_VALUE) == 0) {
- gain->setStepValueInMb(atoi(node->value));
- } else if (strcmp(node->name, GAIN_MIN_RAMP_MS) == 0) {
- gain->setMinRampInMs(atoi(node->value));
- } else if (strcmp(node->name, GAIN_MAX_RAMP_MS) == 0) {
- gain->setMaxRampInMs(atoi(node->value));
- }
- node = node->next;
- }
-
- ALOGV("loadGain() adding new gain mode %08x channel mask %08x min mB %d max mB %d",
- gain->getMode(), gain->getChannelMask(), gain->getMinValueInMb(),
- gain->getMaxValueInMb());
-
- if (gain->getMode() == 0) {
- return;
- }
- audioPort.mGains.add(gain);
-}
-
-void ConfigParsingUtils::loadAudioPortGains(cnode *root, AudioPort &audioPort)
-{
- cnode *node = root->first_child;
- int index = 0;
- while (node) {
- ALOGV("loadGains() loading gain %s", node->name);
- loadAudioPortGain(node, audioPort, index++);
- node = node->next;
- }
-}
-
-//static
-void ConfigParsingUtils::loadDeviceDescriptorGains(cnode *root, sp<DeviceDescriptor> &deviceDesc)
-{
- loadAudioPortGains(root, *deviceDesc);
- if (deviceDesc->mGains.size() > 0) {
- deviceDesc->mGains[0]->getDefaultConfig(&deviceDesc->mGain);
- }
-}
-
-//static
-status_t ConfigParsingUtils::loadHwModuleDevice(cnode *root, DeviceVector &devices)
-{
- cnode *node = root->first_child;
-
- audio_devices_t type = AUDIO_DEVICE_NONE;
- while (node) {
- if (strcmp(node->name, APM_DEVICE_TYPE) == 0) {
- deviceFromString(node->value, type);
- break;
- }
- node = node->next;
- }
- if (type == AUDIO_DEVICE_NONE ||
- (!audio_is_input_device(type) && !audio_is_output_device(type))) {
- ALOGW("loadDevice() bad type %08x", type);
- return BAD_VALUE;
- }
- sp<DeviceDescriptor> deviceDesc = new DeviceDescriptor(type, String8(root->name));
-
- node = root->first_child;
- while (node) {
- if (strcmp(node->name, APM_DEVICE_ADDRESS) == 0) {
- deviceDesc->mAddress = String8((char *)node->value);
- } else if (strcmp(node->name, CHANNELS_TAG) == 0) {
- if (audio_is_input_device(type)) {
- deviceDesc->addAudioProfile(
- new AudioProfile(gDynamicFormat,
- inputChannelMasksFromString(node->value),
- SampleRateVector()));
- } else {
- deviceDesc->addAudioProfile(
- new AudioProfile(gDynamicFormat,
- outputChannelMasksFromString(node->value),
- SampleRateVector()));
- }
- } else if (strcmp(node->name, GAINS_TAG) == 0) {
- loadDeviceDescriptorGains(node, deviceDesc);
- }
- node = node->next;
- }
-
- ALOGV("loadDevice() adding device tag (literal type) %s type %08x address %s",
- deviceDesc->getTagName().string(), type, deviceDesc->mAddress.string());
-
- devices.add(deviceDesc);
- return NO_ERROR;
-}
-
-//static
-status_t ConfigParsingUtils::loadHwModuleProfile(cnode *root, sp<HwModule> &module,
- audio_port_role_t role)
-{
- cnode *node = root->first_child;
-
- sp<IOProfile> profile = new IOProfile(String8(root->name), role);
-
- AudioProfileVector audioProfiles;
- SampleRateVector sampleRates;
- ChannelsVector channels;
- FormatVector formats;
-
- while (node) {
- if (strcmp(node->name, FORMATS_TAG) == 0 &&
- strcmp(node->value, DYNAMIC_VALUE_TAG) != 0) {
- formats = formatsFromString(node->value);
- } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0 &&
- strcmp(node->value, DYNAMIC_VALUE_TAG) != 0) {
- collectionFromString<SampleRateTraits>(node->value, sampleRates);
- } else if (strcmp(node->name, CHANNELS_TAG) == 0 &&
- strcmp(node->value, DYNAMIC_VALUE_TAG) != 0) {
- if (role == AUDIO_PORT_ROLE_SINK) {
- channels = inputChannelMasksFromString(node->value);
- } else {
- channels = outputChannelMasksFromString(node->value);
- }
- } else if (strcmp(node->name, DEVICES_TAG) == 0) {
- DeviceVector devices;
- loadDevicesFromTag(node->value, devices, module->getDeclaredDevices());
- profile->setSupportedDevices(devices);
- } else if (strcmp(node->name, FLAGS_TAG) == 0) {
- if (role == AUDIO_PORT_ROLE_SINK) {
- profile->setFlags(InputFlagConverter::maskFromString(node->value));
- } else {
- profile->setFlags(OutputFlagConverter::maskFromString(node->value));
- }
- } else if (strcmp(node->name, GAINS_TAG) == 0) {
- loadAudioPortGains(node, *profile);
- }
- node = node->next;
- }
- if (formats.isEmpty()) {
- sp<AudioProfile> profileToAdd = new AudioProfile(gDynamicFormat, channels, sampleRates);
- profileToAdd->setDynamicFormat(true);
- profileToAdd->setDynamicChannels(channels.isEmpty());
- profileToAdd->setDynamicRate(sampleRates.isEmpty());
- audioProfiles.add(profileToAdd);
- } else {
- for (size_t i = 0; i < formats.size(); i++) {
- // For compatibility reason, for each format, creates a profile with the same
- // collection of rate and channels.
- sp<AudioProfile> profileToAdd = new AudioProfile(formats[i], channels, sampleRates);
- profileToAdd->setDynamicFormat(formats[i] == gDynamicFormat);
- profileToAdd->setDynamicChannels(channels.isEmpty());
- profileToAdd->setDynamicRate(sampleRates.isEmpty());
- audioProfiles.add(profileToAdd);
- }
- }
- profile->setAudioProfiles(audioProfiles);
- ALOGW_IF(!profile->hasSupportedDevices(), "load%s() invalid supported devices",
- role == AUDIO_PORT_ROLE_SINK ? "Input" : "Output");
- if (profile->hasSupportedDevices()) {
- ALOGV("load%s() adding Supported Devices %04x, mFlags %04x",
- role == AUDIO_PORT_ROLE_SINK ? "Input" : "Output",
- profile->getSupportedDevicesType(), profile->getFlags());
- return module->addProfile(profile);
- }
- return BAD_VALUE;
-}
-
-//static
-status_t ConfigParsingUtils::loadHwModule(cnode *root, sp<HwModule> &module,
- AudioPolicyConfig &config)
-{
- status_t status = NAME_NOT_FOUND;
- cnode *node = config_find(root, DEVICES_TAG);
- if (node != NULL) {
- node = node->first_child;
- DeviceVector devices;
- while (node) {
- ALOGV("loadHwModule() loading device %s", node->name);
- status_t tmpStatus = loadHwModuleDevice(node, devices);
- if (status == NAME_NOT_FOUND || status == NO_ERROR) {
- status = tmpStatus;
- }
- node = node->next;
- }
- module->setDeclaredDevices(devices);
- }
- node = config_find(root, OUTPUTS_TAG);
- if (node != NULL) {
- node = node->first_child;
- while (node) {
- ALOGV("loadHwModule() loading output %s", node->name);
- status_t tmpStatus = loadHwModuleProfile(node, module, AUDIO_PORT_ROLE_SOURCE);
- if (status == NAME_NOT_FOUND || status == NO_ERROR) {
- status = tmpStatus;
- }
- node = node->next;
- }
- }
- node = config_find(root, INPUTS_TAG);
- if (node != NULL) {
- node = node->first_child;
- while (node) {
- ALOGV("loadHwModule() loading input %s", node->name);
- status_t tmpStatus = loadHwModuleProfile(node, module, AUDIO_PORT_ROLE_SINK);
- if (status == NAME_NOT_FOUND || status == NO_ERROR) {
- status = tmpStatus;
- }
- node = node->next;
- }
- }
- loadModuleGlobalConfig(root, module, config);
- return status;
-}
-
-//static
-void ConfigParsingUtils::loadHwModules(cnode *root, HwModuleCollection &hwModules,
- AudioPolicyConfig &config)
-{
- cnode *node = config_find(root, AUDIO_HW_MODULE_TAG);
- if (node == NULL) {
- return;
- }
-
- node = node->first_child;
- while (node) {
- ALOGV("loadHwModules() loading module %s", node->name);
- sp<HwModule> module = new HwModule(node->name);
- if (loadHwModule(node, module, config) == NO_ERROR) {
- hwModules.add(module);
- }
- node = node->next;
- }
-}
-
-//static
-void ConfigParsingUtils::loadDevicesFromTag(const char *tag, DeviceVector &devices,
- const DeviceVector &declaredDevices)
-{
- char *tagLiteral = strndup(tag, strlen(tag));
- char *devTag = strtok(tagLiteral, AudioParameter::valueListSeparator);
- while (devTag != NULL) {
- if (strlen(devTag) != 0) {
- audio_devices_t type;
- if (deviceFromString(devTag, type)) {
- uint32_t inBit = type & AUDIO_DEVICE_BIT_IN;
- type &= ~AUDIO_DEVICE_BIT_IN;
- while (type) {
- audio_devices_t singleType =
- inBit | (1 << (31 - __builtin_clz(type)));
- type &= ~singleType;
- sp<DeviceDescriptor> dev = new DeviceDescriptor(singleType);
- devices.add(dev);
- }
- } else {
- sp<DeviceDescriptor> deviceDesc =
- declaredDevices.getDeviceFromTagName(String8(devTag));
- if (deviceDesc != 0) {
- devices.add(deviceDesc);
- }
- }
- }
- devTag = strtok(NULL, AudioParameter::valueListSeparator);
- }
- free(tagLiteral);
-}
-
-//static
-void ConfigParsingUtils::loadModuleGlobalConfig(cnode *root, const sp<HwModule> &module,
- AudioPolicyConfig &config)
-{
- cnode *node = config_find(root, GLOBAL_CONFIG_TAG);
-
- if (node == NULL) {
- return;
- }
- DeviceVector declaredDevices;
- if (module != NULL) {
- declaredDevices = module->getDeclaredDevices();
- }
-
- node = node->first_child;
- while (node) {
- if (strcmp(ATTACHED_OUTPUT_DEVICES_TAG, node->name) == 0) {
- DeviceVector availableOutputDevices;
- loadDevicesFromTag(node->value, availableOutputDevices, declaredDevices);
- ALOGV("loadGlobalConfig() Attached Output Devices %08x",
- availableOutputDevices.types());
- config.addAvailableOutputDevices(availableOutputDevices);
- } else if (strcmp(DEFAULT_OUTPUT_DEVICE_TAG, node->name) == 0) {
- audio_devices_t device = AUDIO_DEVICE_NONE;
- deviceFromString(node->value, device);
- if (device != AUDIO_DEVICE_NONE) {
- sp<DeviceDescriptor> defaultOutputDevice = new DeviceDescriptor(device);
- config.setDefaultOutputDevice(defaultOutputDevice);
- ALOGV("loadGlobalConfig() mDefaultOutputDevice %08x", defaultOutputDevice->type());
- } else {
- ALOGW("loadGlobalConfig() default device not specified");
- }
- } else if (strcmp(ATTACHED_INPUT_DEVICES_TAG, node->name) == 0) {
- DeviceVector availableInputDevices;
- loadDevicesFromTag(node->value, availableInputDevices, declaredDevices);
- ALOGV("loadGlobalConfig() Available InputDevices %08x", availableInputDevices.types());
- config.addAvailableInputDevices(availableInputDevices);
- } else if (strcmp(AUDIO_HAL_VERSION_TAG, node->name) == 0) {
- uint32_t major, minor;
- sscanf((char *)node->value, "%u.%u", &major, &minor);
- module->setHalVersion(major, minor);
- ALOGV("loadGlobalConfig() mHalVersion = major %u minor %u", major, minor);
- }
- node = node->next;
- }
-}
-
-//static
-void ConfigParsingUtils::loadGlobalConfig(cnode *root, AudioPolicyConfig &config,
- const sp<HwModule>& primaryModule)
-{
- cnode *node = config_find(root, GLOBAL_CONFIG_TAG);
-
- if (node == NULL) {
- return;
- }
- node = node->first_child;
- while (node) {
- if (strcmp(SPEAKER_DRC_ENABLED_TAG, node->name) == 0) {
- bool speakerDrcEnabled;
- if (utilities::convertTo<std::string, bool>(node->value, speakerDrcEnabled)) {
- ALOGV("loadGlobalConfig() mSpeakerDrcEnabled = %d", speakerDrcEnabled);
- config.setSpeakerDrcEnabled(speakerDrcEnabled);
- }
- }
- node = node->next;
- }
- loadModuleGlobalConfig(root, primaryModule, config);
-}
-
-//static
-status_t ConfigParsingUtils::loadConfig(const char *path, AudioPolicyConfig &config)
-{
- cnode *root;
- char *data;
-
- data = (char *)load_file(path, NULL);
- if (data == NULL) {
- return -ENODEV;
- }
- root = config_node("", "");
- config_load(root, data);
-
- HwModuleCollection hwModules;
- loadHwModules(root, hwModules, config);
-
- // legacy audio_policy.conf files have one global_configuration section, attached to primary.
- loadGlobalConfig(root, config, hwModules.getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY));
-
- config.setHwModules(hwModules);
-
- config.setDefaultSurroundFormats();
-
- config_free(root);
- free(root);
- free(data);
-
- ALOGI("loadAudioPolicyConfig() loaded %s\n", path);
- config.setSource(path);
-
- return NO_ERROR;
-}
-
-} // namespace android
diff --git a/services/audiopolicy/common/managerdefinitions/src/Gains.cpp b/services/audiopolicy/common/managerdefinitions/src/Gains.cpp
deleted file mode 100644
index 6407a17..0000000
--- a/services/audiopolicy/common/managerdefinitions/src/Gains.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#define LOG_TAG "APM::Gains"
-//#define LOG_NDEBUG 0
-
-//#define VERY_VERBOSE_LOGGING
-#ifdef VERY_VERBOSE_LOGGING
-#define ALOGVV ALOGV
-#else
-#define ALOGVV(a...) do { } while(0)
-#endif
-
-#include "Gains.h"
-#include <Volume.h>
-#include <math.h>
-#include <utils/String8.h>
-
-namespace android {
-
-// Enginedefault
-const VolumeCurvePoint
-Gains::sDefaultVolumeCurve[Volume::VOLCNT] = {
- {1, -49.5f}, {33, -33.5f}, {66, -17.0f}, {100, 0.0f}
-};
-
-
-const VolumeCurvePoint
-Gains::sDefaultMediaVolumeCurve[Volume::VOLCNT] = {
- {1, -58.0f}, {20, -40.0f}, {60, -17.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sExtMediaSystemVolumeCurve[Volume::VOLCNT] = {
- {1, -58.0f}, {20, -40.0f}, {60, -21.0f}, {100, -10.0f}
-};
-
-const VolumeCurvePoint
-Gains::sSpeakerMediaVolumeCurve[Volume::VOLCNT] = {
- {1, -56.0f}, {20, -34.0f}, {60, -11.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sSpeakerMediaVolumeCurveDrc[Volume::VOLCNT] = {
- {1, -55.0f}, {20, -43.0f}, {86, -12.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sSpeakerSonificationVolumeCurve[Volume::VOLCNT] = {
- {1, -29.7f}, {33, -20.1f}, {66, -10.2f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sSpeakerSonificationVolumeCurveDrc[Volume::VOLCNT] = {
- {1, -35.7f}, {33, -26.1f}, {66, -13.2f}, {100, 0.0f}
-};
-
-// AUDIO_STREAM_SYSTEM, AUDIO_STREAM_ENFORCED_AUDIBLE and AUDIO_STREAM_DTMF volume tracks
-// AUDIO_STREAM_RING on phones and AUDIO_STREAM_MUSIC on tablets.
-// AUDIO_STREAM_DTMF tracks AUDIO_STREAM_VOICE_CALL while in call (See AudioService.java).
-// The range is constrained between -24dB and -6dB over speaker and -30dB and -18dB over headset.
-
-const VolumeCurvePoint
-Gains::sDefaultSystemVolumeCurve[Volume::VOLCNT] = {
- {1, -24.0f}, {33, -18.0f}, {66, -12.0f}, {100, -6.0f}
-};
-
-const VolumeCurvePoint
-Gains::sDefaultSystemVolumeCurveDrc[Volume::VOLCNT] = {
- {1, -34.0f}, {33, -24.0f}, {66, -15.0f}, {100, -6.0f}
-};
-
-const VolumeCurvePoint
-Gains::sHeadsetSystemVolumeCurve[Volume::VOLCNT] = {
- {1, -30.0f}, {33, -26.0f}, {66, -22.0f}, {100, -18.0f}
-};
-
-const VolumeCurvePoint
-Gains::sDefaultVoiceVolumeCurve[Volume::VOLCNT] = {
- {0, -42.0f}, {33, -28.0f}, {66, -14.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sSpeakerVoiceVolumeCurve[Volume::VOLCNT] = {
- {0, -24.0f}, {33, -16.0f}, {66, -8.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sLinearVolumeCurve[Volume::VOLCNT] = {
- {0, -96.0f}, {33, -68.0f}, {66, -34.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sSilentVolumeCurve[Volume::VOLCNT] = {
- {0, -96.0f}, {1, -96.0f}, {2, -96.0f}, {100, -96.0f}
-};
-
-const VolumeCurvePoint
-Gains::sFullScaleVolumeCurve[Volume::VOLCNT] = {
- {0, 0.0f}, {1, 0.0f}, {2, 0.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint
-Gains::sHearingAidVolumeCurve[Volume::VOLCNT] = {
- {1, -128.0f}, {20, -80.0f}, {60, -40.0f}, {100, 0.0f}
-};
-
-const VolumeCurvePoint *Gains::sVolumeProfiles[AUDIO_STREAM_CNT]
- [DEVICE_CATEGORY_CNT] = {
- { // AUDIO_STREAM_VOICE_CALL
- Gains::sDefaultVoiceVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sSpeakerVoiceVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sSpeakerVoiceVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_SYSTEM
- Gains::sHeadsetSystemVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sExtMediaSystemVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_RING
- Gains::sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sExtMediaSystemVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_MUSIC
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sSpeakerMediaVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_ALARM
- Gains::sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sExtMediaSystemVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_NOTIFICATION
- Gains::sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sExtMediaSystemVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_BLUETOOTH_SCO
- Gains::sDefaultVoiceVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sSpeakerVoiceVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultVoiceVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_ENFORCED_AUDIBLE
- Gains::sHeadsetSystemVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sExtMediaSystemVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_DTMF
- Gains::sHeadsetSystemVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sExtMediaSystemVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_TTS
- // "Transmitted Through Speaker": always silent except on DEVICE_CATEGORY_SPEAKER
- Gains::sSilentVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sSilentVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sSilentVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_ACCESSIBILITY
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sSpeakerMediaVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sHearingAidVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_REROUTING
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sFullScaleVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
- { // AUDIO_STREAM_PATCH
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_HEADSET
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_SPEAKER
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_EARPIECE
- Gains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_EXT_MEDIA
- Gains::sFullScaleVolumeCurve // DEVICE_CATEGORY_HEARING_AID
- },
-};
-
-//static
-float Gains::volIndexToDb(const VolumeCurvePoint *curve, int indexMin, int indexMax, int indexInUi)
-{
- // the volume index in the UI is relative to the min and max volume indices for this stream type
- int nbSteps = 1 + curve[Volume::VOLMAX].mIndex - curve[Volume::VOLMIN].mIndex;
- int volIdx = (nbSteps * (indexInUi - indexMin)) / (indexMax - indexMin);
-
- // find what part of the curve this index volume belongs to, or if it's out of bounds
- int segment = 0;
- if (volIdx < curve[Volume::VOLMIN].mIndex) { // out of bounds
- return VOLUME_MIN_DB;
- } else if (volIdx < curve[Volume::VOLKNEE1].mIndex) {
- segment = 0;
- } else if (volIdx < curve[Volume::VOLKNEE2].mIndex) {
- segment = 1;
- } else if (volIdx <= curve[Volume::VOLMAX].mIndex) {
- segment = 2;
- } else { // out of bounds
- return 0.0f;
- }
-
- // linear interpolation in the attenuation table in dB
- float decibels = curve[segment].mDBAttenuation +
- ((float)(volIdx - curve[segment].mIndex)) *
- ( (curve[segment+1].mDBAttenuation -
- curve[segment].mDBAttenuation) /
- ((float)(curve[segment+1].mIndex -
- curve[segment].mIndex)) );
-
- ALOGVV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f]",
- curve[segment].mIndex, volIdx,
- curve[segment+1].mIndex,
- curve[segment].mDBAttenuation,
- decibels,
- curve[segment+1].mDBAttenuation);
-
- return decibels;
-}
-
-} // namespace android
diff --git a/services/audiopolicy/common/managerdefinitions/src/StreamDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/StreamDescriptor.cpp
deleted file mode 100644
index c311a4f..0000000
--- a/services/audiopolicy/common/managerdefinitions/src/StreamDescriptor.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#define LOG_TAG "APM::Volumes"
-//#define LOG_NDEBUG 0
-
-//#define VERY_VERBOSE_LOGGING
-#ifdef VERY_VERBOSE_LOGGING
-#define ALOGVV ALOGV
-#else
-#define ALOGVV(a...) do { } while(0)
-#endif
-
-#include "StreamDescriptor.h"
-#include "Gains.h"
-#include "policy.h"
-#include <utils/Log.h>
-#include <utils/String8.h>
-
-namespace android {
-
-// --- StreamDescriptor class implementation
-
-StreamDescriptor::StreamDescriptor()
- : mIndexMin(0), mIndexMax(1), mCanBeMuted(true)
-{
- // Initialize the current stream's index to mIndexMax so volume isn't 0 in
- // cases where the Java layer doesn't call into the audio policy service to
- // set the default volume.
- mIndexCur.add(AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME, mIndexMax);
-}
-
-int StreamDescriptor::getVolumeIndex(audio_devices_t device) const
-{
- device = Volume::getDeviceForVolume(device);
- // there is always a valid entry for AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME
- if (mIndexCur.indexOfKey(device) < 0) {
- device = AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME;
- }
- return mIndexCur.valueFor(device);
-}
-
-void StreamDescriptor::clearCurrentVolumeIndex()
-{
- mIndexCur.clear();
-}
-
-void StreamDescriptor::addCurrentVolumeIndex(audio_devices_t device, int index)
-{
- mIndexCur.add(device, index);
-}
-
-void StreamDescriptor::setVolumeIndexMin(int volIndexMin)
-{
- mIndexMin = volIndexMin;
-}
-
-void StreamDescriptor::setVolumeIndexMax(int volIndexMax)
-{
- mIndexMax = volIndexMax;
-}
-
-void StreamDescriptor::setVolumeCurvePoint(device_category deviceCategory,
- const VolumeCurvePoint *point)
-{
- mVolumeCurve[deviceCategory] = point;
-}
-
-void StreamDescriptor::dump(String8 *dst) const
-{
- dst->appendFormat("%s %02d %02d ",
- mCanBeMuted ? "true " : "false", mIndexMin, mIndexMax);
- for (size_t i = 0; i < mIndexCur.size(); i++) {
- dst->appendFormat("%04x : %02d, ",
- mIndexCur.keyAt(i),
- mIndexCur.valueAt(i));
- }
- dst->append("\n");
-}
-
-StreamDescriptorCollection::StreamDescriptorCollection()
-{
- for (size_t stream = 0 ; stream < AUDIO_STREAM_CNT; stream++) {
- add(static_cast<audio_stream_type_t>(stream), StreamDescriptor());
- }
-}
-
-bool StreamDescriptorCollection::canBeMuted(audio_stream_type_t stream)
-{
- return valueAt(stream).canBeMuted();
-}
-
-void StreamDescriptorCollection::clearCurrentVolumeIndex(audio_stream_type_t stream)
-{
- editValueAt(stream).clearCurrentVolumeIndex();
-}
-
-void StreamDescriptorCollection::addCurrentVolumeIndex(audio_stream_type_t stream,
- audio_devices_t device, int index)
-{
- editValueAt(stream).addCurrentVolumeIndex(device, index);
-}
-
-void StreamDescriptorCollection::setVolumeCurvePoint(audio_stream_type_t stream,
- device_category deviceCategory,
- const VolumeCurvePoint *point)
-{
- editValueAt(stream).setVolumeCurvePoint(deviceCategory, point);
-}
-
-const VolumeCurvePoint *StreamDescriptorCollection::getVolumeCurvePoint(audio_stream_type_t stream,
- device_category deviceCategory) const
-{
- return valueAt(stream).getVolumeCurvePoint(deviceCategory);
-}
-
-void StreamDescriptorCollection::setVolumeIndexMin(audio_stream_type_t stream,int volIndexMin)
-{
- return editValueAt(stream).setVolumeIndexMin(volIndexMin);
-}
-
-void StreamDescriptorCollection::setVolumeIndexMax(audio_stream_type_t stream,int volIndexMax)
-{
- return editValueAt(stream).setVolumeIndexMax(volIndexMax);
-}
-
-float StreamDescriptorCollection::volIndexToDb(audio_stream_type_t stream, device_category category,
- int indexInUi) const
-{
- const StreamDescriptor &streamDesc = valueAt(stream);
- return Gains::volIndexToDb(streamDesc.getVolumeCurvePoint(category),
- streamDesc.getVolumeIndexMin(), streamDesc.getVolumeIndexMax(),
- indexInUi);
-}
-
-status_t StreamDescriptorCollection::initStreamVolume(audio_stream_type_t stream,
- int indexMin, int indexMax)
-{
- ALOGV("initStreamVolume() stream %d, min %d, max %d", stream , indexMin, indexMax);
- if (indexMin < 0 || indexMin >= indexMax) {
- ALOGW("initStreamVolume() invalid index limits for stream %d, min %d, max %d",
- stream , indexMin, indexMax);
- return BAD_VALUE;
- }
- setVolumeIndexMin(stream, indexMin);
- setVolumeIndexMax(stream, indexMax);
- return NO_ERROR;
-}
-
-void StreamDescriptorCollection::initializeVolumeCurves(bool isSpeakerDrcEnabled)
-{
- for (int i = 0; i < AUDIO_STREAM_CNT; i++) {
- for (int j = 0; j < DEVICE_CATEGORY_CNT; j++) {
- setVolumeCurvePoint(static_cast<audio_stream_type_t>(i),
- static_cast<device_category>(j),
- Gains::sVolumeProfiles[i][j]);
- }
- }
-
- // Check availability of DRC on speaker path: if available, override some of the speaker curves
- if (isSpeakerDrcEnabled) {
- setVolumeCurvePoint(AUDIO_STREAM_SYSTEM, DEVICE_CATEGORY_SPEAKER,
- Gains::sDefaultSystemVolumeCurveDrc);
- setVolumeCurvePoint(AUDIO_STREAM_RING, DEVICE_CATEGORY_SPEAKER,
- Gains::sSpeakerSonificationVolumeCurveDrc);
- setVolumeCurvePoint(AUDIO_STREAM_ALARM, DEVICE_CATEGORY_SPEAKER,
- Gains::sSpeakerSonificationVolumeCurveDrc);
- setVolumeCurvePoint(AUDIO_STREAM_NOTIFICATION, DEVICE_CATEGORY_SPEAKER,
- Gains::sSpeakerSonificationVolumeCurveDrc);
- setVolumeCurvePoint(AUDIO_STREAM_MUSIC, DEVICE_CATEGORY_SPEAKER,
- Gains::sSpeakerMediaVolumeCurveDrc);
- setVolumeCurvePoint(AUDIO_STREAM_ACCESSIBILITY, DEVICE_CATEGORY_SPEAKER,
- Gains::sSpeakerMediaVolumeCurveDrc);
- }
-}
-
-void StreamDescriptorCollection::switchVolumeCurve(audio_stream_type_t streamSrc,
- audio_stream_type_t streamDst)
-{
- for (int j = 0; j < DEVICE_CATEGORY_CNT; j++) {
- setVolumeCurvePoint(streamDst, static_cast<device_category>(j),
- Gains::sVolumeProfiles[streamSrc][j]);
- }
-}
-
-void StreamDescriptorCollection::dump(String8 *dst) const
-{
- dst->append("\nStreams dump:\n");
- dst->append(
- " Stream Can be muted Index Min Index Max Index Cur [device : index]...\n");
- for (size_t i = 0; i < size(); i++) {
- dst->appendFormat(" %02zu ", i);
- valueAt(i).dump(dst);
- }
-}
-
-} // namespace android
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 3909202..a4e6cc4 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -49,10 +49,6 @@
#include <system/audio.h>
#include <audio_policy_conf.h>
#include "AudioPolicyManager.h"
-#ifndef USE_XML_AUDIO_POLICY_CONF
-#include <ConfigParsingUtils.h>
-#include <StreamDescriptor.h>
-#endif
#include <Serializer.h>
#include "TypeConverter.h"
#include <policy.h>
@@ -3794,7 +3790,6 @@
return mAudioPortGeneration++;
}
-#ifdef USE_XML_AUDIO_POLICY_CONF
// Treblized audio policy xml config will be located in /odm/etc or /vendor/etc.
static const char *kConfigLocationList[] =
{"/odm/etc", "/vendor/etc", "/system/etc"};
@@ -3826,7 +3821,6 @@
}
return ret;
}
-#endif
AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterface,
bool /*forTesting*/)
@@ -3835,15 +3829,9 @@
mpClientInterface(clientInterface),
mLimitRingtoneVolume(false), mLastVoiceVolume(-1.0f),
mA2dpSuspended(false),
-#ifdef USE_XML_AUDIO_POLICY_CONF
mVolumeCurves(new VolumeCurvesCollection()),
mConfig(mHwModulesAll, mAvailableOutputDevices, mAvailableInputDevices,
mDefaultOutputDevice, static_cast<VolumeCurvesCollection*>(mVolumeCurves.get())),
-#else
- mVolumeCurves(new StreamDescriptorCollection()),
- mConfig(mHwModulesAll, mAvailableOutputDevices, mAvailableInputDevices,
- mDefaultOutputDevice),
-#endif
mAudioPortGeneration(1),
mBeaconMuteRefCount(0),
mBeaconPlayingRefCount(0),
@@ -3862,13 +3850,16 @@
initialize();
}
-void AudioPolicyManager::loadConfig() {
-#ifdef USE_XML_AUDIO_POLICY_CONF
- if (deserializeAudioPolicyXmlConfig(getConfig()) != NO_ERROR) {
-#else
- if ((ConfigParsingUtils::loadConfig(AUDIO_POLICY_VENDOR_CONFIG_FILE, getConfig()) != NO_ERROR)
- && (ConfigParsingUtils::loadConfig(AUDIO_POLICY_CONFIG_FILE, getConfig()) != NO_ERROR)) {
+// This check is to catch any legacy platform updating to Q without having
+// switched to XML since its deprecation on O.
+// TODO: after Q release, remove this check and flag as XML is now the only
+// option and all legacy platform should have transitioned to XML.
+#ifndef USE_XML_AUDIO_POLICY_CONF
+#error Audio policy no longer supports legacy .conf configuration format
#endif
+
+void AudioPolicyManager::loadConfig() {
+ if (deserializeAudioPolicyXmlConfig(getConfig()) != NO_ERROR) {
ALOGE("could not load audio policy configuration file, setting defaults");
getConfig().setDefault();
}