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

Commit f2ae3e19 authored by Wei Jia's avatar Wei Jia
Browse files

BatteryNotifier: attribute battery usage of video to correct uid.

Test: manual check batterystats
Bug: 32361950
Change-Id: Id052220e87f6667ca908d5bf6be6164dc8c14c53
parent 2aa19a96
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -64,14 +64,15 @@ struct MediaCodec : public AHandler {
    };
    };


    static const pid_t kNoPid = -1;
    static const pid_t kNoPid = -1;
    static const uid_t kNoUid = -1;


    static sp<MediaCodec> CreateByType(
    static sp<MediaCodec> CreateByType(
            const sp<ALooper> &looper, const AString &mime, bool encoder, status_t *err = NULL,
            const sp<ALooper> &looper, const AString &mime, bool encoder, status_t *err = NULL,
            pid_t pid = kNoPid);
            pid_t pid = kNoPid, uid_t uid = kNoUid);


    static sp<MediaCodec> CreateByComponentName(
    static sp<MediaCodec> CreateByComponentName(
            const sp<ALooper> &looper, const AString &name, status_t *err = NULL,
            const sp<ALooper> &looper, const AString &name, status_t *err = NULL,
            pid_t pid = kNoPid);
            pid_t pid = kNoPid, uid_t uid = kNoUid);


    static sp<PersistentSurface> CreatePersistentInputSurface();
    static sp<PersistentSurface> CreatePersistentInputSurface();


@@ -287,6 +288,7 @@ private:
    };
    };


    State mState;
    State mState;
    uid_t mUid;
    bool mReleasedByResourceManager;
    bool mReleasedByResourceManager;
    sp<ALooper> mLooper;
    sp<ALooper> mLooper;
    sp<ALooper> mCodecLooper;
    sp<ALooper> mCodecLooper;
@@ -345,7 +347,7 @@ private:
    bool mHaveInputSurface;
    bool mHaveInputSurface;
    bool mHavePendingInputBuffers;
    bool mHavePendingInputBuffers;


    MediaCodec(const sp<ALooper> &looper, pid_t pid);
    MediaCodec(const sp<ALooper> &looper, pid_t pid, uid_t uid);


    static sp<CodecBase> GetCodecBase(const AString &name, bool nameIsType = false);
    static sp<CodecBase> GetCodecBase(const AString &name, bool nameIsType = false);


+2 −2
Original line number Original line Diff line number Diff line
@@ -1641,7 +1641,7 @@ status_t NuPlayer::instantiateDecoder(
        } else {
        } else {
            mSource->setOffloadAudio(false /* offload */);
            mSource->setOffloadAudio(false /* offload */);


            *decoder = new Decoder(notify, mSource, mPID, mRenderer);
            *decoder = new Decoder(notify, mSource, mPID, mUID, mRenderer);
        }
        }
    } else {
    } else {
        sp<AMessage> notify = new AMessage(kWhatVideoNotify, this);
        sp<AMessage> notify = new AMessage(kWhatVideoNotify, this);
@@ -1649,7 +1649,7 @@ status_t NuPlayer::instantiateDecoder(
        notify->setInt32("generation", mVideoDecoderGeneration);
        notify->setInt32("generation", mVideoDecoderGeneration);


        *decoder = new Decoder(
        *decoder = new Decoder(
                notify, mSource, mPID, mRenderer, mSurface, mCCDecoder);
                notify, mSource, mPID, mUID, mRenderer, mSurface, mCCDecoder);


        // enable FRC if high-quality AV sync is requested, even if not
        // enable FRC if high-quality AV sync is requested, even if not
        // directly queuing to display, as this will even improve textureview
        // directly queuing to display, as this will even improve textureview
+4 −2
Original line number Original line Diff line number Diff line
@@ -58,6 +58,7 @@ NuPlayer::Decoder::Decoder(
        const sp<AMessage> &notify,
        const sp<AMessage> &notify,
        const sp<Source> &source,
        const sp<Source> &source,
        pid_t pid,
        pid_t pid,
        uid_t uid,
        const sp<Renderer> &renderer,
        const sp<Renderer> &renderer,
        const sp<Surface> &surface,
        const sp<Surface> &surface,
        const sp<CCDecoder> &ccDecoder)
        const sp<CCDecoder> &ccDecoder)
@@ -67,6 +68,7 @@ NuPlayer::Decoder::Decoder(
      mRenderer(renderer),
      mRenderer(renderer),
      mCCDecoder(ccDecoder),
      mCCDecoder(ccDecoder),
      mPid(pid),
      mPid(pid),
      mUid(uid),
      mSkipRenderingUntilMediaTimeUs(-1ll),
      mSkipRenderingUntilMediaTimeUs(-1ll),
      mNumFramesTotal(0ll),
      mNumFramesTotal(0ll),
      mNumInputFramesDropped(0ll),
      mNumInputFramesDropped(0ll),
@@ -266,7 +268,7 @@ void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
    ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), mSurface.get());
    ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), mSurface.get());


    mCodec = MediaCodec::CreateByType(
    mCodec = MediaCodec::CreateByType(
            mCodecLooper, mime.c_str(), false /* encoder */, NULL /* err */, mPid);
            mCodecLooper, mime.c_str(), false /* encoder */, NULL /* err */, mPid, mUid);
    int32_t secure = 0;
    int32_t secure = 0;
    if (format->findInt32("secure", &secure) && secure != 0) {
    if (format->findInt32("secure", &secure) && secure != 0) {
        if (mCodec != NULL) {
        if (mCodec != NULL) {
@@ -275,7 +277,7 @@ void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
            mCodec->release();
            mCodec->release();
            ALOGI("[%s] creating", mComponentName.c_str());
            ALOGI("[%s] creating", mComponentName.c_str());
            mCodec = MediaCodec::CreateByComponentName(
            mCodec = MediaCodec::CreateByComponentName(
                    mCodecLooper, mComponentName.c_str(), NULL /* err */, mPid);
                    mCodecLooper, mComponentName.c_str(), NULL /* err */, mPid, mUid);
        }
        }
    }
    }
    if (mCodec == NULL) {
    if (mCodec == NULL) {
+2 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ struct NuPlayer::Decoder : public DecoderBase {
    Decoder(const sp<AMessage> &notify,
    Decoder(const sp<AMessage> &notify,
            const sp<Source> &source,
            const sp<Source> &source,
            pid_t pid,
            pid_t pid,
            uid_t uid,
            const sp<Renderer> &renderer = NULL,
            const sp<Renderer> &renderer = NULL,
            const sp<Surface> &surface = NULL,
            const sp<Surface> &surface = NULL,
            const sp<CCDecoder> &ccDecoder = NULL);
            const sp<CCDecoder> &ccDecoder = NULL);
@@ -85,6 +86,7 @@ private:
    Vector<size_t> mDequeuedInputBuffers;
    Vector<size_t> mDequeuedInputBuffers;


    const pid_t mPid;
    const pid_t mPid;
    const uid_t mUid;
    int64_t mSkipRenderingUntilMediaTimeUs;
    int64_t mSkipRenderingUntilMediaTimeUs;
    int64_t mNumFramesTotal;
    int64_t mNumFramesTotal;
    int64_t mNumInputFramesDropped;
    int64_t mNumInputFramesDropped;
+13 −7
Original line number Original line Diff line number Diff line
@@ -173,8 +173,9 @@ bool MediaCodec::ResourceManagerServiceProxy::reclaimResource(


// static
// static
sp<MediaCodec> MediaCodec::CreateByType(
sp<MediaCodec> MediaCodec::CreateByType(
        const sp<ALooper> &looper, const AString &mime, bool encoder, status_t *err, pid_t pid) {
        const sp<ALooper> &looper, const AString &mime, bool encoder, status_t *err, pid_t pid,
    sp<MediaCodec> codec = new MediaCodec(looper, pid);
        uid_t uid) {
    sp<MediaCodec> codec = new MediaCodec(looper, pid, uid);


    const status_t ret = codec->init(mime, true /* nameIsType */, encoder);
    const status_t ret = codec->init(mime, true /* nameIsType */, encoder);
    if (err != NULL) {
    if (err != NULL) {
@@ -185,8 +186,8 @@ sp<MediaCodec> MediaCodec::CreateByType(


// static
// static
sp<MediaCodec> MediaCodec::CreateByComponentName(
sp<MediaCodec> MediaCodec::CreateByComponentName(
        const sp<ALooper> &looper, const AString &name, status_t *err, pid_t pid) {
        const sp<ALooper> &looper, const AString &name, status_t *err, pid_t pid, uid_t uid) {
    sp<MediaCodec> codec = new MediaCodec(looper, pid);
    sp<MediaCodec> codec = new MediaCodec(looper, pid, uid);


    const status_t ret = codec->init(name, false /* nameIsType */, false /* encoder */);
    const status_t ret = codec->init(name, false /* nameIsType */, false /* encoder */);
    if (err != NULL) {
    if (err != NULL) {
@@ -234,7 +235,7 @@ sp<PersistentSurface> MediaCodec::CreatePersistentInputSurface() {
    return new PersistentSurface(bufferProducer, bufferSource);
    return new PersistentSurface(bufferProducer, bufferSource);
}
}


MediaCodec::MediaCodec(const sp<ALooper> &looper, pid_t pid)
MediaCodec::MediaCodec(const sp<ALooper> &looper, pid_t pid, uid_t uid)
    : mState(UNINITIALIZED),
    : mState(UNINITIALIZED),
      mReleasedByResourceManager(false),
      mReleasedByResourceManager(false),
      mLooper(looper),
      mLooper(looper),
@@ -256,6 +257,11 @@ MediaCodec::MediaCodec(const sp<ALooper> &looper, pid_t pid)
      mDequeueOutputReplyID(0),
      mDequeueOutputReplyID(0),
      mHaveInputSurface(false),
      mHaveInputSurface(false),
      mHavePendingInputBuffers(false) {
      mHavePendingInputBuffers(false) {
    if (uid == kNoUid) {
        mUid = IPCThreadState::self()->getCallingUid();
    } else {
        mUid = uid;
    }
}
}


MediaCodec::~MediaCodec() {
MediaCodec::~MediaCodec() {
@@ -2921,10 +2927,10 @@ void MediaCodec::updateBatteryStat() {
    }
    }


    if (mState == CONFIGURED && !mBatteryStatNotified) {
    if (mState == CONFIGURED && !mBatteryStatNotified) {
        BatteryNotifier::getInstance().noteStartVideo();
        BatteryNotifier::getInstance().noteStartVideo(mUid);
        mBatteryStatNotified = true;
        mBatteryStatNotified = true;
    } else if (mState == UNINITIALIZED && mBatteryStatNotified) {
    } else if (mState == UNINITIALIZED && mBatteryStatNotified) {
        BatteryNotifier::getInstance().noteStopVideo();
        BatteryNotifier::getInstance().noteStopVideo(mUid);
        mBatteryStatNotified = false;
        mBatteryStatNotified = false;
    }
    }
}
}
Loading