1 #include "AudioControl.h"
2
3 #include <hidl/HidlTransportSupport.h>
4 #include <log/log.h>
5
6
7 namespace android {
8 namespace hardware {
9 namespace automotive {
10 namespace audiocontrol {
11 namespace V1_0 {
12 namespace implementation {
13
14
15 // This is the static map we're using to associate a ContextNumber with a
16 // bus number from the audio_policy_configuration.xml setup. Every valid context needs
17 // to be mapped to a bus address that actually exists in the platforms configuration.
18 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) // Would be nice if this were common...
19 static int sContextToBusMap[] = {
20 -1, // INVALID
21 0, // MUSIC_CONTEXT
22 1, // NAVIGATION_CONTEXT
23 2, // VOICE_COMMAND_CONTEXT
24 3, // CALL_RING_CONTEXT
25 4, // CALL_CONTEXT
26 5, // ALARM_CONTEXT
27 6, // NOTIFICATION_CONTEXT
28 7, // SYSTEM_SOUND_CONTEXT
29 };
30 static const unsigned sContextMapSize = ARRAY_SIZE(sContextToBusMap);
31 static const unsigned sContextCount = sContextMapSize - 1; // Less one for the INVALID entry
32 static const unsigned sContextNumberMax = sContextCount; // contextNumber is counted from 1
33
34
AudioControl()35 AudioControl::AudioControl() {
36 };
37
38
getBusForContext(ContextNumber ctxt)39 Return<int32_t> AudioControl::getBusForContext(ContextNumber ctxt) {
40 unsigned contextNumber = static_cast<unsigned>(ctxt);
41 if (contextNumber > sContextNumberMax) {
42 ALOGE("Unexpected context number %d (max expected is %d)", contextNumber, sContextCount);
43 return -1;
44 } else {
45 return sContextToBusMap[contextNumber];
46 }
47 }
48
49
setBalanceTowardRight(float value)50 Return<void> AudioControl::setBalanceTowardRight(float value) {
51 // For completeness, lets bounds check the input...
52 if ((value > 1.0f) || (value < -1.0f)) {
53 ALOGE("Balance value out of range -1 to 1 at %0.2f", value);
54 } else {
55 // Just log in this default mock implementation
56 ALOGI("Balance set to %0.2f", value);
57 }
58 return Void();
59 }
60
61
setFadeTowardFront(float value)62 Return<void> AudioControl::setFadeTowardFront(float value) {
63 // For completeness, lets bounds check the input...
64 if ((value > 1.0f) || (value < -1.0f)) {
65 ALOGE("Fader value out of range -1 to 1 at %0.2f", value);
66 } else {
67 // Just log in this default mock implementation
68 ALOGI("Fader set to %0.2f", value);
69 }
70 return Void();
71 }
72
73 } // namespace implementation
74 } // namespace V1_0
75 } // namespace audiocontrol
76 } // namespace automotive
77 } // namespace hardware
78 } // namespace android
79