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 
20 #include "AudioPolicyManagerInterface.h"
21 #include <AudioGain.h>
22 #include <policy.h>
23 
24 namespace android
25 {
26 
27 class AudioPolicyManagerObserver;
28 
29 namespace audio_policy
30 {
31 
32 class Engine
33 {
34 public:
35     Engine();
36     virtual ~Engine();
37 
38     template <class RequestedInterface>
39     RequestedInterface *queryInterface();
40 
41 private:
42     /// Interface members
43     class ManagerInterfaceImpl : public AudioPolicyManagerInterface
44     {
45     public:
ManagerInterfaceImpl(Engine * policyEngine)46         ManagerInterfaceImpl(Engine *policyEngine)
47             : mPolicyEngine(policyEngine) {}
48 
setObserver(AudioPolicyManagerObserver * observer)49         virtual void setObserver(AudioPolicyManagerObserver *observer)
50         {
51             mPolicyEngine->setObserver(observer);
52         }
initCheck()53         virtual status_t initCheck()
54         {
55             return mPolicyEngine->initCheck();
56         }
getDeviceForInputSource(audio_source_t inputSource)57         virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const
58         {
59             return mPolicyEngine->getDeviceForInputSource(inputSource);
60         }
getDeviceForStrategy(routing_strategy strategy)61         virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy) const
62         {
63             return mPolicyEngine->getDeviceForStrategy(strategy);
64         }
getStrategyForStream(audio_stream_type_t stream)65         virtual routing_strategy getStrategyForStream(audio_stream_type_t stream)
66         {
67             return mPolicyEngine->getStrategyForStream(stream);
68         }
getStrategyForUsage(audio_usage_t usage)69         virtual routing_strategy getStrategyForUsage(audio_usage_t usage)
70         {
71             return mPolicyEngine->getStrategyForUsage(usage);
72         }
setPhoneState(audio_mode_t mode)73         virtual status_t setPhoneState(audio_mode_t mode)
74         {
75             return mPolicyEngine->setPhoneState(mode);
76         }
getPhoneState()77         virtual audio_mode_t getPhoneState() const
78         {
79             return mPolicyEngine->getPhoneState();
80         }
setForceUse(audio_policy_force_use_t usage,audio_policy_forced_cfg_t config)81         virtual status_t setForceUse(audio_policy_force_use_t usage,
82                                      audio_policy_forced_cfg_t config)
83         {
84             return mPolicyEngine->setForceUse(usage, config);
85         }
getForceUse(audio_policy_force_use_t usage)86         virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const
87         {
88             return mPolicyEngine->getForceUse(usage);
89         }
setDeviceConnectionState(const sp<DeviceDescriptor>,audio_policy_dev_state_t)90         virtual status_t setDeviceConnectionState(const sp<DeviceDescriptor> /*devDesc*/,
91                                                   audio_policy_dev_state_t /*state*/)
92         {
93             return NO_ERROR;
94         }
95     private:
96         Engine *mPolicyEngine;
97     } mManagerInterface;
98 
99 private:
100     /* Copy facilities are put private to disable copy. */
101     Engine(const Engine &object);
102     Engine &operator=(const Engine &object);
103 
104     void setObserver(AudioPolicyManagerObserver *observer);
105 
106     status_t initCheck();
107 
isInCall()108     inline bool isInCall() const
109     {
110         return is_state_in_call(mPhoneState);
111     }
112 
113     status_t setPhoneState(audio_mode_t mode);
getPhoneState()114     audio_mode_t getPhoneState() const
115     {
116         return mPhoneState;
117     }
118     status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
getForceUse(audio_policy_force_use_t usage)119     audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const
120     {
121         return mForceUse[usage];
122     }
123     status_t setDefaultDevice(audio_devices_t device);
124 
125     routing_strategy getStrategyForStream(audio_stream_type_t stream);
126     routing_strategy getStrategyForUsage(audio_usage_t usage);
127     audio_devices_t getDeviceForStrategy(routing_strategy strategy) const;
128     audio_devices_t getDeviceForStrategyInt(routing_strategy strategy,
129                                             DeviceVector availableOutputDevices,
130                                             DeviceVector availableInputDevices,
131                                             const SwAudioOutputCollection &outputs) const;
132     audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const;
133     audio_mode_t mPhoneState;  /**< current phone state. */
134 
135     /** current forced use configuration. */
136     audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT];
137 
138     AudioPolicyManagerObserver *mApmObserver;
139 };
140 } // namespace audio_policy
141 } // namespace android
142 
143