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

Commit baf9bda6 authored by Ray Essick's avatar Ray Essick Committed by android-build-merger
Browse files

Merge "track pkgname/version in media.metrics" into oc-mr1-dev

am: dbedf0ab

Change-Id: I57b07ed336fd60e326fad48206cad5fa19268d82
parents 9600c9d0 dbedf0ab
Loading
Loading
Loading
Loading
+89 −6
Original line number Diff line number Diff line
@@ -120,6 +120,8 @@ MediaAnalyticsItem *MediaAnalyticsItem::dup() {
        // key as part of constructor
        dst->mPid = this->mPid;
        dst->mUid = this->mUid;
        dst->mPkgName = this->mPkgName;
        dst->mPkgVersionCode = this->mPkgVersionCode;
        dst->mSessionID = this->mSessionID;
        dst->mTimestamp = this->mTimestamp;
        dst->mFinalized = this->mFinalized;
@@ -201,6 +203,24 @@ uid_t MediaAnalyticsItem::getUid() const {
    return mUid;
}

MediaAnalyticsItem &MediaAnalyticsItem::setPkgName(AString pkgName) {
    mPkgName = pkgName;
    return *this;
}

AString MediaAnalyticsItem::getPkgName() const {
    return mPkgName;
}

MediaAnalyticsItem &MediaAnalyticsItem::setPkgVersionCode(int32_t pkgVersionCode) {
    mPkgVersionCode = pkgVersionCode;
    return *this;
}

int32_t MediaAnalyticsItem::getPkgVersionCode() const {
    return mPkgVersionCode;
}

// this key is for the overall record -- "codec", "player", "drm", etc
MediaAnalyticsItem &MediaAnalyticsItem::setKey(MediaAnalyticsItem::Key key) {
    mKey = key;
@@ -263,11 +283,29 @@ MediaAnalyticsItem::Prop *MediaAnalyticsItem::allocateProp(const char *name) {
        i = mPropCount++;
        prop = &mProps[i];
        prop->setName(name, len);
        prop->mType = kTypeNone;        // make caller set type info
    }

    return prop;
}

// used within the summarizers; return whether property existed
bool MediaAnalyticsItem::removeProp(const char *name) {
    size_t len = strlen(name);
    size_t i = findPropIndex(name, len);
    if (i < mPropCount) {
        Prop *prop = &mProps[i];
        clearProp(prop);
        if (i != mPropCount-1) {
            // in the middle, bring last one down to fill gap
            mProps[i] = mProps[mPropCount-1];
        }
        mPropCount--;
        return true;
    }
    return false;
}

// set the values
void MediaAnalyticsItem::setInt32(MediaAnalyticsItem::Attr name, int32_t value) {
    Prop *prop = allocateProp(name);
@@ -568,6 +606,10 @@ int32_t MediaAnalyticsItem::readFromParcel(const Parcel& data) {
    // into 'this' object
    // .. we make a copy of the string to put away.
    mKey = data.readCString();
    mPid = data.readInt32();
    mUid = data.readInt32();
    mPkgName = data.readCString();
    mPkgVersionCode = data.readInt32();
    mSessionID = data.readInt64();
    mFinalized = data.readInt32();
    mTimestamp = data.readInt64();
@@ -611,6 +653,10 @@ int32_t MediaAnalyticsItem::writeToParcel(Parcel *data) {


    data->writeCString(mKey.c_str());
    data->writeInt32(mPid);
    data->writeInt32(mUid);
    data->writeCString(mPkgName.c_str());
    data->writeInt32(mPkgVersionCode);
    data->writeInt64(mSessionID);
    data->writeInt32(mFinalized);
    data->writeInt64(mTimestamp);
@@ -651,21 +697,54 @@ int32_t MediaAnalyticsItem::writeToParcel(Parcel *data) {


AString MediaAnalyticsItem::toString() {
   return toString(-1);
}

AString MediaAnalyticsItem::toString(int version) {

    // v0 : released with 'o'
    // v1 : bug fix (missing pid/finalized separator),
    //      adds apk name, apk version code

    AString result = "(";
    if (version <= PROTO_FIRST) {
        // default to original v0 format, until proper parsers are in place
        version = PROTO_V0;
    } else if (version > PROTO_LAST) {
        version = PROTO_LAST;
    }

    AString result;
    char buffer[512];

    if (version == PROTO_V0) {
        result = "(";
    } else {
        snprintf(buffer, sizeof(buffer), "[%d:", version);
        result.append(buffer);
    }

    // same order as we spill into the parcel, although not required
    // key+session are our primary matching criteria
    //RBE ALOGD("mKey.c_str");
    result.append(mKey.c_str());
    //RBE ALOGD("post-mKey.c_str");
    result.append(":");
    snprintf(buffer, sizeof(buffer), "%" PRId64 ":", mSessionID);
    result.append(buffer);

    // we need these internally, but don't want to upload them
    snprintf(buffer, sizeof(buffer), "%d:%d", mUid, mPid);
    snprintf(buffer, sizeof(buffer), "%d:", mUid);
    result.append(buffer);

    if (version >= PROTO_V1) {
        result.append(mPkgName);
        snprintf(buffer, sizeof(buffer), ":%d:", mPkgVersionCode);
        result.append(buffer);
    }

    // in 'o' (v1) , the separator between pid and finalized was omitted
    if (version <= PROTO_V0) {
        snprintf(buffer, sizeof(buffer), "%d", mPid);
    } else {
        snprintf(buffer, sizeof(buffer), "%d:", mPid);
    }
    result.append(buffer);

    snprintf(buffer, sizeof(buffer), "%d:", mFinalized);
@@ -713,7 +792,11 @@ AString MediaAnalyticsItem::toString() {
            result.append(buffer);
    }

    if (version == PROTO_V0) {
        result.append(")");
    } else {
        result.append("]");
    }

    return result;
}
+18 −0
Original line number Diff line number Diff line
@@ -75,6 +75,14 @@ class MediaAnalyticsItem {
        typedef const char *Attr;


        enum {
            PROTO_V0 = 0,
            PROTO_FIRST = PROTO_V0,
            PROTO_V1 = 1,
            PROTO_LAST = PROTO_V1,
        };


    public:

        // access functions for the class
@@ -161,11 +169,18 @@ class MediaAnalyticsItem {
        MediaAnalyticsItem &setUid(uid_t);
        uid_t getUid() const;

        MediaAnalyticsItem &setPkgName(AString);
        AString getPkgName() const;

        MediaAnalyticsItem &setPkgVersionCode(int32_t);
        int32_t getPkgVersionCode() const;

        // our serialization code for binder calls
        int32_t writeToParcel(Parcel *);
        int32_t readFromParcel(const Parcel&);

        AString toString();
        AString toString(int version);

        // are we collecting analytics data
        static bool isEnabled();
@@ -188,6 +203,8 @@ class MediaAnalyticsItem {
        // to help validate that A doesn't mess with B's records
        pid_t     mPid;
        uid_t     mUid;
        AString   mPkgName;
        int32_t   mPkgVersionCode;

        // let's reuse a binder connection
        static sp<IMediaAnalyticsService> sAnalyticsService;
@@ -228,6 +245,7 @@ class MediaAnalyticsItem {
        size_t findPropIndex(const char *name, size_t len);
        Prop *findProp(const char *name);
        Prop *allocateProp(const char *name);
        bool removeProp(const char *name);

        size_t mPropCount;
        size_t mPropSize;
+6 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ NuPlayerDriver::NuPlayerDriver(pid_t pid)
      mPlayer(new NuPlayer(pid)),
      mPlayerFlags(0),
      mAnalyticsItem(NULL),
      mClientUid(-1),
      mAtEOS(false),
      mLooping(false),
      mAutoLoop(false) {
@@ -109,6 +110,10 @@ status_t NuPlayerDriver::initCheck() {

status_t NuPlayerDriver::setUID(uid_t uid) {
    mPlayer->setUID(uid);
    mClientUid = uid;
    if (mAnalyticsItem) {
        mAnalyticsItem->setUid(mClientUid);
    }

    return OK;
}
@@ -601,6 +606,7 @@ void NuPlayerDriver::logMetrics(const char *where) {
        mAnalyticsItem = new MediaAnalyticsItem("nuplayer");
        if (mAnalyticsItem) {
            mAnalyticsItem->generateSessionID();
            mAnalyticsItem->setUid(mClientUid);
        }
    } else {
        ALOGV("did not have anything to record");
+2 −0
Original line number Diff line number Diff line
@@ -132,11 +132,13 @@ private:
    uint32_t mPlayerFlags;

    MediaAnalyticsItem *mAnalyticsItem;
    uid_t mClientUid;

    bool mAtEOS;
    bool mLooping;
    bool mAutoLoop;


    void updateMetrics(const char *where);
    void logMetrics(const char *where);

+1 −0
Original line number Diff line number Diff line
@@ -5224,6 +5224,7 @@ MPEG4Extractor::Track *MPEG4Extractor::findTrackByMimePrefix(

void MPEG4Extractor::populateMetrics() {
    ALOGV("MPEG4Extractor::populateMetrics");
    // write into mAnalyticsItem
}

static bool LegacySniffMPEG4(
Loading