blob: 498cc3bf82ff96127b2112ad3e658374dfa5a49a [file] [log] [blame]
François Gaffie2110e042015-03-24 08:41:51 +01001/*
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 <AudioPolicyManagerObserver.h>
François Gaffied0ba9ed2018-11-05 11:50:42 +010020#include <media/AudioProductStrategy.h>
François Gaffiedc7553f2018-11-02 10:39:57 +010021#include <policy.h>
François Gaffie2110e042015-03-24 08:41:51 +010022#include <Volume.h>
23#include <HwModule.h>
24#include <DeviceDescriptor.h>
25#include <system/audio.h>
26#include <system/audio_policy.h>
27#include <utils/Errors.h>
28#include <utils/Vector.h>
29
30namespace android {
31
François Gaffiedc7553f2018-11-02 10:39:57 +010032using DeviceStrategyMap = std::map<product_strategy_t, DeviceVector>;
33using StrategyVector = std::vector<product_strategy_t>;
34
35
François Gaffie2110e042015-03-24 08:41:51 +010036/**
37 * This interface is dedicated to the policy manager that a Policy Engine shall implement.
38 */
39class AudioPolicyManagerInterface
40{
41public:
42 /**
43 * Checks if the engine was correctly initialized.
44 *
45 * @return NO_ERROR if initialization has been done correctly, error code otherwise..
46 */
47 virtual status_t initCheck() = 0;
48
49 /**
50 * Sets the Manager observer that allows the engine to retrieve information on collection
51 * of devices, streams, HwModules, ...
52 *
53 * @param[in] observer handle on the manager.
54 */
55 virtual void setObserver(AudioPolicyManagerObserver *observer) = 0;
56
57 /**
François Gaffie2110e042015-03-24 08:41:51 +010058 * Set the Telephony Mode.
59 *
60 * @param[in] mode: Android Phone state (normal, ringtone, csv, in communication)
61 *
62 * @return NO_ERROR if Telephony Mode set correctly, error code otherwise.
63 */
64 virtual status_t setPhoneState(audio_mode_t mode) = 0;
65
66 /**
67 * Get the telephony Mode
68 *
69 * @return the current telephony mode
70 */
71 virtual audio_mode_t getPhoneState() const = 0;
72
73 /**
74 * Set Force Use config for a given usage.
75 *
76 * @param[in] usage for which a configuration shall be forced.
77 * @param[in] config wished to be forced for the given usage.
78 *
François Gaffie20f06f92015-03-24 09:01:14 +010079 * @return NO_ERROR if the Force Use config was set correctly, error code otherwise (e.g. config
80 * not allowed a given usage...)
François Gaffie2110e042015-03-24 08:41:51 +010081 */
82 virtual status_t setForceUse(audio_policy_force_use_t usage,
83 audio_policy_forced_cfg_t config) = 0;
84
85 /**
86 * Get Force Use config for a given usage.
87 *
88 * @param[in] usage for which a configuration shall be forced.
89 *
90 * @return config wished to be forced for the given usage.
91 */
92 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const = 0;
93
94 /**
95 * Set the connection state of device(s).
96 *
97 * @param[in] devDesc for which the state has changed.
98 * @param[in] state of availability of this(these) device(s).
99 *
100 * @return NO_ERROR if devices criterion updated correctly, error code otherwise.
101 */
102 virtual status_t setDeviceConnectionState(const android::sp<android::DeviceDescriptor> devDesc,
103 audio_policy_dev_state_t state) = 0;
104
François Gaffiedc7553f2018-11-02 10:39:57 +0100105 /**
106 * Get the strategy selected for a given audio attributes.
107 *
108 * @param[in] audio attributes to get the selected @product_strategy_t followed by.
109 *
110 * @return @product_strategy_t to be followed.
111 */
112 virtual product_strategy_t getProductStrategyForAttributes(
113 const audio_attributes_t &attr) const = 0;
114
115 /**
116 * @brief getOutputDevicesForAttributes retrieves the devices to be used for given
117 * audio attributes.
118 * @param attributes of the output requesting Device(s) selection
119 * @param preferedDevice valid reference if a prefered device is requested, nullptr otherwise.
120 * @param fromCache if true, the device is returned from internal cache,
121 * otherwise it is determined by current state (device connected,phone state,
122 * force use, a2dp output...)
123 * @return vector of selected device descriptors.
124 * Appropriate device for streams handled by the specified audio attributes according
125 * to current phone state, forced states, connected devices...
126 * if fromCache is true, the device is returned from internal cache,
127 * otherwise it is determined by current state (device connected,phone state, force use,
128 * a2dp output...)
129 * This allows to:
130 * 1 speed up process when the state is stable (when starting or stopping an output)
131 * 2 access to either current device selection (fromCache == true) or
132 * "future" device selection (fromCache == false) when called from a context
133 * where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
134 * before manager updates its outputs.
135 */
136 virtual DeviceVector getOutputDevicesForAttributes(
137 const audio_attributes_t &attributes,
138 const sp<DeviceDescriptor> &preferedDevice = nullptr,
139 bool fromCache = false) const = 0;
140
141 /**
142 * @brief getOutputDevicesForStream Legacy function retrieving devices from a stream type.
143 * @param stream type of the output requesting Device(s) selection
144 * @param fromCache if true, the device is returned from internal cache,
145 * otherwise it is determined by current state (device connected,phone state,
146 * force use, a2dp output...)
147 * @return appropriate device for streams handled by the specified audio attributes according
148 * to current phone state, forced states, connected devices...
149 * if fromCache is true, the device is returned from internal cache,
150 * otherwise it is determined by current state (device connected,phone state, force use,
151 * a2dp output...)
152 * This allows to:
153 * 1 speed up process when the state is stable (when starting or stopping an output)
154 * 2 access to either current device selection (fromCache == true) or
155 * "future" device selection (fromCache == false) when called from a context
156 * where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
157 * before manager updates its outputs.
158 */
159 virtual DeviceVector getOutputDevicesForStream(audio_stream_type_t stream,
160 bool fromCache = false) const = 0;
161
162 /**
163 * Get the input device selected for given audio attributes.
164 *
165 * @param[in] attr audio attributes to consider
166 * @param[out] mix to be used if a mix has been installed for the given audio attributes.
167 * @return selected input device for the audio attributes, may be null if error.
168 */
169 virtual sp<DeviceDescriptor> getInputDeviceForAttributes(
170 const audio_attributes_t &attr, AudioMix **mix = nullptr) const = 0;
171
172 /**
173 * Get the legacy stream type for a given audio attributes.
174 *
175 * @param[in] audio attributes to get the associated audio_stream_type_t.
176 *
177 * @return audio_stream_type_t associated to the attributes.
178 */
179 virtual audio_stream_type_t getStreamTypeForAttributes(
180 const audio_attributes_t &attr) const = 0;
181
182 /**
183 * @brief getAttributesForStream get the audio attributes from legacy stream type
184 * @param stream to consider
185 * @return audio attributes matching the legacy stream type
186 */
187 virtual audio_attributes_t getAttributesForStreamType(audio_stream_type_t stream) const = 0;
188
189 /**
190 * @brief getStreamTypesForProductStrategy retrieves the list of legacy stream type following
191 * the given product strategy
192 * @param ps product strategy to consider
193 * @return associated legacy Stream Types vector of the given product strategy
194 */
195 virtual StreamTypeVector getStreamTypesForProductStrategy(product_strategy_t ps) const = 0;
196
197 /**
198 * @brief getAllAttributesForProductStrategy retrieves all the attributes following the given
199 * product strategy. Any attributes that "matches" with this one will follow the product
200 * strategy.
201 * "matching" means the usage shall match if reference attributes has a defined usage, AND
202 * content type shall match if reference attributes has a defined content type AND
203 * flags shall match if reference attributes has defined flags AND
204 * tags shall match if reference attributes has defined tags.
205 * @param ps product strategy to consider
206 * @return vector of product strategy ids, empty if unknown strategy.
207 */
208 virtual AttributesVector getAllAttributesForProductStrategy(product_strategy_t ps) const = 0;
209
210 /**
211 * @brief getOrderedAudioProductStrategies
212 * @return priority ordered product strategies to help the AudioPolicyManager evaluating the
213 * device selection per output according to the prioritized strategies.
214 */
215 virtual StrategyVector getOrderedProductStrategies() const = 0;
216
217 /**
218 * @brief updateDeviceSelectionCache. Device selection for AudioAttribute / Streams is cached
219 * in the engine in order to speed up process when the audio system is stable.
220 * When a device is connected, the android mode is changed, engine is notified and can update
221 * the cache.
222 * When starting / stopping an output with a stream that can affect notification, the engine
223 * needs to update the cache upon this function call.
224 */
225 virtual void updateDeviceSelectionCache() = 0;
226
François Gaffied0ba9ed2018-11-05 11:50:42 +0100227 /**
228 * @brief listAudioProductStrategies. Introspection API to retrieve a collection of
229 * AudioProductStrategyVector that allows to build AudioAttributes according to a
230 * product_strategy which is just an index. It has also a human readable name to help the
231 * Car/Oem/AudioManager identiying the use case.
232 * @param strategies collection.
233 * @return OK if the list has been retrieved, error code otherwise
234 */
235 virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies) const = 0;
236
François Gaffiedc7553f2018-11-02 10:39:57 +0100237 virtual void dump(String8 *dst) const = 0;
238
François Gaffie2110e042015-03-24 08:41:51 +0100239protected:
240 virtual ~AudioPolicyManagerInterface() {}
241};
242
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800243} // namespace android