audio: Remove android.hardware.audio.core.AudioMode type

I missed that there is already android.media.audio.common.AudioMode.
However, due to use by the framework, it contains more values
(all of them are SYS_RESERVED), thus the implementation and VTS
have to be updated as well.

Bug: 205884982
Test: atest VtsHalAudioCoreTargetTest
Change-Id: If260413b1f774a69514de978792d5ad2eb46481a
Merged-In: If260413b1f774a69514de978792d5ad2eb46481a
This commit is contained in:
Mikhail Naganov 2023-01-11 15:48:10 -08:00
parent 248026347f
commit 04ae822302
14 changed files with 69 additions and 99 deletions

View file

@ -109,7 +109,6 @@ aidl_interface {
"android.hardware.audio_defaults",
],
srcs: [
"android/hardware/audio/core/AudioMode.aidl",
"android/hardware/audio/core/AudioPatch.aidl",
"android/hardware/audio/core/AudioRoute.aidl",
"android/hardware/audio/core/IBluetooth.aidl",

View file

@ -1,42 +0,0 @@
/*
* Copyright (C) 2022 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.
*/
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
///////////////////////////////////////////////////////////////////////////////
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
// the interface (from the latest frozen version), the build system will
// prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible change to any AIDL file 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.audio.core;
@Backing(type="int") @VintfStability
enum AudioMode {
NORMAL = 0,
RINGTONE = 1,
IN_CALL = 2,
IN_COMMUNICATION = 3,
CALL_SCREEN = 4,
}

View file

@ -44,10 +44,10 @@ interface IBluetooth {
@nullable @utf8InCpp String debugName;
@VintfStability
enum Mode {
UNSPECIFIED = 0,
SCO = 1,
SCO_WB = 2,
SCO_SWB = 3,
UNSPECIFIED,
SCO,
SCO_WB,
SCO_SWB,
}
}
@JavaDerive(equals=true, toString=true) @VintfStability

View file

@ -59,7 +59,7 @@ interface IModule {
boolean getMicMute();
void setMicMute(boolean mute);
android.hardware.audio.core.MicrophoneInfo[] getMicrophones();
void updateAudioMode(android.hardware.audio.core.AudioMode mode);
void updateAudioMode(android.media.audio.common.AudioMode mode);
void updateScreenRotation(android.hardware.audio.core.IModule.ScreenRotation rotation);
void updateScreenState(boolean isTurnedOn);
@nullable android.hardware.audio.core.sounddose.ISoundDose getSoundDose();

View file

@ -34,8 +34,8 @@
package android.hardware.audio.core;
@VintfStability
interface ITelephony {
android.hardware.audio.core.AudioMode[] getSupportedAudioModes();
void switchAudioMode(android.hardware.audio.core.AudioMode mode);
android.media.audio.common.AudioMode[] getSupportedAudioModes();
void switchAudioMode(android.media.audio.common.AudioMode mode);
android.hardware.audio.core.ITelephony.TelecomConfig setTelecomConfig(in android.hardware.audio.core.ITelephony.TelecomConfig config);
@JavaDerive(equals=true, toString=true) @VintfStability
parcelable TelecomConfig {

View file

@ -1,38 +0,0 @@
/*
* Copyright (C) 2022 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.audio.core;
/**
* The audio mode describes states of the audio system of the device that
* can significantly affect the rules of audio routing, volume control, etc.
* The audio mode is controlled by the framework, however the HAL has some
* flexibility in the choice of modes to support, see 'IModule.updateAudioMode'.
*/
@VintfStability
@Backing(type="int")
enum AudioMode {
/** No active calls. */
NORMAL = 0,
/** The device is playing the ringtone. */
RINGTONE = 1,
/** The call is handled by the telephony stack ("voice call"). */
IN_CALL = 2,
/** The call is handled by an application ("VoIP call"). */
IN_COMMUNICATION = 3,
/** Call screening is in progress. */
CALL_SCREEN = 4,
}

View file

@ -18,7 +18,6 @@ package android.hardware.audio.core;
import android.hardware.audio.common.SinkMetadata;
import android.hardware.audio.common.SourceMetadata;
import android.hardware.audio.core.AudioMode;
import android.hardware.audio.core.AudioPatch;
import android.hardware.audio.core.AudioRoute;
import android.hardware.audio.core.IBluetooth;
@ -33,6 +32,7 @@ import android.hardware.audio.core.StreamDescriptor;
import android.hardware.audio.core.VendorParameter;
import android.hardware.audio.core.sounddose.ISoundDose;
import android.hardware.audio.effect.IEffect;
import android.media.audio.common.AudioMode;
import android.media.audio.common.AudioOffloadInfo;
import android.media.audio.common.AudioPort;
import android.media.audio.common.AudioPortConfig;
@ -684,6 +684,7 @@ interface IModule {
* method.
*
* @param mode The current mode.
* @throws EX_ILLEGAL_ARGUMENT If the mode is out of range of valid values.
*/
void updateAudioMode(AudioMode mode);

View file

@ -16,7 +16,7 @@
package android.hardware.audio.core;
import android.hardware.audio.core.AudioMode;
import android.media.audio.common.AudioMode;
import android.media.audio.common.Boolean;
import android.media.audio.common.Float;
@ -52,6 +52,7 @@ interface ITelephony {
*
* @param mode The mode to switch to.
* @throws EX_UNSUPPORTED_OPERATION If the HAL does not support the specified mode.
* @throws EX_ILLEGAL_ARGUMENT If the mode is out of range of valid values.
* @throws EX_ILLEGAL_STATE If there was an error during switching.
*/
void switchAudioMode(AudioMode mode);

View file

@ -16,6 +16,8 @@
#pragma once
#include <algorithm>
#include <array>
#include <initializer_list>
#include <type_traits>
@ -23,11 +25,22 @@
#include <aidl/android/media/audio/common/AudioDeviceType.h>
#include <aidl/android/media/audio/common/AudioFormatDescription.h>
#include <aidl/android/media/audio/common/AudioInputFlags.h>
#include <aidl/android/media/audio/common/AudioMode.h>
#include <aidl/android/media/audio/common/AudioOutputFlags.h>
#include <aidl/android/media/audio/common/PcmType.h>
namespace android::hardware::audio::common {
// Some values are reserved for use by the system code only.
// HALs must not accept or emit values outside from the provided list.
constexpr std::array<::aidl::android::media::audio::common::AudioMode, 5> kValidAudioModes = {
::aidl::android::media::audio::common::AudioMode::NORMAL,
::aidl::android::media::audio::common::AudioMode::RINGTONE,
::aidl::android::media::audio::common::AudioMode::IN_CALL,
::aidl::android::media::audio::common::AudioMode::IN_COMMUNICATION,
::aidl::android::media::audio::common::AudioMode::CALL_SCREEN,
};
constexpr size_t getPcmSampleSizeInBytes(::aidl::android::media::audio::common::PcmType pcm) {
using ::aidl::android::media::audio::common::PcmType;
switch (pcm) {
@ -91,6 +104,11 @@ constexpr bool isTelephonyDeviceType(
device == ::aidl::android::media::audio::common::AudioDeviceType::OUT_TELEPHONY_TX;
}
constexpr bool isValidAudioMode(::aidl::android::media::audio::common::AudioMode mode) {
return std::find(kValidAudioModes.begin(), kValidAudioModes.end(), mode) !=
kValidAudioModes.end();
}
// The helper functions defined below are only applicable to the case when an enum type
// specifies zero-based bit positions, not bit masks themselves. This is why instantiation
// is restricted to certain enum types.

View file

@ -41,6 +41,7 @@ using aidl::android::media::audio::common::AudioFormatDescription;
using aidl::android::media::audio::common::AudioFormatType;
using aidl::android::media::audio::common::AudioInputFlags;
using aidl::android::media::audio::common::AudioIoFlags;
using aidl::android::media::audio::common::AudioMode;
using aidl::android::media::audio::common::AudioOffloadInfo;
using aidl::android::media::audio::common::AudioOutputFlags;
using aidl::android::media::audio::common::AudioPort;
@ -52,6 +53,7 @@ using aidl::android::media::audio::common::Int;
using aidl::android::media::audio::common::PcmType;
using android::hardware::audio::common::getFrameSizeInBytes;
using android::hardware::audio::common::isBitPositionFlagSet;
using android::hardware::audio::common::isValidAudioMode;
namespace aidl::android::hardware::audio::core {
@ -952,6 +954,10 @@ ndk::ScopedAStatus Module::getMicrophones(std::vector<MicrophoneInfo>* _aidl_ret
}
ndk::ScopedAStatus Module::updateAudioMode(AudioMode in_mode) {
if (!isValidAudioMode(in_mode)) {
LOG(ERROR) << __func__ << ": invalid mode " << toString(in_mode);
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
// No checks for supported audio modes here, it's an informative notification.
LOG(DEBUG) << __func__ << ": " << toString(in_mode);
return ndk::ScopedAStatus::ok();

View file

@ -14,14 +14,18 @@
* limitations under the License.
*/
#include <android/binder_to_string.h>
#define LOG_TAG "AHAL_Telephony"
#include <android-base/logging.h>
#include <Utils.h>
#include <android/binder_to_string.h>
#include "core-impl/Telephony.h"
using aidl::android::media::audio::common::AudioMode;
using aidl::android::media::audio::common::Boolean;
using aidl::android::media::audio::common::Float;
using android::hardware::audio::common::isValidAudioMode;
namespace aidl::android::hardware::audio::core {
@ -38,6 +42,10 @@ ndk::ScopedAStatus Telephony::getSupportedAudioModes(std::vector<AudioMode>* _ai
}
ndk::ScopedAStatus Telephony::switchAudioMode(AudioMode in_mode) {
if (!isValidAudioMode(in_mode)) {
LOG(ERROR) << __func__ << ": invalid mode " << toString(in_mode);
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
if (std::find(mSupportedAudioModes.begin(), mSupportedAudioModes.end(), in_mode) !=
mSupportedAudioModes.end()) {
LOG(DEBUG) << __func__ << ": " << toString(in_mode);

View file

@ -92,7 +92,7 @@ class Module : public BnModule {
ndk::ScopedAStatus setMicMute(bool in_mute) override;
ndk::ScopedAStatus getMicrophones(std::vector<MicrophoneInfo>* _aidl_return) override;
ndk::ScopedAStatus updateAudioMode(
::aidl::android::hardware::audio::core::AudioMode in_mode) override;
::aidl::android::media::audio::common::AudioMode in_mode) override;
ndk::ScopedAStatus updateScreenRotation(
::aidl::android::hardware::audio::core::IModule::ScreenRotation in_rotation) override;
ndk::ScopedAStatus updateScreenState(bool in_isTurnedOn) override;

View file

@ -27,13 +27,20 @@ class Telephony : public BnTelephony {
Telephony();
private:
ndk::ScopedAStatus getSupportedAudioModes(std::vector<AudioMode>* _aidl_return) override;
ndk::ScopedAStatus switchAudioMode(AudioMode in_mode) override;
ndk::ScopedAStatus getSupportedAudioModes(
std::vector<::aidl::android::media::audio::common::AudioMode>* _aidl_return) override;
ndk::ScopedAStatus switchAudioMode(
::aidl::android::media::audio::common::AudioMode in_mode) override;
ndk::ScopedAStatus setTelecomConfig(const TelecomConfig& in_config,
TelecomConfig* _aidl_return) override;
const std::vector<AudioMode> mSupportedAudioModes = {::ndk::enum_range<AudioMode>().begin(),
::ndk::enum_range<AudioMode>().end()};
const std::vector<::aidl::android::media::audio::common::AudioMode> mSupportedAudioModes = {
::aidl::android::media::audio::common::AudioMode::NORMAL,
::aidl::android::media::audio::common::AudioMode::RINGTONE,
::aidl::android::media::audio::common::AudioMode::IN_CALL,
::aidl::android::media::audio::common::AudioMode::IN_COMMUNICATION,
// Omit CALL_SCREEN for a better VTS coverage.
};
TelecomConfig mTelecomConfig;
};

View file

@ -54,7 +54,6 @@ using aidl::android::hardware::audio::common::PlaybackTrackMetadata;
using aidl::android::hardware::audio::common::RecordTrackMetadata;
using aidl::android::hardware::audio::common::SinkMetadata;
using aidl::android::hardware::audio::common::SourceMetadata;
using aidl::android::hardware::audio::core::AudioMode;
using aidl::android::hardware::audio::core::AudioPatch;
using aidl::android::hardware::audio::core::AudioRoute;
using aidl::android::hardware::audio::core::IBluetooth;
@ -78,6 +77,7 @@ using aidl::android::media::audio::common::AudioDualMonoMode;
using aidl::android::media::audio::common::AudioFormatType;
using aidl::android::media::audio::common::AudioIoFlags;
using aidl::android::media::audio::common::AudioLatencyMode;
using aidl::android::media::audio::common::AudioMode;
using aidl::android::media::audio::common::AudioOutputFlags;
using aidl::android::media::audio::common::AudioPlaybackRate;
using aidl::android::media::audio::common::AudioPort;
@ -93,6 +93,7 @@ using aidl::android::media::audio::common::Void;
using android::hardware::audio::common::getChannelCount;
using android::hardware::audio::common::isBitPositionFlagSet;
using android::hardware::audio::common::isTelephonyDeviceType;
using android::hardware::audio::common::isValidAudioMode;
using android::hardware::audio::common::StreamLogic;
using android::hardware::audio::common::StreamWorker;
using ndk::enum_range;
@ -1805,7 +1806,11 @@ TEST_P(AudioCoreModule, GetMicrophones) {
TEST_P(AudioCoreModule, UpdateAudioMode) {
for (const auto mode : ::ndk::enum_range<AudioMode>()) {
EXPECT_IS_OK(module->updateAudioMode(mode)) << toString(mode);
if (isValidAudioMode(mode)) {
EXPECT_IS_OK(module->updateAudioMode(mode)) << toString(mode);
} else {
EXPECT_STATUS(EX_ILLEGAL_ARGUMENT, module->updateAudioMode(mode)) << toString(mode);
}
}
EXPECT_IS_OK(module->updateAudioMode(AudioMode::NORMAL));
}
@ -1994,6 +1999,9 @@ TEST_P(AudioCoreTelephony, GetSupportedAudioModes) {
}
std::vector<AudioMode> modes1;
ASSERT_IS_OK(telephony->getSupportedAudioModes(&modes1));
for (const auto mode : modes1) {
EXPECT_TRUE(isValidAudioMode(mode)) << toString(mode);
}
const std::vector<AudioMode> kMandatoryModes = {AudioMode::NORMAL, AudioMode::RINGTONE,
AudioMode::IN_CALL,
AudioMode::IN_COMMUNICATION};
@ -2025,7 +2033,9 @@ TEST_P(AudioCoreTelephony, SwitchAudioMode) {
unsupportedModes.erase(mode);
}
for (const auto mode : unsupportedModes) {
EXPECT_STATUS(EX_UNSUPPORTED_OPERATION, telephony->switchAudioMode(mode)) << toString(mode);
EXPECT_STATUS(isValidAudioMode(mode) ? EX_UNSUPPORTED_OPERATION : EX_ILLEGAL_ARGUMENT,
telephony->switchAudioMode(mode))
<< toString(mode);
}
}