Scott Randolph | 46bc128 | 2017-07-27 18:26:27 -0700 | [diff] [blame] | 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 | |
| 35 | AudioControl::AudioControl() { |
| 36 | }; |
| 37 | |
| 38 | |
| 39 | // Methods from ::android::hardware::automotive::audiocontrol::V1_0::IAudioControl follow. |
| 40 | Return<AudioResult> AudioControl::setCallback(const sp<IAudioControlCallback>& notificationObject) { |
| 41 | // Hang onto the provided callback object for future use |
| 42 | callback = notificationObject; |
| 43 | |
| 44 | return AudioResult::OK; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | Return<int32_t> AudioControl::getBusForContext(uint32_t contextNumber) { |
| 49 | if (contextNumber > sContextNumberMax) { |
| 50 | ALOGE("Unexpected context number %d (max expected is %d)", contextNumber, sContextCount); |
| 51 | return -1; |
| 52 | } else { |
| 53 | return sContextToBusMap[contextNumber]; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | Return<void> AudioControl::setBalanceTowardRight(float value) { |
| 59 | // For completeness, lets bounds check the input... |
| 60 | if ((value > 1.0f) || (value < -1.0f)) { |
| 61 | ALOGE("Balance value out of range -1 to 1 at %0.2f", value); |
| 62 | } else { |
| 63 | // Just log in this default mock implementation |
| 64 | ALOGI("Balance set to %0.2f", value); |
| 65 | } |
| 66 | return Void(); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | Return<void> AudioControl::setFadeTowardFront(float value) { |
| 71 | // For completeness, lets bounds check the input... |
| 72 | if ((value > 1.0f) || (value < -1.0f)) { |
| 73 | ALOGE("Fader value out of range -1 to 1 at %0.2f", value); |
| 74 | } else { |
| 75 | // Just log in this default mock implementation |
| 76 | ALOGI("Fader set to %0.2f", value); |
| 77 | } |
| 78 | return Void(); |
| 79 | } |
| 80 | |
| 81 | } // namespace implementation |
| 82 | } // namespace V1_0 |
| 83 | } // namespace audiocontrol |
| 84 | } // namespace automotive |
| 85 | } // namespace hardware |
| 86 | } // namespace android |