1 /* 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 17 18 #pragma once 19 20 #include <android/media/AudioProductStrategy.h> 21 #include <media/AidlConversionUtil.h> 22 #include <media/AudioCommonTypes.h> 23 #include <media/VolumeGroupAttributes.h> 24 #include <system/audio.h> 25 #include <system/audio_policy.h> 26 #include <binder/Parcelable.h> 27 28 namespace android { 29 30 class AudioProductStrategy : public Parcelable 31 { 32 public: AudioProductStrategy()33 AudioProductStrategy() {} AudioProductStrategy(const std::string & name,const std::vector<VolumeGroupAttributes> & attributes,product_strategy_t id)34 AudioProductStrategy(const std::string &name, 35 const std::vector<VolumeGroupAttributes> &attributes, 36 product_strategy_t id) : 37 mName(name), mVolumeGroupAttributes(attributes), mId(id) {} 38 getName()39 const std::string &getName() const { return mName; } getVolumeGroupAttributes()40 std::vector<VolumeGroupAttributes> getVolumeGroupAttributes() const { 41 return mVolumeGroupAttributes; 42 } getId()43 product_strategy_t getId() const { return mId; } 44 45 status_t readFromParcel(const Parcel *parcel) override; 46 status_t writeToParcel(Parcel *parcel) const override; 47 48 /** 49 * @brief attributesMatchesScore: checks if client attributes matches with a reference 50 * attributes "matching" means the usage shall match if reference attributes has a defined 51 * usage, AND content type shall match if reference attributes has a defined content type AND 52 * flags shall match if reference attributes has defined flags AND 53 * tags shall match if reference attributes has defined tags. 54 * Reference attributes "default" shall be considered as a weak match case. This convention 55 * is used to identify the default strategy. 56 * @param refAttributes to be considered 57 * @param clientAttritubes to be considered 58 * @return {@code INVALID_SCORE} if not matching, {@code MATCH_ON_DEFAULT_SCORE} if matching 59 * to default strategy, non zero positive score if matching a strategy. 60 */ 61 static int attributesMatchesScore(audio_attributes_t refAttributes, 62 audio_attributes_t clientAttritubes); 63 attributesMatches(audio_attributes_t refAttributes,audio_attributes_t clientAttritubes)64 static bool attributesMatches(audio_attributes_t refAttributes, 65 audio_attributes_t clientAttritubes) { 66 return attributesMatchesScore(refAttributes, clientAttritubes) > 0; 67 } 68 69 static const int MATCH_ON_TAGS_SCORE = 1 << 3; 70 static const int MATCH_ON_FLAGS_SCORE = 1 << 2; 71 static const int MATCH_ON_USAGE_SCORE = 1 << 1; 72 static const int MATCH_ON_CONTENT_TYPE_SCORE = 1 << 0; 73 static const int MATCH_ON_DEFAULT_SCORE = 0; 74 static const int MATCH_EQUALS = MATCH_ON_TAGS_SCORE | MATCH_ON_FLAGS_SCORE 75 | MATCH_ON_USAGE_SCORE | MATCH_ON_CONTENT_TYPE_SCORE; 76 static const int NO_MATCH = -1; 77 78 private: 79 std::string mName; 80 std::vector<VolumeGroupAttributes> mVolumeGroupAttributes; 81 product_strategy_t mId; 82 }; 83 84 using AudioProductStrategyVector = std::vector<AudioProductStrategy>; 85 86 // AIDL conversion routines. 87 ConversionResult<media::AudioProductStrategy> 88 legacy2aidl_AudioProductStrategy(const AudioProductStrategy& legacy); 89 ConversionResult<AudioProductStrategy> 90 aidl2legacy_AudioProductStrategy(const media::AudioProductStrategy& aidl); 91 92 } // namespace android 93 94