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 <RoutingStrategy.h>
20 #include <EngineDefinition.h>
21 #include <Volume.h>
22 #include <system/audio.h>
23 #include <utils/Errors.h>
24 #include <string>
25 #include <vector>
26 
27 namespace android {
28 
29 /**
30  * This interface allows the parameter plugin to:
31  *  - instantiate all the members of the policy engine (strategies, input sources, usages, profiles)
32  *  - keep up to date the attributes of these policy members ( i.e. devices to be used for a
33  *    strategy, strategy to be followed by a usage or a stream, ...)
34  */
35 class AudioPolicyPluginInterface
36 {
37 public:
38     /**
39      * Add a strategy to the engine
40      *
41      * @param[in] name of the strategy to add
42      * @param[in] identifier: the numerical value associated to this member. It MUST match either
43      *            system/audio.h or system/audio_policy.h enumration value in order to link the
44      *            parameter controled by the PFW and the policy manager component.
45      *
46      * @return NO_ERROR if the strategy has been added successfully, error code otherwise.
47      *
48      */
49     virtual android::status_t addStrategy(const std::string &name, routing_strategy id) = 0;
50 
51     /**
52      * Add a streams to the engine.
53      *
54      * @param[in] name of the stream to add
55      * @param[in] identifier: the numerical value associated to this member. It MUST match either
56      *            system/audio.h or system/audio_policy.h enumration value in order to link the
57      *            parameter controled by the PFW and the policy manager component.
58      *
59      * @return NO_ERROR if the stream has been added successfully, error code otherwise.
60      *
61      */
62     virtual android::status_t addStream(const std::string &name, audio_stream_type_t id) = 0;
63 
64     /**
65      * Add a usage to the engine
66      *
67      * @param[in] name of the usage to add
68      * @param[in] identifier: the numerical value associated to this member. It MUST match either
69      *            system/audio.h or system/audio_policy.h enumration value in order to link the
70      *            parameter controled by the PFW and the policy manager component.
71      *
72      * @return NO_ERROR if the usage has been added successfully, error code otherwise.
73      *
74      */
75     virtual android::status_t addUsage(const std::string &name, audio_usage_t id) = 0;
76 
77     /**
78      * Add an input source to the engine
79      *
80      * @param[in] name of the input source to add
81      * @param[in] identifier: the numerical value associated to this member. It MUST match either
82      *            system/audio.h or system/audio_policy.h enumration value in order to link the
83      *            parameter controled by the PFW and the policy manager component.
84      *
85      * @return NO_ERROR if the input source has been added successfully, error code otherwise.
86      *
87      */
88     virtual android::status_t addInputSource(const std::string &name, audio_source_t id) = 0;
89 
90     /**
91      * Set the device to be used by a strategy.
92      *
93      * @param[in] strategy: name of the 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 setDeviceForStrategy(const routing_strategy &strategy, audio_devices_t devices) = 0;
99 
100     /**
101      * Set the strategy to be followed by a stream.
102      *
103      * @param[in] stream: name of the stream for which the strategy to use has to be set
104      * @param[in] strategy to follow for the given stream.
105      *
106      * @return true if the strategy were set correclty for this stream, false otherwise.
107      */
108     virtual bool setStrategyForStream(const audio_stream_type_t &stream, routing_strategy strategy) = 0;
109 
110     /**
111      * Set the strategy to be followed by a stream.
112      *
113      * @param[in] stream: name of the stream for which the strategy to use has to be set
114      * @param[in] strategy to follow for the given stream.
115      *
116      * @return true if the strategy were set correclty for this stream, false otherwise.
117      */
118     virtual bool setVolumeProfileForStream(const audio_stream_type_t &stream,
119                                            Volume::device_category category,
120                                            const VolumeCurvePoints &points) = 0;
121 
122     /**
123      * Set the strategy to be followed by a usage.
124      *
125      * @param[in] usage: name of the usage for which the strategy to use has to be set
126      * @param[in] strategy to follow for the given usage.
127      *
128      * @return true if the strategy were set correclty for this usage, false otherwise.
129      */
130     virtual bool setStrategyForUsage(const audio_usage_t &usage, routing_strategy strategy) = 0;
131 
132     /**
133      * Set the input device to be used by an input source.
134      *
135      * @param[in] inputSource: name of the input source for which the device to use has to be set
136      * @param[in] devices; mask of devices to be used for the given input source.
137      *
138      * @return true if the devices were set correclty for this input source, false otherwise.
139      */
140     virtual bool setDeviceForInputSource(const audio_source_t &inputSource,
141                                          audio_devices_t device) = 0;
142 
143 protected:
~AudioPolicyPluginInterface()144     virtual ~AudioPolicyPluginInterface() {}
145 };
146 
147 }; // namespace android
148