Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cb98562 authored by Vlad Popa's avatar Vlad Popa
Browse files

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
parent 5fb036fd
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -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

+4 −0
Original line number Diff line number Diff line
@@ -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;
};

// ----------------------------------------------------------------------------
+11 −0
Original line number Diff line number Diff line
@@ -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");