blob: 938e574fbae4341c65ab5aee9b3e1191681220f2 [file] [log] [blame]
François Gaffied0ba9ed2018-11-05 11:50:42 +01001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
François Gaffie1e2b56f2022-04-01 14:34:29 +020017#define LOG_TAG "VolumeGroupAttributes"
François Gaffied0ba9ed2018-11-05 11:50:42 +010018//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
21#include <binder/Parcel.h>
22
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080023#include <media/AidlConversion.h>
François Gaffie8d7fd5a2023-01-17 17:28:09 +010024#include <media/AudioProductStrategy.h>
François Gaffie1e2b56f2022-04-01 14:34:29 +020025#include <media/VolumeGroupAttributes.h>
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080026#include <media/PolicyAidlConversion.h>
27
François Gaffied0ba9ed2018-11-05 11:50:42 +010028namespace android {
29
François Gaffie8d7fd5a2023-01-17 17:28:09 +010030int VolumeGroupAttributes::matchesScore(const audio_attributes_t &attributes) const {
31 return AudioProductStrategy::attributesMatchesScore(mAttributes, attributes);
32}
33
François Gaffie1e2b56f2022-04-01 14:34:29 +020034status_t VolumeGroupAttributes::readFromParcel(const Parcel* parcel) {
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080035 media::AudioAttributesEx aidl;
36 RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
François Gaffie1e2b56f2022-04-01 14:34:29 +020037 *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioAttributesEx_VolumeGroupAttributes(aidl));
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080038 return OK;
François Gaffied0ba9ed2018-11-05 11:50:42 +010039}
40
François Gaffie1e2b56f2022-04-01 14:34:29 +020041status_t VolumeGroupAttributes::writeToParcel(Parcel* parcel) const {
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080042 media::AudioAttributesEx aidl = VALUE_OR_RETURN_STATUS(
François Gaffie1e2b56f2022-04-01 14:34:29 +020043 legacy2aidl_VolumeGroupAttributes_AudioAttributesEx(*this));
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080044 return aidl.writeToParcel(parcel);
45}
46
47ConversionResult<media::AudioAttributesEx>
François Gaffie1e2b56f2022-04-01 14:34:29 +020048legacy2aidl_VolumeGroupAttributes_AudioAttributesEx(const VolumeGroupAttributes& legacy) {
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080049 media::AudioAttributesEx aidl;
50 aidl.attributes = VALUE_OR_RETURN(
Mikhail Naganov1c400902023-05-17 11:48:43 -070051 legacy2aidl_audio_attributes_t_AudioAttributes(legacy.getAttributes()));
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080052 aidl.streamType = VALUE_OR_RETURN(
53 legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.getStreamType()));
54 aidl.groupId = VALUE_OR_RETURN(legacy2aidl_volume_group_t_int32_t(legacy.getGroupId()));
55 return aidl;
56}
57
François Gaffie1e2b56f2022-04-01 14:34:29 +020058ConversionResult<VolumeGroupAttributes>
59aidl2legacy_AudioAttributesEx_VolumeGroupAttributes(const media::AudioAttributesEx& aidl) {
60 return VolumeGroupAttributes(VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080061 VALUE_OR_RETURN(aidl2legacy_AudioStreamType_audio_stream_type_t(
62 aidl.streamType)),
Mikhail Naganov1c400902023-05-17 11:48:43 -070063 VALUE_OR_RETURN(aidl2legacy_AudioAttributes_audio_attributes_t(
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080064 aidl.attributes)));
François Gaffied0ba9ed2018-11-05 11:50:42 +010065}
66
67} // namespace android