diff options
author | Hayden Gomes <haydengomes@google.com> | 2020-04-02 14:29:00 -0700 |
---|---|---|
committer | Hayden Gomes <haydengomes@google.com> | 2020-04-09 16:13:11 -0700 |
commit | c4199eabf83bacc608c188a30d009b7ff7396360 (patch) | |
tree | 13052dc372a56137861c109aa74efff5178a09ee /automotive/audiocontrol | |
parent | fa81977e1a072a42fcdfd1515eee0a13cdd59f43 (diff) | |
download | platform_hardware_interfaces-c4199eabf83bacc608c188a30d009b7ff7396360.tar.gz platform_hardware_interfaces-c4199eabf83bacc608c188a30d009b7ff7396360.tar.bz2 platform_hardware_interfaces-c4199eabf83bacc608c188a30d009b7ff7396360.zip |
Adding a lshal command for abandoning focus
Bug: 148098383
Test: adb shell lshal debug
android.hardware.automotive.audiocontrol@2.0::IAudioControl/default
--abandon 1 0
Change-Id: I4bec12ec3ae0fc6b73de8b823501f0f478d75d94
Diffstat (limited to 'automotive/audiocontrol')
-rw-r--r-- | automotive/audiocontrol/2.0/default/AudioControl.cpp | 28 | ||||
-rw-r--r-- | automotive/audiocontrol/2.0/default/AudioControl.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/automotive/audiocontrol/2.0/default/AudioControl.cpp b/automotive/audiocontrol/2.0/default/AudioControl.cpp index 7a121f5d3f..5bde8396f2 100644 --- a/automotive/audiocontrol/2.0/default/AudioControl.cpp +++ b/automotive/audiocontrol/2.0/default/AudioControl.cpp @@ -110,6 +110,8 @@ void AudioControl::cmdDump(int fd, const hidl_vec<hidl_string>& options) { cmdHelp(fd); } else if (EqualsIgnoreCase(option, "--request")) { cmdRequestFocus(fd, options); + } else if (EqualsIgnoreCase(option, "--abandon")) { + cmdAbandonFocus(fd, options); } else { dprintf(fd, "Invalid option: %s\n", option.c_str()); } @@ -130,6 +132,9 @@ void AudioControl::cmdHelp(int fd) const { dprintf(fd, "--request <USAGE> <ZONE_ID> <FOCUS_GAIN>: requests audio focus for specified " "usage (int), audio zone ID (int), and focus gain type (int)\n"); + dprintf(fd, + "--abandon <USAGE> <ZONE_ID>: abandons audio focus for specified usage (int) and " + "audio zone ID (int)\n"); } void AudioControl::cmdRequestFocus(int fd, const hidl_vec<hidl_string>& options) { @@ -161,6 +166,29 @@ void AudioControl::cmdRequestFocus(int fd, const hidl_vec<hidl_string>& options) focusGain); } +void AudioControl::cmdAbandonFocus(int fd, const hidl_vec<hidl_string>& options) { + if (!checkCallerHasWritePermissions(fd) || !checkArgumentsSize(fd, options, 2)) return; + + hidl_bitfield<AudioUsage> usage; + if (!safelyParseInt(options[1], &usage)) { + dprintf(fd, "Non-integer usage provided with abandon: %s\n", options[1].c_str()); + return; + } + int zoneId; + if (!safelyParseInt(options[2], &zoneId)) { + dprintf(fd, "Non-integer zoneId provided with abandon: %s\n", options[2].c_str()); + return; + } + + if (mFocusListener == nullptr) { + dprintf(fd, "Unable to abandon focus - no focus listener registered\n"); + return; + } + + mFocusListener->abandonAudioFocus(usage, zoneId); + dprintf(fd, "Abandoned focus for usage %d and zoneId %d\n", usage, zoneId); +} + bool AudioControl::checkCallerHasWritePermissions(int fd) { // Double check that's only called by root - it should be be blocked at the HIDL debug() level, // but it doesn't hurt to make sure... diff --git a/automotive/audiocontrol/2.0/default/AudioControl.h b/automotive/audiocontrol/2.0/default/AudioControl.h index 1cd7cbc5de..d66458ec05 100644 --- a/automotive/audiocontrol/2.0/default/AudioControl.h +++ b/automotive/audiocontrol/2.0/default/AudioControl.h @@ -51,6 +51,7 @@ class AudioControl : public IAudioControl { void cmdDump(int fd, const hidl_vec<hidl_string>& options); void cmdHelp(int fd) const; void cmdRequestFocus(int fd, const hidl_vec<hidl_string>& options); + void cmdAbandonFocus(int fd, const hidl_vec<hidl_string>& options); void dump(int fd); }; |