Move AudioDeviceTypeAddr to libaudiofoundation.

Move AudioDeviceTypeAddr from AudioPolicy.h to libaudiofoundation.
AudioDeviceTypeAddr is a class that contains audio device type and
address. It can be used not only in audio policy, but also other places.

Bug: 135621476
Test: make, atest AudioHostTest
Change-Id: Ib257859891c647c07f22771012efdada438a4ff5
Merged-In: Ib257859891c647c07f22771012efdada438a4ff5
gugelfrei
jiabin 5 years ago
parent ea64c67d2c
commit 5b78141fb6

@ -13,6 +13,7 @@ cc_library_shared {
"AudioVolumeGroup.cpp",
],
shared_libs: [
"libaudiofoundation",
"libaudioutils",
"libbinder",
"libcutils",

@ -21,22 +21,6 @@
namespace android {
//
// AudioDeviceTypeAddr implementation
//
status_t AudioDeviceTypeAddr::readFromParcel(Parcel *parcel) {
mType = (audio_devices_t) parcel->readInt32();
mAddress = parcel->readString8();
return NO_ERROR;
}
status_t AudioDeviceTypeAddr::writeToParcel(Parcel *parcel) const {
parcel->writeInt32((int32_t) mType);
parcel->writeString8(mAddress);
return NO_ERROR;
}
//
// AudioMixMatchCriterion implementation
//

@ -18,9 +18,10 @@
#ifndef ANDROID_AUDIO_POLICY_H
#define ANDROID_AUDIO_POLICY_H
#include <binder/Parcel.h>
#include <media/AudioDeviceTypeAddr.h>
#include <system/audio.h>
#include <system/audio_policy.h>
#include <binder/Parcel.h>
#include <utils/String8.h>
#include <utils/Vector.h>
@ -60,19 +61,6 @@ namespace android {
#define MAX_MIXES_PER_POLICY 10
#define MAX_CRITERIA_PER_MIX 20
class AudioDeviceTypeAddr {
public:
AudioDeviceTypeAddr() {}
AudioDeviceTypeAddr(audio_devices_t type, String8 address) :
mType(type), mAddress(address) {}
status_t readFromParcel(Parcel *parcel);
status_t writeToParcel(Parcel *parcel) const;
audio_devices_t mType;
String8 mAddress;
};
class AudioMixMatchCriterion {
public:
AudioMixMatchCriterion() {}

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <media/AudioDeviceTypeAddr.h>
#include <media/AudioPolicy.h>
#include <media/AudioProductStrategy.h>
#include <media/AudioVolumeGroup.h>

@ -23,6 +23,7 @@
#include <utils/RefBase.h>
#include <utils/Errors.h>
#include <binder/IInterface.h>
#include <media/AudioDeviceTypeAddr.h>
#include <media/AudioSystem.h>
#include <media/AudioPolicy.h>
#include <media/IAudioPolicyServiceClient.h>

@ -20,6 +20,7 @@ cc_library_shared {
srcs: [
"AudioContainers.cpp",
"AudioDeviceTypeAddr.cpp",
"AudioGain.cpp",
"AudioPort.cpp",
"AudioProfile.cpp",

@ -0,0 +1,43 @@
/*
* Copyright (C) 2019 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 <media/AudioDeviceTypeAddr.h>
namespace android {
const char* AudioDeviceTypeAddr::getAddress() const {
return mAddress.c_str();
}
bool AudioDeviceTypeAddr::equals(const AudioDeviceTypeAddr& other) const {
return mType == other.mType && mAddress == other.mAddress;
}
status_t AudioDeviceTypeAddr::readFromParcel(const Parcel *parcel) {
status_t status;
if ((status = parcel->readUint32(&mType)) != NO_ERROR) return status;
status = parcel->readUtf8FromUtf16(&mAddress);
return status;
}
status_t AudioDeviceTypeAddr::writeToParcel(Parcel *parcel) const {
status_t status;
if ((status = parcel->writeUint32(mType)) != NO_ERROR) return status;
status = parcel->writeUtf8AsUtf16(mAddress);
return status;
}
}

@ -0,0 +1,46 @@
/*
* Copyright (C) 2019 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 <string>
#include <binder/Parcelable.h>
#include <binder/Parcel.h>
#include <system/audio.h>
#include <utils/Errors.h>
namespace android {
struct AudioDeviceTypeAddr : public Parcelable {
AudioDeviceTypeAddr() = default;
AudioDeviceTypeAddr(audio_devices_t type, const std::string& address) :
mType(type), mAddress(address) {}
const char* getAddress() const;
bool equals(const AudioDeviceTypeAddr& other) const;
status_t readFromParcel(const Parcel *parcel) override;
status_t writeToParcel(Parcel *parcel) const override;
audio_devices_t mType = AUDIO_DEVICE_NONE;
std::string mAddress;
};
}

@ -17,6 +17,7 @@
#ifndef ANDROID_AUDIOPOLICY_INTERFACE_H
#define ANDROID_AUDIOPOLICY_INTERFACE_H
#include <media/AudioDeviceTypeAddr.h>
#include <media/AudioSystem.h>
#include <media/AudioPolicy.h>
#include <utils/String8.h>

@ -18,6 +18,7 @@
#include "DeviceDescriptor.h"
#include <utils/RefBase.h>
#include <media/AudioDeviceTypeAddr.h>
#include <media/AudioPolicy.h>
#include <utils/Vector.h>
#include <system/audio.h>

@ -455,9 +455,9 @@ status_t AudioPolicyMixCollection::setUidDeviceAffinities(uid_t uid,
}
// check if this mix goes to a device in the list of devices
bool deviceMatch = false;
const AudioDeviceTypeAddr mixDevice(mix->mDeviceType, mix->mDeviceAddress.string());
for (size_t j = 0; j < devices.size(); j++) {
if (devices[j].mType == mix->mDeviceType
&& devices[j].mAddress == mix->mDeviceAddress) {
if (mixDevice.equals(devices[j])) {
deviceMatch = true;
break;
}
@ -522,7 +522,7 @@ status_t AudioPolicyMixCollection::getDevicesForUid(uid_t uid,
}
}
if (ruleAllowsUid) {
devices.add(AudioDeviceTypeAddr(mix->mDeviceType, mix->mDeviceAddress));
devices.add(AudioDeviceTypeAddr(mix->mDeviceType, mix->mDeviceAddress.string()));
}
}
return NO_ERROR;

@ -3058,13 +3058,13 @@ status_t AudioPolicyManager::setUidDeviceAffinities(uid_t uid,
// reevaluate outputs for all given devices
for (size_t i = 0; i < devices.size(); i++) {
sp<DeviceDescriptor> devDesc = mHwModules.getDeviceDescriptor(
devices[i].mType, devices[i].mAddress, String8(),
devices[i].mType, devices[i].mAddress.c_str(), String8(),
AUDIO_FORMAT_DEFAULT);
SortedVector<audio_io_handle_t> outputs;
if (checkOutputsForDevice(devDesc, AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
outputs) != NO_ERROR) {
ALOGE("setUidDeviceAffinities() error in checkOutputsForDevice for device=%08x"
" addr=%s", devices[i].mType, devices[i].mAddress.string());
" addr=%s", devices[i].mType, devices[i].mAddress.c_str());
return INVALID_OPERATION;
}
}

Loading…
Cancel
Save