1 /*
2  * Copyright (C) 2015 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 #pragma once
18 
19 #include <policy.h>
20 #include <EngineDefinition.h>
21 #include <Volume.h>
22 #include <system/audio.h>
23 #include <media/AudioCommonTypes.h>
24 #include <utils/Errors.h>
25 #include <string>
26 #include <vector>
27 
28 namespace android {
29 
30 /**
31  * This interface allows the parameter plugin to:
32  *  - instantiate all the members of the policy engine (strategies, input sources, usages, profiles)
33  *  - keep up to date the attributes of these policy members ( i.e. devices to be used for a
34  *    strategy, strategy to be followed by a usage or a stream, ...)
35  */
36 class AudioPolicyPluginInterface
37 {
38 public:
39     /**
40      * Add a streams to the engine.
41      *
42      * @param[in] name of the stream to add
43      * @param[in] identifier: the numerical value associated to this member. It MUST match either
44      *            system/audio.h or system/audio_policy.h enumration value in order to link the
45      *            parameter controled by the PFW and the policy manager component.
46      *
47      * @return NO_ERROR if the stream has been added successfully, error code otherwise.
48      *
49      */
50     virtual android::status_t addStream(const std::string &name, audio_stream_type_t id) = 0;
51 
52     /**
53      * Add an input source to the engine
54      *
55      * @param[in] name of the input source to add
56      * @param[in] identifier: the numerical value associated to this member. It MUST match either
57      *            system/audio.h or system/audio_policy.h enumration value in order to link the
58      *            parameter controled by the PFW and the policy manager component.
59      *
60      * @return NO_ERROR if the input source has been added successfully, error code otherwise.
61      *
62      */
63     virtual android::status_t addInputSource(const std::string &name, audio_source_t id) = 0;
64 
65     /**
66      * Set the strategy to be followed by a stream.
67      *
68      * @param[in] stream: name of the stream for which the strategy to use has to be set
69      * @param[in] volumeProfile to follow for the given stream.
70      *
71      * @return true if the profile was set correclty for this stream, false otherwise.
72      */
73     virtual bool setVolumeProfileForStream(const audio_stream_type_t &stream,
74                                            const audio_stream_type_t &volumeProfile) = 0;
75 
76     /**
77      * Set the input device to be used by an input source.
78      *
79      * @param[in] inputSource: name of the input source for which the device to use has to be set
80      * @param[in] devices; mask of devices to be used for the given input source.
81      *
82      * @return true if the devices were set correclty for this input source, false otherwise.
83      */
84     virtual bool setDeviceForInputSource(const audio_source_t &inputSource,
85                                          audio_devices_t device) = 0;
86 
87     virtual void setDeviceAddressForProductStrategy(product_strategy_t strategy,
88                                                     const std::string &address) = 0;
89 
90     /**
91      * Set the device to be used by a product strategy.
92      *
93      * @param[in] strategy: name of the product strategy for which the device to use has to be set
94      * @param[in] devices; mask of devices to be used for the given strategy.
95      *
96      * @return true if the devices were set correclty for this strategy, false otherwise.
97      */
98     virtual bool setDeviceTypesForProductStrategy(product_strategy_t strategy,
99                                                   audio_devices_t devices) = 0;
100 
101     virtual product_strategy_t getProductStrategyByName(const std::string &address) = 0;
102 
103 protected:
~AudioPolicyPluginInterface()104     virtual ~AudioPolicyPluginInterface() {}
105 };
106 
107 } // namespace android
108