Merge "wifi: Fix bridged interface property and allociation"
diff --git a/audio/7.0/IStream.hal b/audio/7.0/IStream.hal
index 4fe8218..ab9aa7d 100644
--- a/audio/7.0/IStream.hal
+++ b/audio/7.0/IStream.hal
@@ -66,9 +66,10 @@
* Retrieves basic stream configuration: sample rate, audio format,
* channel mask.
*
+ * @return retval operation completion status.
* @return config basic stream configuration.
*/
- getAudioProperties() generates (AudioConfigBase config);
+ getAudioProperties() generates (Result retval, AudioConfigBase config);
/**
* Sets stream parameters. Only sets parameters that are specified.
diff --git a/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h b/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h
index 414eede..b7c1cc9 100644
--- a/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h
+++ b/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h
@@ -225,6 +225,10 @@
return stringToAudioChannelMask(mask) == AudioChannelMask::UNKNOWN;
}
+static inline bool isUnknownAudioContentType(const std::string& contentType) {
+ return stringToAudioContentType(contentType) == AudioContentType::UNKNOWN;
+}
+
static inline bool isUnknownAudioDevice(const std::string& device) {
return stringToAudioDevice(device) == AudioDevice::UNKNOWN && !isVendorExtension(device);
}
@@ -237,6 +241,10 @@
return stringToAudioGainMode(mode) == AudioGainMode::UNKNOWN;
}
+static inline bool isUnknownAudioInOutFlag(const std::string& flag) {
+ return stringToAudioInOutFlag(flag) == AudioInOutFlag::UNKNOWN;
+}
+
static inline bool isUnknownAudioSource(const std::string& source) {
return stringToAudioSource(source) == AudioSource::UNKNOWN;
}
diff --git a/audio/common/7.0/example/Effect.cpp b/audio/common/7.0/example/Effect.cpp
index 9d5ab31..27f28c6 100644
--- a/audio/common/7.0/example/Effect.cpp
+++ b/audio/common/7.0/example/Effect.cpp
@@ -107,14 +107,14 @@
}
Return<void> Effect::getConfig(getConfig_cb _hidl_cb) {
- const EffectConfig config = {{} /* inputCfg */,
- // outputCfg
- {{} /* buffer */,
- 48000 /* samplingRateHz */,
- toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO),
- toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT),
- EffectBufferAccess::ACCESS_ACCUMULATE,
- 0 /* mask */}};
+ const EffectConfig config = {
+ {} /* inputCfg */,
+ // outputCfg
+ {{} /* buffer */,
+ {toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT), 48000 /* samplingRateHz */,
+ toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO)}, /* base */
+ EffectBufferAccess::ACCESS_ACCUMULATE,
+ 0 /* mask */}};
_hidl_cb(Result::OK, config);
return Void();
}
diff --git a/audio/common/all-versions/default/7.0/HidlUtils.cpp b/audio/common/all-versions/default/7.0/HidlUtils.cpp
index 1a66282..c985a70 100644
--- a/audio/common/all-versions/default/7.0/HidlUtils.cpp
+++ b/audio/common/all-versions/default/7.0/HidlUtils.cpp
@@ -95,6 +95,25 @@
return NO_ERROR;
}
+status_t HidlUtils::audioChannelMasksFromHal(const std::vector<std::string>& halChannelMasks,
+ hidl_vec<AudioChannelMask>* channelMasks) {
+ hidl_vec<AudioChannelMask> tempChannelMasks;
+ tempChannelMasks.resize(halChannelMasks.size());
+ size_t tempPos = 0;
+ for (const auto& halChannelMask : halChannelMasks) {
+ if (!halChannelMask.empty() && !xsd::isUnknownAudioChannelMask(halChannelMask)) {
+ tempChannelMasks[tempPos++] = halChannelMask;
+ }
+ }
+ if (tempPos == tempChannelMasks.size()) {
+ *channelMasks = std::move(tempChannelMasks);
+ } else {
+ *channelMasks = hidl_vec<AudioChannelMask>(tempChannelMasks.begin(),
+ tempChannelMasks.begin() + tempPos);
+ }
+ return halChannelMasks.size() == channelMasks->size() ? NO_ERROR : BAD_VALUE;
+}
+
status_t HidlUtils::audioChannelMaskToHal(const AudioChannelMask& channelMask,
audio_channel_mask_t* halChannelMask) {
if (!xsd::isUnknownAudioChannelMask(channelMask) &&
@@ -127,6 +146,28 @@
return result;
}
+status_t HidlUtils::audioContentTypeFromHal(const audio_content_type_t halContentType,
+ AudioContentType* contentType) {
+ *contentType = audio_content_type_to_string(halContentType);
+ if (!contentType->empty() && !xsd::isUnknownAudioContentType(*contentType)) {
+ return NO_ERROR;
+ }
+ ALOGE("Unknown audio content type value 0x%X", halContentType);
+ *contentType = toString(xsd::AudioContentType::AUDIO_CONTENT_TYPE_UNKNOWN);
+ return BAD_VALUE;
+}
+
+status_t HidlUtils::audioContentTypeToHal(const AudioContentType& contentType,
+ audio_content_type_t* halContentType) {
+ if (!xsd::isUnknownAudioContentType(contentType) &&
+ audio_content_type_from_string(contentType.c_str(), halContentType)) {
+ return NO_ERROR;
+ }
+ ALOGE("Unknown audio content type \"%s\"", contentType.c_str());
+ *halContentType = AUDIO_CONTENT_TYPE_UNKNOWN;
+ return BAD_VALUE;
+}
+
status_t HidlUtils::audioDeviceTypeFromHal(audio_devices_t halDevice, AudioDevice* device) {
*device = audio_device_to_string(halDevice);
if (!device->empty() && !xsd::isUnknownAudioDevice(*device)) {
@@ -155,6 +196,24 @@
return BAD_VALUE;
}
+status_t HidlUtils::audioFormatsFromHal(const std::vector<std::string>& halFormats,
+ hidl_vec<AudioFormat>* formats) {
+ hidl_vec<AudioFormat> tempFormats;
+ tempFormats.resize(halFormats.size());
+ size_t tempPos = 0;
+ for (const auto& halFormat : halFormats) {
+ if (!halFormat.empty() && !xsd::isUnknownAudioFormat(halFormat)) {
+ tempFormats[tempPos++] = halFormat;
+ }
+ }
+ if (tempPos == tempFormats.size()) {
+ *formats = std::move(tempFormats);
+ } else {
+ *formats = hidl_vec<AudioFormat>(tempFormats.begin(), tempFormats.begin() + tempPos);
+ }
+ return halFormats.size() == formats->size() ? NO_ERROR : BAD_VALUE;
+}
+
status_t HidlUtils::audioFormatToHal(const AudioFormat& format, audio_format_t* halFormat) {
if (!xsd::isUnknownAudioFormat(format) && audio_format_from_string(format.c_str(), halFormat)) {
return NO_ERROR;
diff --git a/audio/common/all-versions/default/Android.bp b/audio/common/all-versions/default/Android.bp
index b83a58a..45f0b8f 100644
--- a/audio/common/all-versions/default/Android.bp
+++ b/audio/common/all-versions/default/Android.bp
@@ -43,6 +43,7 @@
name: "android.hardware.audio.common-util@2-6",
srcs: [
"HidlUtils.cpp",
+ "HidlUtilsCommon.cpp",
"UuidUtils.cpp",
],
}
@@ -132,6 +133,7 @@
defaults: ["android.hardware.audio.common-util_default"],
srcs: [
"7.0/HidlUtils.cpp",
+ "HidlUtilsCommon.cpp",
"UuidUtils.cpp",
],
shared_libs: [
diff --git a/audio/common/all-versions/default/HidlUtils.cpp b/audio/common/all-versions/default/HidlUtils.cpp
index ab3c1c7..c0dcd80 100644
--- a/audio/common/all-versions/default/HidlUtils.cpp
+++ b/audio/common/all-versions/default/HidlUtils.cpp
@@ -28,7 +28,7 @@
namespace CPP_VERSION {
namespace implementation {
-status_t HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config) {
+status_t HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, bool, AudioConfig* config) {
config->sampleRateHz = halConfig.sample_rate;
config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
config->format = AudioFormat(halConfig.format);
@@ -47,8 +47,8 @@
return NO_ERROR;
}
-void HidlUtils::audioGainConfigFromHal(const struct audio_gain_config& halConfig,
- AudioGainConfig* config) {
+status_t HidlUtils::audioGainConfigFromHal(const struct audio_gain_config& halConfig, bool,
+ AudioGainConfig* config) {
config->index = halConfig.index;
config->mode = EnumBitfield<AudioGainMode>(halConfig.mode);
config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
@@ -56,6 +56,7 @@
config->values[i] = halConfig.values[i];
}
config->rampDurationMs = halConfig.ramp_duration_ms;
+ return NO_ERROR;
}
status_t HidlUtils::audioGainConfigToHal(const AudioGainConfig& config,
@@ -71,7 +72,7 @@
return NO_ERROR;
}
-void HidlUtils::audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain) {
+status_t HidlUtils::audioGainFromHal(const struct audio_gain& halGain, bool, AudioGain* gain) {
gain->mode = EnumBitfield<AudioGainMode>(halGain.mode);
gain->channelMask = EnumBitfield<AudioChannelMask>(halGain.channel_mask);
gain->minValue = halGain.min_value;
@@ -80,6 +81,7 @@
gain->stepValue = halGain.step_value;
gain->minRampMs = halGain.min_ramp_ms;
gain->maxRampMs = halGain.max_ramp_ms;
+ return NO_ERROR;
}
status_t HidlUtils::audioGainToHal(const AudioGain& gain, struct audio_gain* halGain) {
@@ -182,7 +184,7 @@
config->sampleRateHz = halConfig.sample_rate;
config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
config->format = AudioFormat(halConfig.format);
- audioGainConfigFromHal(halConfig.gain, &config->gain);
+ audioGainConfigFromHal(halConfig.gain, false /*isInput--ignored*/, &config->gain);
switch (halConfig.type) {
case AUDIO_PORT_TYPE_NONE:
break;
@@ -272,7 +274,7 @@
}
port->gains.resize(halPort.num_gains);
for (size_t i = 0; i < halPort.num_gains; ++i) {
- audioGainFromHal(halPort.gains[i], &port->gains[i]);
+ audioGainFromHal(halPort.gains[i], false /*isInput--ignored*/, &port->gains[i]);
}
audioPortConfigFromHal(halPort.active_config, &port->activeConfig);
switch (halPort.type) {
@@ -351,6 +353,18 @@
return NO_ERROR;
}
+#if MAJOR_VERSION >= 5
+status_t HidlUtils::deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
+ char* halDeviceAddress) {
+ return deviceAddressToHalImpl(device, halDeviceType, halDeviceAddress);
+}
+
+status_t HidlUtils::deviceAddressFromHal(audio_devices_t halDeviceType,
+ const char* halDeviceAddress, DeviceAddress* device) {
+ return deviceAddressFromHalImpl(halDeviceType, halDeviceAddress, device);
+}
+#endif
+
} // namespace implementation
} // namespace CPP_VERSION
} // namespace common
diff --git a/audio/common/all-versions/default/HidlUtils.h b/audio/common/all-versions/default/HidlUtils.h
index 4e609ca..c420a2f 100644
--- a/audio/common/all-versions/default/HidlUtils.h
+++ b/audio/common/all-versions/default/HidlUtils.h
@@ -23,8 +23,6 @@
#include <system/audio.h>
-using ::android::hardware::hidl_vec;
-
namespace android {
namespace hardware {
namespace audio {
@@ -32,25 +30,25 @@
namespace CPP_VERSION {
namespace implementation {
+using ::android::hardware::hidl_vec;
using namespace ::android::hardware::audio::common::CPP_VERSION;
struct HidlUtils {
-#if MAJOR_VERSION < 7
- static status_t audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config);
- static void audioGainConfigFromHal(const struct audio_gain_config& halConfig,
- AudioGainConfig* config);
- static void audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain);
-#else
static status_t audioConfigFromHal(const audio_config_t& halConfig, bool isInput,
AudioConfig* config);
+ static status_t audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig);
+#if MAJOR_VERSION >= 4
+ static status_t audioContentTypeFromHal(const audio_content_type_t halContentType,
+ AudioContentType* contentType);
+ static status_t audioContentTypeToHal(const AudioContentType& contentType,
+ audio_content_type_t* halContentType);
+#endif
static status_t audioGainConfigFromHal(const struct audio_gain_config& halConfig, bool isInput,
AudioGainConfig* config);
- static status_t audioGainFromHal(const struct audio_gain& halGain, bool isInput,
- AudioGain* gain);
-#endif
- static status_t audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig);
static status_t audioGainConfigToHal(const AudioGainConfig& config,
struct audio_gain_config* halConfig);
+ static status_t audioGainFromHal(const struct audio_gain& halGain, bool isInput,
+ AudioGain* gain);
static status_t audioGainToHal(const AudioGain& gain, struct audio_gain* halGain);
static status_t audioUsageFromHal(audio_usage_t halUsage, AudioUsage* usage);
static status_t audioUsageToHal(const AudioUsage& usage, audio_usage_t* halUsage);
@@ -64,43 +62,37 @@
struct audio_port_config* halConfig);
static status_t audioPortConfigsFromHal(unsigned int numHalConfigs,
const struct audio_port_config* halConfigs,
- hidl_vec<AudioPortConfig>* configs) {
- status_t result = NO_ERROR;
- configs->resize(numHalConfigs);
- for (unsigned int i = 0; i < numHalConfigs; ++i) {
- if (status_t status = audioPortConfigFromHal(halConfigs[i], &(*configs)[i]);
- status != NO_ERROR) {
- result = status;
- }
- }
- return result;
- }
+ hidl_vec<AudioPortConfig>* configs);
static status_t audioPortConfigsToHal(const hidl_vec<AudioPortConfig>& configs,
- std::unique_ptr<audio_port_config[]>* halConfigs) {
- status_t result = NO_ERROR;
- halConfigs->reset(new audio_port_config[configs.size()]);
- for (size_t i = 0; i < configs.size(); ++i) {
- if (status_t status = audioPortConfigToHal(configs[i], &(*halConfigs)[i]);
- status != NO_ERROR) {
- result = status;
- }
- }
- return result;
- }
+ std::unique_ptr<audio_port_config[]>* halConfigs);
+ static status_t audioPortFromHal(const struct audio_port& halPort, AudioPort* port);
+ static status_t audioPortToHal(const AudioPort& port, struct audio_port* halPort);
+ static status_t audioSourceFromHal(audio_source_t halSource, AudioSource* source);
+ static status_t audioSourceToHal(const AudioSource& source, audio_source_t* halSource);
+#if MAJOR_VERSION >= 5
+ static status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
+ char* halDeviceAddress);
+ static status_t deviceAddressFromHal(audio_devices_t halDeviceType,
+ const char* halDeviceAddress, DeviceAddress* device);
+#endif
- // PLEASE DO NOT USE, will be removed in a couple of days
+#if MAJOR_VERSION <= 6
+ // Temporary versions for compatibility with forks of the default implementation.
+ // Will be removed, do not use!
+ static status_t audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config) {
+ return audioConfigFromHal(halConfig, false /*isInput--ignored*/, config);
+ }
static std::unique_ptr<audio_port_config[]> audioPortConfigsToHal(
const hidl_vec<AudioPortConfig>& configs) {
std::unique_ptr<audio_port_config[]> halConfigs;
(void)audioPortConfigsToHal(configs, &halConfigs);
return halConfigs;
}
-
- static status_t audioPortFromHal(const struct audio_port& halPort, AudioPort* port);
- static status_t audioPortToHal(const AudioPort& port, struct audio_port* halPort);
-#if MAJOR_VERSION >= 7
+#else // V7 and above
static status_t audioChannelMaskFromHal(audio_channel_mask_t halChannelMask, bool isInput,
AudioChannelMask* channelMask);
+ static status_t audioChannelMasksFromHal(const std::vector<std::string>& halChannelMasks,
+ hidl_vec<AudioChannelMask>* channelMasks);
static status_t audioChannelMaskToHal(const AudioChannelMask& channelMask,
audio_channel_mask_t* halChannelMask);
static status_t audioConfigBaseFromHal(const audio_config_base_t& halConfigBase, bool isInput,
@@ -110,6 +102,8 @@
static status_t audioDeviceTypeFromHal(audio_devices_t halDevice, AudioDevice* device);
static status_t audioDeviceTypeToHal(const AudioDevice& device, audio_devices_t* halDevice);
static status_t audioFormatFromHal(audio_format_t halFormat, AudioFormat* format);
+ static status_t audioFormatsFromHal(const std::vector<std::string>& halFormats,
+ hidl_vec<AudioFormat>* formats);
static status_t audioFormatToHal(const AudioFormat& format, audio_format_t* halFormat);
static status_t audioGainModeMaskFromHal(audio_gain_mode_t halGainModeMask,
hidl_vec<AudioGainMode>* gainModeMask);
@@ -121,16 +115,10 @@
AudioProfile* profile);
static status_t audioProfileToHal(const AudioProfile& profile,
struct audio_profile* halProfile);
- static status_t audioSourceFromHal(audio_source_t halSource, AudioSource* source);
- static status_t audioSourceToHal(const AudioSource& source, audio_source_t* halSource);
static status_t audioStreamTypeFromHal(audio_stream_type_t halStreamType,
AudioStreamType* streamType);
static status_t audioStreamTypeToHal(const AudioStreamType& streamType,
audio_stream_type_t* halStreamType);
- static status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
- char* halDeviceAddress);
- static status_t deviceAddressFromHal(audio_devices_t halDeviceType,
- const char* halDeviceAddress, DeviceAddress* device);
private:
static status_t audioIndexChannelMaskFromHal(audio_channel_mask_t halChannelMask,
@@ -151,8 +139,113 @@
struct audio_port_config_mix_ext* mix,
struct audio_port_config_session_ext* session);
#endif
+
+ // V4 and below have DeviceAddress defined in the 'core' interface.
+ // To avoid duplicating code, the implementations of deviceAddressTo/FromHal
+ // are defined as templates. These templates can be only used directly by V4
+ // and below.
+#if MAJOR_VERSION >= 5
+ private:
+#endif
+ template <typename DA>
+ static status_t deviceAddressToHalImpl(const DA& device, audio_devices_t* halDeviceType,
+ char* halDeviceAddress);
+ template <typename DA>
+ static status_t deviceAddressFromHalImpl(audio_devices_t halDeviceType,
+ const char* halDeviceAddress, DA* device);
};
+#if MAJOR_VERSION <= 6
+#if MAJOR_VERSION >= 4
+inline status_t HidlUtils::audioContentTypeFromHal(const audio_content_type_t halContentType,
+ AudioContentType* contentType) {
+ *contentType = AudioContentType(halContentType);
+ return NO_ERROR;
+}
+
+inline status_t HidlUtils::audioContentTypeToHal(const AudioContentType& contentType,
+ audio_content_type_t* halContentType) {
+ *halContentType = static_cast<audio_content_type_t>(contentType);
+ return NO_ERROR;
+}
+#endif
+
+inline status_t HidlUtils::audioSourceFromHal(audio_source_t halSource, AudioSource* source) {
+ *source = AudioSource(halSource);
+ return NO_ERROR;
+}
+
+inline status_t HidlUtils::audioSourceToHal(const AudioSource& source, audio_source_t* halSource) {
+ *halSource = static_cast<audio_source_t>(source);
+ return NO_ERROR;
+}
+
+template <typename DA>
+status_t HidlUtils::deviceAddressToHalImpl(const DA& device, audio_devices_t* halDeviceType,
+ char* halDeviceAddress) {
+ *halDeviceType = static_cast<audio_devices_t>(device.device);
+ memset(halDeviceAddress, 0, AUDIO_DEVICE_MAX_ADDRESS_LEN);
+ if (audio_is_a2dp_out_device(*halDeviceType) || audio_is_a2dp_in_device(*halDeviceType)) {
+ snprintf(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
+ device.address.mac[0], device.address.mac[1], device.address.mac[2],
+ device.address.mac[3], device.address.mac[4], device.address.mac[5]);
+ } else if (*halDeviceType == AUDIO_DEVICE_OUT_IP || *halDeviceType == AUDIO_DEVICE_IN_IP) {
+ snprintf(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN, "%d.%d.%d.%d",
+ device.address.ipv4[0], device.address.ipv4[1], device.address.ipv4[2],
+ device.address.ipv4[3]);
+ } else if (audio_is_usb_out_device(*halDeviceType) || audio_is_usb_in_device(*halDeviceType)) {
+ snprintf(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN, "card=%d;device=%d",
+ device.address.alsa.card, device.address.alsa.device);
+ } else if (*halDeviceType == AUDIO_DEVICE_OUT_BUS || *halDeviceType == AUDIO_DEVICE_IN_BUS) {
+ snprintf(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN, "%s", device.busAddress.c_str());
+ } else if (*halDeviceType == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
+ *halDeviceType == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
+ snprintf(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN, "%s",
+ device.rSubmixAddress.c_str());
+ }
+ return NO_ERROR;
+}
+
+template <typename DA>
+status_t HidlUtils::deviceAddressFromHalImpl(audio_devices_t halDeviceType,
+ const char* halDeviceAddress, DA* device) {
+ if (device == nullptr) {
+ return BAD_VALUE;
+ }
+ device->device = AudioDevice(halDeviceType);
+ if (halDeviceAddress == nullptr ||
+ strnlen(halDeviceAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) {
+ return NO_ERROR;
+ }
+
+ if (audio_is_a2dp_out_device(halDeviceType) || audio_is_a2dp_in_device(halDeviceType)) {
+ int status =
+ sscanf(halDeviceAddress, "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX", &device->address.mac[0],
+ &device->address.mac[1], &device->address.mac[2], &device->address.mac[3],
+ &device->address.mac[4], &device->address.mac[5]);
+ return status == 6 ? OK : BAD_VALUE;
+ } else if (halDeviceType == AUDIO_DEVICE_OUT_IP || halDeviceType == AUDIO_DEVICE_IN_IP) {
+ int status = sscanf(halDeviceAddress, "%hhu.%hhu.%hhu.%hhu", &device->address.ipv4[0],
+ &device->address.ipv4[1], &device->address.ipv4[2],
+ &device->address.ipv4[3]);
+ return status == 4 ? OK : BAD_VALUE;
+ } else if (audio_is_usb_out_device(halDeviceType) || audio_is_usb_in_device(halDeviceType)) {
+ int status = sscanf(halDeviceAddress, "card=%d;device=%d", &device->address.alsa.card,
+ &device->address.alsa.device);
+ return status == 2 ? OK : BAD_VALUE;
+ } else if (halDeviceType == AUDIO_DEVICE_OUT_BUS || halDeviceType == AUDIO_DEVICE_IN_BUS) {
+ device->busAddress = halDeviceAddress;
+ return OK;
+ } else if (halDeviceType == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
+ halDeviceType == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
+ device->rSubmixAddress = halDeviceAddress;
+ return OK;
+ }
+ device->busAddress = halDeviceAddress;
+ return NO_ERROR;
+}
+#endif // MAJOR_VERSION <= 6
+
} // namespace implementation
} // namespace CPP_VERSION
} // namespace common
diff --git a/audio/common/all-versions/default/HidlUtilsCommon.cpp b/audio/common/all-versions/default/HidlUtilsCommon.cpp
new file mode 100644
index 0000000..d2da193
--- /dev/null
+++ b/audio/common/all-versions/default/HidlUtilsCommon.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2020 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 "HidlUtils.h"
+
+namespace android {
+namespace hardware {
+namespace audio {
+namespace common {
+namespace CPP_VERSION {
+namespace implementation {
+
+status_t HidlUtils::audioPortConfigsFromHal(unsigned int numHalConfigs,
+ const struct audio_port_config* halConfigs,
+ hidl_vec<AudioPortConfig>* configs) {
+ status_t result = NO_ERROR;
+ configs->resize(numHalConfigs);
+ for (unsigned int i = 0; i < numHalConfigs; ++i) {
+ if (status_t status = audioPortConfigFromHal(halConfigs[i], &(*configs)[i]);
+ status != NO_ERROR) {
+ result = status;
+ }
+ }
+ return result;
+}
+
+status_t HidlUtils::audioPortConfigsToHal(const hidl_vec<AudioPortConfig>& configs,
+ std::unique_ptr<audio_port_config[]>* halConfigs) {
+ status_t result = NO_ERROR;
+ halConfigs->reset(new audio_port_config[configs.size()]);
+ for (size_t i = 0; i < configs.size(); ++i) {
+ if (status_t status = audioPortConfigToHal(configs[i], &(*halConfigs)[i]);
+ status != NO_ERROR) {
+ result = status;
+ }
+ }
+ return result;
+}
+
+} // namespace implementation
+} // namespace CPP_VERSION
+} // namespace common
+} // namespace audio
+} // namespace hardware
+} // namespace android
diff --git a/audio/common/all-versions/default/tests/hidlutils_tests.cpp b/audio/common/all-versions/default/tests/hidlutils_tests.cpp
index bfc99e6..22571c0 100644
--- a/audio/common/all-versions/default/tests/hidlutils_tests.cpp
+++ b/audio/common/all-versions/default/tests/hidlutils_tests.cpp
@@ -28,6 +28,7 @@
#include <xsdc/XsdcSupport.h>
using namespace android;
+using ::android::hardware::hidl_vec;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
namespace xsd {
@@ -36,6 +37,8 @@
static constexpr audio_channel_mask_t kInvalidHalChannelMask =
static_cast<audio_channel_mask_t>(0xFFFFFFFFU);
+static constexpr audio_content_type_t kInvalidHalContentType =
+ static_cast<audio_content_type_t>(0xFFFFFFFFU);
static constexpr audio_devices_t kInvalidHalDevice = static_cast<audio_devices_t>(0xFFFFFFFFU);
static constexpr audio_format_t kInvalidHalFormat = static_cast<audio_format_t>(0xFFFFFFFFU);
static constexpr audio_gain_mode_t kInvalidHalGainMode =
@@ -117,6 +120,34 @@
}
}
+TEST(HidlUtils, ConvertInvalidChannelMasksFromHal) {
+ std::vector<std::string> validAndInvalidChannelMasks = {
+ toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO), "random string", ""};
+ hidl_vec<AudioChannelMask> validChannelMask;
+ EXPECT_EQ(BAD_VALUE,
+ HidlUtils::audioChannelMasksFromHal(validAndInvalidChannelMasks, &validChannelMask));
+ EXPECT_EQ(1, validChannelMask.size());
+ EXPECT_EQ(validAndInvalidChannelMasks[0], validChannelMask[0]);
+
+ std::vector<std::string> invalidChannelMasks = {"random string", ""};
+ hidl_vec<AudioChannelMask> empty;
+ EXPECT_EQ(BAD_VALUE, HidlUtils::audioChannelMasksFromHal(invalidChannelMasks, &empty));
+ EXPECT_EQ(0, empty.size());
+}
+
+TEST(HidlUtils, ConvertChannelMasksFromHal) {
+ std::vector<std::string> allHalChannelMasks;
+ for (const auto enumVal : xsdc_enum_range<xsd::AudioChannelMask>{}) {
+ allHalChannelMasks.push_back(toString(enumVal));
+ }
+ hidl_vec<AudioChannelMask> allChannelMasks;
+ EXPECT_EQ(NO_ERROR, HidlUtils::audioChannelMasksFromHal(allHalChannelMasks, &allChannelMasks));
+ EXPECT_EQ(allHalChannelMasks.size(), allChannelMasks.size());
+ for (size_t i = 0; i < allHalChannelMasks.size(); ++i) {
+ EXPECT_EQ(allHalChannelMasks[i], allChannelMasks[i]);
+ }
+}
+
TEST(HidlUtils, ConvertInvalidConfigBase) {
AudioConfigBase invalid;
EXPECT_EQ(BAD_VALUE, HidlUtils::audioConfigBaseFromHal({.sample_rate = 0,
@@ -147,6 +178,26 @@
EXPECT_EQ(configBase, configBaseBack);
}
+TEST(HidlUtils, ConvertInvalidContentType) {
+ AudioContentType invalid;
+ EXPECT_EQ(BAD_VALUE, HidlUtils::audioContentTypeFromHal(kInvalidHalContentType, &invalid));
+ audio_content_type_t halInvalid;
+ EXPECT_EQ(BAD_VALUE, HidlUtils::audioContentTypeToHal("random string", &halInvalid));
+}
+
+TEST(HidlUtils, ConvertContentType) {
+ for (const auto enumVal : xsdc_enum_range<xsd::AudioContentType>{}) {
+ const AudioContentType contentType = toString(enumVal);
+ audio_content_type_t halContentType;
+ AudioContentType contentTypeBack;
+ EXPECT_EQ(NO_ERROR, HidlUtils::audioContentTypeToHal(contentType, &halContentType))
+ << "Conversion of \"" << contentType << "\" failed";
+ EXPECT_EQ(NO_ERROR, HidlUtils::audioContentTypeFromHal(halContentType, &contentTypeBack))
+ << "Conversion of content type " << halContentType << " failed";
+ EXPECT_EQ(contentType, contentTypeBack);
+ }
+}
+
TEST(HidlUtils, ConvertInvalidDeviceType) {
AudioDevice invalid;
EXPECT_EQ(BAD_VALUE, HidlUtils::audioDeviceTypeFromHal(kInvalidHalDevice, &invalid));
@@ -314,6 +365,33 @@
}
}
+TEST(HidlUtils, ConvertInvalidFormatsFromHal) {
+ std::vector<std::string> validAndInvalidFormats = {
+ toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT), "random string", ""};
+ hidl_vec<AudioFormat> validFormat;
+ EXPECT_EQ(BAD_VALUE, HidlUtils::audioFormatsFromHal(validAndInvalidFormats, &validFormat));
+ EXPECT_EQ(1, validFormat.size());
+ EXPECT_EQ(validAndInvalidFormats[0], validFormat[0]);
+
+ std::vector<std::string> invalidFormats = {"random string", ""};
+ hidl_vec<AudioFormat> empty;
+ EXPECT_EQ(BAD_VALUE, HidlUtils::audioFormatsFromHal(invalidFormats, &empty));
+ EXPECT_EQ(0, empty.size());
+}
+
+TEST(HidlUtils, ConvertFormatsFromHal) {
+ std::vector<std::string> allHalFormats;
+ for (const auto enumVal : xsdc_enum_range<xsd::AudioFormat>{}) {
+ allHalFormats.push_back(toString(enumVal));
+ }
+ hidl_vec<AudioFormat> allFormats;
+ EXPECT_EQ(NO_ERROR, HidlUtils::audioFormatsFromHal(allHalFormats, &allFormats));
+ EXPECT_EQ(allHalFormats.size(), allFormats.size());
+ for (size_t i = 0; i < allHalFormats.size(); ++i) {
+ EXPECT_EQ(allHalFormats[i], allFormats[i]);
+ }
+}
+
TEST(HidlUtils, ConvertInvalidGainModeMask) {
hidl_vec<AudioGainMode> invalid;
EXPECT_EQ(BAD_VALUE, HidlUtils::audioGainModeMaskFromHal(kInvalidHalGainMode, &invalid));
diff --git a/audio/core/all-versions/default/Android.bp b/audio/core/all-versions/default/Android.bp
index 6be0628..e0f0860 100644
--- a/audio/core/all-versions/default/Android.bp
+++ b/audio/core/all-versions/default/Android.bp
@@ -125,13 +125,15 @@
}
cc_library_shared {
- enabled: false,
name: "android.hardware.audio@7.0-impl",
defaults: ["android.hardware.audio-impl_default"],
shared_libs: [
"android.hardware.audio@7.0",
"android.hardware.audio.common@7.0",
+ "android.hardware.audio.common@7.0-enums",
"android.hardware.audio.common@7.0-util",
+ "libbase",
+ "libxml2",
],
cflags: [
"-DMAJOR_VERSION=7",
diff --git a/audio/core/all-versions/default/Conversions.cpp b/audio/core/all-versions/default/Conversions.cpp
index 28d8f78..8e0a140 100644
--- a/audio/core/all-versions/default/Conversions.cpp
+++ b/audio/core/all-versions/default/Conversions.cpp
@@ -18,8 +18,11 @@
#include <stdio.h>
+#if MAJOR_VERSION >= 7
+#include <android_audio_policy_configuration_V7_0-enums.h>
+#endif
+#include <HidlUtils.h>
#include <log/log.h>
-#include <media/AudioContainers.h>
namespace android {
namespace hardware {
@@ -27,73 +30,36 @@
namespace CPP_VERSION {
namespace implementation {
-// TODO(mnaganov): Use method from HidlUtils for V7
+using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
+
+#if MAJOR_VERSION <= 6
std::string deviceAddressToHal(const DeviceAddress& address) {
- // HAL assumes that the address is NUL-terminated.
+ audio_devices_t halDevice;
char halAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
- memset(halAddress, 0, sizeof(halAddress));
- audio_devices_t halDevice = static_cast<audio_devices_t>(address.device);
- if (getAudioDeviceOutAllA2dpSet().count(halDevice) > 0 ||
- halDevice == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
- snprintf(halAddress, sizeof(halAddress), "%02X:%02X:%02X:%02X:%02X:%02X",
- address.address.mac[0], address.address.mac[1], address.address.mac[2],
- address.address.mac[3], address.address.mac[4], address.address.mac[5]);
- } else if (halDevice == AUDIO_DEVICE_OUT_IP || halDevice == AUDIO_DEVICE_IN_IP) {
- snprintf(halAddress, sizeof(halAddress), "%d.%d.%d.%d", address.address.ipv4[0],
- address.address.ipv4[1], address.address.ipv4[2], address.address.ipv4[3]);
- } else if (getAudioDeviceOutAllUsbSet().count(halDevice) > 0 ||
- getAudioDeviceInAllUsbSet().count(halDevice) > 0) {
- snprintf(halAddress, sizeof(halAddress), "card=%d;device=%d", address.address.alsa.card,
- address.address.alsa.device);
- } else if (halDevice == AUDIO_DEVICE_OUT_BUS || halDevice == AUDIO_DEVICE_IN_BUS) {
- snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str());
- } else if (halDevice == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
- halDevice == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
- snprintf(halAddress, sizeof(halAddress), "%s", address.rSubmixAddress.c_str());
- }
+ (void)deviceAddressToHal(address, &halDevice, halAddress);
return halAddress;
}
+#endif
+
+status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
+ char* halDeviceAddress) {
+#if MAJOR_VERSION >= 5
+ return HidlUtils::deviceAddressToHal(device, halDeviceType, halDeviceAddress);
+#else
+ return HidlUtils::deviceAddressToHalImpl(device, halDeviceType, halDeviceAddress);
+#endif
+}
+
+status_t deviceAddressFromHal(audio_devices_t halDeviceType, const char* halDeviceAddress,
+ DeviceAddress* device) {
+#if MAJOR_VERSION >= 5
+ return HidlUtils::deviceAddressFromHal(halDeviceType, halDeviceAddress, device);
+#else
+ return HidlUtils::deviceAddressFromHalImpl(halDeviceType, halDeviceAddress, device);
+#endif
+}
#if MAJOR_VERSION >= 4
-status_t deviceAddressFromHal(audio_devices_t device, const char* halAddress,
- DeviceAddress* address) {
- if (address == nullptr) {
- return BAD_VALUE;
- }
- address->device = AudioDevice(device);
- if (halAddress == nullptr || strnlen(halAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) {
- return OK;
- }
-
- if (getAudioDeviceOutAllA2dpSet().count(device) > 0 ||
- device == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
- int status =
- sscanf(halAddress, "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX", &address->address.mac[0],
- &address->address.mac[1], &address->address.mac[2], &address->address.mac[3],
- &address->address.mac[4], &address->address.mac[5]);
- return status == 6 ? OK : BAD_VALUE;
- } else if (device == AUDIO_DEVICE_OUT_IP || device == AUDIO_DEVICE_IN_IP) {
- int status =
- sscanf(halAddress, "%hhu.%hhu.%hhu.%hhu", &address->address.ipv4[0],
- &address->address.ipv4[1], &address->address.ipv4[2], &address->address.ipv4[3]);
- return status == 4 ? OK : BAD_VALUE;
- } else if (getAudioDeviceOutAllUsbSet().count(device) > 0 ||
- getAudioDeviceInAllUsbSet().count(device) > 0) {
- int status = sscanf(halAddress, "card=%d;device=%d", &address->address.alsa.card,
- &address->address.alsa.device);
- return status == 2 ? OK : BAD_VALUE;
- } else if (device == AUDIO_DEVICE_OUT_BUS || device == AUDIO_DEVICE_IN_BUS) {
- address->busAddress = halAddress;
- return OK;
- } else if (device == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
- device == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
- address->rSubmixAddress = halAddress;
- return OK;
- }
- address->busAddress = halAddress;
- return OK;
-}
-
bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
const struct audio_microphone_characteristic_t& src) {
bool status = false;
@@ -131,6 +97,44 @@
}
return status;
}
+#endif // MAJOR_VERSION >= 4
+
+#if MAJOR_VERSION >= 7
+namespace xsd {
+using namespace ::android::audio::policy::configuration::V7_0;
+}
+
+bool audioInputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_input_flags_t* halFlags) {
+ bool success = true;
+ *halFlags = {};
+ for (const auto& flag : flags) {
+ audio_input_flags_t halFlag;
+ if (!xsd::isUnknownAudioInOutFlag(flag) &&
+ audio_input_flag_from_string(flag.c_str(), &halFlag)) {
+ *halFlags = static_cast<audio_input_flags_t>(*halFlags | halFlag);
+ } else {
+ ALOGE("Unknown audio input flag \"%s\"", flag.c_str());
+ success = false;
+ }
+ }
+ return success;
+}
+
+bool audioOutputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_output_flags_t* halFlags) {
+ bool success = true;
+ *halFlags = {};
+ for (const auto& flag : flags) {
+ audio_output_flags_t halFlag;
+ if (!xsd::isUnknownAudioInOutFlag(flag) &&
+ audio_output_flag_from_string(flag.c_str(), &halFlag)) {
+ *halFlags = static_cast<audio_output_flags_t>(*halFlags | halFlag);
+ } else {
+ ALOGE("Unknown audio output flag \"%s\"", flag.c_str());
+ success = false;
+ }
+ }
+ return success;
+}
#endif
} // namespace implementation
diff --git a/audio/core/all-versions/default/Device.cpp b/audio/core/all-versions/default/Device.cpp
index 3c28159..bb69f0b 100644
--- a/audio/core/all-versions/default/Device.cpp
+++ b/audio/core/all-versions/default/Device.cpp
@@ -150,63 +150,76 @@
std::tuple<Result, sp<IStreamOut>> Device::openOutputStreamImpl(int32_t ioHandle,
const DeviceAddress& device,
const AudioConfig& config,
- AudioOutputFlagBitfield flags,
+ const AudioOutputFlags& flags,
AudioConfig* suggestedConfig) {
audio_config_t halConfig;
HidlUtils::audioConfigToHal(config, &halConfig);
audio_stream_out_t* halStream;
- ALOGV(
- "open_output_stream handle: %d devices: %x flags: %#x "
- "srate: %d format %#x channels %x address %s",
- ioHandle, static_cast<audio_devices_t>(device.device),
- static_cast<audio_output_flags_t>(flags), halConfig.sample_rate, halConfig.format,
- halConfig.channel_mask, deviceAddressToHal(device).c_str());
- int status =
- mDevice->open_output_stream(mDevice, ioHandle, static_cast<audio_devices_t>(device.device),
- static_cast<audio_output_flags_t>(flags), &halConfig,
- &halStream, deviceAddressToHal(device).c_str());
+ audio_devices_t halDevice;
+ char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
+ if (deviceAddressToHal(device, &halDevice, halDeviceAddress) != NO_ERROR) {
+ return {Result::INVALID_ARGUMENTS, nullptr};
+ }
+ audio_output_flags_t halFlags;
+ if (!audioOutputFlagsToHal(flags, &halFlags)) {
+ return {Result::INVALID_ARGUMENTS, nullptr};
+ }
+ ALOGV("open_output_stream handle: %d devices: %x flags: %#x "
+ "srate: %d format %#x channels %x address %s",
+ ioHandle, halDevice, halFlags, halConfig.sample_rate, halConfig.format,
+ halConfig.channel_mask, halDeviceAddress);
+ int status = mDevice->open_output_stream(mDevice, ioHandle, halDevice, halFlags, &halConfig,
+ &halStream, halDeviceAddress);
ALOGV("open_output_stream status %d stream %p", status, halStream);
sp<IStreamOut> streamOut;
if (status == OK) {
streamOut = new StreamOut(this, halStream);
++mOpenedStreamsCount;
}
- status_t convertStatus = HidlUtils::audioConfigFromHal(halConfig, suggestedConfig);
+ status_t convertStatus =
+ HidlUtils::audioConfigFromHal(halConfig, false /*isInput*/, suggestedConfig);
ALOGW_IF(convertStatus != OK, "%s: suggested config with incompatible fields", __func__);
return {analyzeStatus("open_output_stream", status, {EINVAL} /*ignore*/), streamOut};
}
std::tuple<Result, sp<IStreamIn>> Device::openInputStreamImpl(
- int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
- AudioInputFlagBitfield flags, AudioSource source, AudioConfig* suggestedConfig) {
+ int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
+ const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig) {
audio_config_t halConfig;
HidlUtils::audioConfigToHal(config, &halConfig);
audio_stream_in_t* halStream;
- ALOGV(
- "open_input_stream handle: %d devices: %x flags: %#x "
- "srate: %d format %#x channels %x address %s source %d",
- ioHandle, static_cast<audio_devices_t>(device.device),
- static_cast<audio_input_flags_t>(flags), halConfig.sample_rate, halConfig.format,
- halConfig.channel_mask, deviceAddressToHal(device).c_str(),
- static_cast<audio_source_t>(source));
- int status = mDevice->open_input_stream(
- mDevice, ioHandle, static_cast<audio_devices_t>(device.device), &halConfig, &halStream,
- static_cast<audio_input_flags_t>(flags), deviceAddressToHal(device).c_str(),
- static_cast<audio_source_t>(source));
+ audio_devices_t halDevice;
+ char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
+ if (deviceAddressToHal(device, &halDevice, halDeviceAddress) != NO_ERROR) {
+ return {Result::INVALID_ARGUMENTS, nullptr};
+ }
+ audio_input_flags_t halFlags;
+ audio_source_t halSource;
+ if (!audioInputFlagsToHal(flags, &halFlags) ||
+ HidlUtils::audioSourceToHal(source, &halSource) != NO_ERROR) {
+ return {Result::INVALID_ARGUMENTS, nullptr};
+ }
+ ALOGV("open_input_stream handle: %d devices: %x flags: %#x "
+ "srate: %d format %#x channels %x address %s source %d",
+ ioHandle, halDevice, halFlags, halConfig.sample_rate, halConfig.format,
+ halConfig.channel_mask, halDeviceAddress, halSource);
+ int status = mDevice->open_input_stream(mDevice, ioHandle, halDevice, &halConfig, &halStream,
+ halFlags, halDeviceAddress, halSource);
ALOGV("open_input_stream status %d stream %p", status, halStream);
sp<IStreamIn> streamIn;
if (status == OK) {
streamIn = new StreamIn(this, halStream);
++mOpenedStreamsCount;
}
- status_t convertStatus = HidlUtils::audioConfigFromHal(halConfig, suggestedConfig);
+ status_t convertStatus =
+ HidlUtils::audioConfigFromHal(halConfig, true /*isInput*/, suggestedConfig);
ALOGW_IF(convertStatus != OK, "%s: suggested config with incompatible fields", __func__);
return {analyzeStatus("open_input_stream", status, {EINVAL} /*ignore*/), streamIn};
}
#if MAJOR_VERSION == 2
Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioOutputFlagBitfield flags,
+ const AudioConfig& config, AudioOutputFlags flags,
openOutputStream_cb _hidl_cb) {
AudioConfig suggestedConfig;
auto [result, streamOut] =
@@ -216,7 +229,7 @@
}
Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
+ const AudioConfig& config, AudioInputFlags flags,
AudioSource source, openInputStream_cb _hidl_cb) {
AudioConfig suggestedConfig;
auto [result, streamIn] =
@@ -227,7 +240,12 @@
#elif MAJOR_VERSION >= 4
Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioOutputFlagBitfield flags,
+ const AudioConfig& config,
+#if MAJOR_VERSION <= 6
+ AudioOutputFlags flags,
+#else
+ const AudioOutputFlags& flags,
+#endif
const SourceMetadata& sourceMetadata,
openOutputStream_cb _hidl_cb) {
AudioConfig suggestedConfig;
@@ -241,7 +259,12 @@
}
Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
+ const AudioConfig& config,
+#if MAJOR_VERSION <= 6
+ AudioInputFlags flags,
+#else
+ const AudioInputFlags& flags,
+#endif
const SinkMetadata& sinkMetadata,
openInputStream_cb _hidl_cb) {
if (sinkMetadata.tracks.size() == 0) {
@@ -271,9 +294,7 @@
Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
const hidl_vec<AudioPortConfig>& sinks,
createAudioPatch_cb _hidl_cb) {
- auto [retval, patch] = createOrUpdateAudioPatch(
- static_cast<AudioPatchHandle>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE), sources,
- sinks);
+ auto [retval, patch] = createOrUpdateAudioPatch(AudioPatchHandle{}, sources, sinks);
_hidl_cb(retval, patch);
return Void();
}
@@ -454,7 +475,7 @@
const hidl_vec<AudioPortConfig>& sources,
const hidl_vec<AudioPortConfig>& sinks,
createAudioPatch_cb _hidl_cb) {
- if (previousPatch != static_cast<int32_t>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE)) {
+ if (previousPatch != static_cast<int32_t>(AudioPatchHandle{})) {
auto [retval, patch] = createOrUpdateAudioPatch(previousPatch, sources, sinks);
_hidl_cb(retval, patch);
} else {
diff --git a/audio/core/all-versions/default/ParametersUtil.cpp b/audio/core/all-versions/default/ParametersUtil.cpp
index 0c8e28a..694eb73 100644
--- a/audio/core/all-versions/default/ParametersUtil.cpp
+++ b/audio/core/all-versions/default/ParametersUtil.cpp
@@ -149,9 +149,15 @@
}
return setParams(params);
}
+
Result ParametersUtil::setParam(const char* name, const DeviceAddress& address) {
- AudioParameter params(String8(deviceAddressToHal(address).c_str()));
- params.addInt(String8(name), int(address.device));
+ audio_devices_t halDeviceType;
+ char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
+ if (deviceAddressToHal(address, &halDeviceType, halDeviceAddress) != NO_ERROR) {
+ return Result::INVALID_ARGUMENTS;
+ }
+ AudioParameter params{String8(halDeviceAddress)};
+ params.addInt(String8(name), halDeviceType);
return setParams(params);
}
diff --git a/audio/core/all-versions/default/PrimaryDevice.cpp b/audio/core/all-versions/default/PrimaryDevice.cpp
index 11c1c5a..fe56177 100644
--- a/audio/core/all-versions/default/PrimaryDevice.cpp
+++ b/audio/core/all-versions/default/PrimaryDevice.cpp
@@ -73,28 +73,36 @@
#if MAJOR_VERSION == 2
Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config,
- AudioOutputFlagBitfield flags,
+ const AudioConfig& config, AudioOutputFlags flags,
openOutputStream_cb _hidl_cb) {
return mDevice->openOutputStream(ioHandle, device, config, flags, _hidl_cb);
}
Return<void> PrimaryDevice::openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
+ const AudioConfig& config, AudioInputFlags flags,
AudioSource source, openInputStream_cb _hidl_cb) {
return mDevice->openInputStream(ioHandle, device, config, flags, source, _hidl_cb);
}
#elif MAJOR_VERSION >= 4
Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config,
- AudioOutputFlagBitfield flags,
+#if MAJOR_VERSION <= 6
+ AudioOutputFlags flags,
+#else
+ const AudioOutputFlags& flags,
+#endif
const SourceMetadata& sourceMetadata,
openOutputStream_cb _hidl_cb) {
return mDevice->openOutputStream(ioHandle, device, config, flags, sourceMetadata, _hidl_cb);
}
Return<void> PrimaryDevice::openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
+ const AudioConfig& config,
+#if MAJOR_VERSION <= 6
+ AudioInputFlags flags,
+#else
+ const AudioInputFlags& flags,
+#endif
const SinkMetadata& sinkMetadata,
openInputStream_cb _hidl_cb) {
return mDevice->openInputStream(ioHandle, device, config, flags, sinkMetadata, _hidl_cb);
diff --git a/audio/core/all-versions/default/Stream.cpp b/audio/core/all-versions/default/Stream.cpp
index 74e5945..c74079d 100644
--- a/audio/core/all-versions/default/Stream.cpp
+++ b/audio/core/all-versions/default/Stream.cpp
@@ -23,6 +23,7 @@
#include <inttypes.h>
+#include <HidlUtils.h>
#include <android/log.h>
#include <hardware/audio.h>
#include <hardware/audio_effect.h>
@@ -35,7 +36,11 @@
namespace CPP_VERSION {
namespace implementation {
-Stream::Stream(audio_stream_t* stream) : mStream(stream) {}
+using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
+
+Stream::Stream(bool isInput, audio_stream_t* stream) : mIsInput(isInput), mStream(stream) {
+ (void)mIsInput; // prevent 'unused field' warnings in pre-V7 versions.
+}
Stream::~Stream() {
mStream = nullptr;
@@ -78,6 +83,7 @@
return mStream->get_buffer_size(mStream);
}
+#if MAJOR_VERSION <= 6
Return<uint32_t> Stream::getSampleRate() {
return mStream->get_sample_rate(mStream);
}
@@ -201,6 +207,96 @@
return Void();
}
+#else // MAJOR_VERSION <= 6
+
+Return<void> Stream::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
+ String8 halListValue;
+ Result result = getParam(AudioParameter::keyStreamSupportedFormats, &halListValue);
+ hidl_vec<AudioProfile> profiles;
+ if (result != Result::OK) {
+ _hidl_cb(result, profiles);
+ return Void();
+ }
+ // Ensure that the separator is one character, despite that it's defined as a C string.
+ static_assert(sizeof(AUDIO_PARAMETER_VALUE_LIST_SEPARATOR) == 2);
+ std::vector<std::string> halFormats =
+ util::splitString(halListValue.string(), AUDIO_PARAMETER_VALUE_LIST_SEPARATOR[0]);
+ hidl_vec<AudioFormat> formats;
+ (void)HidlUtils::audioFormatsFromHal(halFormats, &formats);
+ std::vector<AudioProfile> tempProfiles;
+ for (const auto& format : formats) {
+ audio_format_t halFormat;
+ if (status_t status = HidlUtils::audioFormatToHal(format, &halFormat); status != NO_ERROR) {
+ continue;
+ }
+ AudioParameter context;
+ context.addInt(String8(AUDIO_PARAMETER_STREAM_FORMAT), int(halFormat));
+ // Query supported sample rates for the format.
+ result = getParam(AudioParameter::keyStreamSupportedSamplingRates, &halListValue, context);
+ if (result != Result::OK) break;
+ std::vector<std::string> halSampleRates =
+ util::splitString(halListValue.string(), AUDIO_PARAMETER_VALUE_LIST_SEPARATOR[0]);
+ hidl_vec<uint32_t> sampleRates;
+ sampleRates.resize(halSampleRates.size());
+ for (size_t i = 0; i < sampleRates.size(); ++i) {
+ sampleRates[i] = std::stoi(halSampleRates[i]);
+ }
+ // Query supported channel masks for the format.
+ result = getParam(AudioParameter::keyStreamSupportedChannels, &halListValue, context);
+ if (result != Result::OK) break;
+ std::vector<std::string> halChannelMasks =
+ util::splitString(halListValue.string(), AUDIO_PARAMETER_VALUE_LIST_SEPARATOR[0]);
+ hidl_vec<AudioChannelMask> channelMasks;
+ (void)HidlUtils::audioChannelMasksFromHal(halChannelMasks, &channelMasks);
+ // Create a profile.
+ if (channelMasks.size() != 0 && sampleRates.size() != 0) {
+ tempProfiles.push_back({.format = format,
+ .sampleRates = std::move(sampleRates),
+ .channelMasks = std::move(channelMasks)});
+ }
+ }
+ // Legacy get_parameter does not return a status_t, thus can not advertise of failure.
+ // Note that the method must not return an empty list if this capability is supported.
+ if (!tempProfiles.empty()) {
+ profiles = tempProfiles;
+ } else {
+ result = Result::NOT_SUPPORTED;
+ }
+ _hidl_cb(result, profiles);
+ return Void();
+}
+
+Return<void> Stream::getAudioProperties(getAudioProperties_cb _hidl_cb) {
+ audio_config_base_t halConfigBase = {mStream->get_sample_rate(mStream),
+ mStream->get_channels(mStream),
+ mStream->get_format(mStream)};
+ AudioConfigBase configBase = {};
+ status_t status = HidlUtils::audioConfigBaseFromHal(halConfigBase, mIsInput, &configBase);
+ _hidl_cb(Stream::analyzeStatus("get_audio_properties", status), configBase);
+ return Void();
+}
+
+Return<Result> Stream::setAudioProperties(const AudioConfigBase& config) {
+ audio_config_base_t halConfigBase = {};
+ status_t status = HidlUtils::audioConfigBaseToHal(config, &halConfigBase);
+ if (status != NO_ERROR) {
+ return Stream::analyzeStatus("set_audio_properties", status);
+ }
+ if (Result result = setParam(AudioParameter::keySamplingRate,
+ static_cast<int>(halConfigBase.sample_rate));
+ result != Result::OK) {
+ return result;
+ }
+ if (Result result =
+ setParam(AudioParameter::keyChannels, static_cast<int>(halConfigBase.channel_mask));
+ result != Result::OK) {
+ return result;
+ }
+ return setParam(AudioParameter::keyFormat, static_cast<int>(halConfigBase.format));
+}
+
+#endif // MAJOR_VERSION <= 6
+
Return<Result> Stream::addEffect(uint64_t effectId) {
effect_handle_t halEffect = EffectMap::getInstance().get(effectId);
if (halEffect != NULL) {
@@ -257,12 +353,14 @@
}
#elif MAJOR_VERSION >= 4
Return<void> Stream::getDevices(getDevices_cb _hidl_cb) {
- int device = 0;
- Result retval = getParam(AudioParameter::keyRouting, &device);
+ int halDevice = 0;
+ Result retval = getParam(AudioParameter::keyRouting, &halDevice);
hidl_vec<DeviceAddress> devices;
if (retval == Result::OK) {
devices.resize(1);
- devices[0].device = static_cast<AudioDevice>(device);
+ retval = Stream::analyzeStatus("get_devices",
+ deviceAddressFromHal(static_cast<audio_devices_t>(halDevice),
+ nullptr, &devices[0]));
}
_hidl_cb(retval, devices);
return Void();
@@ -273,14 +371,13 @@
if (devices.size() > 1) {
return Result::NOT_SUPPORTED;
}
- DeviceAddress address;
+ DeviceAddress address{};
if (devices.size() == 1) {
address = devices[0];
- } else {
- address.device = AudioDevice::NONE;
}
return setParam(AudioParameter::keyRouting, address);
}
+
Return<void> Stream::getParameters(const hidl_vec<ParameterValue>& context,
const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
getParametersImpl(context, keys, _hidl_cb);
diff --git a/audio/core/all-versions/default/StreamIn.cpp b/audio/core/all-versions/default/StreamIn.cpp
index f1152ca..ead7204 100644
--- a/audio/core/all-versions/default/StreamIn.cpp
+++ b/audio/core/all-versions/default/StreamIn.cpp
@@ -24,11 +24,12 @@
//#define LOG_NDEBUG 0
#define ATRACE_TAG ATRACE_TAG_AUDIO
+#include <HidlUtils.h>
#include <android/log.h>
#include <hardware/audio.h>
#include <utils/Trace.h>
-#include <memory>
#include <cmath>
+#include <memory>
namespace android {
namespace hardware {
@@ -36,6 +37,8 @@
namespace CPP_VERSION {
namespace implementation {
+using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
+
namespace {
class ReadThread : public Thread {
@@ -141,7 +144,7 @@
StreamIn::StreamIn(const sp<Device>& device, audio_stream_in_t* stream)
: mDevice(device),
mStream(stream),
- mStreamCommon(new Stream(&stream->common)),
+ mStreamCommon(new Stream(true /*isInput*/, &stream->common)),
mStreamMmap(new StreamMmap<audio_stream_in_t>(stream)),
mEfGroup(nullptr),
mStopReadThread(false) {}
@@ -177,6 +180,7 @@
return mStreamCommon->getBufferSize();
}
+#if MAJOR_VERSION <= 6
Return<uint32_t> StreamIn::getSampleRate() {
return mStreamCommon->getSampleRate();
}
@@ -223,6 +227,18 @@
return mStreamCommon->setFormat(format);
}
+#else
+
+Return<void> StreamIn::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
+ return mStreamCommon->getSupportedProfiles(_hidl_cb);
+}
+
+Return<Result> StreamIn::setAudioProperties(const AudioConfigBase& config) {
+ return mStreamCommon->setAudioProperties(config);
+}
+
+#endif // MAJOR_VERSION <= 6
+
Return<void> StreamIn::getAudioProperties(getAudioProperties_cb _hidl_cb) {
return mStreamCommon->getAudioProperties(_hidl_cb);
}
@@ -321,9 +337,11 @@
Return<void> StreamIn::getAudioSource(getAudioSource_cb _hidl_cb) {
int halSource;
Result retval = mStreamCommon->getParam(AudioParameter::keyInputSource, &halSource);
- AudioSource source(AudioSource::DEFAULT);
+ AudioSource source = {};
if (retval == Result::OK) {
- source = AudioSource(halSource);
+ retval = Stream::analyzeStatus(
+ "get_audio_source",
+ HidlUtils::audioSourceFromHal(static_cast<audio_source_t>(halSource), &source));
}
_hidl_cb(retval, source);
return Void();
@@ -340,7 +358,11 @@
Return<void> StreamIn::prepareForReading(uint32_t frameSize, uint32_t framesCount,
prepareForReading_cb _hidl_cb) {
status_t status;
+#if MAJOR_VERSION <= 6
ThreadInfo threadInfo = {0, 0};
+#else
+ int32_t threadInfo = 0;
+#endif
// Wrap the _hidl_cb to return an error
auto sendError = [&threadInfo, &_hidl_cb](Result result) {
@@ -410,8 +432,12 @@
mStatusMQ = std::move(tempStatusMQ);
mReadThread = tempReadThread.release();
mEfGroup = tempElfGroup.release();
+#if MAJOR_VERSION <= 6
threadInfo.pid = getpid();
threadInfo.tid = mReadThread->getTid();
+#else
+ threadInfo = mReadThread->getTid();
+#endif
_hidl_cb(Result::OK, *mCommandMQ->getDesc(), *mDataMQ->getDesc(), *mStatusMQ->getDesc(),
threadInfo);
return Void();
@@ -459,16 +485,13 @@
std::vector<record_track_metadata> halTracks;
halTracks.reserve(sinkMetadata.tracks.size());
for (auto& metadata : sinkMetadata.tracks) {
- record_track_metadata halTrackMetadata = {
- .source = static_cast<audio_source_t>(metadata.source), .gain = metadata.gain};
+ record_track_metadata halTrackMetadata = {.gain = metadata.gain};
+ (void)HidlUtils::audioSourceToHal(metadata.source, &halTrackMetadata.source);
#if MAJOR_VERSION >= 5
if (metadata.destination.getDiscriminator() ==
RecordTrackMetadata::Destination::hidl_discriminator::device) {
- halTrackMetadata.dest_device =
- static_cast<audio_devices_t>(metadata.destination.device().device);
- strncpy(halTrackMetadata.dest_device_address,
- deviceAddressToHal(metadata.destination.device()).c_str(),
- AUDIO_DEVICE_MAX_ADDRESS_LEN);
+ (void)deviceAddressToHal(metadata.destination.device(), &halTrackMetadata.dest_device,
+ halTrackMetadata.dest_device_address);
}
#endif
halTracks.push_back(halTrackMetadata);
diff --git a/audio/core/all-versions/default/StreamOut.cpp b/audio/core/all-versions/default/StreamOut.cpp
index 007eb45..5633cbb 100644
--- a/audio/core/all-versions/default/StreamOut.cpp
+++ b/audio/core/all-versions/default/StreamOut.cpp
@@ -26,6 +26,7 @@
#include <memory>
+#include <HidlUtils.h>
#include <android/log.h>
#include <hardware/audio.h>
#include <utils/Trace.h>
@@ -36,6 +37,8 @@
namespace CPP_VERSION {
namespace implementation {
+using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
+
namespace {
class WriteThread : public Thread {
@@ -142,7 +145,7 @@
StreamOut::StreamOut(const sp<Device>& device, audio_stream_out_t* stream)
: mDevice(device),
mStream(stream),
- mStreamCommon(new Stream(&stream->common)),
+ mStreamCommon(new Stream(false /*isInput*/, &stream->common)),
mStreamMmap(new StreamMmap<audio_stream_out_t>(stream)),
mEfGroup(nullptr),
mStopWriteThread(false) {}
@@ -182,6 +185,7 @@
return mStreamCommon->getBufferSize();
}
+#if MAJOR_VERSION <= 6
Return<uint32_t> StreamOut::getSampleRate() {
return mStreamCommon->getSampleRate();
}
@@ -228,6 +232,18 @@
return mStreamCommon->setFormat(format);
}
+#else
+
+Return<void> StreamOut::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
+ return mStreamCommon->getSupportedProfiles(_hidl_cb);
+}
+
+Return<Result> StreamOut::setAudioProperties(const AudioConfigBase& config) {
+ return mStreamCommon->setAudioProperties(config);
+}
+
+#endif // MAJOR_VERSION <= 6
+
Return<void> StreamOut::getAudioProperties(getAudioProperties_cb _hidl_cb) {
return mStreamCommon->getAudioProperties(_hidl_cb);
}
@@ -327,7 +343,11 @@
Return<void> StreamOut::prepareForWriting(uint32_t frameSize, uint32_t framesCount,
prepareForWriting_cb _hidl_cb) {
status_t status;
+#if MAJOR_VERSION <= 6
ThreadInfo threadInfo = {0, 0};
+#else
+ int32_t threadInfo = 0;
+#endif
// Wrap the _hidl_cb to return an error
auto sendError = [&threadInfo, &_hidl_cb](Result result) {
@@ -396,8 +416,12 @@
mStatusMQ = std::move(tempStatusMQ);
mWriteThread = tempWriteThread.release();
mEfGroup = tempElfGroup.release();
+#if MAJOR_VERSION <= 6
threadInfo.pid = getpid();
threadInfo.tid = mWriteThread->getTid();
+#else
+ threadInfo = mWriteThread->getTid();
+#endif
_hidl_cb(Result::OK, *mCommandMQ->getDesc(), *mDataMQ->getDesc(), *mStatusMQ->getDesc(),
threadInfo);
return Void();
@@ -565,14 +589,14 @@
if (mStream->update_source_metadata == nullptr) {
return Void(); // not supported by the HAL
}
- std::vector<playback_track_metadata> halTracks;
+ std::vector<playback_track_metadata_t> halTracks;
halTracks.reserve(sourceMetadata.tracks.size());
for (auto& metadata : sourceMetadata.tracks) {
- halTracks.push_back({
- .usage = static_cast<audio_usage_t>(metadata.usage),
- .content_type = static_cast<audio_content_type_t>(metadata.contentType),
- .gain = metadata.gain,
- });
+ playback_track_metadata_t halTrackMetadata = {.gain = metadata.gain};
+ (void)HidlUtils::audioUsageToHal(metadata.usage, &halTrackMetadata.usage);
+ (void)HidlUtils::audioContentTypeToHal(metadata.contentType,
+ &halTrackMetadata.content_type);
+ halTracks.push_back(std::move(halTrackMetadata));
}
const source_metadata_t halMetadata = {
.track_count = halTracks.size(),
diff --git a/audio/core/all-versions/default/include/core/default/Conversions.h b/audio/core/all-versions/default/include/core/default/Conversions.h
index cb7914f..2372771 100644
--- a/audio/core/all-versions/default/include/core/default/Conversions.h
+++ b/audio/core/all-versions/default/include/core/default/Conversions.h
@@ -23,22 +23,54 @@
#include <system/audio.h>
+#include <VersionUtils.h>
+
namespace android {
namespace hardware {
namespace audio {
namespace CPP_VERSION {
namespace implementation {
+using ::android::hardware::hidl_vec;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
+#if MAJOR_VERSION <= 6
+// Temporary version for compatibility with forks of the default implementation.
+// Will be removed, do not use!
std::string deviceAddressToHal(const DeviceAddress& address);
+#endif
+
+status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
+ char* halDeviceAddress);
+status_t deviceAddressFromHal(audio_devices_t halDeviceType, const char* halDeviceAddress,
+ DeviceAddress* device);
#if MAJOR_VERSION >= 4
bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
const struct audio_microphone_characteristic_t& src);
#endif
+#if MAJOR_VERSION <= 6
+using AudioInputFlags =
+ ::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield;
+using AudioOutputFlags =
+ ::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield;
+
+inline bool audioInputFlagsToHal(AudioInputFlags flags, audio_input_flags_t* halFlags) {
+ *halFlags = static_cast<audio_input_flags_t>(flags);
+ return true;
+}
+
+inline bool audioOutputFlagsToHal(AudioOutputFlags flags, audio_output_flags_t* halFlags) {
+ *halFlags = static_cast<audio_output_flags_t>(flags);
+ return true;
+}
+#else
+bool audioInputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_input_flags_t* halFlags);
+bool audioOutputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_output_flags_t* halFlags);
+#endif
+
} // namespace implementation
} // namespace CPP_VERSION
} // namespace audio
diff --git a/audio/core/all-versions/default/include/core/default/Device.h b/audio/core/all-versions/default/include/core/default/Device.h
index 907acd7..461c253 100644
--- a/audio/core/all-versions/default/include/core/default/Device.h
+++ b/audio/core/all-versions/default/include/core/default/Device.h
@@ -44,8 +44,13 @@
using ::android::hardware::Return;
using ::android::hardware::Void;
#if MAJOR_VERSION <= 6
-using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield;
-using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield;
+using AudioInputFlags =
+ ::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield;
+using AudioOutputFlags =
+ ::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield;
+#else
+using AudioInputFlags = hidl_vec<::android::hardware::audio::CPP_VERSION::AudioInOutFlag>;
+using AudioOutputFlags = hidl_vec<::android::hardware::audio::CPP_VERSION::AudioInOutFlag>;
#endif
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
@@ -67,28 +72,36 @@
std::tuple<Result, sp<IStreamOut>> openOutputStreamImpl(int32_t ioHandle,
const DeviceAddress& device,
const AudioConfig& config,
- AudioOutputFlagBitfield flags,
+ const AudioOutputFlags& flags,
AudioConfig* suggestedConfig);
std::tuple<Result, sp<IStreamIn>> openInputStreamImpl(
- int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
- AudioInputFlagBitfield flags, AudioSource source, AudioConfig* suggestedConfig);
-#if MAJOR_VERSION == 2
+ int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
+ const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig);
+
Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioOutputFlagBitfield flags,
- openOutputStream_cb _hidl_cb) override;
- Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
- AudioSource source, openInputStream_cb _hidl_cb) override;
-#elif MAJOR_VERSION >= 4
- Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioOutputFlagBitfield flags,
- const SourceMetadata& sourceMetadata,
- openOutputStream_cb _hidl_cb) override;
- Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
- const SinkMetadata& sinkMetadata,
- openInputStream_cb _hidl_cb) override;
+ const AudioConfig& config,
+#if MAJOR_VERSION <= 6
+ AudioOutputFlags flags,
+#else
+ const AudioOutputFlags& flags,
#endif
+#if MAJOR_VERSION >= 4
+ const SourceMetadata& sourceMetadata,
+#endif
+ openOutputStream_cb _hidl_cb) override;
+ Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
+ const AudioConfig& config,
+#if MAJOR_VERSION <= 6
+ AudioInputFlags flags,
+#else
+ const AudioInputFlags& flags,
+#endif
+#if MAJOR_VERSION == 2
+ AudioSource source,
+#elif MAJOR_VERSION >= 4
+ const SinkMetadata& sinkMetadata,
+#endif
+ openInputStream_cb _hidl_cb) override;
Return<bool> supportsAudioPatches() override;
Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
diff --git a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h
index ccdb7b2..5f65acf 100644
--- a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h
+++ b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h
@@ -54,21 +54,29 @@
getInputBufferSize_cb _hidl_cb) override;
Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioOutputFlagBitfield flags,
+ const AudioConfig& config,
+#if MAJOR_VERSION <= 6
+ AudioOutputFlags flags,
+#else
+ const AudioOutputFlags& flags,
+#endif
#if MAJOR_VERSION >= 4
const SourceMetadata& sourceMetadata,
#endif
openOutputStream_cb _hidl_cb) override;
-
Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
- AudioSource source, openInputStream_cb _hidl_cb);
-#if MAJOR_VERSION >= 4
- Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
- const AudioConfig& config, AudioInputFlagBitfield flags,
- const SinkMetadata& sinkMetadata,
- openInputStream_cb _hidl_cb) override;
+ const AudioConfig& config,
+#if MAJOR_VERSION <= 6
+ AudioInputFlags flags,
+#else
+ const AudioInputFlags& flags,
#endif
+#if MAJOR_VERSION == 2
+ AudioSource source,
+#elif MAJOR_VERSION >= 4
+ const SinkMetadata& sinkMetadata,
+#endif
+ openInputStream_cb _hidl_cb) override;
Return<bool> supportsAudioPatches() override;
Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
diff --git a/audio/core/all-versions/default/include/core/default/Stream.h b/audio/core/all-versions/default/include/core/default/Stream.h
index ce0003b..0865992 100644
--- a/audio/core/all-versions/default/include/core/default/Stream.h
+++ b/audio/core/all-versions/default/include/core/default/Stream.h
@@ -41,12 +41,14 @@
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
+#if MAJOR_VERSION <= 6
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioChannelBitfield;
+#endif
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
struct Stream : public IStream, public ParametersUtil {
- explicit Stream(audio_stream_t* stream);
+ Stream(bool isInput, audio_stream_t* stream);
/** 1GiB is the maximum buffer size the HAL client is allowed to request.
* This value has been chosen to be under SIZE_MAX and still big enough
@@ -59,6 +61,7 @@
Return<uint64_t> getFrameSize() override;
Return<uint64_t> getFrameCount() override;
Return<uint64_t> getBufferSize() override;
+#if MAJOR_VERSION <= 6
Return<uint32_t> getSampleRate() override;
#if MAJOR_VERSION == 2
Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
@@ -72,6 +75,10 @@
Return<AudioFormat> getFormat() override;
Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
Return<Result> setFormat(AudioFormat format) override;
+#else
+ Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override;
+ Return<Result> setAudioProperties(const AudioConfigBase& config) override;
+#endif // MAJOR_VERSION <= 6
Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
Return<Result> addEffect(uint64_t effectId) override;
Return<Result> removeEffect(uint64_t effectId) override;
@@ -110,13 +117,14 @@
const std::vector<int>& ignoreErrors);
private:
- audio_stream_t* mStream;
+ const bool mIsInput;
+ audio_stream_t* mStream;
- virtual ~Stream();
+ virtual ~Stream();
- // Methods from ParametersUtil.
- char* halGetParameters(const char* keys) override;
- int halSetParameters(const char* keysAndValues) override;
+ // Methods from ParametersUtil.
+ char* halGetParameters(const char* keys) override;
+ int halSetParameters(const char* keysAndValues) override;
};
template <typename T>
diff --git a/audio/core/all-versions/default/include/core/default/StreamIn.h b/audio/core/all-versions/default/include/core/default/StreamIn.h
index 24f9944..b861c6c 100644
--- a/audio/core/all-versions/default/include/core/default/StreamIn.h
+++ b/audio/core/all-versions/default/include/core/default/StreamIn.h
@@ -56,6 +56,7 @@
Return<uint64_t> getFrameSize() override;
Return<uint64_t> getFrameCount() override;
Return<uint64_t> getBufferSize() override;
+#if MAJOR_VERSION <= 6
Return<uint32_t> getSampleRate() override;
#if MAJOR_VERSION == 2
Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
@@ -69,6 +70,10 @@
Return<AudioFormat> getFormat() override;
Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
Return<Result> setFormat(AudioFormat format) override;
+#else
+ Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override;
+ Return<Result> setAudioProperties(const AudioConfigBase& config) override;
+#endif // MAJOR_VERSION <= 6
Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
Return<Result> addEffect(uint64_t effectId) override;
Return<Result> removeEffect(uint64_t effectId) override;
diff --git a/audio/core/all-versions/default/include/core/default/StreamOut.h b/audio/core/all-versions/default/include/core/default/StreamOut.h
index e647da9..9f64e3e 100644
--- a/audio/core/all-versions/default/include/core/default/StreamOut.h
+++ b/audio/core/all-versions/default/include/core/default/StreamOut.h
@@ -56,6 +56,7 @@
Return<uint64_t> getFrameSize() override;
Return<uint64_t> getFrameCount() override;
Return<uint64_t> getBufferSize() override;
+#if MAJOR_VERSION <= 6
Return<uint32_t> getSampleRate() override;
#if MAJOR_VERSION == 2
Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
@@ -69,6 +70,10 @@
Return<AudioFormat> getFormat() override;
Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
Return<Result> setFormat(AudioFormat format) override;
+#else
+ Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override;
+ Return<Result> setAudioProperties(const AudioConfigBase& config) override;
+#endif // MAJOR_VERSION <= 6
Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
Return<Result> addEffect(uint64_t effectId) override;
Return<Result> removeEffect(uint64_t effectId) override;
diff --git a/audio/core/all-versions/default/include/core/default/Util.h b/audio/core/all-versions/default/include/core/default/Util.h
index 78ae03e..3d629cd 100644
--- a/audio/core/all-versions/default/include/core/default/Util.h
+++ b/audio/core/all-versions/default/include/core/default/Util.h
@@ -20,6 +20,8 @@
#include PATH(android/hardware/audio/FILE_VERSION/types.h)
#include <algorithm>
+#include <sstream>
+#include <string>
#include <vector>
#include <system/audio.h>
@@ -70,6 +72,16 @@
return analyzeStatus(status);
}
+static inline std::vector<std::string> splitString(const std::string& s, char separator) {
+ std::istringstream iss(s);
+ std::string t;
+ std::vector<std::string> result;
+ while (std::getline(iss, t, separator)) {
+ result.push_back(std::move(t));
+ }
+ return result;
+}
+
} // namespace util
} // namespace implementation
} // namespace CPP_VERSION
diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
index 1ead47c..05c9bf7 100644
--- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
+++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
@@ -1179,9 +1179,11 @@
EXPECT_EQ(expectedConfig.channelMask, mask);
EXPECT_EQ(expectedConfig.format, format);
#elif MAJOR_VERSION >= 7
+ Result res;
AudioConfigBase actualConfig{};
- auto ret = stream->getAudioProperties(returnIn(actualConfig));
+ auto ret = stream->getAudioProperties(returnIn(res, actualConfig));
EXPECT_TRUE(ret.isOk());
+ EXPECT_EQ(Result::OK, res);
EXPECT_EQ(expectedConfig.base.sampleRateHz, actualConfig.sampleRateHz);
EXPECT_EQ(expectedConfig.base.channelMask, actualConfig.channelMask);
EXPECT_EQ(expectedConfig.base.format, actualConfig.format);
diff --git a/audio/effect/7.0/IVirtualizerEffect.hal b/audio/effect/7.0/IVirtualizerEffect.hal
index 141b4e6..5d11435 100644
--- a/audio/effect/7.0/IVirtualizerEffect.hal
+++ b/audio/effect/7.0/IVirtualizerEffect.hal
@@ -46,23 +46,38 @@
*/
getStrength() generates (Result retval, uint16_t strength);
- struct SpeakerAngle {
+ struct SpeakerAngles {
/** Speaker channel mask */
- vec<AudioChannelMask> mask;
- // all angles are expressed in degrees and
- // are relative to the listener.
- int16_t azimuth; // 0 is the direction the listener faces
- // 180 is behind the listener
- // -90 is to their left
- int16_t elevation; // 0 is the horizontal plane
- // +90 is above the listener, -90 is below
+ AudioChannelMask mask;
+ /**
+ * Horizontal speaker position angles for each channel ordered from LSb
+ * to MSb in the channel mask. The number of values is the number of
+ * channels in the channel mask.
+ *
+ * All angles are expressed in degrees and are relative to the listener.
+ * - 0 is the direction the listener faces;
+ * - 180 is behind the listener;
+ * - -90 is to their left.
+ */
+ vec<int16_t> azimuth;
+ /**
+ * Vertical speaker position angles for each channel ordered from LSb
+ * to MSb in the channel mask. The number of values is the number of
+ * channels in the channel mask.
+ *
+ * All angles are expressed in degrees and are relative to the listener.
+ * - 0 is the horizontal plane of the listener;
+ * - +90 is above the listener;
+ * - -90 is below the listener.
+ */
+ vec<int16_t> elevation;
};
/**
* Retrieves virtual speaker angles for the given channel mask on the
* specified device.
*/
- getVirtualSpeakerAngles(vec<AudioChannelMask> mask, DeviceAddress device)
- generates (Result retval, vec<SpeakerAngle> speakerAngles);
+ getVirtualSpeakerAngles(AudioChannelMask mask, DeviceAddress device)
+ generates (Result retval, SpeakerAngles speakerAngles);
/**
* Forces the virtualizer effect for the given output device.
diff --git a/audio/effect/7.0/types.hal b/audio/effect/7.0/types.hal
index b0a0709..c4cb213 100644
--- a/audio/effect/7.0/types.hal
+++ b/audio/effect/7.0/types.hal
@@ -271,9 +271,7 @@
*/
struct EffectBufferConfig {
AudioBuffer buffer;
- uint32_t samplingRateHz;
- AudioChannelMask channels;
- AudioFormat format;
+ AudioConfigBase base;
EffectBufferAccess accessMode;
bitfield<EffectConfigParameters> mask;
};
@@ -292,9 +290,9 @@
struct EffectAuxChannelsConfig {
/** Channel mask for main channels. */
- vec<AudioChannelMask> mainChannels;
+ AudioChannelMask mainChannels;
/** Channel mask for auxiliary channels. */
- vec<AudioChannelMask> auxChannels;
+ AudioChannelMask auxChannels;
};
struct EffectOffloadParameter {
diff --git a/audio/effect/all-versions/default/AcousticEchoCancelerEffect.cpp b/audio/effect/all-versions/default/AcousticEchoCancelerEffect.cpp
index 137ea24..c1a8b55 100644
--- a/audio/effect/all-versions/default/AcousticEchoCancelerEffect.cpp
+++ b/audio/effect/all-versions/default/AcousticEchoCancelerEffect.cpp
@@ -31,9 +31,7 @@
namespace implementation {
AcousticEchoCancelerEffect::AcousticEchoCancelerEffect(effect_handle_t handle)
- : mEffect(new Effect(handle)) {}
-
-AcousticEchoCancelerEffect::~AcousticEchoCancelerEffect() {}
+ : mEffect(new Effect(true /*isInput*/, handle)) {}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> AcousticEchoCancelerEffect::init() {
@@ -58,10 +56,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> AcousticEchoCancelerEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> AcousticEchoCancelerEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> AcousticEchoCancelerEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> AcousticEchoCancelerEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> AcousticEchoCancelerEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> AcousticEchoCancelerEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> AcousticEchoCancelerEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -82,10 +102,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> AcousticEchoCancelerEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> AcousticEchoCancelerEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -108,10 +124,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> AcousticEchoCancelerEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> AcousticEchoCancelerEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/AcousticEchoCancelerEffect.h b/audio/effect/all-versions/default/AcousticEchoCancelerEffect.h
index 971f64d..d7a84f2 100644
--- a/audio/effect/all-versions/default/AcousticEchoCancelerEffect.h
+++ b/audio/effect/all-versions/default/AcousticEchoCancelerEffect.h
@@ -53,7 +53,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -61,14 +69,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -98,7 +104,7 @@
private:
sp<Effect> mEffect;
- virtual ~AcousticEchoCancelerEffect();
+ virtual ~AcousticEchoCancelerEffect() = default;
};
} // namespace implementation
diff --git a/audio/effect/all-versions/default/Android.bp b/audio/effect/all-versions/default/Android.bp
index 1c3dc74..a0cd612 100644
--- a/audio/effect/all-versions/default/Android.bp
+++ b/audio/effect/all-versions/default/Android.bp
@@ -105,7 +105,6 @@
}
cc_library_shared {
- enabled: false,
name: "android.hardware.audio.effect@7.0-impl",
defaults: ["android.hardware.audio.effect-impl_default"],
shared_libs: [
diff --git a/audio/effect/all-versions/default/AutomaticGainControlEffect.cpp b/audio/effect/all-versions/default/AutomaticGainControlEffect.cpp
index 655a4cd..110b1b6 100644
--- a/audio/effect/all-versions/default/AutomaticGainControlEffect.cpp
+++ b/audio/effect/all-versions/default/AutomaticGainControlEffect.cpp
@@ -30,9 +30,7 @@
namespace implementation {
AutomaticGainControlEffect::AutomaticGainControlEffect(effect_handle_t handle)
- : mEffect(new Effect(handle)) {}
-
-AutomaticGainControlEffect::~AutomaticGainControlEffect() {}
+ : mEffect(new Effect(true /*isInput*/, handle)) {}
void AutomaticGainControlEffect::propertiesFromHal(
const t_agc_settings& halProperties, IAutomaticGainControlEffect::AllProperties* properties) {
@@ -71,10 +69,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> AutomaticGainControlEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> AutomaticGainControlEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> AutomaticGainControlEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> AutomaticGainControlEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> AutomaticGainControlEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> AutomaticGainControlEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> AutomaticGainControlEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -95,10 +115,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> AutomaticGainControlEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> AutomaticGainControlEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -121,10 +137,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> AutomaticGainControlEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> AutomaticGainControlEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/AutomaticGainControlEffect.h b/audio/effect/all-versions/default/AutomaticGainControlEffect.h
index 67e260a..f30d7a5 100644
--- a/audio/effect/all-versions/default/AutomaticGainControlEffect.h
+++ b/audio/effect/all-versions/default/AutomaticGainControlEffect.h
@@ -55,7 +55,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -63,14 +71,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -107,7 +113,7 @@
private:
sp<Effect> mEffect;
- virtual ~AutomaticGainControlEffect();
+ virtual ~AutomaticGainControlEffect() = default;
void propertiesFromHal(const t_agc_settings& halProperties,
IAutomaticGainControlEffect::AllProperties* properties);
diff --git a/audio/effect/all-versions/default/BassBoostEffect.cpp b/audio/effect/all-versions/default/BassBoostEffect.cpp
index 04fd486..33fea3b 100644
--- a/audio/effect/all-versions/default/BassBoostEffect.cpp
+++ b/audio/effect/all-versions/default/BassBoostEffect.cpp
@@ -30,9 +30,8 @@
namespace CPP_VERSION {
namespace implementation {
-BassBoostEffect::BassBoostEffect(effect_handle_t handle) : mEffect(new Effect(handle)) {}
-
-BassBoostEffect::~BassBoostEffect() {}
+BassBoostEffect::BassBoostEffect(effect_handle_t handle)
+ : mEffect(new Effect(false /*isInput*/, handle)) {}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> BassBoostEffect::init() {
@@ -57,10 +56,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> BassBoostEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> BassBoostEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> BassBoostEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> BassBoostEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> BassBoostEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> BassBoostEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> BassBoostEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -80,10 +101,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> BassBoostEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> BassBoostEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -105,10 +122,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> BassBoostEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> BassBoostEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/BassBoostEffect.h b/audio/effect/all-versions/default/BassBoostEffect.h
index b89bb22..48f586c 100644
--- a/audio/effect/all-versions/default/BassBoostEffect.h
+++ b/audio/effect/all-versions/default/BassBoostEffect.h
@@ -55,7 +55,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -63,14 +71,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -100,7 +106,7 @@
private:
sp<Effect> mEffect;
- virtual ~BassBoostEffect();
+ virtual ~BassBoostEffect() = default;
};
} // namespace implementation
diff --git a/audio/effect/all-versions/default/DownmixEffect.cpp b/audio/effect/all-versions/default/DownmixEffect.cpp
index c001a5f..f324cff 100644
--- a/audio/effect/all-versions/default/DownmixEffect.cpp
+++ b/audio/effect/all-versions/default/DownmixEffect.cpp
@@ -30,9 +30,8 @@
namespace CPP_VERSION {
namespace implementation {
-DownmixEffect::DownmixEffect(effect_handle_t handle) : mEffect(new Effect(handle)) {}
-
-DownmixEffect::~DownmixEffect() {}
+DownmixEffect::DownmixEffect(effect_handle_t handle)
+ : mEffect(new Effect(false /*isInput*/, handle)) {}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> DownmixEffect::init() {
@@ -57,10 +56,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> DownmixEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> DownmixEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> DownmixEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> DownmixEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> DownmixEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> DownmixEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> DownmixEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -80,10 +101,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> DownmixEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> DownmixEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -105,10 +122,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> DownmixEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> DownmixEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/DownmixEffect.h b/audio/effect/all-versions/default/DownmixEffect.h
index 40e462e..caacd06 100644
--- a/audio/effect/all-versions/default/DownmixEffect.h
+++ b/audio/effect/all-versions/default/DownmixEffect.h
@@ -53,7 +53,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -61,14 +69,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -97,7 +103,7 @@
private:
sp<Effect> mEffect;
- virtual ~DownmixEffect();
+ virtual ~DownmixEffect() = default;
};
} // namespace implementation
diff --git a/audio/effect/all-versions/default/Effect.cpp b/audio/effect/all-versions/default/Effect.cpp
index 406a571..edd364c 100644
--- a/audio/effect/all-versions/default/Effect.cpp
+++ b/audio/effect/all-versions/default/Effect.cpp
@@ -27,6 +27,7 @@
#define ATRACE_TAG ATRACE_TAG_AUDIO
+#include <HidlUtils.h>
#include <android/log.h>
#include <media/EffectsFactoryApi.h>
#include <utils/Trace.h>
@@ -40,7 +41,10 @@
namespace CPP_VERSION {
namespace implementation {
+#if MAJOR_VERSION <= 6
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioChannelBitfield;
+#endif
+using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
namespace {
@@ -136,9 +140,12 @@
const char* Effect::sContextResultOfCommand = "returned status";
const char* Effect::sContextCallToCommand = "error";
const char* Effect::sContextCallFunction = sContextCallToCommand;
+const char* Effect::sContextConversion = "conversion";
-Effect::Effect(effect_handle_t handle)
- : mHandle(handle), mEfGroup(nullptr), mStopProcessThread(false) {}
+Effect::Effect(bool isInput, effect_handle_t handle)
+ : mIsInput(isInput), mHandle(handle), mEfGroup(nullptr), mStopProcessThread(false) {
+ (void)mIsInput; // prevent 'unused field' warnings in pre-V7 versions.
+}
Effect::~Effect() {
ATRACE_CALL();
@@ -180,7 +187,8 @@
return halData;
}
-// static
+#if MAJOR_VERSION <= 6
+
void Effect::effectAuxChannelsConfigFromHal(const channel_config_t& halConfig,
EffectAuxChannelsConfig* config) {
config->mainChannels = AudioChannelBitfield(halConfig.main_channels);
@@ -194,7 +202,6 @@
halConfig->aux_channels = static_cast<audio_channel_mask_t>(config.auxChannels);
}
-// static
void Effect::effectBufferConfigFromHal(const buffer_config_t& halConfig,
EffectBufferConfig* config) {
config->buffer.id = 0;
@@ -223,7 +230,56 @@
halConfig->mask = static_cast<uint8_t>(config.mask);
}
+#else // MAJOR_VERSION <= 6
+
+void Effect::effectAuxChannelsConfigFromHal(const channel_config_t& halConfig,
+ EffectAuxChannelsConfig* config) {
+ (void)HidlUtils::audioChannelMaskFromHal(halConfig.main_channels, mIsInput,
+ &config->mainChannels);
+ (void)HidlUtils::audioChannelMaskFromHal(halConfig.aux_channels, mIsInput,
+ &config->auxChannels);
+}
+
// static
+void Effect::effectAuxChannelsConfigToHal(const EffectAuxChannelsConfig& config,
+ channel_config_t* halConfig) {
+ (void)HidlUtils::audioChannelMaskToHal(config.mainChannels, &halConfig->main_channels);
+ (void)HidlUtils::audioChannelMaskToHal(config.auxChannels, &halConfig->aux_channels);
+}
+
+void Effect::effectBufferConfigFromHal(const buffer_config_t& halConfig,
+ EffectBufferConfig* config) {
+ config->buffer.id = 0;
+ config->buffer.frameCount = 0;
+ audio_config_base_t halConfigBase = {halConfig.samplingRate,
+ static_cast<audio_channel_mask_t>(halConfig.channels),
+ static_cast<audio_format_t>(halConfig.format)};
+ (void)HidlUtils::audioConfigBaseFromHal(halConfigBase, mIsInput, &config->base);
+ config->accessMode = EffectBufferAccess(halConfig.accessMode);
+ config->mask = static_cast<decltype(config->mask)>(halConfig.mask);
+}
+
+// static
+void Effect::effectBufferConfigToHal(const EffectBufferConfig& config, buffer_config_t* halConfig) {
+ // Note: setting the buffers directly is considered obsolete. They need to be set
+ // using 'setProcessBuffers'.
+ halConfig->buffer.frameCount = 0;
+ halConfig->buffer.raw = nullptr;
+ audio_config_base_t halConfigBase;
+ (void)HidlUtils::audioConfigBaseToHal(config.base, &halConfigBase);
+ halConfig->samplingRate = halConfigBase.sample_rate;
+ halConfig->channels = halConfigBase.channel_mask;
+ halConfig->format = halConfigBase.format;
+ // Note: The framework code does not use BP.
+ halConfig->bufferProvider.cookie = nullptr;
+ halConfig->bufferProvider.getBuffer = nullptr;
+ halConfig->bufferProvider.releaseBuffer = nullptr;
+ halConfig->accessMode = static_cast<uint8_t>(config.accessMode);
+ halConfig->mask = static_cast<uint8_t>(config.mask);
+}
+
+#endif // MAJOR_VERSION <= 6
+
void Effect::effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config) {
effectBufferConfigFromHal(halConfig.inputCfg, &config->inputCfg);
effectBufferConfigFromHal(halConfig.outputCfg, &config->outputCfg);
@@ -507,11 +563,65 @@
return sendCommandReturningStatus(EFFECT_CMD_DISABLE, "DISABLE");
}
+Return<Result> Effect::setAudioSource(
+#if MAJOR_VERSION <= 6
+ AudioSource source
+#else
+ const AudioSource& source
+#endif
+) {
+ audio_source_t halSource;
+ if (status_t status = HidlUtils::audioSourceToHal(source, &halSource); status == NO_ERROR) {
+ uint32_t halSourceParam = static_cast<uint32_t>(halSource);
+ return sendCommand(EFFECT_CMD_SET_AUDIO_SOURCE, "SET_AUDIO_SOURCE", sizeof(uint32_t),
+ &halSourceParam);
+ } else {
+ return analyzeStatus(__func__, "audioSourceToHal", sContextConversion, status);
+ }
+}
+
+#if MAJOR_VERSION <= 6
+
Return<Result> Effect::setDevice(AudioDeviceBitfield device) {
uint32_t halDevice = static_cast<uint32_t>(device);
return sendCommand(EFFECT_CMD_SET_DEVICE, "SET_DEVICE", sizeof(uint32_t), &halDevice);
}
+Return<Result> Effect::setInputDevice(AudioDeviceBitfield device) {
+ uint32_t halDevice = static_cast<uint32_t>(device);
+ return sendCommand(EFFECT_CMD_SET_INPUT_DEVICE, "SET_INPUT_DEVICE", sizeof(uint32_t),
+ &halDevice);
+}
+
+#else // MAJOR_VERSION <= 6
+
+Return<Result> Effect::setDevice(const DeviceAddress& device) {
+ audio_devices_t halDevice;
+ char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
+ if (status_t status = HidlUtils::deviceAddressToHal(device, &halDevice, halDeviceAddress);
+ status == NO_ERROR) {
+ uint32_t halDeviceParam = static_cast<uint32_t>(halDevice);
+ return sendCommand(EFFECT_CMD_SET_DEVICE, "SET_DEVICE", sizeof(uint32_t), &halDeviceParam);
+ } else {
+ return analyzeStatus(__func__, "deviceAddressToHal", sContextConversion, status);
+ }
+}
+
+Return<Result> Effect::setInputDevice(const DeviceAddress& device) {
+ audio_devices_t halDevice;
+ char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
+ if (status_t status = HidlUtils::deviceAddressToHal(device, &halDevice, halDeviceAddress);
+ status == NO_ERROR) {
+ uint32_t halDeviceParam = static_cast<uint32_t>(halDevice);
+ return sendCommand(EFFECT_CMD_SET_INPUT_DEVICE, "SET_INPUT_DEVICE", sizeof(uint32_t),
+ &halDeviceParam);
+ } else {
+ return analyzeStatus(__func__, "deviceAddressToHal", sContextConversion, status);
+ }
+}
+
+#endif // MAJOR_VERSION <= 6
+
Return<void> Effect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
uint32_t halDataSize;
@@ -546,12 +656,6 @@
inputBufferProvider, outputBufferProvider);
}
-Return<Result> Effect::setInputDevice(AudioDeviceBitfield device) {
- uint32_t halDevice = static_cast<uint32_t>(device);
- return sendCommand(EFFECT_CMD_SET_INPUT_DEVICE, "SET_INPUT_DEVICE", sizeof(uint32_t),
- &halDevice);
-}
-
Return<void> Effect::getConfig(getConfig_cb _hidl_cb) {
getConfigImpl(EFFECT_CMD_GET_CONFIG, "GET_CONFIG", _hidl_cb);
return Void();
@@ -598,12 +702,6 @@
"SET_FEATURE_CONFIG AUX_CHANNELS", halCmd.size(), &halCmd[0]);
}
-Return<Result> Effect::setAudioSource(AudioSource source) {
- uint32_t halSource = static_cast<uint32_t>(source);
- return sendCommand(EFFECT_CMD_SET_AUDIO_SOURCE, "SET_AUDIO_SOURCE", sizeof(uint32_t),
- &halSource);
-}
-
Return<Result> Effect::offload(const EffectOffloadParameter& param) {
effect_offload_param_t halParam;
effectOffloadParamToHal(param, &halParam);
diff --git a/audio/effect/all-versions/default/Effect.h b/audio/effect/all-versions/default/Effect.h
index 181e542..9aa47ea 100644
--- a/audio/effect/all-versions/default/Effect.h
+++ b/audio/effect/all-versions/default/Effect.h
@@ -47,7 +47,9 @@
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
+#if MAJOR_VERSION <= 6
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioDeviceBitfield;
+#endif
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::effect::CPP_VERSION;
@@ -56,7 +58,7 @@
using GetParameterSuccessCallback =
std::function<void(uint32_t valueSize, const void* valueData)>;
- explicit Effect(effect_handle_t handle);
+ Effect(bool isInput, effect_handle_t handle);
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> init() override;
@@ -66,7 +68,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -74,14 +84,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -104,6 +112,10 @@
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
// Utility methods for extending interfaces.
+ static const char* sContextConversion;
+
+ Result analyzeStatus(const char* funcName, const char* subFuncName,
+ const char* contextDescription, status_t status);
template <typename T>
Return<void> getIntegerParam(uint32_t paramId,
std::function<void(Result retval, T paramValue)> cb) {
@@ -170,6 +182,7 @@
static const char* sContextCallToCommand;
static const char* sContextCallFunction;
+ const bool mIsInput;
effect_handle_t mHandle;
sp<AudioBufferWrapper> mInBuffer;
sp<AudioBufferWrapper> mOutBuffer;
@@ -186,15 +199,14 @@
static size_t alignedSizeIn(size_t s);
template <typename T>
std::unique_ptr<uint8_t[]> hidlVecToHal(const hidl_vec<T>& vec, uint32_t* halDataSize);
- static void effectAuxChannelsConfigFromHal(const channel_config_t& halConfig,
- EffectAuxChannelsConfig* config);
+ void effectAuxChannelsConfigFromHal(const channel_config_t& halConfig,
+ EffectAuxChannelsConfig* config);
static void effectAuxChannelsConfigToHal(const EffectAuxChannelsConfig& config,
channel_config_t* halConfig);
- static void effectBufferConfigFromHal(const buffer_config_t& halConfig,
- EffectBufferConfig* config);
+ void effectBufferConfigFromHal(const buffer_config_t& halConfig, EffectBufferConfig* config);
static void effectBufferConfigToHal(const EffectBufferConfig& config,
buffer_config_t* halConfig);
- static void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config);
+ void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config);
static void effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig);
static void effectOffloadParamToHal(const EffectOffloadParameter& offload,
effect_offload_param_t* halOffload);
@@ -202,8 +214,6 @@
uint32_t valueSize, const void** valueData);
Result analyzeCommandStatus(const char* commandName, const char* context, status_t status);
- Result analyzeStatus(const char* funcName, const char* subFuncName,
- const char* contextDescription, status_t status);
void getConfigImpl(int commandCode, const char* commandName, GetConfigCallback cb);
Result getCurrentConfigImpl(uint32_t featureId, uint32_t configSize,
GetCurrentConfigSuccessCallback onSuccess);
diff --git a/audio/effect/all-versions/default/EffectsFactory.cpp b/audio/effect/all-versions/default/EffectsFactory.cpp
index b265d3d..1ea990b 100644
--- a/audio/effect/all-versions/default/EffectsFactory.cpp
+++ b/audio/effect/all-versions/default/EffectsFactory.cpp
@@ -82,7 +82,9 @@
} else if (memcmp(halUuid, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0) {
return new VisualizerEffect(handle);
}
- return new Effect(handle);
+ const bool isInput =
+ (halDescriptor.flags & EFFECT_FLAG_TYPE_PRE_PROC) == EFFECT_FLAG_TYPE_PRE_PROC;
+ return new Effect(isInput, handle);
}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffectsFactory follow.
diff --git a/audio/effect/all-versions/default/EnvironmentalReverbEffect.cpp b/audio/effect/all-versions/default/EnvironmentalReverbEffect.cpp
index 78122d4..e95a267 100644
--- a/audio/effect/all-versions/default/EnvironmentalReverbEffect.cpp
+++ b/audio/effect/all-versions/default/EnvironmentalReverbEffect.cpp
@@ -31,9 +31,7 @@
namespace implementation {
EnvironmentalReverbEffect::EnvironmentalReverbEffect(effect_handle_t handle)
- : mEffect(new Effect(handle)) {}
-
-EnvironmentalReverbEffect::~EnvironmentalReverbEffect() {}
+ : mEffect(new Effect(false /*isInput*/, handle)) {}
void EnvironmentalReverbEffect::propertiesFromHal(
const t_reverb_settings& halProperties, IEnvironmentalReverbEffect::AllProperties* properties) {
@@ -86,10 +84,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> EnvironmentalReverbEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> EnvironmentalReverbEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> EnvironmentalReverbEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> EnvironmentalReverbEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> EnvironmentalReverbEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> EnvironmentalReverbEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> EnvironmentalReverbEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -110,10 +130,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> EnvironmentalReverbEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> EnvironmentalReverbEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -136,10 +152,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> EnvironmentalReverbEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> EnvironmentalReverbEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/EnvironmentalReverbEffect.h b/audio/effect/all-versions/default/EnvironmentalReverbEffect.h
index bb422d4..9694b5d 100644
--- a/audio/effect/all-versions/default/EnvironmentalReverbEffect.h
+++ b/audio/effect/all-versions/default/EnvironmentalReverbEffect.h
@@ -57,7 +57,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -65,14 +73,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -125,7 +131,7 @@
private:
sp<Effect> mEffect;
- virtual ~EnvironmentalReverbEffect();
+ virtual ~EnvironmentalReverbEffect() = default;
void propertiesFromHal(const t_reverb_settings& halProperties,
IEnvironmentalReverbEffect::AllProperties* properties);
diff --git a/audio/effect/all-versions/default/EqualizerEffect.cpp b/audio/effect/all-versions/default/EqualizerEffect.cpp
index 1b983ec..fffe8cd 100644
--- a/audio/effect/all-versions/default/EqualizerEffect.cpp
+++ b/audio/effect/all-versions/default/EqualizerEffect.cpp
@@ -31,9 +31,8 @@
namespace CPP_VERSION {
namespace implementation {
-EqualizerEffect::EqualizerEffect(effect_handle_t handle) : mEffect(new Effect(handle)) {}
-
-EqualizerEffect::~EqualizerEffect() {}
+EqualizerEffect::EqualizerEffect(effect_handle_t handle)
+ : mEffect(new Effect(false /*isInput*/, handle)) {}
void EqualizerEffect::propertiesFromHal(const t_equalizer_settings& halProperties,
IEqualizerEffect::AllProperties* properties) {
@@ -80,10 +79,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> EqualizerEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> EqualizerEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> EqualizerEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> EqualizerEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> EqualizerEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> EqualizerEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> EqualizerEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -103,10 +124,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> EqualizerEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> EqualizerEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -128,10 +145,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> EqualizerEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> EqualizerEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/EqualizerEffect.h b/audio/effect/all-versions/default/EqualizerEffect.h
index b1cbefd..7a6bc0a 100644
--- a/audio/effect/all-versions/default/EqualizerEffect.h
+++ b/audio/effect/all-versions/default/EqualizerEffect.h
@@ -57,7 +57,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -65,14 +73,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -111,7 +117,7 @@
private:
sp<Effect> mEffect;
- virtual ~EqualizerEffect();
+ virtual ~EqualizerEffect() = default;
void propertiesFromHal(const t_equalizer_settings& halProperties,
IEqualizerEffect::AllProperties* properties);
diff --git a/audio/effect/all-versions/default/LoudnessEnhancerEffect.cpp b/audio/effect/all-versions/default/LoudnessEnhancerEffect.cpp
index ebd5197..c7add86 100644
--- a/audio/effect/all-versions/default/LoudnessEnhancerEffect.cpp
+++ b/audio/effect/all-versions/default/LoudnessEnhancerEffect.cpp
@@ -33,9 +33,7 @@
namespace implementation {
LoudnessEnhancerEffect::LoudnessEnhancerEffect(effect_handle_t handle)
- : mEffect(new Effect(handle)) {}
-
-LoudnessEnhancerEffect::~LoudnessEnhancerEffect() {}
+ : mEffect(new Effect(false /*isInput*/, handle)) {}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> LoudnessEnhancerEffect::init() {
@@ -60,10 +58,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> LoudnessEnhancerEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> LoudnessEnhancerEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> LoudnessEnhancerEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> LoudnessEnhancerEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> LoudnessEnhancerEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> LoudnessEnhancerEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> LoudnessEnhancerEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -83,10 +103,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> LoudnessEnhancerEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> LoudnessEnhancerEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -108,10 +124,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> LoudnessEnhancerEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> LoudnessEnhancerEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/LoudnessEnhancerEffect.h b/audio/effect/all-versions/default/LoudnessEnhancerEffect.h
index 8baf128..6d80207 100644
--- a/audio/effect/all-versions/default/LoudnessEnhancerEffect.h
+++ b/audio/effect/all-versions/default/LoudnessEnhancerEffect.h
@@ -53,7 +53,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -61,14 +69,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -98,7 +104,7 @@
private:
sp<Effect> mEffect;
- virtual ~LoudnessEnhancerEffect();
+ virtual ~LoudnessEnhancerEffect() = default;
};
} // namespace implementation
diff --git a/audio/effect/all-versions/default/NoiseSuppressionEffect.cpp b/audio/effect/all-versions/default/NoiseSuppressionEffect.cpp
index d01bbe5..9e75237 100644
--- a/audio/effect/all-versions/default/NoiseSuppressionEffect.cpp
+++ b/audio/effect/all-versions/default/NoiseSuppressionEffect.cpp
@@ -30,9 +30,7 @@
namespace implementation {
NoiseSuppressionEffect::NoiseSuppressionEffect(effect_handle_t handle)
- : mEffect(new Effect(handle)) {}
-
-NoiseSuppressionEffect::~NoiseSuppressionEffect() {}
+ : mEffect(new Effect(true /*isInput*/, handle)) {}
void NoiseSuppressionEffect::propertiesFromHal(const t_ns_settings& halProperties,
INoiseSuppressionEffect::AllProperties* properties) {
@@ -69,10 +67,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> NoiseSuppressionEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> NoiseSuppressionEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> NoiseSuppressionEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> NoiseSuppressionEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> NoiseSuppressionEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> NoiseSuppressionEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> NoiseSuppressionEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -92,10 +112,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> NoiseSuppressionEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> NoiseSuppressionEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -117,10 +133,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> NoiseSuppressionEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> NoiseSuppressionEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/NoiseSuppressionEffect.h b/audio/effect/all-versions/default/NoiseSuppressionEffect.h
index c49bf7b..6cc45b9 100644
--- a/audio/effect/all-versions/default/NoiseSuppressionEffect.h
+++ b/audio/effect/all-versions/default/NoiseSuppressionEffect.h
@@ -55,7 +55,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -63,14 +71,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -105,7 +111,7 @@
private:
sp<Effect> mEffect;
- virtual ~NoiseSuppressionEffect();
+ virtual ~NoiseSuppressionEffect() = default;
void propertiesFromHal(const t_ns_settings& halProperties,
INoiseSuppressionEffect::AllProperties* properties);
diff --git a/audio/effect/all-versions/default/PresetReverbEffect.cpp b/audio/effect/all-versions/default/PresetReverbEffect.cpp
index 4a2a3a4..1ae8492 100644
--- a/audio/effect/all-versions/default/PresetReverbEffect.cpp
+++ b/audio/effect/all-versions/default/PresetReverbEffect.cpp
@@ -30,9 +30,8 @@
namespace CPP_VERSION {
namespace implementation {
-PresetReverbEffect::PresetReverbEffect(effect_handle_t handle) : mEffect(new Effect(handle)) {}
-
-PresetReverbEffect::~PresetReverbEffect() {}
+PresetReverbEffect::PresetReverbEffect(effect_handle_t handle)
+ : mEffect(new Effect(false /*isInput*/, handle)) {}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> PresetReverbEffect::init() {
@@ -57,10 +56,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> PresetReverbEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> PresetReverbEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> PresetReverbEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> PresetReverbEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> PresetReverbEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> PresetReverbEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> PresetReverbEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -80,10 +101,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> PresetReverbEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> PresetReverbEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -105,10 +122,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> PresetReverbEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> PresetReverbEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/PresetReverbEffect.h b/audio/effect/all-versions/default/PresetReverbEffect.h
index 58a6829..eb55e20 100644
--- a/audio/effect/all-versions/default/PresetReverbEffect.h
+++ b/audio/effect/all-versions/default/PresetReverbEffect.h
@@ -53,7 +53,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -61,14 +69,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -98,7 +104,7 @@
private:
sp<Effect> mEffect;
- virtual ~PresetReverbEffect();
+ virtual ~PresetReverbEffect() = default;
};
} // namespace implementation
diff --git a/audio/effect/all-versions/default/VirtualizerEffect.cpp b/audio/effect/all-versions/default/VirtualizerEffect.cpp
index 1b69a90..1dce181 100644
--- a/audio/effect/all-versions/default/VirtualizerEffect.cpp
+++ b/audio/effect/all-versions/default/VirtualizerEffect.cpp
@@ -19,7 +19,9 @@
#include "VirtualizerEffect.h"
#include <memory.h>
+#include <stdlib.h>
+#include <HidlUtils.h>
#include <android/log.h>
#include <system/audio_effects/effect_virtualizer.h>
@@ -32,19 +34,10 @@
namespace CPP_VERSION {
namespace implementation {
-VirtualizerEffect::VirtualizerEffect(effect_handle_t handle) : mEffect(new Effect(handle)) {}
+using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
-VirtualizerEffect::~VirtualizerEffect() {}
-
-void VirtualizerEffect::speakerAnglesFromHal(const int32_t* halAngles, uint32_t channelCount,
- hidl_vec<SpeakerAngle>& speakerAngles) {
- speakerAngles.resize(channelCount);
- for (uint32_t i = 0; i < channelCount; ++i) {
- speakerAngles[i].mask = AudioChannelBitfield(*halAngles++);
- speakerAngles[i].azimuth = *halAngles++;
- speakerAngles[i].elevation = *halAngles++;
- }
-}
+VirtualizerEffect::VirtualizerEffect(effect_handle_t handle)
+ : mEffect(new Effect(false /*isInput*/, handle)) {}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> VirtualizerEffect::init() {
@@ -69,10 +62,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> VirtualizerEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> VirtualizerEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> VirtualizerEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> VirtualizerEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> VirtualizerEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> VirtualizerEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> VirtualizerEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -92,10 +107,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> VirtualizerEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> VirtualizerEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -117,10 +128,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> VirtualizerEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> VirtualizerEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
@@ -192,43 +199,117 @@
return mEffect->getIntegerParam(VIRTUALIZER_PARAM_STRENGTH, _hidl_cb);
}
-Return<void> VirtualizerEffect::getVirtualSpeakerAngles(AudioChannelBitfield mask,
- AudioDevice device,
- getVirtualSpeakerAngles_cb _hidl_cb) {
- uint32_t channelCount =
- audio_channel_count_from_out_mask(static_cast<audio_channel_mask_t>(mask));
+Return<void> VirtualizerEffect::getVirtualSpeakerAngles(
+#if MAJOR_VERSION <= 6
+ AudioChannelBitfield mask, AudioDevice device, getVirtualSpeakerAngles_cb _hidl_cb) {
+ audio_channel_mask_t halChannelMask = static_cast<audio_channel_mask_t>(mask);
+ audio_devices_t halDeviceType = static_cast<audio_devices_t>(device);
+#else
+ const AudioChannelMask& mask, const DeviceAddress& device,
+ getVirtualSpeakerAngles_cb _hidl_cb) {
+ audio_channel_mask_t halChannelMask;
+ if (status_t status = HidlUtils::audioChannelMaskToHal(mask, &halChannelMask);
+ status != NO_ERROR) {
+ _hidl_cb(mEffect->analyzeStatus(__func__, "audioChannelMaskToHal",
+ Effect::sContextConversion, status),
+ SpeakerAngles{});
+ return Void();
+ }
+ audio_devices_t halDeviceType;
+ char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
+ if (status_t status = HidlUtils::deviceAddressToHal(device, &halDeviceType, halDeviceAddress);
+ status != NO_ERROR) {
+ _hidl_cb(mEffect->analyzeStatus(__func__, "deviceAddressToHal", Effect::sContextConversion,
+ status),
+ SpeakerAngles{});
+ return Void();
+ }
+#endif
+ uint32_t channelCount = audio_channel_count_from_out_mask(halChannelMask);
size_t halSpeakerAnglesSize = sizeof(int32_t) * 3 * channelCount;
- uint32_t halParam[3] = {VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES,
- static_cast<audio_channel_mask_t>(mask),
- static_cast<audio_devices_t>(device)};
- hidl_vec<SpeakerAngle> speakerAngles;
+ uint32_t halParam[3] = {VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES, halChannelMask,
+ halDeviceType};
+ SpeakerAngles speakerAngles;
+ status_t status = NO_ERROR;
Result retval = mEffect->getParameterImpl(
- sizeof(halParam), halParam, halSpeakerAnglesSize,
- [&](uint32_t valueSize, const void* valueData) {
- if (valueSize > halSpeakerAnglesSize) {
- valueSize = halSpeakerAnglesSize;
- } else if (valueSize < halSpeakerAnglesSize) {
- channelCount = valueSize / (sizeof(int32_t) * 3);
- }
- speakerAnglesFromHal(reinterpret_cast<const int32_t*>(valueData), channelCount,
- speakerAngles);
- });
+ sizeof(halParam), halParam, halSpeakerAnglesSize,
+ [&](uint32_t valueSize, const void* valueData) {
+ if (valueSize < halSpeakerAnglesSize) {
+ channelCount = valueSize / (sizeof(int32_t) * 3);
+ }
+ status = speakerAnglesFromHal(reinterpret_cast<const int32_t*>(valueData),
+ channelCount, speakerAngles);
+ });
+ if (retval == Result::OK) {
+ retval = mEffect->analyzeStatus(__func__, "speakerAnglesFromHal", "", status);
+ }
_hidl_cb(retval, speakerAngles);
return Void();
}
-Return<Result> VirtualizerEffect::forceVirtualizationMode(AudioDevice device) {
- return mEffect->setParam(VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE,
- static_cast<audio_devices_t>(device));
-}
-
Return<void> VirtualizerEffect::getVirtualizationMode(getVirtualizationMode_cb _hidl_cb) {
uint32_t halMode = 0;
Result retval = mEffect->getParam(VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE, halMode);
+#if MAJOR_VERSION <= 6
_hidl_cb(retval, AudioDevice(halMode));
+#else
+ DeviceAddress device;
+ (void)HidlUtils::deviceAddressFromHal(static_cast<audio_devices_t>(halMode), nullptr, &device);
+ _hidl_cb(retval, device);
+#endif
return Void();
}
+Return<Result> VirtualizerEffect::forceVirtualizationMode(
+#if MAJOR_VERSION <= 6
+ AudioDevice device) {
+ audio_devices_t halDeviceType = static_cast<audio_devices_t>(device);
+#else
+ const DeviceAddress& device) {
+ audio_devices_t halDeviceType;
+ char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
+ (void)HidlUtils::deviceAddressToHal(device, &halDeviceType, halDeviceAddress);
+#endif
+ return mEffect->setParam(VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE, halDeviceType);
+}
+
+#if MAJOR_VERSION <= 6
+// static
+status_t VirtualizerEffect::speakerAnglesFromHal(const int32_t* halAngles, uint32_t channelCount,
+ hidl_vec<SpeakerAngle>& speakerAngles) {
+ speakerAngles.resize(channelCount);
+ for (uint32_t i = 0; i < channelCount; ++i) {
+ speakerAngles[i].mask = AudioChannelBitfield(*halAngles++);
+ speakerAngles[i].azimuth = *halAngles++;
+ speakerAngles[i].elevation = *halAngles++;
+ }
+ return NO_ERROR;
+}
+#else
+static int compare_channels(const void* lhs, const void* rhs) {
+ return *(int32_t*)lhs - *(int32_t*)rhs;
+}
+
+// static
+status_t VirtualizerEffect::speakerAnglesFromHal(const int32_t* halAngles, uint32_t channelCount,
+ SpeakerAngles& speakerAngles) {
+ speakerAngles.azimuth.resize(channelCount);
+ speakerAngles.elevation.resize(channelCount);
+ int32_t halAnglesSorted[channelCount * 3];
+ memcpy(halAnglesSorted, halAngles, sizeof(halAnglesSorted));
+ // Ensure that channels are ordered from LSb to MSb.
+ qsort(halAnglesSorted, channelCount, sizeof(int32_t) * 3, compare_channels);
+ audio_channel_mask_t halMask = AUDIO_CHANNEL_NONE;
+ int32_t* halAnglesPtr = halAnglesSorted;
+ for (uint32_t i = 0; i < channelCount; ++i) {
+ halMask = static_cast<audio_channel_mask_t>(halMask | *halAnglesPtr++);
+ speakerAngles.azimuth[i] = *halAnglesPtr++;
+ speakerAngles.elevation[i] = *halAnglesPtr++;
+ }
+ return HidlUtils::audioChannelMaskFromHal(halMask, false /*isInput*/, &speakerAngles.mask);
+}
+#endif
+
} // namespace implementation
} // namespace CPP_VERSION
} // namespace effect
diff --git a/audio/effect/all-versions/default/VirtualizerEffect.h b/audio/effect/all-versions/default/VirtualizerEffect.h
index c630b2e..3ed06d1 100644
--- a/audio/effect/all-versions/default/VirtualizerEffect.h
+++ b/audio/effect/all-versions/default/VirtualizerEffect.h
@@ -39,7 +39,9 @@
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
+#if MAJOR_VERSION <= 6
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioChannelBitfield;
+#endif
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::effect::CPP_VERSION;
@@ -54,7 +56,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -62,14 +72,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -96,18 +104,27 @@
Return<bool> isStrengthSupported() override;
Return<Result> setStrength(uint16_t strength) override;
Return<void> getStrength(getStrength_cb _hidl_cb) override;
+ Return<void> getVirtualizationMode(getVirtualizationMode_cb _hidl_cb) override;
+#if MAJOR_VERSION <= 6
Return<void> getVirtualSpeakerAngles(AudioChannelBitfield mask, AudioDevice device,
getVirtualSpeakerAngles_cb _hidl_cb) override;
Return<Result> forceVirtualizationMode(AudioDevice device) override;
- Return<void> getVirtualizationMode(getVirtualizationMode_cb _hidl_cb) override;
+#else
+ Return<void> getVirtualSpeakerAngles(const AudioChannelMask& mask, const DeviceAddress& device,
+ getVirtualSpeakerAngles_cb _hidl_cb) override;
+ Return<Result> forceVirtualizationMode(const DeviceAddress& device) override;
+#endif
- private:
+ private:
sp<Effect> mEffect;
- virtual ~VirtualizerEffect();
+ virtual ~VirtualizerEffect() = default;
- void speakerAnglesFromHal(const int32_t* halAngles, uint32_t channelCount,
- hidl_vec<SpeakerAngle>& speakerAngles);
+#if MAJOR_VERSION <= 6
+ using SpeakerAngles = hidl_vec<SpeakerAngle>;
+#endif
+ static status_t speakerAnglesFromHal(const int32_t* halAngles, uint32_t channelCount,
+ SpeakerAngles& speakerAngles);
};
} // namespace implementation
diff --git a/audio/effect/all-versions/default/VisualizerEffect.cpp b/audio/effect/all-versions/default/VisualizerEffect.cpp
index ae533bf..80c8637 100644
--- a/audio/effect/all-versions/default/VisualizerEffect.cpp
+++ b/audio/effect/all-versions/default/VisualizerEffect.cpp
@@ -31,9 +31,9 @@
namespace implementation {
VisualizerEffect::VisualizerEffect(effect_handle_t handle)
- : mEffect(new Effect(handle)), mCaptureSize(0), mMeasurementMode(MeasurementMode::NONE) {}
-
-VisualizerEffect::~VisualizerEffect() {}
+ : mEffect(new Effect(false /*isInput*/, handle)),
+ mCaptureSize(0),
+ mMeasurementMode(MeasurementMode::NONE) {}
// Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
Return<Result> VisualizerEffect::init() {
@@ -58,10 +58,32 @@
return mEffect->disable();
}
+#if MAJOR_VERSION <= 6
+Return<Result> VisualizerEffect::setAudioSource(AudioSource source) {
+ return mEffect->setAudioSource(source);
+}
+
Return<Result> VisualizerEffect::setDevice(AudioDeviceBitfield device) {
return mEffect->setDevice(device);
}
+Return<Result> VisualizerEffect::setInputDevice(AudioDeviceBitfield device) {
+ return mEffect->setInputDevice(device);
+}
+#else
+Return<Result> VisualizerEffect::setAudioSource(const AudioSource& source) {
+ return mEffect->setAudioSource(source);
+}
+
+Return<Result> VisualizerEffect::setDevice(const DeviceAddress& device) {
+ return mEffect->setDevice(device);
+}
+
+Return<Result> VisualizerEffect::setInputDevice(const DeviceAddress& device) {
+ return mEffect->setInputDevice(device);
+}
+#endif
+
Return<void> VisualizerEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
@@ -81,10 +103,6 @@
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
-Return<Result> VisualizerEffect::setInputDevice(AudioDeviceBitfield device) {
- return mEffect->setInputDevice(device);
-}
-
Return<void> VisualizerEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
@@ -106,10 +124,6 @@
return mEffect->setAuxChannelsConfig(config);
}
-Return<Result> VisualizerEffect::setAudioSource(AudioSource source) {
- return mEffect->setAudioSource(source);
-}
-
Return<Result> VisualizerEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
diff --git a/audio/effect/all-versions/default/VisualizerEffect.h b/audio/effect/all-versions/default/VisualizerEffect.h
index 315f844..3ae4b08 100644
--- a/audio/effect/all-versions/default/VisualizerEffect.h
+++ b/audio/effect/all-versions/default/VisualizerEffect.h
@@ -53,7 +53,15 @@
Return<Result> reset() override;
Return<Result> enable() override;
Return<Result> disable() override;
+#if MAJOR_VERSION <= 6
+ Return<Result> setAudioSource(AudioSource source) override;
Return<Result> setDevice(AudioDeviceBitfield device) override;
+ Return<Result> setInputDevice(AudioDeviceBitfield device) override;
+#else
+ Return<Result> setAudioSource(const AudioSource& source) override;
+ Return<Result> setDevice(const DeviceAddress& device) override;
+ Return<Result> setInputDevice(const DeviceAddress& device) override;
+#endif
Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
@@ -61,14 +69,12 @@
Return<Result> setConfigReverse(
const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
- Return<Result> setInputDevice(AudioDeviceBitfield device) override;
Return<void> getConfig(getConfig_cb _hidl_cb) override;
Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
- Return<Result> setAudioSource(AudioSource source) override;
Return<Result> offload(const EffectOffloadParameter& param) override;
Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
@@ -107,7 +113,7 @@
uint16_t mCaptureSize;
MeasurementMode mMeasurementMode;
- virtual ~VisualizerEffect();
+ virtual ~VisualizerEffect() = default;
};
} // namespace implementation
diff --git a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp
index 199a8a5..d39fbcd 100644
--- a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp
+++ b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp
@@ -263,7 +263,7 @@
static_cast<audio_channel_mask_t>(currentConfig.outputCfg.channels));
#else
*channelCount = android::audio::policy::configuration::V7_0::getChannelCount(
- currentConfig.outputCfg.channels);
+ currentConfig.outputCfg.base.channelMask);
ASSERT_NE(*channelCount, 0);
#endif
}
@@ -353,8 +353,14 @@
}
inline bool operator==(const EffectBufferConfig& lhs, const EffectBufferConfig& rhs) {
- return lhs.buffer == rhs.buffer && lhs.samplingRateHz == rhs.samplingRateHz &&
- lhs.channels == rhs.channels && lhs.format == rhs.format &&
+ return lhs.buffer == rhs.buffer &&
+#if MAJOR_VERSION <= 6
+ lhs.samplingRateHz == rhs.samplingRateHz && lhs.channels == rhs.channels &&
+ lhs.format == rhs.format &&
+#else
+ lhs.base.sampleRateHz == rhs.base.sampleRateHz &&
+ lhs.base.channelMask == rhs.base.channelMask && lhs.base.format == rhs.base.format &&
+#endif
lhs.accessMode == rhs.accessMode && lhs.mask == rhs.mask;
}
diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml
index b16ae40..e12d920 100644
--- a/compatibility_matrices/compatibility_matrix.current.xml
+++ b/compatibility_matrices/compatibility_matrix.current.xml
@@ -354,6 +354,13 @@
<instance>default</instance>
</interface>
</hal>
+ <hal format="aidl" optional="true">
+ <name>android.hardware.memtrack</name>
+ <interface>
+ <name>IMemtrack</name>
+ <instance>default</instance>
+ </interface>
+ </hal>
<hal format="hidl" optional="true">
<name>android.hardware.memtrack</name>
<version>1.0</version>
diff --git a/memtrack/aidl/Android.bp b/memtrack/aidl/Android.bp
new file mode 100644
index 0000000..fe4d01b
--- /dev/null
+++ b/memtrack/aidl/Android.bp
@@ -0,0 +1,33 @@
+// Copyright (C) 2020 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.
+
+aidl_interface {
+ name: "android.hardware.memtrack",
+ vendor_available: true,
+ srcs: ["android/hardware/memtrack/*.aidl"],
+ stability: "vintf",
+ backend: {
+ cpp: {
+ enabled: false,
+ },
+ java: {
+ enabled: false,
+ },
+ ndk: {
+ vndk: {
+ enabled: true,
+ },
+ },
+ },
+}
diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/DeviceInfo.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/DeviceInfo.aidl
new file mode 100644
index 0000000..00abff9
--- /dev/null
+++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/DeviceInfo.aidl
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
+// edit this file. It looks like you are doing that because you have modified
+// an AIDL interface in a backward-incompatible way, e.g., deleting a function
+// from an interface or a field from a parcelable and it broke the build. That
+// breakage is intended.
+//
+// You must not make a backward incompatible changes to the AIDL files built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.memtrack;
+@VintfStability
+parcelable DeviceInfo {
+ int id;
+ @utf8InCpp String name;
+}
diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/IMemtrack.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/IMemtrack.aidl
new file mode 100644
index 0000000..844a1bb
--- /dev/null
+++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/IMemtrack.aidl
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
+// edit this file. It looks like you are doing that because you have modified
+// an AIDL interface in a backward-incompatible way, e.g., deleting a function
+// from an interface or a field from a parcelable and it broke the build. That
+// breakage is intended.
+//
+// You must not make a backward incompatible changes to the AIDL files built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.memtrack;
+@VintfStability
+interface IMemtrack {
+ android.hardware.memtrack.MemtrackRecord[] getMemory(in int pid, in android.hardware.memtrack.MemtrackType type);
+ android.hardware.memtrack.DeviceInfo[] getGpuDeviceInfo();
+}
diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackRecord.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackRecord.aidl
new file mode 100644
index 0000000..09ecefc
--- /dev/null
+++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackRecord.aidl
@@ -0,0 +1,32 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
+// edit this file. It looks like you are doing that because you have modified
+// an AIDL interface in a backward-incompatible way, e.g., deleting a function
+// from an interface or a field from a parcelable and it broke the build. That
+// breakage is intended.
+//
+// You must not make a backward incompatible changes to the AIDL files built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.memtrack;
+@VintfStability
+parcelable MemtrackRecord {
+ int flags;
+ long sizeInBytes;
+ const int FLAG_SMAPS_ACCOUNTED = 2;
+ const int FLAG_SMAPS_UNACCOUNTED = 4;
+ const int FLAG_SHARED = 8;
+ const int FLAG_SHARED_PSS = 16;
+ const int FLAG_PRIVATE = 32;
+ const int FLAG_SYSTEM = 64;
+ const int FLAG_DEDICATED = 128;
+ const int FLAG_NONSECURE = 256;
+ const int FLAG_SECURE = 512;
+}
diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackType.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackType.aidl
new file mode 100644
index 0000000..7f3f939
--- /dev/null
+++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackType.aidl
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
+// edit this file. It looks like you are doing that because you have modified
+// an AIDL interface in a backward-incompatible way, e.g., deleting a function
+// from an interface or a field from a parcelable and it broke the build. That
+// breakage is intended.
+//
+// You must not make a backward incompatible changes to the AIDL files built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.memtrack;
+@Backing(type="int") @VintfStability
+enum MemtrackType {
+ OTHER = 0,
+ GL = 1,
+ GRAPHICS = 2,
+ MULTIMEDIA = 3,
+ CAMERA = 4,
+ NUM_TYPES = 5,
+}
diff --git a/memtrack/aidl/android/hardware/memtrack/DeviceInfo.aidl b/memtrack/aidl/android/hardware/memtrack/DeviceInfo.aidl
new file mode 100644
index 0000000..aec11e9
--- /dev/null
+++ b/memtrack/aidl/android/hardware/memtrack/DeviceInfo.aidl
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+package android.hardware.memtrack;
+
+/*
+ * A vector of DeviceInfo is returned by the function getGpuDeviceInfo().
+ * Each entry consists of the device name and the device id.
+ * See getGpuDeviceInfo() for further details.
+ */
+@VintfStability
+parcelable DeviceInfo {
+ int id;
+ @utf8InCpp String name;
+}
+
diff --git a/memtrack/aidl/android/hardware/memtrack/IMemtrack.aidl b/memtrack/aidl/android/hardware/memtrack/IMemtrack.aidl
new file mode 100644
index 0000000..33c6956
--- /dev/null
+++ b/memtrack/aidl/android/hardware/memtrack/IMemtrack.aidl
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+package android.hardware.memtrack;
+
+import android.hardware.memtrack.DeviceInfo;
+import android.hardware.memtrack.MemtrackRecord;
+import android.hardware.memtrack.MemtrackType;
+
+/**
+ * The Memory Tracker HAL is designed to return information about
+ * device-specific memory usage.
+ * The primary goal is to be able to track memory that is not
+ * trackable in any other way, for example texture memory that is allocated by
+ * a process, but not mapped in to that process's address space.
+ * A secondary goal is to be able to categorize memory used by a process into
+ * GL, graphics, etc. All memory sizes must be in real memory usage,
+ * accounting for stride, bit depth, rounding up to page size, etc.
+ *
+ * Constructor for the interface should be used to perform memtrack management
+ * setup actions and is called once before any calls to getMemory().
+ */
+@VintfStability
+interface IMemtrack {
+ /**
+ * getMemory() populates MemtrackRecord vector with the sizes of memory
+ * plus associated flags for that memory.
+ *
+ * A process collecting memory statistics will call getMemory for each
+ * combination of pid and memory type. For each memory type that it
+ * recognizes, the HAL must fill out an array of memtrack_record
+ * structures breaking down the statistics of that memory type as much as
+ * possible. For example,
+ * getMemory(<pid>, GL) might return:
+ * { { 4096, ACCOUNTED | PRIVATE | SYSTEM },
+ * { 40960, UNACCOUNTED | PRIVATE | SYSTEM },
+ * { 8192, ACCOUNTED | PRIVATE | DEDICATED },
+ * { 8192, UNACCOUNTED | PRIVATE | DEDICATED } }
+ * If the HAL cannot differentiate between SYSTEM and DEDICATED memory, it
+ * could return:
+ * { { 12288, ACCOUNTED | PRIVATE },
+ * { 49152, UNACCOUNTED | PRIVATE } }
+ *
+ * Memory must not overlap between types. For example, a graphics buffer
+ * that has been mapped into the GPU as a surface must show up when
+ * GRAPHICS is requested and not when GL
+ * is requested.
+ *
+ * @param pid process for which memory information is requested
+ * @param type memory type that information is being requested about
+ * @return vector of MemtrackRecord containing memory information
+ */
+ MemtrackRecord[] getMemory(in int pid, in MemtrackType type);
+
+ /**
+ * getGpuDeviceInfo() populates DeviceInfo with the ID and name
+ * of each GPU device.
+ *
+ * For example, getGpuDeviceInfor, might return:
+ * { { 0, <gpu-device-name> },
+ * { 1, <gpu-device-name> } }
+ *
+ * This information is used to identify GPU devices for GPU specific
+ * memory accounting (e.g. DMA buffer usage).
+ *
+ * @return vector of DeviceInfo populated for all GPU devices.
+ */
+ DeviceInfo[] getGpuDeviceInfo();
+}
diff --git a/memtrack/aidl/android/hardware/memtrack/MemtrackRecord.aidl b/memtrack/aidl/android/hardware/memtrack/MemtrackRecord.aidl
new file mode 100644
index 0000000..95254e9
--- /dev/null
+++ b/memtrack/aidl/android/hardware/memtrack/MemtrackRecord.aidl
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+package android.hardware.memtrack;
+
+/*
+ * A vector of MemtrackRecord is returned by the function getMemory().
+ * Each record consists of the size of the memory used by the process and
+ * flags indicate all the MemtrackFlags that are valid for this record.
+ * see getMemory() comments for further details.
+ */
+@VintfStability
+parcelable MemtrackRecord {
+ /* Memtrack Flags */
+ const int FLAG_SMAPS_ACCOUNTED = 1 << 1;
+ const int FLAG_SMAPS_UNACCOUNTED = 1 << 2;
+ const int FLAG_SHARED = 1 << 3;
+ const int FLAG_SHARED_PSS = 1 << 4;
+ const int FLAG_PRIVATE = 1 << 5;
+ const int FLAG_SYSTEM = 1 << 6;
+ const int FLAG_DEDICATED = 1 << 7;
+ const int FLAG_NONSECURE = 1 << 8;
+ const int FLAG_SECURE = 1 << 9;
+
+ /* Bitfield indicating all flags that are valid for this record */
+ int flags;
+
+ long sizeInBytes;
+}
+
diff --git a/memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl b/memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl
new file mode 100644
index 0000000..715c6bf
--- /dev/null
+++ b/memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+package android.hardware.memtrack;
+
+/**
+ * Tags which define the usage of the memory buffers.
+ */
+@VintfStability
+@Backing(type="int")
+enum MemtrackType {
+ OTHER = 0,
+ GL = 1,
+ GRAPHICS = 2,
+ MULTIMEDIA = 3,
+ CAMERA = 4,
+ NUM_TYPES,
+}
diff --git a/memtrack/aidl/default/Android.bp b/memtrack/aidl/default/Android.bp
new file mode 100644
index 0000000..52f88c8
--- /dev/null
+++ b/memtrack/aidl/default/Android.bp
@@ -0,0 +1,30 @@
+// Copyright (C) 2020 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.
+
+cc_binary {
+ name: "android.hardware.memtrack-service.example",
+ relative_install_path: "hw",
+ init_rc: ["memtrack-default.rc"],
+ vintf_fragments: ["memtrack-default.xml"],
+ vendor: true,
+ shared_libs: [
+ "libbase",
+ "libbinder_ndk",
+ "android.hardware.memtrack-ndk_platform",
+ ],
+ srcs: [
+ "main.cpp",
+ "Memtrack.cpp",
+ ],
+}
diff --git a/memtrack/aidl/default/Memtrack.cpp b/memtrack/aidl/default/Memtrack.cpp
new file mode 100644
index 0000000..7361719
--- /dev/null
+++ b/memtrack/aidl/default/Memtrack.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2020 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 "Memtrack.h"
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace memtrack {
+
+ndk::ScopedAStatus Memtrack::getMemory(int pid, MemtrackType type,
+ std::vector<MemtrackRecord>* _aidl_return) {
+ if (pid < 0) {
+ return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
+ }
+ if (type < MemtrackType::OTHER || type >= MemtrackType::NUM_TYPES) {
+ return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
+ }
+ _aidl_return->clear();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Memtrack::getGpuDeviceInfo(std::vector<DeviceInfo>* _aidl_return) {
+ _aidl_return->clear();
+ return ndk::ScopedAStatus::ok();
+}
+
+} // namespace memtrack
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/memtrack/aidl/default/Memtrack.h b/memtrack/aidl/default/Memtrack.h
new file mode 100644
index 0000000..f2ef60e
--- /dev/null
+++ b/memtrack/aidl/default/Memtrack.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 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 <aidl/android/hardware/memtrack/BnMemtrack.h>
+#include <aidl/android/hardware/memtrack/DeviceInfo.h>
+#include <aidl/android/hardware/memtrack/MemtrackRecord.h>
+#include <aidl/android/hardware/memtrack/MemtrackType.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace memtrack {
+
+class Memtrack : public BnMemtrack {
+ ndk::ScopedAStatus getMemory(int pid, MemtrackType type,
+ std::vector<MemtrackRecord>* _aidl_return) override;
+
+ ndk::ScopedAStatus getGpuDeviceInfo(std::vector<DeviceInfo>* _aidl_return) override;
+};
+
+} // namespace memtrack
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/memtrack/aidl/default/main.cpp b/memtrack/aidl/default/main.cpp
new file mode 100644
index 0000000..d063d2a
--- /dev/null
+++ b/memtrack/aidl/default/main.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 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 "Memtrack.h"
+
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+using aidl::android::hardware::memtrack::Memtrack;
+
+int main() {
+ ABinderProcess_setThreadPoolMaxThreadCount(0);
+ std::shared_ptr<Memtrack> memtrack = ndk::SharedRefBase::make<Memtrack>();
+
+ const std::string instance = std::string() + Memtrack::descriptor + "/default";
+ binder_status_t status =
+ AServiceManager_addService(memtrack->asBinder().get(), instance.c_str());
+ CHECK(status == STATUS_OK);
+
+ ABinderProcess_joinThreadPool();
+ return EXIT_FAILURE; // Unreachable
+}
diff --git a/memtrack/aidl/default/memtrack-default.rc b/memtrack/aidl/default/memtrack-default.rc
new file mode 100644
index 0000000..1725cd0
--- /dev/null
+++ b/memtrack/aidl/default/memtrack-default.rc
@@ -0,0 +1,4 @@
+service vendor.memtrack-default /vendor/bin/hw/android.hardware.memtrack-service.example
+ class hal
+ user nobody
+ group system
diff --git a/memtrack/aidl/default/memtrack-default.xml b/memtrack/aidl/default/memtrack-default.xml
new file mode 100644
index 0000000..3e3e0f6
--- /dev/null
+++ b/memtrack/aidl/default/memtrack-default.xml
@@ -0,0 +1,7 @@
+<manifest version="1.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.memtrack</name>
+ <fqname>IMemtrack/default</fqname>
+ </hal>
+</manifest>
+
diff --git a/memtrack/aidl/vts/Android.bp b/memtrack/aidl/vts/Android.bp
new file mode 100644
index 0000000..ea36677
--- /dev/null
+++ b/memtrack/aidl/vts/Android.bp
@@ -0,0 +1,17 @@
+cc_test {
+ name: "VtsHalMemtrackTargetTest",
+ defaults: [
+ "VtsHalTargetTestDefaults",
+ "use_libaidlvintf_gtest_helper_static",
+ ],
+ srcs: ["VtsHalMemtrackTargetTest.cpp"],
+ shared_libs: [
+ "libbinder_ndk",
+ ],
+ static_libs: [
+ "android.hardware.memtrack-unstable-ndk_platform",
+ ],
+ test_suites: [
+ "vts-core",
+ ],
+}
diff --git a/memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp b/memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp
new file mode 100644
index 0000000..a3bd293
--- /dev/null
+++ b/memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2020 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 <aidl/Gtest.h>
+#include <aidl/Vintf.h>
+
+#include <aidl/android/hardware/memtrack/DeviceInfo.h>
+#include <aidl/android/hardware/memtrack/IMemtrack.h>
+#include <aidl/android/hardware/memtrack/MemtrackType.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+using aidl::android::hardware::memtrack::DeviceInfo;
+using aidl::android::hardware::memtrack::IMemtrack;
+using aidl::android::hardware::memtrack::MemtrackRecord;
+using aidl::android::hardware::memtrack::MemtrackType;
+
+class MemtrackAidlTest : public testing::TestWithParam<std::string> {
+ public:
+ virtual void SetUp() override {
+ const auto instance = std::string() + IMemtrack::descriptor + "/default";
+ auto memtrackBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str()));
+ memtrack_ = IMemtrack::fromBinder(memtrackBinder);
+ ASSERT_NE(memtrack_, nullptr);
+ }
+
+ std::shared_ptr<IMemtrack> memtrack_;
+};
+
+TEST_P(MemtrackAidlTest, GetMemoryInvalidPid) {
+ int pid = -1;
+ MemtrackType type = MemtrackType::OTHER;
+ std::vector<MemtrackRecord> records;
+
+ auto status = memtrack_->getMemory(pid, type, &records);
+
+ EXPECT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT);
+}
+
+TEST_P(MemtrackAidlTest, GetMemoryInvalidType) {
+ int pid = 1;
+ MemtrackType type = MemtrackType::NUM_TYPES;
+ std::vector<MemtrackRecord> records;
+
+ auto status = memtrack_->getMemory(pid, type, &records);
+
+ EXPECT_EQ(status.getExceptionCode(), EX_UNSUPPORTED_OPERATION);
+}
+
+TEST_P(MemtrackAidlTest, GetMemory) {
+ int pid = 1;
+ MemtrackType type = MemtrackType::OTHER;
+ std::vector<MemtrackRecord> records;
+
+ auto status = memtrack_->getMemory(pid, type, &records);
+
+ EXPECT_TRUE(status.isOk());
+}
+
+TEST_P(MemtrackAidlTest, GetGpuDeviceInfo) {
+ std::vector<DeviceInfo> device_info;
+
+ auto status = memtrack_->getGpuDeviceInfo(&device_info);
+
+ EXPECT_TRUE(status.isOk());
+}
+
+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MemtrackAidlTest);
+INSTANTIATE_TEST_SUITE_P(PerInstance, MemtrackAidlTest,
+ testing::ValuesIn(android::getAidlHalInstanceNames(IMemtrack::descriptor)),
+ android::PrintInstanceNameToString);
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ABinderProcess_setThreadPoolMaxThreadCount(1);
+ ABinderProcess_startThreadPool();
+ return RUN_ALL_TESTS();
+}
diff --git a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h
index 65b75e5..2e00fce 100644
--- a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h
+++ b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h
@@ -27,6 +27,9 @@
#include <nnapi/hal/ProtectCallback.h>
#include <nnapi/hal/TransferValue.h>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_0::utils {
class PreparedModelCallback final : public IPreparedModelCallback,
diff --git a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Device.h b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Device.h
index ee103ba..db3b2ad 100644
--- a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Device.h
+++ b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Device.h
@@ -32,8 +32,12 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_0::utils {
+// Class that adapts V1_0::IDevice to nn::IDevice.
class Device final : public nn::IDevice {
struct PrivateConstructorTag {};
diff --git a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/PreparedModel.h b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/PreparedModel.h
index 31f366d..2de1828 100644
--- a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/PreparedModel.h
+++ b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/PreparedModel.h
@@ -29,8 +29,12 @@
#include <utility>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_0::utils {
+// Class that adapts V1_0::IPreparedModel to nn::IPreparedModel.
class PreparedModel final : public nn::IPreparedModel {
struct PrivateConstructorTag {};
@@ -44,13 +48,13 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> execute(
const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration) const override;
+ const nn::OptionalDuration& loopTimeoutDuration) const override;
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> executeFenced(
const nn::Request& request, const std::vector<nn::SyncFence>& waitFor,
nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration,
- const nn::OptionalTimeoutDuration& timeoutDurationAfterFence) const override;
+ const nn::OptionalDuration& loopTimeoutDuration,
+ const nn::OptionalDuration& timeoutDurationAfterFence) const override;
std::any getUnderlyingResource() const override;
diff --git a/neuralnetworks/1.0/utils/src/Callbacks.cpp b/neuralnetworks/1.0/utils/src/Callbacks.cpp
index b1259c3..a0bdb3c 100644
--- a/neuralnetworks/1.0/utils/src/Callbacks.cpp
+++ b/neuralnetworks/1.0/utils/src/Callbacks.cpp
@@ -32,6 +32,9 @@
#include <utility>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_0::utils {
namespace {
diff --git a/neuralnetworks/1.0/utils/src/Device.cpp b/neuralnetworks/1.0/utils/src/Device.cpp
index 285c515..83e0015 100644
--- a/neuralnetworks/1.0/utils/src/Device.cpp
+++ b/neuralnetworks/1.0/utils/src/Device.cpp
@@ -38,6 +38,9 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_0::utils {
namespace {
diff --git a/neuralnetworks/1.0/utils/src/PreparedModel.cpp b/neuralnetworks/1.0/utils/src/PreparedModel.cpp
index 46dd3f8..c1dd1d9 100644
--- a/neuralnetworks/1.0/utils/src/PreparedModel.cpp
+++ b/neuralnetworks/1.0/utils/src/PreparedModel.cpp
@@ -34,6 +34,9 @@
#include <utility>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_0::utils {
nn::GeneralResult<std::shared_ptr<const PreparedModel>> PreparedModel::create(
@@ -55,7 +58,7 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> PreparedModel::execute(
const nn::Request& request, nn::MeasureTiming /*measure*/,
const nn::OptionalTimePoint& /*deadline*/,
- const nn::OptionalTimeoutDuration& /*loopTimeoutDuration*/) const {
+ const nn::OptionalDuration& /*loopTimeoutDuration*/) const {
// Ensure that request is ready for IPC.
std::optional<nn::Request> maybeRequestInShared;
const nn::Request& requestInShared = NN_TRY(hal::utils::makeExecutionFailure(
@@ -81,11 +84,12 @@
}
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>>
-PreparedModel::executeFenced(
- const nn::Request& /*request*/, const std::vector<nn::SyncFence>& /*waitFor*/,
- nn::MeasureTiming /*measure*/, const nn::OptionalTimePoint& /*deadline*/,
- const nn::OptionalTimeoutDuration& /*loopTimeoutDuration*/,
- const nn::OptionalTimeoutDuration& /*timeoutDurationAfterFence*/) const {
+PreparedModel::executeFenced(const nn::Request& /*request*/,
+ const std::vector<nn::SyncFence>& /*waitFor*/,
+ nn::MeasureTiming /*measure*/,
+ const nn::OptionalTimePoint& /*deadline*/,
+ const nn::OptionalDuration& /*loopTimeoutDuration*/,
+ const nn::OptionalDuration& /*timeoutDurationAfterFence*/) const {
return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
<< "IPreparedModel::executeFenced is not supported on 1.0 HAL service";
}
diff --git a/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Device.h b/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Device.h
index c1e95fe1a..5e224b5 100644
--- a/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Device.h
+++ b/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Device.h
@@ -32,8 +32,12 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_1::utils {
+// Class that adapts V1_1::IDevice to nn::IDevice.
class Device final : public nn::IDevice {
struct PrivateConstructorTag {};
diff --git a/neuralnetworks/1.1/utils/src/Device.cpp b/neuralnetworks/1.1/utils/src/Device.cpp
index f73d3f8..b57c7f4 100644
--- a/neuralnetworks/1.1/utils/src/Device.cpp
+++ b/neuralnetworks/1.1/utils/src/Device.cpp
@@ -39,6 +39,9 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_1::utils {
namespace {
diff --git a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h
index bc7d92a..1162bc3 100644
--- a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h
+++ b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h
@@ -31,6 +31,9 @@
#include <nnapi/hal/ProtectCallback.h>
#include <nnapi/hal/TransferValue.h>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_2::utils {
class PreparedModelCallback final : public IPreparedModelCallback,
diff --git a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Device.h b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Device.h
index a68830d..79c3b04 100644
--- a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Device.h
+++ b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Device.h
@@ -32,6 +32,9 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_2::utils {
nn::GeneralResult<std::string> initVersionString(V1_2::IDevice* device);
@@ -40,6 +43,7 @@
nn::GeneralResult<std::pair<uint32_t, uint32_t>> initNumberOfCacheFilesNeeded(
V1_2::IDevice* device);
+// Class that adapts V1_2::IDevice to nn::IDevice.
class Device final : public nn::IDevice {
struct PrivateConstructorTag {};
diff --git a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/PreparedModel.h b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/PreparedModel.h
index 65e1e8a..8ed5ca7 100644
--- a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/PreparedModel.h
+++ b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/PreparedModel.h
@@ -30,8 +30,12 @@
#include <utility>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_2::utils {
+// Class that adapts V1_2::IPreparedModel to nn::IPreparedModel.
class PreparedModel final : public nn::IPreparedModel {
struct PrivateConstructorTag {};
@@ -45,13 +49,13 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> execute(
const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration) const override;
+ const nn::OptionalDuration& loopTimeoutDuration) const override;
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> executeFenced(
const nn::Request& request, const std::vector<nn::SyncFence>& waitFor,
nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration,
- const nn::OptionalTimeoutDuration& timeoutDurationAfterFence) const override;
+ const nn::OptionalDuration& loopTimeoutDuration,
+ const nn::OptionalDuration& timeoutDurationAfterFence) const override;
std::any getUnderlyingResource() const override;
diff --git a/neuralnetworks/1.2/utils/src/Callbacks.cpp b/neuralnetworks/1.2/utils/src/Callbacks.cpp
index 39f88c2..ab3e0ca 100644
--- a/neuralnetworks/1.2/utils/src/Callbacks.cpp
+++ b/neuralnetworks/1.2/utils/src/Callbacks.cpp
@@ -36,6 +36,9 @@
#include <utility>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_2::utils {
namespace {
diff --git a/neuralnetworks/1.2/utils/src/Conversions.cpp b/neuralnetworks/1.2/utils/src/Conversions.cpp
index f11474f..3790d1f 100644
--- a/neuralnetworks/1.2/utils/src/Conversions.cpp
+++ b/neuralnetworks/1.2/utils/src/Conversions.cpp
@@ -43,7 +43,9 @@
return static_cast<std::underlying_type_t<Type>>(value);
}
+using HalDuration = std::chrono::duration<uint64_t, std::micro>;
constexpr auto kVersion = android::nn::Version::ANDROID_Q;
+constexpr uint64_t kNoTiming = std::numeric_limits<uint64_t>::max();
} // namespace
@@ -270,7 +272,18 @@
}
GeneralResult<Timing> unvalidatedConvert(const hal::V1_2::Timing& timing) {
- return Timing{.timeOnDevice = timing.timeOnDevice, .timeInDriver = timing.timeInDriver};
+ constexpr uint64_t kMaxTiming = std::chrono::floor<HalDuration>(Duration::max()).count();
+ constexpr auto convertTiming = [](uint64_t halTiming) -> OptionalDuration {
+ if (halTiming == kNoTiming) {
+ return {};
+ }
+ if (halTiming > kMaxTiming) {
+ return Duration::max();
+ }
+ return HalDuration{halTiming};
+ };
+ return Timing{.timeOnDevice = convertTiming(timing.timeOnDevice),
+ .timeInDriver = convertTiming(timing.timeInDriver)};
}
GeneralResult<Extension> unvalidatedConvert(const hal::V1_2::Extension& extension) {
@@ -547,7 +560,14 @@
}
nn::GeneralResult<Timing> unvalidatedConvert(const nn::Timing& timing) {
- return Timing{.timeOnDevice = timing.timeOnDevice, .timeInDriver = timing.timeInDriver};
+ constexpr auto convertTiming = [](nn::OptionalDuration canonicalTiming) -> uint64_t {
+ if (!canonicalTiming.has_value()) {
+ return kNoTiming;
+ }
+ return std::chrono::ceil<HalDuration>(*canonicalTiming).count();
+ };
+ return Timing{.timeOnDevice = convertTiming(timing.timeOnDevice),
+ .timeInDriver = convertTiming(timing.timeInDriver)};
}
nn::GeneralResult<Extension> unvalidatedConvert(const nn::Extension& extension) {
diff --git a/neuralnetworks/1.2/utils/src/Device.cpp b/neuralnetworks/1.2/utils/src/Device.cpp
index 0061065..6cca841 100644
--- a/neuralnetworks/1.2/utils/src/Device.cpp
+++ b/neuralnetworks/1.2/utils/src/Device.cpp
@@ -41,6 +41,9 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_2::utils {
namespace {
diff --git a/neuralnetworks/1.2/utils/src/PreparedModel.cpp b/neuralnetworks/1.2/utils/src/PreparedModel.cpp
index dad9a7e..b422ced 100644
--- a/neuralnetworks/1.2/utils/src/PreparedModel.cpp
+++ b/neuralnetworks/1.2/utils/src/PreparedModel.cpp
@@ -37,6 +37,9 @@
#include <utility>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_2::utils {
namespace {
@@ -106,7 +109,7 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> PreparedModel::execute(
const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& /*deadline*/,
- const nn::OptionalTimeoutDuration& /*loopTimeoutDuration*/) const {
+ const nn::OptionalDuration& /*loopTimeoutDuration*/) const {
// Ensure that request is ready for IPC.
std::optional<nn::Request> maybeRequestInShared;
const nn::Request& requestInShared = NN_TRY(hal::utils::makeExecutionFailure(
@@ -140,11 +143,12 @@
}
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>>
-PreparedModel::executeFenced(
- const nn::Request& /*request*/, const std::vector<nn::SyncFence>& /*waitFor*/,
- nn::MeasureTiming /*measure*/, const nn::OptionalTimePoint& /*deadline*/,
- const nn::OptionalTimeoutDuration& /*loopTimeoutDuration*/,
- const nn::OptionalTimeoutDuration& /*timeoutDurationAfterFence*/) const {
+PreparedModel::executeFenced(const nn::Request& /*request*/,
+ const std::vector<nn::SyncFence>& /*waitFor*/,
+ nn::MeasureTiming /*measure*/,
+ const nn::OptionalTimePoint& /*deadline*/,
+ const nn::OptionalDuration& /*loopTimeoutDuration*/,
+ const nn::OptionalDuration& /*timeoutDurationAfterFence*/) const {
return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
<< "IPreparedModel::executeFenced is not supported on 1.2 HAL service";
}
diff --git a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Buffer.h b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Buffer.h
index 637179d..fda79c8 100644
--- a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Buffer.h
+++ b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Buffer.h
@@ -24,8 +24,12 @@
#include <nnapi/Types.h>
#include <memory>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
+// Class that adapts V1_3::IBuffer to nn::IBuffer.
class Buffer final : public nn::IBuffer {
struct PrivateConstructorTag {};
diff --git a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h
index d46b111..cb2a56a 100644
--- a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h
+++ b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h
@@ -34,6 +34,9 @@
#include <nnapi/hal/ProtectCallback.h>
#include <nnapi/hal/TransferValue.h>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
class PreparedModelCallback final : public IPreparedModelCallback,
diff --git a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Conversions.h b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Conversions.h
index 9653a05..477bb7b 100644
--- a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Conversions.h
+++ b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Conversions.h
@@ -44,7 +44,7 @@
const hal::V1_3::Request::MemoryPool& memoryPool);
GeneralResult<OptionalTimePoint> unvalidatedConvert(
const hal::V1_3::OptionalTimePoint& optionalTimePoint);
-GeneralResult<OptionalTimeoutDuration> unvalidatedConvert(
+GeneralResult<OptionalDuration> unvalidatedConvert(
const hal::V1_3::OptionalTimeoutDuration& optionalTimeoutDuration);
GeneralResult<ErrorStatus> unvalidatedConvert(const hal::V1_3::ErrorStatus& errorStatus);
@@ -54,7 +54,7 @@
GeneralResult<BufferDesc> convert(const hal::V1_3::BufferDesc& bufferDesc);
GeneralResult<Request> convert(const hal::V1_3::Request& request);
GeneralResult<OptionalTimePoint> convert(const hal::V1_3::OptionalTimePoint& optionalTimePoint);
-GeneralResult<OptionalTimeoutDuration> convert(
+GeneralResult<OptionalDuration> convert(
const hal::V1_3::OptionalTimeoutDuration& optionalTimeoutDuration);
GeneralResult<ErrorStatus> convert(const hal::V1_3::ErrorStatus& errorStatus);
@@ -86,7 +86,7 @@
nn::GeneralResult<OptionalTimePoint> unvalidatedConvert(
const nn::OptionalTimePoint& optionalTimePoint);
nn::GeneralResult<OptionalTimeoutDuration> unvalidatedConvert(
- const nn::OptionalTimeoutDuration& optionalTimeoutDuration);
+ const nn::OptionalDuration& optionalTimeoutDuration);
nn::GeneralResult<ErrorStatus> unvalidatedConvert(const nn::ErrorStatus& errorStatus);
nn::GeneralResult<Priority> convert(const nn::Priority& priority);
@@ -96,7 +96,7 @@
nn::GeneralResult<Request> convert(const nn::Request& request);
nn::GeneralResult<OptionalTimePoint> convert(const nn::OptionalTimePoint& optionalTimePoint);
nn::GeneralResult<OptionalTimeoutDuration> convert(
- const nn::OptionalTimeoutDuration& optionalTimeoutDuration);
+ const nn::OptionalDuration& optionalTimeoutDuration);
nn::GeneralResult<ErrorStatus> convert(const nn::ErrorStatus& errorStatus);
nn::GeneralResult<hidl_handle> convert(const nn::SharedHandle& handle);
diff --git a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Device.h b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Device.h
index 0f5234b..84f606a 100644
--- a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Device.h
+++ b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Device.h
@@ -32,8 +32,12 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
+// Class that adapts V1_3::IDevice to nn::IDevice.
class Device final : public nn::IDevice {
struct PrivateConstructorTag {};
diff --git a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/PreparedModel.h b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/PreparedModel.h
index e0d69dd..c4ba483 100644
--- a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/PreparedModel.h
+++ b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/PreparedModel.h
@@ -29,8 +29,12 @@
#include <utility>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
+// Class that adapts V1_3::IPreparedModel to nn::IPreparedModel.
class PreparedModel final : public nn::IPreparedModel {
struct PrivateConstructorTag {};
@@ -44,13 +48,13 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> execute(
const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration) const override;
+ const nn::OptionalDuration& loopTimeoutDuration) const override;
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> executeFenced(
const nn::Request& request, const std::vector<nn::SyncFence>& waitFor,
nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration,
- const nn::OptionalTimeoutDuration& timeoutDurationAfterFence) const override;
+ const nn::OptionalDuration& loopTimeoutDuration,
+ const nn::OptionalDuration& timeoutDurationAfterFence) const override;
std::any getUnderlyingResource() const override;
diff --git a/neuralnetworks/1.3/utils/src/Buffer.cpp b/neuralnetworks/1.3/utils/src/Buffer.cpp
index ffdeccd..4ef54a2 100644
--- a/neuralnetworks/1.3/utils/src/Buffer.cpp
+++ b/neuralnetworks/1.3/utils/src/Buffer.cpp
@@ -33,6 +33,9 @@
#include <memory>
#include <utility>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
nn::GeneralResult<std::shared_ptr<const Buffer>> Buffer::create(
diff --git a/neuralnetworks/1.3/utils/src/Callbacks.cpp b/neuralnetworks/1.3/utils/src/Callbacks.cpp
index e3c6074..17c20fb 100644
--- a/neuralnetworks/1.3/utils/src/Callbacks.cpp
+++ b/neuralnetworks/1.3/utils/src/Callbacks.cpp
@@ -39,6 +39,9 @@
#include <utility>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
namespace {
diff --git a/neuralnetworks/1.3/utils/src/Conversions.cpp b/neuralnetworks/1.3/utils/src/Conversions.cpp
index 949dd0d..c89a69f 100644
--- a/neuralnetworks/1.3/utils/src/Conversions.cpp
+++ b/neuralnetworks/1.3/utils/src/Conversions.cpp
@@ -272,47 +272,26 @@
GeneralResult<OptionalTimePoint> unvalidatedConvert(
const hal::V1_3::OptionalTimePoint& optionalTimePoint) {
- constexpr auto kTimePointMaxCount = TimePoint::max().time_since_epoch().count();
- const auto makeTimePoint = [](uint64_t count) -> GeneralResult<OptionalTimePoint> {
- if (count > kTimePointMaxCount) {
- return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
- << "Unable to unvalidatedConvert OptionalTimePoint because the count exceeds "
- "the max";
- }
- const auto nanoseconds = std::chrono::nanoseconds{count};
- return TimePoint{nanoseconds};
- };
-
using Discriminator = hal::V1_3::OptionalTimePoint::hidl_discriminator;
switch (optionalTimePoint.getDiscriminator()) {
case Discriminator::none:
- return std::nullopt;
+ return {};
case Discriminator::nanosecondsSinceEpoch:
- return makeTimePoint(optionalTimePoint.nanosecondsSinceEpoch());
+ return TimePoint{Duration{optionalTimePoint.nanosecondsSinceEpoch()}};
}
return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
<< "Invalid OptionalTimePoint discriminator "
<< underlyingType(optionalTimePoint.getDiscriminator());
}
-GeneralResult<OptionalTimeoutDuration> unvalidatedConvert(
+GeneralResult<OptionalDuration> unvalidatedConvert(
const hal::V1_3::OptionalTimeoutDuration& optionalTimeoutDuration) {
- constexpr auto kTimeoutDurationMaxCount = TimeoutDuration::max().count();
- const auto makeTimeoutDuration = [](uint64_t count) -> GeneralResult<OptionalTimeoutDuration> {
- if (count > kTimeoutDurationMaxCount) {
- return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
- << "Unable to unvalidatedConvert OptionalTimeoutDuration because the count "
- "exceeds the max";
- }
- return TimeoutDuration{count};
- };
-
using Discriminator = hal::V1_3::OptionalTimeoutDuration::hidl_discriminator;
switch (optionalTimeoutDuration.getDiscriminator()) {
case Discriminator::none:
- return std::nullopt;
+ return {};
case Discriminator::nanoseconds:
- return makeTimeoutDuration(optionalTimeoutDuration.nanoseconds());
+ return Duration(optionalTimeoutDuration.nanoseconds());
}
return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
<< "Invalid OptionalTimeoutDuration discriminator "
@@ -360,7 +339,7 @@
return validatedConvert(optionalTimePoint);
}
-GeneralResult<OptionalTimeoutDuration> convert(
+GeneralResult<OptionalDuration> convert(
const hal::V1_3::OptionalTimeoutDuration& optionalTimeoutDuration) {
return validatedConvert(optionalTimeoutDuration);
}
@@ -629,27 +608,16 @@
OptionalTimePoint ret;
if (optionalTimePoint.has_value()) {
const auto count = optionalTimePoint.value().time_since_epoch().count();
- if (count < 0) {
- return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
- << "Unable to unvalidatedConvert OptionalTimePoint because time since epoch "
- "count is "
- "negative";
- }
ret.nanosecondsSinceEpoch(count);
}
return ret;
}
nn::GeneralResult<OptionalTimeoutDuration> unvalidatedConvert(
- const nn::OptionalTimeoutDuration& optionalTimeoutDuration) {
+ const nn::OptionalDuration& optionalTimeoutDuration) {
OptionalTimeoutDuration ret;
if (optionalTimeoutDuration.has_value()) {
const auto count = optionalTimeoutDuration.value().count();
- if (count < 0) {
- return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
- << "Unable to unvalidatedConvert OptionalTimeoutDuration because count is "
- "negative";
- }
ret.nanoseconds(count);
}
return ret;
@@ -697,7 +665,7 @@
}
nn::GeneralResult<OptionalTimeoutDuration> convert(
- const nn::OptionalTimeoutDuration& optionalTimeoutDuration) {
+ const nn::OptionalDuration& optionalTimeoutDuration) {
return validatedConvert(optionalTimeoutDuration);
}
diff --git a/neuralnetworks/1.3/utils/src/Device.cpp b/neuralnetworks/1.3/utils/src/Device.cpp
index 82837ba..6056498 100644
--- a/neuralnetworks/1.3/utils/src/Device.cpp
+++ b/neuralnetworks/1.3/utils/src/Device.cpp
@@ -47,6 +47,9 @@
#include <string>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
namespace {
diff --git a/neuralnetworks/1.3/utils/src/PreparedModel.cpp b/neuralnetworks/1.3/utils/src/PreparedModel.cpp
index 49b9b0b..0bae95d 100644
--- a/neuralnetworks/1.3/utils/src/PreparedModel.cpp
+++ b/neuralnetworks/1.3/utils/src/PreparedModel.cpp
@@ -39,6 +39,9 @@
#include <utility>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::V1_3::utils {
namespace {
@@ -159,7 +162,7 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> PreparedModel::execute(
const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration) const {
+ const nn::OptionalDuration& loopTimeoutDuration) const {
// Ensure that request is ready for IPC.
std::optional<nn::Request> maybeRequestInShared;
const nn::Request& requestInShared = NN_TRY(hal::utils::makeExecutionFailure(
@@ -200,8 +203,8 @@
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>>
PreparedModel::executeFenced(const nn::Request& request, const std::vector<nn::SyncFence>& waitFor,
nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration,
- const nn::OptionalTimeoutDuration& timeoutDurationAfterFence) const {
+ const nn::OptionalDuration& loopTimeoutDuration,
+ const nn::OptionalDuration& timeoutDurationAfterFence) const {
// Ensure that request is ready for IPC.
std::optional<nn::Request> maybeRequestInShared;
const nn::Request& requestInShared =
diff --git a/neuralnetworks/utils/README.md b/neuralnetworks/utils/README.md
index 0dee103..45ca0b4 100644
--- a/neuralnetworks/utils/README.md
+++ b/neuralnetworks/utils/README.md
@@ -1,11 +1,11 @@
# NNAPI Conversions
`convert` fails if either the source type or the destination type is invalid, and it yields a valid
-object if the conversion succeeds. For example, let's say that an enumeration in the current
-version has fewer possible values than the "same" canonical enumeration, such as `OperationType`.
-The new value of `HARD_SWISH` (introduced in Android R / NN HAL 1.3) does not map to any valid
-existing value in `OperationType`, but an older value of `ADD` (introduced in Android OC-MR1 / NN
-HAL 1.0) is valid. This can be seen in the following model conversions:
+object if the conversion succeeds. For example, let's say that an enumeration in the current version
+has fewer possible values than the "same" canonical enumeration, such as `OperationType`. The new
+value of `HARD_SWISH` (introduced in Android R / NN HAL 1.3) does not map to any valid existing
+value in `OperationType`, but an older value of `ADD` (introduced in Android OC-MR1 / NN HAL 1.0) is
+valid. This can be seen in the following model conversions:
```cpp
// Unsuccessful conversion
@@ -48,3 +48,50 @@
`unvalidatedConvert` functions operate on types that are either used in a HIDL method call directly
(i.e., not as a nested class) or used in a subsequent version of the NN HAL. Prefer using `convert`
over `unvalidatedConvert`.
+
+# HIDL Interface Lifetimes across Processes
+
+Some notes about HIDL interface objects and lifetimes across processes:
+
+All HIDL interface objects inherit from `IBase`, which itself inherits from `::android::RefBase`. As
+such, all HIDL interface objects are reference counted and must be owned through `::android::sp` (or
+referenced through `::android::wp`). Allocating `RefBase` objects on the stack will log errors and
+may result in crashes, and deleting a `RefBase` object through another means (e.g., "delete",
+"free", or RAII-cleanup through `std::unique_ptr` or some equivalent) will result in double-free
+and/or use-after-free undefined behavior.
+
+HIDL/Binder manages the reference count of HIDL interface objects automatically across processes. If
+a process that references (but did not create) the HIDL interface object dies, HIDL/Binder ensures
+any reference count it held is properly released. (Caveat: it might be possible that HIDL/Binder
+behave strangely with `::android::wp` references.)
+
+If the process which created the HIDL interface object dies, any call on this object from another
+process will result in a HIDL transport error with the code `DEAD_OBJECT`.
+
+# Protecting Asynchronous Calls across HIDL
+
+Some notes about asynchronous calls across HIDL:
+
+For synchronous calls across HIDL, if an error occurs after the function was called but before it
+returns, HIDL will return a transport error. For example, if the message cannot be delivered to the
+server process or if the server process dies before returning a result, HIDL will return from the
+function with the appropriate transport error in the `Return<>` object, which can be queried with
+`Return<>::isOk()`, `Return<>::isDeadObject()`, `Return<>::description()`, etc.
+
+However, HIDL offers no such error management in the case of asynchronous calls. By default, if the
+client launches an asynchronous task and the server fails to return a result through the callback,
+the client will be left waiting indefinitely for a result it will never receive.
+
+In the NNAPI, `IDevice::prepareModel*` and `IPreparedModel::execute*` (but not
+`IPreparedModel::executeSynchronously*`) are asynchronous calls across HIDL. Specifically, these
+asynchronous functions are called with a HIDL interface callback object (`IPrepareModelCallback` for
+`IDevice::prepareModel*` and `IExecutionCallback` for `IPreparedModel::execute*`) and are expected
+to quickly return, and the results are returned at a later time through these callback objects.
+
+To protect against the case when the server dies after the asynchronous task was called successfully
+but before the results could be returned, HIDL provides an object called a "`hidl_death_recipient`,"
+which can be used to detect when an interface object (and more generally, the server process) has
+died. nnapi/hal/ProtectCallback.h's `DeathHandler` uses `hidl_death_recipient`s to detect when the
+driver process has died, and `DeathHandler` will unblock any thread waiting on the results of an
+`IProtectedCallback` callback object that may otherwise not be signaled. In order for this to work,
+the `IProtectedCallback` object must have been registered via `DeathHandler::protectCallback()`.
diff --git a/neuralnetworks/utils/common/include/nnapi/hal/InvalidPreparedModel.h b/neuralnetworks/utils/common/include/nnapi/hal/InvalidPreparedModel.h
index 4b32b4e..985cddb 100644
--- a/neuralnetworks/utils/common/include/nnapi/hal/InvalidPreparedModel.h
+++ b/neuralnetworks/utils/common/include/nnapi/hal/InvalidPreparedModel.h
@@ -32,13 +32,13 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> execute(
const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration) const override;
+ const nn::OptionalDuration& loopTimeoutDuration) const override;
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> executeFenced(
const nn::Request& request, const std::vector<nn::SyncFence>& waitFor,
nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration,
- const nn::OptionalTimeoutDuration& timeoutDurationAfterFence) const override;
+ const nn::OptionalDuration& loopTimeoutDuration,
+ const nn::OptionalDuration& timeoutDurationAfterFence) const override;
std::any getUnderlyingResource() const override;
};
diff --git a/neuralnetworks/utils/common/include/nnapi/hal/ProtectCallback.h b/neuralnetworks/utils/common/include/nnapi/hal/ProtectCallback.h
index 85bd613..c921885 100644
--- a/neuralnetworks/utils/common/include/nnapi/hal/ProtectCallback.h
+++ b/neuralnetworks/utils/common/include/nnapi/hal/ProtectCallback.h
@@ -28,6 +28,9 @@
#include <mutex>
#include <vector>
+// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
+// lifetimes across processes and for protecting asynchronous calls across HIDL.
+
namespace android::hardware::neuralnetworks::utils {
class IProtectedCallback {
diff --git a/neuralnetworks/utils/common/include/nnapi/hal/ResilientPreparedModel.h b/neuralnetworks/utils/common/include/nnapi/hal/ResilientPreparedModel.h
index c2940d1..d86c88b 100644
--- a/neuralnetworks/utils/common/include/nnapi/hal/ResilientPreparedModel.h
+++ b/neuralnetworks/utils/common/include/nnapi/hal/ResilientPreparedModel.h
@@ -49,13 +49,13 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> execute(
const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration) const override;
+ const nn::OptionalDuration& loopTimeoutDuration) const override;
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> executeFenced(
const nn::Request& request, const std::vector<nn::SyncFence>& waitFor,
nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration,
- const nn::OptionalTimeoutDuration& timeoutDurationAfterFence) const override;
+ const nn::OptionalDuration& loopTimeoutDuration,
+ const nn::OptionalDuration& timeoutDurationAfterFence) const override;
std::any getUnderlyingResource() const override;
diff --git a/neuralnetworks/utils/common/src/InvalidPreparedModel.cpp b/neuralnetworks/utils/common/src/InvalidPreparedModel.cpp
index 9ae7a63..a46f4ac 100644
--- a/neuralnetworks/utils/common/src/InvalidPreparedModel.cpp
+++ b/neuralnetworks/utils/common/src/InvalidPreparedModel.cpp
@@ -29,7 +29,7 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>>
InvalidPreparedModel::execute(const nn::Request& /*request*/, nn::MeasureTiming /*measure*/,
const nn::OptionalTimePoint& /*deadline*/,
- const nn::OptionalTimeoutDuration& /*loopTimeoutDuration*/) const {
+ const nn::OptionalDuration& /*loopTimeoutDuration*/) const {
return NN_ERROR() << "InvalidPreparedModel";
}
@@ -37,8 +37,8 @@
InvalidPreparedModel::executeFenced(
const nn::Request& /*request*/, const std::vector<nn::SyncFence>& /*waitFor*/,
nn::MeasureTiming /*measure*/, const nn::OptionalTimePoint& /*deadline*/,
- const nn::OptionalTimeoutDuration& /*loopTimeoutDuration*/,
- const nn::OptionalTimeoutDuration& /*timeoutDurationAfterFence*/) const {
+ const nn::OptionalDuration& /*loopTimeoutDuration*/,
+ const nn::OptionalDuration& /*timeoutDurationAfterFence*/) const {
return NN_ERROR() << "InvalidPreparedModel";
}
diff --git a/neuralnetworks/utils/common/src/ResilientPreparedModel.cpp b/neuralnetworks/utils/common/src/ResilientPreparedModel.cpp
index 1c9ecba..012a1de 100644
--- a/neuralnetworks/utils/common/src/ResilientPreparedModel.cpp
+++ b/neuralnetworks/utils/common/src/ResilientPreparedModel.cpp
@@ -64,16 +64,17 @@
nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>>
ResilientPreparedModel::execute(const nn::Request& request, nn::MeasureTiming measure,
const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration) const {
+ const nn::OptionalDuration& loopTimeoutDuration) const {
return getPreparedModel()->execute(request, measure, deadline, loopTimeoutDuration);
}
nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>>
-ResilientPreparedModel::executeFenced(
- const nn::Request& request, const std::vector<nn::SyncFence>& waitFor,
- nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline,
- const nn::OptionalTimeoutDuration& loopTimeoutDuration,
- const nn::OptionalTimeoutDuration& timeoutDurationAfterFence) const {
+ResilientPreparedModel::executeFenced(const nn::Request& request,
+ const std::vector<nn::SyncFence>& waitFor,
+ nn::MeasureTiming measure,
+ const nn::OptionalTimePoint& deadline,
+ const nn::OptionalDuration& loopTimeoutDuration,
+ const nn::OptionalDuration& timeoutDurationAfterFence) const {
return getPreparedModel()->executeFenced(request, waitFor, measure, deadline,
loopTimeoutDuration, timeoutDurationAfterFence);
}
diff --git a/radio/1.6/IRadio.hal b/radio/1.6/IRadio.hal
index 4566558..3dc80b9 100644
--- a/radio/1.6/IRadio.hal
+++ b/radio/1.6/IRadio.hal
@@ -420,4 +420,13 @@
* Response function is IRadioResponse.getDataRegistrationStateResponse_1_6()
*/
oneway getDataRegistrationState_1_6(int32_t serial);
+
+ /**
+ * Requests current call list
+ *
+ * @param serial Serial number of request.
+ *
+ * Response function is IRadioResponse.getCurrentCallsResponse_1_6()
+ */
+ oneway getCurrentCalls_1_6(int32_t serial);
};
diff --git a/radio/1.6/IRadioResponse.hal b/radio/1.6/IRadioResponse.hal
index f13ee2b..6ac86c3 100644
--- a/radio/1.6/IRadioResponse.hal
+++ b/radio/1.6/IRadioResponse.hal
@@ -19,6 +19,7 @@
import @1.0::SendSmsResult;
import @1.4::RadioAccessFamily;
import @1.5::IRadioResponse;
+import @1.6::Call;
import @1.6::CellInfo;
import @1.6::RegStateResult;
import @1.6::RadioResponseInfo;
@@ -401,4 +402,16 @@
*/
oneway getDataRegistrationStateResponse_1_6(RadioResponseInfo info,
RegStateResult dataRegResponse);
+
+ /**
+ * @param calls Current call list
+ * RadioError:NO_MEMORY
+ * RadioError:INTERNAL_ERR
+ * RadioError:SYSTEM_ERR
+ * RadioError:INVALID_ARGUMENTS
+ * RadioError:REQUEST_NOT_SUPPORTED
+ * RadioError:NO_RESOURCES
+ * RadioError:CANCELLED
+ */
+ oneway getCurrentCallsResponse_1_6(RadioResponseInfo info, vec<Call> calls);
};
diff --git a/radio/1.6/types.hal b/radio/1.6/types.hal
index 20dc612..f4dc0bd 100644
--- a/radio/1.6/types.hal
+++ b/radio/1.6/types.hal
@@ -24,6 +24,7 @@
import @1.0::RadioResponseType;
import @1.0::RegState;
import @1.1::ScanStatus;
+import @1.2::Call;
import @1.2::CellInfoCdma;
import @1.2::CellConnectionStatus;
import @1.2::TdscdmaSignalStrength;
@@ -723,3 +724,12 @@
} ngranInfo;
} accessTechnologySpecificInfo;
};
+
+struct Call {
+ @1.2::Call base;
+ /**
+ * Forwarded number. It can set only one forwarded number based on 3GPP rule of the CS.
+ * Reference: 3GPP TS 24.008 section 10.5.4.21b
+ */
+ string forwardedNumber;
+};
diff --git a/radio/1.6/vts/functional/radio_hidl_hal_api.cpp b/radio/1.6/vts/functional/radio_hidl_hal_api.cpp
index 75772cd..47babed 100644
--- a/radio/1.6/vts/functional/radio_hidl_hal_api.cpp
+++ b/radio/1.6/vts/functional/radio_hidl_hal_api.cpp
@@ -406,3 +406,15 @@
EXPECT_EQ(CardState::PRESENT, cardStatus.base.base.base.cardState);
}
}
+
+/*
+ * Test IRadio.getCurrentCalls_1_6() for the response returned.
+ */
+TEST_P(RadioHidlTest_v1_6, getCurrentCalls_1_6) {
+ serial = GetRandomSerialNumber();
+ radio_v1_6->getCurrentCalls_1_6(serial);
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_6->rspInfo.type);
+ EXPECT_EQ(serial, radioRsp_v1_6->rspInfo.serial);
+ EXPECT_EQ(::android::hardware::radio::V1_6::RadioError::NONE, radioRsp_v1_6->rspInfo.error);
+}
diff --git a/radio/1.6/vts/functional/radio_hidl_hal_utils_v1_6.h b/radio/1.6/vts/functional/radio_hidl_hal_utils_v1_6.h
index ab56540..fbcd7a9 100644
--- a/radio/1.6/vts/functional/radio_hidl_hal_utils_v1_6.h
+++ b/radio/1.6/vts/functional/radio_hidl_hal_utils_v1_6.h
@@ -821,6 +821,10 @@
Return<void> getDataRegistrationStateResponse_1_6(
const ::android::hardware::radio::V1_6::RadioResponseInfo& info,
const ::android::hardware::radio::V1_6::RegStateResult& regResponse);
+
+ Return<void> getCurrentCallsResponse_1_6(
+ const ::android::hardware::radio::V1_6::RadioResponseInfo& info,
+ const ::android::hardware::hidl_vec<::android::hardware::radio::V1_6::Call>& calls);
};
/* Callback class for radio indication */
diff --git a/radio/1.6/vts/functional/radio_response.cpp b/radio/1.6/vts/functional/radio_response.cpp
index e37efdd..7c5cf6d 100644
--- a/radio/1.6/vts/functional/radio_response.cpp
+++ b/radio/1.6/vts/functional/radio_response.cpp
@@ -1207,3 +1207,11 @@
parent_v1_6.notify(info.serial);
return Void();
}
+
+Return<void> RadioResponse_v1_6::getCurrentCallsResponse_1_6(
+ const ::android::hardware::radio::V1_6::RadioResponseInfo& info,
+ const ::android::hardware::hidl_vec<::android::hardware::radio::V1_6::Call>& /*calls*/) {
+ rspInfo = info;
+ parent_v1_6.notify(info.serial);
+ return Void();
+}
diff --git a/security/keymint/aidl/android/hardware/security/keymint/Tag.aidl b/security/keymint/aidl/android/hardware/security/keymint/Tag.aidl
index 532bc5d..3bc3f16 100644
--- a/security/keymint/aidl/android/hardware/security/keymint/Tag.aidl
+++ b/security/keymint/aidl/android/hardware/security/keymint/Tag.aidl
@@ -46,7 +46,7 @@
*
* Must be hardware-enforced.
*/
- PURPOSE = (2 << 28) | 1, /* TagType:ENUM_REP */
+ PURPOSE = (2 << 28) /* TagType:ENUM_REP */ | 1,
/**
* Tag::ALGORITHM specifies the cryptographic algorithm with which the key is used. This tag
@@ -55,7 +55,7 @@
*
* Must be hardware-enforced.
*/
- ALGORITHM = (1 << 28) | 2, /* TagType:ENUM */
+ ALGORITHM = (1 << 28) /* TagType:ENUM */ | 2,
/**
* Tag::KEY_SIZE pecifies the size, in bits, of the key, measuring in the normal way for the
@@ -67,7 +67,7 @@
*
* Must be hardware-enforced.
*/
- KEY_SIZE = (3 << 28) | 3, /* TagType:UINT */
+ KEY_SIZE = (3 << 28) /* TagType:UINT */ | 3,
/**
* Tag::BLOCK_MODE specifies the block cipher mode(s) with which the key may be used. This tag
@@ -80,8 +80,8 @@
*
* Must be hardware-enforced.
*/
- BLOCK_MODE = (2 << 28) | 4,
- /* BlockMode. */ /* TagType:ENUM_REP */
+ BLOCK_MODE = (2 << 28) /* TagType:ENUM_REP */ | 4,
+
/**
* Tag::DIGEST specifies the digest algorithms that may be used with the key to perform signing
@@ -95,7 +95,7 @@
*
* Must be hardware-enforced.
*/
- DIGEST = (2 << 28) | 5, /* TagType:ENUM_REP */
+ DIGEST = (2 << 28) /* TagType:ENUM_REP */ | 5,
/**
* Tag::PADDING specifies the padding modes that may be used with the key. This tag is relevant
@@ -123,7 +123,7 @@
*
* Must be hardware-enforced.
*/
- PADDING = (2 << 28) | 6, /* TagType:ENUM_REP */
+ PADDING = (2 << 28) /* TagType:ENUM_REP */ | 6,
/**
* Tag::CALLER_NONCE specifies that the caller can provide a nonce for nonce-requiring
@@ -136,7 +136,7 @@
*
* Must be hardware-enforced.
*/
- CALLER_NONCE = (7 << 28) | 7, /* TagType:BOOL */
+ CALLER_NONCE = (7 << 28) /* TagType:BOOL */ | 7,
/**
* Tag::MIN_MAC_LENGTH specifies the minimum length of MAC that can be requested or verified
@@ -149,7 +149,7 @@
*
* Must be hardware-enforced.
*/
- MIN_MAC_LENGTH = (3 << 28) | 8, /* TagType:UINT */
+ MIN_MAC_LENGTH = (3 << 28) /* TagType:UINT */ | 8,
// Tag 9 reserved
@@ -160,7 +160,7 @@
*
* Must be hardware-enforced.
*/
- EC_CURVE = (1 << 28) | 10, /* TagType:ENUM */
+ EC_CURVE = (1 << 28) /* TagType:ENUM */ | 10,
/**
* Tag::RSA_PUBLIC_EXPONENT specifies the value of the public exponent for an RSA key pair.
@@ -174,7 +174,7 @@
*
* Must be hardware-enforced.
*/
- RSA_PUBLIC_EXPONENT = (5 << 28) | 200, /* TagType:ULONG */
+ RSA_PUBLIC_EXPONENT = (5 << 28) /* TagType:ULONG */ | 200,
// Tag 201 reserved
@@ -185,7 +185,7 @@
*
* Must be hardware-enforced.
*/
- INCLUDE_UNIQUE_ID = (7 << 28) | 202, /* TagType:BOOL */
+ INCLUDE_UNIQUE_ID = (7 << 28) /* TagType:BOOL */ | 202,
/**
* TODO(seleneh) this tag needs to be deleted from all codes.
@@ -202,7 +202,7 @@
*
* Must be hardware-enforced.
*/
- BLOB_USAGE_REQUIREMENTS = (1 << 28) | 301, /* TagType:ENUM */
+ BLOB_USAGE_REQUIREMENTS = (1 << 28) /* TagType:ENUM */ | 301,
/**
* Tag::BOOTLOADER_ONLY specifies only the bootloader can use the key.
@@ -212,7 +212,7 @@
*
* Must be hardware-enforced.
*/
- BOOTLOADER_ONLY = (7 << 28) | 302, /* TagType:BOOL */
+ BOOTLOADER_ONLY = (7 << 28) /* TagType:BOOL */ | 302,
/**
* Tag::ROLLBACK_RESISTANCE specifies that the key has rollback resistance, meaning that when
@@ -227,16 +227,16 @@
*
* Must be hardwared-enforced.
*/
- ROLLBACK_RESISTANCE = (7 << 28) | 303, /* TagType:BOOL */
+ ROLLBACK_RESISTANCE = (7 << 28) /* TagType:BOOL */ | 303,
// Reserved for future use.
- HARDWARE_TYPE = (1 << 28) | 304, /* TagType:ENUM */
+ HARDWARE_TYPE = (1 << 28) /* TagType:ENUM */ | 304,
/**
* Keys tagged with EARLY_BOOT_ONLY may only be used, or created, during early boot, until
* IKeyMintDevice::earlyBootEnded() is called.
*/
- EARLY_BOOT_ONLY = (7 << 28) | 305, /* TagType:BOOL */
+ EARLY_BOOT_ONLY = (7 << 28) /* TagType:BOOL */ | 305,
/**
* Tag::ACTIVE_DATETIME specifies the date and time at which the key becomes active, in
@@ -245,8 +245,7 @@
*
* Need not be hardware-enforced.
*/
- ACTIVE_DATETIME = (6 << 28) | 400,
- /* Start of validity. */ /* TagType:DATE */
+ ACTIVE_DATETIME = (6 << 28) /* TagType:DATE */ | 400,
/**
* Tag::ORIGINATION_EXPIRE_DATETIME specifies the date and time at which the key expires for
@@ -258,7 +257,7 @@
*
* Need not be hardware-enforced.
*/
- ORIGINATION_EXPIRE_DATETIME = (6 << 28) | 401, /* TagType:DATE */
+ ORIGINATION_EXPIRE_DATETIME = (6 << 28) /* TagType:DATE */ | 401,
/**
* Tag::USAGE_EXPIRE_DATETIME specifies the date and time at which the key expires for
@@ -270,7 +269,7 @@
*
* Need not be hardware-enforced.
*/
- USAGE_EXPIRE_DATETIME = (6 << 28) | 402, /* TagType:DATE */
+ USAGE_EXPIRE_DATETIME = (6 << 28) /* TagType:DATE */ | 402,
/**
* TODO(seleneh) this tag need to be deleted.
@@ -295,7 +294,7 @@
*
* Must be hardware-enforced.
*/
- MIN_SECONDS_BETWEEN_OPS = (3 << 28) | 403, /* TagType:UINT */
+ MIN_SECONDS_BETWEEN_OPS = (3 << 28) /* TagType:UINT */ | 403,
/**
* Tag::MAX_USES_PER_BOOT specifies the maximum number of times that a key may be used between
@@ -315,14 +314,14 @@
*
* Must be hardware-enforced.
*/
- MAX_USES_PER_BOOT = (3 << 28) | 404, /* TagType:UINT */
+ MAX_USES_PER_BOOT = (3 << 28) /* TagType:UINT */ | 404,
/**
* Tag::USER_ID specifies the ID of the Android user that is permitted to use the key.
*
* Must not be hardware-enforced.
*/
- USER_ID = (3 << 28) | 501, /* TagType:UINT */
+ USER_ID = (3 << 28) /* TagType:UINT */ | 501,
/**
* Tag::USER_SECURE_ID specifies that a key may only be used under a particular secure user
@@ -355,7 +354,7 @@
*
* Must be hardware-enforced.
*/
- USER_SECURE_ID = (10 << 28) | 502, /* TagType:ULONG_REP */
+ USER_SECURE_ID = (10 << 28) /* TagType:ULONG_REP */ | 502,
/**
* Tag::NO_AUTH_REQUIRED specifies that no authentication is required to use this key. This tag
@@ -363,7 +362,7 @@
*
* Must be hardware-enforced.
*/
- NO_AUTH_REQUIRED = (7 << 28) | 503, /* TagType:BOOL */
+ NO_AUTH_REQUIRED = (7 << 28) /* TagType:BOOL */ | 503,
/**
* Tag::USER_AUTH_TYPE specifies the types of user authenticators that may be used to authorize
@@ -382,7 +381,7 @@
*
* Must be hardware-enforced.
*/
- USER_AUTH_TYPE = (1 << 28) | 504, /* TagType:ENUM */
+ USER_AUTH_TYPE = (1 << 28) /* TagType:ENUM */ | 504,
/**
* Tag::AUTH_TIMEOUT specifies the time in seconds for which the key is authorized for use,
@@ -396,7 +395,7 @@
*
* Must be hardware-enforced.
*/
- AUTH_TIMEOUT = (3 << 28) | 505, /* TagType:UINT */
+ AUTH_TIMEOUT = (3 << 28) /* TagType:UINT */ | 505,
/**
* Tag::ALLOW_WHILE_ON_BODY specifies that the key may be used after authentication timeout if
@@ -404,7 +403,7 @@
*
* Cannot be hardware-enforced.
*/
- ALLOW_WHILE_ON_BODY = (7 << 28) | 506, /* TagType:BOOL */
+ ALLOW_WHILE_ON_BODY = (7 << 28) /* TagType:BOOL */ | 506,
/**
* TRUSTED_USER_PRESENCE_REQUIRED is an optional feature that specifies that this key must be
@@ -451,7 +450,7 @@
*
* Must be hardware-enforced.
*/
- TRUSTED_USER_PRESENCE_REQUIRED = (7 << 28) | 507, /* TagType:BOOL */
+ TRUSTED_USER_PRESENCE_REQUIRED = (7 << 28) /* TagType:BOOL */ | 507,
/** Tag::TRUSTED_CONFIRMATION_REQUIRED is only applicable to keys with KeyPurpose SIGN, and
* specifies that this key must not be usable unless the user provides confirmation of the data
@@ -464,7 +463,7 @@
*
* Must be hardware-enforced.
*/
- TRUSTED_CONFIRMATION_REQUIRED = (7 << 28) | 508, /* TagType:BOOL */
+ TRUSTED_CONFIRMATION_REQUIRED = (7 << 28) /* TagType:BOOL */ | 508,
/**
* Tag::UNLOCKED_DEVICE_REQUIRED specifies that the key may only be used when the device is
@@ -472,7 +471,7 @@
*
* Must be software-enforced.
*/
- UNLOCKED_DEVICE_REQUIRED = (7 << 28) | 509, /* TagType:BOOL */
+ UNLOCKED_DEVICE_REQUIRED = (7 << 28) /* TagType:BOOL */ | 509,
/**
* Tag::APPLICATION_ID. When provided to generateKey or importKey, this tag specifies data
@@ -488,7 +487,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- APPLICATION_ID = (9 << 28) | 601, /* TagType:BYTES */
+ APPLICATION_ID = (9 << 28) /* TagType:BYTES */ | 601,
/*
* Semantically unenforceable tags, either because they have no specific meaning or because
@@ -509,7 +508,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- APPLICATION_DATA = (9 << 28) | 700, /* TagType:BYTES */
+ APPLICATION_DATA = (9 << 28) /* TagType:BYTES */ | 700,
/**
* Tag::CREATION_DATETIME specifies the date and time the key was created, in milliseconds since
@@ -518,7 +517,7 @@
* Tag::CREATED is informational only, and not enforced by anything. Must be in the
* software-enforced list, if provided.
*/
- CREATION_DATETIME = (6 << 28) | 701, /* TagType:DATE */
+ CREATION_DATETIME = (6 << 28) /* TagType:DATE */ | 701,
/**
* Tag::ORIGIN specifies where the key was created, if known. This tag must not be specified
@@ -527,7 +526,7 @@
*
* Must be hardware-enforced.
*/
- ORIGIN = (1 << 28) | 702, /* TagType:ENUM */
+ ORIGIN = (1 << 28) /* TagType:ENUM */ | 702,
// 703 is unused.
@@ -539,7 +538,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ROOT_OF_TRUST = (9 << 28) | 704, /* TagType:BYTES */
+ ROOT_OF_TRUST = (9 << 28) /* TagType:BYTES */ | 704,
/**
* Tag::OS_VERSION specifies the system OS version with which the key may be used. This tag is
@@ -562,7 +561,7 @@
*
* Must be hardware-enforced.
*/
- OS_VERSION = (3 << 28) | 705, /* TagType:UINT */
+ OS_VERSION = (3 << 28) /* TagType:UINT */ | 705,
/**
* Tag::OS_PATCHLEVEL specifies the system security patch level with which the key may be used.
@@ -583,7 +582,7 @@
*
* Must be hardware-enforced.
*/
- OS_PATCHLEVEL = (3 << 28) | 706, /* TagType:UINT */
+ OS_PATCHLEVEL = (3 << 28) /* TagType:UINT */ | 706,
/**
* Tag::UNIQUE_ID specifies a unique, time-based identifier. This tag is never provided to or
@@ -617,7 +616,7 @@
*
* Must be hardware-enforced.
*/
- UNIQUE_ID = (9 << 28) | 707, /* TagType:BYTES */
+ UNIQUE_ID = (9 << 28) /* TagType:BYTES */ | 707,
/**
* Tag::ATTESTATION_CHALLENGE is used to deliver a "challenge" value to the attestKey() method,
@@ -626,7 +625,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_CHALLENGE = (9 << 28) | 708, /* TagType:BYTES */
+ ATTESTATION_CHALLENGE = (9 << 28) /* TagType:BYTES */ | 708,
/**
* Tag::ATTESTATION_APPLICATION_ID identifies the set of applications which may use a key, used
@@ -652,7 +651,7 @@
*
* Cannot be hardware-enforced.
*/
- ATTESTATION_APPLICATION_ID = (9 << 28) | 709, /* TagType:BYTES */
+ ATTESTATION_APPLICATION_ID = (9 << 28) /* TagType:BYTES */ | 709,
/**
* Tag::ATTESTATION_ID_BRAND provides the device's brand name, as returned by Build.BRAND in
@@ -665,7 +664,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_BRAND = (9 << 28) | 710, /* TagType:BYTES */
+ ATTESTATION_ID_BRAND = (9 << 28) /* TagType:BYTES */ | 710,
/**
* Tag::ATTESTATION_ID_DEVICE provides the device's device name, as returned by Build.DEVICE in
@@ -678,7 +677,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_DEVICE = (9 << 28) | 711, /* TagType:BYTES */
+ ATTESTATION_ID_DEVICE = (9 << 28) /* TagType:BYTES */ | 711,
/**
* Tag::ATTESTATION_ID_PRODUCT provides the device's product name, as returned by Build.PRODUCT
@@ -691,7 +690,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_PRODUCT = (9 << 28) | 712, /* TagType:BYTES */
+ ATTESTATION_ID_PRODUCT = (9 << 28) /* TagType:BYTES */ | 712,
/**
* Tag::ATTESTATION_ID_SERIAL the device's serial number. This field must be set only when
@@ -703,7 +702,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_SERIAL = (9 << 28) | 713, /* TagType:BYTES */
+ ATTESTATION_ID_SERIAL = (9 << 28) /* TagType:BYTES */ | 713,
/**
* Tag::ATTESTATION_ID_IMEI provides the IMEIs for all radios on the device to attestKey().
@@ -715,7 +714,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_IMEI = (9 << 28) | 714, /* TagType:BYTES */
+ ATTESTATION_ID_IMEI = (9 << 28) /* TagType:BYTES */ | 714,
/**
* Tag::ATTESTATION_ID_MEID provides the MEIDs for all radios on the device to attestKey().
@@ -727,7 +726,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_MEID = (9 << 28) | 715, /* TagType:BYTES */
+ ATTESTATION_ID_MEID = (9 << 28) /* TagType:BYTES */ | 715,
/**
* Tag::ATTESTATION_ID_MANUFACTURER provides the device's manufacturer name, as returned by
@@ -740,7 +739,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_MANUFACTURER = (9 << 28) | 716, /* TagType:BYTES */
+ ATTESTATION_ID_MANUFACTURER = (9 << 28) /* TagType:BYTES */ | 716,
/**
* Tag::ATTESTATION_ID_MODEL provides the device's model name, as returned by Build.MODEL in
@@ -753,7 +752,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- ATTESTATION_ID_MODEL = (9 << 28) | 717, /* TagType:BYTES */
+ ATTESTATION_ID_MODEL = (9 << 28) /* TagType:BYTES */ | 717,
/**
* Tag::VENDOR_PATCHLEVEL specifies the vendor image security patch level with which the key may
@@ -775,7 +774,7 @@
*
* Must be hardware-enforced.
*/
- VENDOR_PATCHLEVEL = (3 << 28) | 718, /* TagType:UINT */
+ VENDOR_PATCHLEVEL = (3 << 28) /* TagType:UINT */ | 718,
/**
* Tag::BOOT_PATCHLEVEL specifies the boot image (kernel) security patch level with which the
@@ -795,7 +794,7 @@
*
* Must be hardware-enforced.
*/
- BOOT_PATCHLEVEL = (3 << 28) | 719, /* TagType:UINT */
+ BOOT_PATCHLEVEL = (3 << 28) /* TagType:UINT */ | 719,
/**
* DEVICE_UNIQUE_ATTESTATION is an argument to IKeyMintDevice::attestKey(). It indicates that
@@ -811,7 +810,7 @@
* IKeyMintDevice implementations that support device-unique attestation MUST add the
* DEVICE_UNIQUE_ATTESTATION tag to device-unique attestations.
*/
- DEVICE_UNIQUE_ATTESTATION = (7 << 28) | 720, /* TagType:BOOL */
+ DEVICE_UNIQUE_ATTESTATION = (7 << 28) /* TagType:BOOL */ | 720,
/**
* IDENTITY_CREDENTIAL_KEY is never used by IKeyMintDevice, is not a valid argument to key
@@ -819,7 +818,7 @@
* attestation. It is used in attestations produced by the IIdentityCredential HAL when that
* HAL attests to Credential Keys. IIdentityCredential produces KeyMint-style attestations.
*/
- IDENTITY_CREDENTIAL_KEY = (7 << 28) | 721, /* TagType:BOOL */
+ IDENTITY_CREDENTIAL_KEY = (7 << 28) /* TagType:BOOL */ | 721,
/**
* To prevent keys from being compromised if an attacker acquires read access to system / kernel
@@ -836,7 +835,7 @@
* ErrorCode::INVALID_OPERATION is returned when a key with Tag::STORAGE_KEY is provided to
* begin().
*/
- STORAGE_KEY = (7 << 28) | 722, /* TagType:BOOL */
+ STORAGE_KEY = (7 << 28) /* TagType:BOOL */ | 722,
/**
* Tag::ASSOCIATED_DATA Provides "associated data" for AES-GCM encryption or decryption. This
@@ -845,7 +844,7 @@
*
* Must never appear KeyCharacteristics.
*/
- ASSOCIATED_DATA = (9 << 28) | 1000, /* TagType:BYTES */
+ ASSOCIATED_DATA = (9 << 28) /* TagType:BYTES */ | 1000,
/**
* Tag::NONCE is used to provide or return a nonce or Initialization Vector (IV) for AES-GCM,
@@ -860,7 +859,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- NONCE = (9 << 28) | 1001, /* TagType:BYTES */
+ NONCE = (9 << 28) /* TagType:BYTES */ | 1001,
/**
* Tag::MAC_LENGTH provides the requested length of a MAC or GCM authentication tag, in bits.
@@ -871,7 +870,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- MAC_LENGTH = (3 << 28) | 1003, /* TagType:UINT */
+ MAC_LENGTH = (3 << 28) /* TagType:UINT */ | 1003,
/**
* Tag::RESET_SINCE_ID_ROTATION specifies whether the device has been factory reset since the
@@ -879,7 +878,7 @@
*
* Must never appear in KeyCharacteristics.
*/
- RESET_SINCE_ID_ROTATION = (7 << 28) | 1004, /* TagType:BOOL */
+ RESET_SINCE_ID_ROTATION = (7 << 28) /* TagType:BOOL */ | 1004,
/**
* Tag::CONFIRMATION_TOKEN is used to deliver a cryptographic token proving that the user
@@ -888,5 +887,5 @@
*
* Must never appear in KeyCharacteristics.
*/
- CONFIRMATION_TOKEN = (9 << 28) | 1005, /* TagType:BYTES */
+ CONFIRMATION_TOKEN = (9 << 28) /* TagType:BYTES */ | 1005,
}
diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h
index 76effcf..052736b 100644
--- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h
+++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h
@@ -14,19 +14,17 @@
* limitations under the License.
*/
-#ifndef VTS_KEYMINT_AIDL_TEST_UTILS_H
-#define VTS_KEYMINT_AIDL_TEST_UTILS_H
-
#pragma once
#include <aidl/Gtest.h>
#include <aidl/Vintf.h>
-#include <android/hardware/security/keymint/ErrorCode.h>
-#include <android/hardware/security/keymint/IKeyMintDevice.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <gtest/gtest.h>
+#include <android/hardware/security/keymint/ErrorCode.h>
+#include <android/hardware/security/keymint/IKeyMintDevice.h>
+
#include <keymint_support/authorization_set.h>
namespace android::hardware::security::keymint::test {
@@ -187,5 +185,3 @@
android::PrintInstanceNameToString)
} // namespace android::hardware::security::keymint::test
-
-#endif // VTS_KEYMINT_AIDL_TEST_UTILS_H
diff --git a/security/keymint/support/attestation_record.cpp b/security/keymint/support/attestation_record.cpp
index afdb208..1b07495 100644
--- a/security/keymint/support/attestation_record.cpp
+++ b/security/keymint/support/attestation_record.cpp
@@ -18,6 +18,9 @@
#include <assert.h>
+#include <android/hardware/security/keymint/Tag.h>
+#include <android/hardware/security/keymint/TagType.h>
+
#include <android-base/logging.h>
#include <openssl/asn1t.h>
@@ -25,9 +28,6 @@
#include <openssl/evp.h>
#include <openssl/x509.h>
-#include <android/hardware/security/keymint/Tag.h>
-#include <android/hardware/security/keymint/TagType.h>
-
#include <keymint_support/authorization_set.h>
#include <keymint_support/openssl_utils.h>
@@ -326,9 +326,8 @@
}
ErrorCode parse_root_of_trust(const uint8_t* asn1_key_desc, size_t asn1_key_desc_len,
- vector<uint8_t>* verified_boot_key,
- keymint_verified_boot_t* verified_boot_state, bool* device_locked,
- vector<uint8_t>* verified_boot_hash) {
+ vector<uint8_t>* verified_boot_key, VerifiedBoot* verified_boot_state,
+ bool* device_locked, vector<uint8_t>* verified_boot_hash) {
if (!verified_boot_key || !verified_boot_state || !device_locked || !verified_boot_hash) {
LOG(ERROR) << AT << "null pointer input(s)";
return ErrorCode::INVALID_ARGUMENT;
@@ -358,8 +357,8 @@
verified_boot_key->resize(vb_key->length);
memcpy(verified_boot_key->data(), vb_key->data, vb_key->length);
- *verified_boot_state = static_cast<keymint_verified_boot_t>(
- ASN1_ENUMERATED_get(root_of_trust->verified_boot_state));
+ *verified_boot_state =
+ static_cast<VerifiedBoot>(ASN1_ENUMERATED_get(root_of_trust->verified_boot_state));
if (!verified_boot_state) {
LOG(ERROR) << AT << " Failed verified boot state parsing";
return ErrorCode::INVALID_ARGUMENT;
diff --git a/security/keymint/support/authorization_set.cpp b/security/keymint/support/authorization_set.cpp
index aa9638f..e2aac9a 100644
--- a/security/keymint/support/authorization_set.cpp
+++ b/security/keymint/support/authorization_set.cpp
@@ -76,16 +76,6 @@
}
}
-void AuthorizationSet::Filter(std::function<bool(const KeyParameter&)> doKeep) {
- std::vector<KeyParameter> result;
- for (auto& param : data_) {
- if (doKeep(param)) {
- result.push_back(std::move(param));
- }
- }
- std::swap(data_, result);
-}
-
KeyParameter& AuthorizationSet::operator[](int at) {
return data_[at];
}
@@ -128,279 +118,6 @@
return data_[pos];
}
-/**
- * Persistent format is:
- * | 32 bit indirect_size |
- * --------------------------------
- * | indirect_size bytes of data | this is where the blob data is stored
- * --------------------------------
- * | 32 bit element_count | number of entries
- * | 32 bit elements_size | total bytes used by entries (entries have variable length)
- * --------------------------------
- * | elementes_size bytes of data | where the elements are stored
- */
-
-/**
- * Persistent format of blobs and bignums:
- * | 32 bit tag |
- * | 32 bit blob_length |
- * | 32 bit indirect_offset |
- */
-
-struct OutStreams {
- std::ostream& indirect;
- std::ostream& elements;
- size_t skipped;
-};
-
-OutStreams& serializeParamValue(OutStreams& out, const vector<uint8_t>& blob) {
- uint32_t buffer;
-
- // write blob_length
- auto blob_length = blob.size();
- if (blob_length > std::numeric_limits<uint32_t>::max()) {
- out.elements.setstate(std::ios_base::badbit);
- return out;
- }
- buffer = blob_length;
- out.elements.write(reinterpret_cast<const char*>(&buffer), sizeof(uint32_t));
-
- // write indirect_offset
- auto offset = out.indirect.tellp();
- if (offset < 0 || offset > std::numeric_limits<uint32_t>::max() ||
- uint32_t(offset) + uint32_t(blob_length) < uint32_t(offset)) { // overflow check
- out.elements.setstate(std::ios_base::badbit);
- return out;
- }
- buffer = offset;
- out.elements.write(reinterpret_cast<const char*>(&buffer), sizeof(uint32_t));
-
- // write blob to indirect stream
- if (blob_length) out.indirect.write(reinterpret_cast<const char*>(&blob[0]), blob_length);
-
- return out;
-}
-
-template <typename T>
-OutStreams& serializeParamValue(OutStreams& out, const T& value) {
- out.elements.write(reinterpret_cast<const char*>(&value), sizeof(T));
- return out;
-}
-
-OutStreams& serialize(TAG_INVALID_t&&, OutStreams& out, const KeyParameter&) {
- // skip invalid entries.
- ++out.skipped;
- return out;
-}
-template <typename T>
-OutStreams& serialize(T ttag, OutStreams& out, const KeyParameter& param) {
- out.elements.write(reinterpret_cast<const char*>(¶m.tag), sizeof(int32_t));
- return serializeParamValue(out, accessTagValue(ttag, param));
-}
-
-template <typename... T>
-struct choose_serializer;
-template <typename... Tags>
-struct choose_serializer<MetaList<Tags...>> {
- static OutStreams& serialize(OutStreams& out, const KeyParameter& param) {
- return choose_serializer<Tags...>::serialize(out, param);
- }
-};
-
-template <>
-struct choose_serializer<> {
- static OutStreams& serialize(OutStreams& out, const KeyParameter& param) {
- LOG(WARNING) << "Trying to serialize unknown tag " << unsigned(param.tag)
- << ". Did you forget to add it to all_tags_t?";
- ++out.skipped;
- return out;
- }
-};
-
-template <TagType tag_type, Tag tag, typename... Tail>
-struct choose_serializer<android::hardware::security::keymint::TypedTag<tag_type, tag>, Tail...> {
- static OutStreams& serialize(OutStreams& out, const KeyParameter& param) {
- if (param.tag == tag) {
- return android::hardware::security::keymint::serialize(TypedTag<tag_type, tag>(), out,
- param);
- } else {
- return choose_serializer<Tail...>::serialize(out, param);
- }
- }
-};
-
-OutStreams& serialize(OutStreams& out, const KeyParameter& param) {
- return choose_serializer<all_tags_t>::serialize(out, param);
-}
-
-std::ostream& serialize(std::ostream& out, const std::vector<KeyParameter>& params) {
- std::stringstream indirect;
- std::stringstream elements;
- OutStreams streams = {indirect, elements, 0};
- for (const auto& param : params) {
- serialize(streams, param);
- }
- if (indirect.bad() || elements.bad()) {
- out.setstate(std::ios_base::badbit);
- return out;
- }
- auto pos = indirect.tellp();
- if (pos < 0 || pos > std::numeric_limits<uint32_t>::max()) {
- out.setstate(std::ios_base::badbit);
- return out;
- }
- uint32_t indirect_size = pos;
- pos = elements.tellp();
- if (pos < 0 || pos > std::numeric_limits<uint32_t>::max()) {
- out.setstate(std::ios_base::badbit);
- return out;
- }
- uint32_t elements_size = pos;
- uint32_t element_count = params.size() - streams.skipped;
-
- out.write(reinterpret_cast<const char*>(&indirect_size), sizeof(uint32_t));
-
- pos = out.tellp();
- if (indirect_size) out << indirect.rdbuf();
- assert(out.tellp() - pos == indirect_size);
-
- out.write(reinterpret_cast<const char*>(&element_count), sizeof(uint32_t));
- out.write(reinterpret_cast<const char*>(&elements_size), sizeof(uint32_t));
-
- pos = out.tellp();
- if (elements_size) out << elements.rdbuf();
- assert(out.tellp() - pos == elements_size);
-
- return out;
-}
-
-struct InStreams {
- std::istream& indirect;
- std::istream& elements;
- size_t invalids;
-};
-
-InStreams& deserializeParamValue(InStreams& in, vector<uint8_t>* blob) {
- uint32_t blob_length = 0;
- uint32_t offset = 0;
- in.elements.read(reinterpret_cast<char*>(&blob_length), sizeof(uint32_t));
- blob->resize(blob_length);
- in.elements.read(reinterpret_cast<char*>(&offset), sizeof(uint32_t));
- in.indirect.seekg(offset);
- in.indirect.read(reinterpret_cast<char*>(&(*blob)[0]), blob->size());
- return in;
-}
-
-template <typename T>
-InStreams& deserializeParamValue(InStreams& in, T* value) {
- in.elements.read(reinterpret_cast<char*>(value), sizeof(T));
- return in;
-}
-
-InStreams& deserialize(TAG_INVALID_t&&, InStreams& in, KeyParameter*) {
- // there should be no invalid KeyParameters but if handle them as zero sized.
- ++in.invalids;
- return in;
-}
-
-template <typename T>
-InStreams& deserialize(T&& ttag, InStreams& in, KeyParameter* param) {
- return deserializeParamValue(in, &accessTagValue(ttag, *param));
-}
-
-template <typename... T>
-struct choose_deserializer;
-template <typename... Tags>
-struct choose_deserializer<MetaList<Tags...>> {
- static InStreams& deserialize(InStreams& in, KeyParameter* param) {
- return choose_deserializer<Tags...>::deserialize(in, param);
- }
-};
-template <>
-struct choose_deserializer<> {
- static InStreams& deserialize(InStreams& in, KeyParameter*) {
- // encountered an unknown tag -> fail parsing
- in.elements.setstate(std::ios_base::badbit);
- return in;
- }
-};
-template <TagType tag_type, Tag tag, typename... Tail>
-struct choose_deserializer<TypedTag<tag_type, tag>, Tail...> {
- static InStreams& deserialize(InStreams& in, KeyParameter* param) {
- if (param->tag == tag) {
- return android::hardware::security::keymint::deserialize(TypedTag<tag_type, tag>(), in,
- param);
- } else {
- return choose_deserializer<Tail...>::deserialize(in, param);
- }
- }
-};
-
-InStreams& deserialize(InStreams& in, KeyParameter* param) {
- in.elements.read(reinterpret_cast<char*>(¶m->tag), sizeof(Tag));
- return choose_deserializer<all_tags_t>::deserialize(in, param);
-}
-
-std::istream& deserialize(std::istream& in, std::vector<KeyParameter>* params) {
- uint32_t indirect_size = 0;
- in.read(reinterpret_cast<char*>(&indirect_size), sizeof(uint32_t));
- std::string indirect_buffer(indirect_size, '\0');
- if (indirect_buffer.size() != indirect_size) {
- in.setstate(std::ios_base::badbit);
- return in;
- }
- in.read(&indirect_buffer[0], indirect_buffer.size());
-
- uint32_t element_count = 0;
- in.read(reinterpret_cast<char*>(&element_count), sizeof(uint32_t));
- uint32_t elements_size = 0;
- in.read(reinterpret_cast<char*>(&elements_size), sizeof(uint32_t));
-
- std::string elements_buffer(elements_size, '\0');
- if (elements_buffer.size() != elements_size) {
- in.setstate(std::ios_base::badbit);
- return in;
- }
- in.read(&elements_buffer[0], elements_buffer.size());
-
- if (in.bad()) return in;
-
- // TODO write one-shot stream buffer to avoid copying here
- std::stringstream indirect(indirect_buffer);
- std::stringstream elements(elements_buffer);
- InStreams streams = {indirect, elements, 0};
-
- params->resize(element_count);
-
- for (uint32_t i = 0; i < element_count; ++i) {
- deserialize(streams, &(*params)[i]);
- }
-
- /*
- * There are legacy blobs which have invalid tags in them due to a bug during serialization.
- * This makes sure that invalid tags are filtered from the result before it is returned.
- */
- if (streams.invalids > 0) {
- std::vector<KeyParameter> filtered(element_count - streams.invalids);
- auto ifiltered = filtered.begin();
- for (auto& p : *params) {
- if (p.tag != Tag::INVALID) {
- *ifiltered++ = std::move(p);
- }
- }
- *params = std::move(filtered);
- }
- return in;
-}
-
-void AuthorizationSet::Serialize(std::ostream* out) const {
- serialize(*out, data_);
-}
-
-void AuthorizationSet::Deserialize(std::istream* in) {
- deserialize(*in, &data_);
-}
-
AuthorizationSetBuilder& AuthorizationSetBuilder::RsaKey(uint32_t key_size,
uint64_t public_exponent) {
Authorization(TAG_ALGORITHM, Algorithm::RSA);
diff --git a/security/keymint/support/include/keymint_support/attestation_record.h b/security/keymint/support/include/keymint_support/attestation_record.h
index d71624c..0739569 100644
--- a/security/keymint/support/include/keymint_support/attestation_record.h
+++ b/security/keymint/support/include/keymint_support/attestation_record.h
@@ -43,18 +43,18 @@
*/
static const char kAttestionRecordOid[] = "1.3.6.1.4.1.11129.2.1.17";
-enum keymint_verified_boot_t {
- KM_VERIFIED_BOOT_VERIFIED = 0,
- KM_VERIFIED_BOOT_SELF_SIGNED = 1,
- KM_VERIFIED_BOOT_UNVERIFIED = 2,
- KM_VERIFIED_BOOT_FAILED = 3,
+enum class VerifiedBoot : uint8_t {
+ VERIFIED = 0,
+ SELF_SIGNED = 1,
+ UNVERIFIED = 2,
+ FAILED = 3,
};
struct RootOfTrust {
SecurityLevel security_level;
vector<uint8_t> verified_boot_key;
vector<uint8_t> verified_boot_hash;
- keymint_verified_boot_t verified_boot_state;
+ VerifiedBoot verified_boot_state;
bool device_locked;
};
@@ -81,7 +81,7 @@
ErrorCode parse_root_of_trust(const uint8_t* asn1_key_desc, size_t asn1_key_desc_len,
std::vector<uint8_t>* verified_boot_key,
- keymint_verified_boot_t* verified_boot_state, bool* device_locked,
+ VerifiedBoot* verified_boot_state, bool* device_locked,
std::vector<uint8_t>* verified_boot_hash);
} // namespace android::hardware::security::keymint
diff --git a/security/keymint/support/include/keymint_support/authorization_set.h b/security/keymint/support/include/keymint_support/authorization_set.h
index 97e1022..0277200 100644
--- a/security/keymint/support/include/keymint_support/authorization_set.h
+++ b/security/keymint/support/include/keymint_support/authorization_set.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef SYSTEM_SECURITY_KEYSTORE_KM4_AUTHORIZATION_SET_H_
-#define SYSTEM_SECURITY_KEYSTORE_KM4_AUTHORIZATION_SET_H_
+#pragma once
#include <vector>
@@ -33,9 +32,8 @@
class AuthorizationSetBuilder;
/**
- * An ordered collection of KeyParameters. It provides memory ownership and some convenient
- * functionality for sorting, deduplicating, joining, and subtracting sets of KeyParameters.
- * For serialization, wrap the backing store of this structure in a vector<KeyParameter>.
+ * A collection of KeyParameters. It provides memory ownership and some convenient functionality for
+ * sorting, deduplicating, joining, and subtracting sets of KeyParameters.
*/
class AuthorizationSet {
public:
@@ -138,19 +136,16 @@
/**
* Returns iterator (pointer) to beginning of elems array, to enable STL-style iteration
*/
- std::vector<KeyParameter>::const_iterator begin() const { return data_.begin(); }
+ auto begin() { return data_.begin(); }
+ auto begin() const { return data_.begin(); }
/**
* Returns iterator (pointer) one past end of elems array, to enable STL-style iteration
*/
- std::vector<KeyParameter>::const_iterator end() const { return data_.end(); }
+ auto end() { return data_.end(); }
+ auto end() const { return data_.end(); }
/**
- * Modifies this Authorization set such that it only keeps the entries for which doKeep
- * returns true.
- */
- void Filter(std::function<bool(const KeyParameter&)> doKeep);
- /**
* Returns the nth element of the set.
* Like for std::vector::operator[] there is no range check performed. Use of out of range
* indices is undefined.
@@ -223,9 +218,6 @@
return result;
}
- void Serialize(std::ostream* out) const;
- void Deserialize(std::istream* in);
-
private:
NullOr<const KeyParameter&> GetEntry(Tag tag) const;
@@ -316,5 +308,3 @@
};
} // namespace android::hardware::security::keymint
-
-#endif // SYSTEM_SECURITY_KEYSTORE_KM4_AUTHORIZATION_SET_H_
diff --git a/security/keymint/support/include/keymint_support/key_param_output.h b/security/keymint/support/include/keymint_support/key_param_output.h
index 82c9689..b109105 100644
--- a/security/keymint/support/include/keymint_support/key_param_output.h
+++ b/security/keymint/support/include/keymint_support/key_param_output.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef HARDWARE_INTERFACES_KEYMINT_SUPPORT_INCLUDE_KEY_PARAM_OUTPUT_H_
-#define HARDWARE_INTERFACES_KEYMINT_SUPPORT_INCLUDE_KEY_PARAM_OUTPUT_H_
+#pragma once
#include <iostream>
#include <vector>
@@ -98,5 +97,3 @@
}
} // namespace android::hardware::security::keymint
-
-#endif // HARDWARE_INTERFACES_KEYMINT_SUPPORT_INCLUDE_KEY_PARAM_OUTPUT_H_
diff --git a/security/keymint/support/include/keymint_support/keymint_tags.h b/security/keymint/support/include/keymint_support/keymint_tags.h
index f23e4f2..d418fec 100644
--- a/security/keymint/support/include/keymint_support/keymint_tags.h
+++ b/security/keymint/support/include/keymint_support/keymint_tags.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef HARDWARE_INTERFACES_KEYMINT_SUPPORT_INCLUDE_KEYMINT_TAGS_H_
-#define HARDWARE_INTERFACES_KEYMINT_SUPPORT_INCLUDE_KEYMINT_TAGS_H_
+#pragma once
#include <android/hardware/security/keymint/Algorithm.h>
#include <android/hardware/security/keymint/BlockMode.h>
@@ -32,22 +31,15 @@
namespace android::hardware::security::keymint {
-// The following create the numeric values that KM_TAG_PADDING and KM_TAG_DIGEST used to have. We
-// need these old values to be able to support old keys that use them.
-// TODO(seleneh) we should delete this code when we stop supporting keymaster1
-// and deletes it.
-static const int32_t KM_TAG_DIGEST_OLD = static_cast<int32_t>(TagType::ENUM) | 5;
-static const int32_t KM_TAG_PADDING_OLD = static_cast<int32_t>(TagType::ENUM) | 7;
-
constexpr TagType typeFromTag(Tag tag) {
return static_cast<TagType>(static_cast<uint32_t>(tag) & static_cast<uint32_t>(0xf0000000));
}
/**
- * TypedTag is a templatized version of Tag, which provides compile-time checking of
- * keymint tag types. Instances are convertible to Tag, so they can be used wherever
- * Tag is expected, and because they encode the tag type it's possible to create
- * function overloads that only operate on tags with a particular type.
+ * TypedTag is a templatized version of Tag, which provides compile-time checking of KeyMint tag
+ * types. Instances are convertible to Tag, so they can be used wherever Tag is expected, and
+ * because they encode the tag type it's possible to create function overloads that only operate on
+ * tags with a particular type.
*/
template <TagType tag_type, Tag tag>
struct TypedTag {
@@ -334,5 +326,3 @@
}
} // namespace android::hardware::security::keymint
-
-#endif // HARDWARE_INTERFACES_KEYMINT_SUPPORT_INCLUDE_KEYMINT_TAGS_H_
diff --git a/security/keymint/support/include/keymint_support/keymint_utils.h b/security/keymint/support/include/keymint_support/keymint_utils.h
index fda1b6c..878b7df 100644
--- a/security/keymint/support/include/keymint_support/keymint_utils.h
+++ b/security/keymint/support/include/keymint_support/keymint_utils.h
@@ -16,9 +16,6 @@
#pragma once
-#ifndef HARDWARE_INTERFACES_KEYMINT_10_SUPPORT_KEYMINT_UTILS_H_
-#define HARDWARE_INTERFACES_KEYMINT_10_SUPPORT_KEYMINT_UTILS_H_
-
#include <android/hardware/security/keymint/HardwareAuthToken.h>
namespace android::hardware::security::keymint {
@@ -43,5 +40,3 @@
uint32_t getOsPatchlevel();
} // namespace android::hardware::security::keymint
-
-#endif // HARDWARE_INTERFACES_KEYMINT_10_SUPPORT_KEYMINT_UTILS_H_
diff --git a/security/keymint/support/include/keymint_support/openssl_utils.h b/security/keymint/support/include/keymint_support/openssl_utils.h
index cb09968..0878810 100644
--- a/security/keymint/support/include/keymint_support/openssl_utils.h
+++ b/security/keymint/support/include/keymint_support/openssl_utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 The Android Open Source Project
+ * Copyright 2020 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.
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef HARDWARE_INTERFACES_KEYMINT_1_0_SUPPORT_OPENSSL_UTILS_H_
-#define HARDWARE_INTERFACES_KEYMINT_1_0_SUPPORT_OPENSSL_UTILS_H_
+#pragma once
#include <android/hardware/security/keymint/Digest.h>
@@ -63,5 +62,3 @@
}
} // namespace android::hardware::security::keymint
-
-#endif // HARDWARE_INTERFACES_KEYMINT_1_0_SUPPORT_OPENSSL_UTILS_H_
diff --git a/security/keymint/support/key_param_output.cpp b/security/keymint/support/key_param_output.cpp
index b699b22..d8e2fff 100644
--- a/security/keymint/support/key_param_output.cpp
+++ b/security/keymint/support/key_param_output.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2020 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.
diff --git a/security/keymint/support/keymint_utils.cpp b/security/keymint/support/keymint_utils.cpp
index cd4cca2..63606f4 100644
--- a/security/keymint/support/keymint_utils.cpp
+++ b/security/keymint/support/keymint_utils.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -16,11 +16,12 @@
#include <regex.h>
+#include <arpa/inet.h>
+
#include <android-base/properties.h>
#include <hardware/hw_auth_token.h>
-#include <keymint_support/keymint_utils.h>
-#include <arpa/inet.h>
+#include <keymint_support/keymint_utils.h>
namespace android::hardware::security::keymint {