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

Commit 9cae2170 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Assign blame for playback wakelocks.

Set a work source for the playback wakelock, so that playback is
counted against the requesting app instead of the media server.

Cherrypicked from master.

b/9464621

Change-Id: I7329f88a288a95a582a78005a1c3d16a5a611e31
parent be567be3
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -187,7 +187,8 @@ public:
                                    int notificationFrames = 0,
                                    int sessionId        = 0,
                                    transfer_type transferType = TRANSFER_DEFAULT,
                                    const audio_offload_info_t *offloadInfo = NULL);
                                    const audio_offload_info_t *offloadInfo = NULL,
                                    int uid = -1);

    /* Creates an audio track and registers it with AudioFlinger.
     * With this constructor, the track is configured for static buffer mode.
@@ -211,7 +212,8 @@ public:
                                    int notificationFrames = 0,
                                    int sessionId       = 0,
                                    transfer_type transferType = TRANSFER_DEFAULT,
                                    const audio_offload_info_t *offloadInfo = NULL);
                                    const audio_offload_info_t *offloadInfo = NULL,
                                    int uid = -1);

    /* Terminates the AudioTrack and unregisters it from AudioFlinger.
     * Also destroys all resources associated with the AudioTrack.
@@ -248,7 +250,8 @@ public:
                            bool threadCanCallJava = false,
                            int sessionId       = 0,
                            transfer_type transferType = TRANSFER_DEFAULT,
                            const audio_offload_info_t *offloadInfo = NULL);
                            const audio_offload_info_t *offloadInfo = NULL,
                            int uid = -1);

    /* Result of constructing the AudioTrack. This must be checked for successful initialization
     * before using any AudioTrack API (except for set()), because using
@@ -751,6 +754,7 @@ private:
    sp<DeathNotifier>       mDeathNotifier;
    uint32_t                mSequence;              // incremented for each new IAudioTrack attempt
    audio_io_handle_t       mOutput;                // cached output io handle
    int                     mClientUid;
};

class TimedAudioTrack : public AudioTrack
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public:
                                // output: server's description of IAudioTrack for display in logs.
                                // Don't attempt to parse, as the format could change.
                                String8& name,
                                int clientUid,
                                status_t *status) = 0;

    virtual sp<IAudioRecord> openRecord(
+15 −5
Original line number Diff line number Diff line
@@ -101,7 +101,8 @@ AudioTrack::AudioTrack(
        int notificationFrames,
        int sessionId,
        transfer_type transferType,
        const audio_offload_info_t *offloadInfo)
        const audio_offload_info_t *offloadInfo,
        int uid)
    : mStatus(NO_INIT),
      mIsTimed(false),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
@@ -109,7 +110,8 @@ AudioTrack::AudioTrack(
{
    mStatus = set(streamType, sampleRate, format, channelMask,
            frameCount, flags, cbf, user, notificationFrames,
            0 /*sharedBuffer*/, false /*threadCanCallJava*/, sessionId, transferType, offloadInfo);
            0 /*sharedBuffer*/, false /*threadCanCallJava*/, sessionId, transferType,
            offloadInfo, uid);
}

AudioTrack::AudioTrack(
@@ -124,7 +126,8 @@ AudioTrack::AudioTrack(
        int notificationFrames,
        int sessionId,
        transfer_type transferType,
        const audio_offload_info_t *offloadInfo)
        const audio_offload_info_t *offloadInfo,
        int uid)
    : mStatus(NO_INIT),
      mIsTimed(false),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
@@ -132,7 +135,7 @@ AudioTrack::AudioTrack(
{
    mStatus = set(streamType, sampleRate, format, channelMask,
            0 /*frameCount*/, flags, cbf, user, notificationFrames,
            sharedBuffer, false /*threadCanCallJava*/, sessionId, transferType, offloadInfo);
            sharedBuffer, false /*threadCanCallJava*/, sessionId, transferType, offloadInfo, uid);
}

AudioTrack::~AudioTrack()
@@ -169,7 +172,8 @@ status_t AudioTrack::set(
        bool threadCanCallJava,
        int sessionId,
        transfer_type transferType,
        const audio_offload_info_t *offloadInfo)
        const audio_offload_info_t *offloadInfo,
        int uid)
{
    switch (transferType) {
    case TRANSFER_DEFAULT:
@@ -313,6 +317,11 @@ status_t AudioTrack::set(
    mNotificationFramesReq = notificationFrames;
    mNotificationFramesAct = 0;
    mSessionId = sessionId;
    if (uid == -1 || (IPCThreadState::self()->getCallingPid() != getpid())) {
        mClientUid = IPCThreadState::self()->getCallingUid();
    } else {
        mClientUid = uid;
    }
    mAuxEffectId = 0;
    mFlags = flags;
    mCbf = cbf;
@@ -962,6 +971,7 @@ status_t AudioTrack::createTrack_l(
                                                      tid,
                                                      &mSessionId,
                                                      mName,
                                                      mClientUid,
                                                      &status);

    if (track == 0) {
+4 −1
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ public:
                                pid_t tid,
                                int *sessionId,
                                String8& name,
                                int clientUid,
                                status_t *status)
    {
        Parcel data, reply;
@@ -121,6 +122,7 @@ public:
            lSessionId = *sessionId;
        }
        data.writeInt32(lSessionId);
        data.writeInt32(clientUid);
        status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
        if (lStatus != NO_ERROR) {
            ALOGE("createTrack error: %s", strerror(-lStatus));
@@ -762,6 +764,7 @@ status_t BnAudioFlinger::onTransact(
            audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
            pid_t tid = (pid_t) data.readInt32();
            int sessionId = data.readInt32();
            int clientUid = data.readInt32();
            String8 name;
            status_t status;
            sp<IAudioTrack> track;
@@ -773,7 +776,7 @@ status_t BnAudioFlinger::onTransact(
                track = createTrack(
                        (audio_stream_type_t) streamType, sampleRate, format,
                        channelMask, frameCount, &flags, buffer, output, tid,
                        &sessionId, name, &status);
                        &sessionId, name, clientUid, &status);
            }
            reply->writeInt32(flags);
            reply->writeInt32(sessionId);
+12 −7
Original line number Diff line number Diff line
@@ -590,7 +590,7 @@ sp<MediaPlayerBase> MediaPlayerService::Client::setDataSource_pre(
    }

    if (!p->hardwareOutput()) {
        mAudioOutput = new AudioOutput(mAudioSessionId);
        mAudioOutput = new AudioOutput(mAudioSessionId, IPCThreadState::self()->getCallingUid());
        static_cast<MediaPlayerInterface*>(p.get())->setAudioSink(mAudioOutput);
    }

@@ -1296,12 +1296,13 @@ Exit:

#undef LOG_TAG
#define LOG_TAG "AudioSink"
MediaPlayerService::AudioOutput::AudioOutput(int sessionId)
MediaPlayerService::AudioOutput::AudioOutput(int sessionId, int uid)
    : mCallback(NULL),
      mCallbackCookie(NULL),
      mCallbackData(NULL),
      mBytesWritten(0),
      mSessionId(sessionId),
      mUid(uid),
      mFlags(AUDIO_OUTPUT_FLAG_NONE) {
    ALOGV("AudioOutput(%d)", sessionId);
    mStreamType = AUDIO_STREAM_MUSIC;
@@ -1549,7 +1550,8 @@ status_t MediaPlayerService::AudioOutput::open(
                    0,  // notification frames
                    mSessionId,
                    AudioTrack::TRANSFER_CALLBACK,
                    offloadInfo);
                    offloadInfo,
                    mUid);
        } else {
            t = new AudioTrack(
                    mStreamType,
@@ -1558,10 +1560,13 @@ status_t MediaPlayerService::AudioOutput::open(
                    channelMask,
                    frameCount,
                    flags,
                    NULL,
                    NULL,
                    0,
                    mSessionId);
                    NULL, // callback
                    NULL, // user data
                    0, // notification frames
                    mSessionId,
                    AudioTrack::TRANSFER_DEFAULT,
                    NULL, // offload info
                    mUid);
        }

        if ((t == 0) || (t->initCheck() != NO_ERROR)) {
Loading