summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--automotive/audiocontrol/2.0/default/AudioControl.cpp28
-rw-r--r--automotive/audiocontrol/2.0/default/AudioControl.h1
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);
};