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 <media/AudioCommonTypes.h>
21 #include <media/AudioAttributes.h>
22 #include <system/audio.h>
23 #include <system/audio_policy.h>
24 #include <binder/Parcelable.h>
25 
26 namespace android {
27 
28 class AudioProductStrategy : public Parcelable
29 {
30 public:
AudioProductStrategy()31     AudioProductStrategy() {}
AudioProductStrategy(const std::string & name,const std::vector<AudioAttributes> & attributes,product_strategy_t id)32     AudioProductStrategy(const std::string &name, const std::vector<AudioAttributes> &attributes,
33                          product_strategy_t id) :
34         mName(name), mAudioAttributes(attributes), mId(id) {}
35 
getName()36     const std::string &getName() const { return mName; }
getAudioAttributes()37     std::vector<AudioAttributes> getAudioAttributes() const { return mAudioAttributes; }
getId()38     product_strategy_t getId() const { return mId; }
39 
40     status_t readFromParcel(const Parcel *parcel) override;
41     status_t writeToParcel(Parcel *parcel) const override;
42 
43     /**
44      * @brief attributesMatches: checks if client attributes matches with a reference attributes
45      * "matching" means the usage shall match if reference attributes has a defined usage, AND
46      * content type shall match if reference attributes has a defined content type AND
47      * flags shall match if reference attributes has defined flags AND
48      * tags shall match if reference attributes has defined tags.
49      * Reference attributes "default" shall not be considered as a "true" case. This convention
50      * is used to identify the default strategy.
51      * @param refAttributes to be considered
52      * @param clientAttritubes to be considered
53      * @return true if matching, false otherwise
54      */
55     static bool attributesMatches(const audio_attributes_t refAttributes,
56                                   const audio_attributes_t clientAttritubes);
57 private:
58     std::string mName;
59     std::vector<AudioAttributes> mAudioAttributes;
60     product_strategy_t mId;
61 };
62 
63 using AudioProductStrategyVector = std::vector<AudioProductStrategy>;
64 
65 } // namespace android
66 
67