diff options
author | 2022-06-30 15:48:16 +0200 | |
---|---|---|
committer | 2022-07-29 11:35:59 +0200 | |
commit | 5cb98562e2c9ed8a18617550e7065ca32617a9f6 (patch) | |
tree | c316b6e688a257f249061e9c5ed1b530d3efbdfc | |
parent | 5fb036fd6d4468b5692a2d62cc39ae86a1764866 (diff) |
Add type used for describing the mute state
This is used by the playback notification API to inform about a
mute/unmute event and also describe the reason for mute (stream, master,
playback restricted by apops mute)
Test: dumpsys audio
Bug: 235521198
Change-Id: I22e57e78e75a276dcb60e2820ec2cf26734b93c1
-rw-r--r-- | include/audiomanager/AudioManager.h | 35 | ||||
-rw-r--r-- | include/audiomanager/IAudioManager.h | 4 | ||||
-rw-r--r-- | services/audiomanager/IAudioManager.cpp | 11 |
3 files changed, 50 insertions, 0 deletions
diff --git a/include/audiomanager/AudioManager.h b/include/audiomanager/AudioManager.h index caf13a0f4b..86e5e352a6 100644 --- a/include/audiomanager/AudioManager.h +++ b/include/audiomanager/AudioManager.h @@ -39,8 +39,43 @@ typedef enum { PLAYER_STATE_STOPPED = 4, PLAYER_UPDATE_DEVICE_ID = 5, PLAYER_UPDATE_PORT_ID = 6, + PLAYER_UPDATE_MUTED = 7, } player_state_t; +static constexpr char + kExtraPlayerEventMuteKey[] = "android.media.extra.PLAYER_EVENT_MUTE"; +enum { + PLAYER_MUTE_MASTER = (1 << 0), + PLAYER_MUTE_STREAM_VOLUME = (1 << 1), + PLAYER_MUTE_STREAM_MUTED = (1 << 2), + PLAYER_MUTE_PLAYBACK_RESTRICTED = (1 << 3), +}; + +struct mute_state_t { + /** Flag used when the master volume is causing the mute state. */ + bool muteFromMasterMute = false; + /** Flag used when the stream volume is causing the mute state. */ + bool muteFromStreamVolume = false; + /** Flag used when the stream muted is causing the mute state. */ + bool muteFromStreamMuted = false; + /** Flag used when playback is restricted by AppOps manager with OP_PLAY_AUDIO. */ + bool muteFromPlaybackRestricted = false; + + explicit operator int() const + { + int result = muteFromMasterMute * PLAYER_MUTE_MASTER; + result |= muteFromStreamVolume * PLAYER_MUTE_STREAM_VOLUME; + result |= muteFromStreamMuted * PLAYER_MUTE_STREAM_MUTED; + result |= muteFromPlaybackRestricted * PLAYER_MUTE_PLAYBACK_RESTRICTED; + return result; + } + + bool operator==(const mute_state_t& other) const + { + return static_cast<int>(*this) == static_cast<int>(other); + } +}; + // must be kept in sync with definitions in AudioManager.java #define RECORD_RIID_INVALID -1 diff --git a/include/audiomanager/IAudioManager.h b/include/audiomanager/IAudioManager.h index 3d531feeac..769670ea99 100644 --- a/include/audiomanager/IAudioManager.h +++ b/include/audiomanager/IAudioManager.h @@ -20,6 +20,7 @@ #include <audiomanager/AudioManager.h> #include <utils/Errors.h> #include <binder/IInterface.h> +#include <binder/PersistableBundle.h> #include <hardware/power.h> #include <system/audio.h> @@ -41,6 +42,7 @@ public: RECORDER_EVENT = IBinder::FIRST_CALL_TRANSACTION + 5, RELEASE_RECORDER = IBinder::FIRST_CALL_TRANSACTION + 6, PLAYER_SESSION_ID = IBinder::FIRST_CALL_TRANSACTION + 7, + PORT_EVENT = IBinder::FIRST_CALL_TRANSACTION + 8, }; DECLARE_META_INTERFACE(AudioManager) @@ -59,6 +61,8 @@ public: /*oneway*/ virtual status_t recorderEvent(audio_unique_id_t riid, recorder_state_t event) = 0; /*oneway*/ virtual status_t releaseRecorder(audio_unique_id_t riid) = 0; /*oneway*/ virtual status_t playerSessionId(audio_unique_id_t piid, audio_session_t sessionId) = 0; + /*oneway*/ virtual status_t portEvent(audio_port_handle_t portId, player_state_t event, + const std::unique_ptr<os::PersistableBundle>& extras) = 0; }; // ---------------------------------------------------------------------------- diff --git a/services/audiomanager/IAudioManager.cpp b/services/audiomanager/IAudioManager.cpp index 700074acd2..3ef5049230 100644 --- a/services/audiomanager/IAudioManager.cpp +++ b/services/audiomanager/IAudioManager.cpp @@ -141,6 +141,17 @@ public: data.writeInt32((int32_t) sessionId); return remote()->transact(PLAYER_SESSION_ID, data, &reply, IBinder::FLAG_ONEWAY); } + + virtual status_t portEvent(audio_port_handle_t portId, player_state_t event, + const std::unique_ptr<os::PersistableBundle>& extras) { + Parcel data, reply; + data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); + data.writeInt32((int32_t) portId); + data.writeInt32((int32_t) event); + // TODO: replace PersistableBundle with own struct + data.writeNullableParcelable(extras); + return remote()->transact(PORT_EVENT, data, &reply, IBinder::FLAG_ONEWAY); + } }; IMPLEMENT_META_INTERFACE(AudioManager, "android.media.IAudioService"); |