diff --git a/drm/libmediadrm/PluginMetricsReporting.cpp b/drm/libmediadrm/PluginMetricsReporting.cpp index cc7fb722b1..26c8427c9d 100644 --- a/drm/libmediadrm/PluginMetricsReporting.cpp +++ b/drm/libmediadrm/PluginMetricsReporting.cpp @@ -80,7 +80,6 @@ status_t reportMetricsGroup(const MetricsGroup& metricsGroup, } } - analyticsItem.setFinalized(true); if (!analyticsItem.selfrecord()) { ALOGE("selfrecord() returned false. sessioId %" PRId64, sessionId); } diff --git a/media/libaudioclient/include/media/AudioRecord.h b/media/libaudioclient/include/media/AudioRecord.h index caaefce11b..893229c909 100644 --- a/media/libaudioclient/include/media/AudioRecord.h +++ b/media/libaudioclient/include/media/AudioRecord.h @@ -703,7 +703,6 @@ private: // mAnalyticsItem alloc failure will be flagged in the constructor // don't log empty records if (mAnalyticsItem->count() > 0) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); } } diff --git a/media/libaudioclient/include/media/AudioTrack.h b/media/libaudioclient/include/media/AudioTrack.h index 8fbe9806b4..e5bb854780 100644 --- a/media/libaudioclient/include/media/AudioTrack.h +++ b/media/libaudioclient/include/media/AudioTrack.h @@ -1198,7 +1198,6 @@ private: // mAnalyticsItem alloc failure will be flagged in the constructor // don't log empty records if (mAnalyticsItem->count() > 0) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); } } diff --git a/media/libmedia/nuplayer2/NuPlayer2Driver.cpp b/media/libmedia/nuplayer2/NuPlayer2Driver.cpp index ccfcc4771b..892e4d3d22 100644 --- a/media/libmedia/nuplayer2/NuPlayer2Driver.cpp +++ b/media/libmedia/nuplayer2/NuPlayer2Driver.cpp @@ -129,7 +129,6 @@ NuPlayer2Driver::NuPlayer2Driver(pid_t pid) // set up an analytics record mAnalyticsItem = new MediaAnalyticsItem(kKeyPlayer); - mAnalyticsItem->generateSessionID(); mNuPlayer2Looper->start( false, /* runOnCallingThread */ @@ -661,14 +660,12 @@ void NuPlayer2Driver::logMetrics(const char *where) { // So the canonical "empty" record has 3 elements in it. if (mAnalyticsItem->count() > 3) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); // re-init in case we prepare() and start() again. delete mAnalyticsItem ; mAnalyticsItem = new MediaAnalyticsItem(kKeyPlayer); if (mAnalyticsItem) { - mAnalyticsItem->generateSessionID(); mAnalyticsItem->setUid(mClientUid); } } else { diff --git a/media/libmediametrics/MediaAnalyticsItem.cpp b/media/libmediametrics/MediaAnalyticsItem.cpp index 2e7efadcb1..dc2bec847f 100644 --- a/media/libmediametrics/MediaAnalyticsItem.cpp +++ b/media/libmediametrics/MediaAnalyticsItem.cpp @@ -60,7 +60,7 @@ MediaAnalyticsItem::MediaAnalyticsItem() mPkgVersionCode(0), mSessionID(MediaAnalyticsItem::SessionIDNone), mTimestamp(0), - mFinalized(0), + mFinalized(1), mPropCount(0), mPropSize(0), mProps(NULL) { mKey = MediaAnalyticsItem::kKeyNone; @@ -72,7 +72,7 @@ MediaAnalyticsItem::MediaAnalyticsItem(MediaAnalyticsItem::Key key) mPkgVersionCode(0), mSessionID(MediaAnalyticsItem::SessionIDNone), mTimestamp(0), - mFinalized(0), + mFinalized(1), mPropCount(0), mPropSize(0), mProps(NULL) { if (DEBUG_ALLOCATIONS) { @@ -137,16 +137,6 @@ MediaAnalyticsItem *MediaAnalyticsItem::dup() { return dst; } -// so clients can send intermediate values to be overlaid later -MediaAnalyticsItem &MediaAnalyticsItem::setFinalized(bool value) { - mFinalized = value; - return *this; -} - -bool MediaAnalyticsItem::getFinalized() const { - return mFinalized; -} - MediaAnalyticsItem &MediaAnalyticsItem::setSessionID(MediaAnalyticsItem::SessionID_t id) { mSessionID = id; return *this; @@ -636,7 +626,10 @@ int32_t MediaAnalyticsItem::readFromParcel(const Parcel& data) { mPkgName = data.readCString(); mPkgVersionCode = data.readInt64(); mSessionID = data.readInt64(); + // We no longer pay attention to user setting of finalized, BUT it's + // still part of the wire packet -- so read & discard. mFinalized = data.readInt32(); + mFinalized = 1; mTimestamp = data.readInt64(); int count = data.readInt32(); @@ -978,9 +971,6 @@ bool MediaAnalyticsItem::merge(MediaAnalyticsItem *incoming) { mSessionID = incoming->mSessionID; } - // we always take the more recent 'finalized' value - setFinalized(incoming->getFinalized()); - // for each attribute from 'incoming', resolve appropriately int nattr = incoming->mPropCount; for (int i = 0 ; i < nattr; i++ ) { diff --git a/media/libmediametrics/include/MediaAnalyticsItem.h b/media/libmediametrics/include/MediaAnalyticsItem.h index 79ff09329e..263cde7858 100644 --- a/media/libmediametrics/include/MediaAnalyticsItem.h +++ b/media/libmediametrics/include/MediaAnalyticsItem.h @@ -89,10 +89,6 @@ class MediaAnalyticsItem { MediaAnalyticsItem(Key); ~MediaAnalyticsItem(); - // so clients can send intermediate values to be overlaid later - MediaAnalyticsItem &setFinalized(bool); - bool getFinalized() const; - // SessionID ties multiple submissions for same key together // so that if video "height" and "width" are known at one point // and "framerate" is only known later, they can be be brought diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp index 77eaefeb86..458b8718ee 100644 --- a/media/libmediaplayerservice/StagefrightRecorder.cpp +++ b/media/libmediaplayerservice/StagefrightRecorder.cpp @@ -125,7 +125,6 @@ StagefrightRecorder::~StagefrightRecorder() { if (mAnalyticsDirty && mAnalyticsItem != NULL) { updateMetrics(); if (mAnalyticsItem->count() > 0) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); } delete mAnalyticsItem; @@ -185,14 +184,12 @@ void StagefrightRecorder::resetMetrics() { if (mAnalyticsDirty && mAnalyticsItem != NULL) { updateMetrics(); if (mAnalyticsItem->count() > 0) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); } delete mAnalyticsItem; mAnalyticsItem = NULL; } mAnalyticsItem = new MediaAnalyticsItem(kKeyRecorder); - (void) mAnalyticsItem->generateSessionID(); mAnalyticsDirty = false; } diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp index 8aa06fc149..b3fd00a6e4 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp @@ -91,7 +91,6 @@ NuPlayerDriver::NuPlayerDriver(pid_t pid) // set up an analytics record mAnalyticsItem = new MediaAnalyticsItem(kKeyPlayer); - mAnalyticsItem->generateSessionID(); mLooper->start( false, /* runOnCallingThread */ @@ -617,14 +616,12 @@ void NuPlayerDriver::logMetrics(const char *where) { // So the canonical "empty" record has 3 elements in it. if (mAnalyticsItem->count() > 3) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); // re-init in case we prepare() and start() again. delete mAnalyticsItem ; mAnalyticsItem = new MediaAnalyticsItem("nuplayer"); if (mAnalyticsItem) { - mAnalyticsItem->generateSessionID(); mAnalyticsItem->setUid(mClientUid); } } else { diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index 559b1087d5..56ac3ed16f 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -502,7 +502,6 @@ void MediaCodec::initAnalyticsItem() { // set up our new record, get a sessionID, put it into the in-progress list mAnalyticsItem = new MediaAnalyticsItem(kCodecKeyName); if (mAnalyticsItem != NULL) { - (void) mAnalyticsItem->generateSessionID(); // don't record it yet; only at the end, when we have decided that we have // data worth writing (e.g. .count() > 0) } @@ -512,7 +511,6 @@ void MediaCodec::flushAnalyticsItem() { if (mAnalyticsItem != NULL) { // don't log empty records if (mAnalyticsItem->count() > 0) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); } delete mAnalyticsItem; diff --git a/media/libstagefright/RemoteMediaExtractor.cpp b/media/libstagefright/RemoteMediaExtractor.cpp index 12654d9602..2ee24ab4ec 100644 --- a/media/libstagefright/RemoteMediaExtractor.cpp +++ b/media/libstagefright/RemoteMediaExtractor.cpp @@ -44,7 +44,6 @@ RemoteMediaExtractor::RemoteMediaExtractor( mAnalyticsItem = nullptr; if (MEDIA_LOG) { mAnalyticsItem = new MediaAnalyticsItem(kKeyExtractor); - (void) mAnalyticsItem->generateSessionID(); // track the container format (mpeg, aac, wvm, etc) size_t ntracks = extractor->countTracks(); @@ -73,7 +72,6 @@ RemoteMediaExtractor::~RemoteMediaExtractor() { if (MEDIA_LOG) { if (mAnalyticsItem != nullptr) { if (mAnalyticsItem->count() > 0) { - mAnalyticsItem->setFinalized(true); mAnalyticsItem->selfrecord(); } } diff --git a/services/mediaanalytics/MediaAnalyticsService.cpp b/services/mediaanalytics/MediaAnalyticsService.cpp index a132e25fe9..6d84a42442 100644 --- a/services/mediaanalytics/MediaAnalyticsService.cpp +++ b/services/mediaanalytics/MediaAnalyticsService.cpp @@ -100,9 +100,6 @@ MediaAnalyticsService::MediaAnalyticsService() mDumpProtoDefault(MediaAnalyticsItem::PROTO_V1) { ALOGD("MediaAnalyticsService created"); - // clear our queues - mOpen = new List(); - mFinalized = new List(); mItemsSubmitted = 0; mItemsFinalized = 0; @@ -118,26 +115,13 @@ MediaAnalyticsService::MediaAnalyticsService() MediaAnalyticsService::~MediaAnalyticsService() { ALOGD("MediaAnalyticsService destroyed"); - // clean out mOpen and mFinalized - while (mOpen->size() > 0) { - MediaAnalyticsItem * oitem = *(mOpen->begin()); - mOpen->erase(mOpen->begin()); + while (mItems.size() > 0) { + MediaAnalyticsItem * oitem = *(mItems.begin()); + mItems.erase(mItems.begin()); delete oitem; mItemsDiscarded++; mItemsDiscardedCount++; } - delete mOpen; - mOpen = NULL; - - while (mFinalized->size() > 0) { - MediaAnalyticsItem * oitem = *(mFinalized->begin()); - mFinalized->erase(mFinalized->begin()); - delete oitem; - mItemsDiscarded++; - mItemsDiscardedCount++; - } - delete mFinalized; - mFinalized = NULL; } @@ -149,9 +133,14 @@ MediaAnalyticsItem::SessionID_t MediaAnalyticsService::generateUniqueSessionID() } // caller surrenders ownership of 'item' -MediaAnalyticsItem::SessionID_t MediaAnalyticsService::submit(MediaAnalyticsItem *item, bool forcenew) { +MediaAnalyticsItem::SessionID_t MediaAnalyticsService::submit(MediaAnalyticsItem *item, bool forcenew) +{ + UNUSED(forcenew); - MediaAnalyticsItem::SessionID_t id = MediaAnalyticsItem::SessionIDInvalid; + // fill in a sessionID if we do not yet have one + if (item->getSessionID() <= MediaAnalyticsItem::SessionIDNone) { + item->setSessionID(generateUniqueSessionID()); + } // we control these, generally not trusting user input nsecs_t now = systemTime(SYSTEM_TIME_REALTIME); @@ -164,9 +153,7 @@ MediaAnalyticsItem::SessionID_t MediaAnalyticsService::submit(MediaAnalyticsItem int uid_given = item->getUid(); int pid_given = item->getPid(); - // although we do make exceptions for particular client uids - // that we know we trust. - // + // although we do make exceptions for some trusted client uids bool isTrusted = false; ALOGV("caller has uid=%d, embedded uid=%d", uid, uid_given); @@ -192,7 +179,6 @@ MediaAnalyticsItem::SessionID_t MediaAnalyticsService::submit(MediaAnalyticsItem break; } - // Overwrite package name and version if the caller was untrusted. if (!isTrusted) { setPkgInfo(item, item->getUid(), true, true); @@ -217,75 +203,23 @@ MediaAnalyticsItem::SessionID_t MediaAnalyticsService::submit(MediaAnalyticsItem return MediaAnalyticsItem::SessionIDInvalid; } - - // if we have a sesisonid in the new record, look to make + // XXX: if we have a sessionid in the new record, look to make // sure it doesn't appear in the finalized list. // XXX: this is for security / DOS prevention. // may also require that we persist the unique sessionIDs // across boots [instead of within a single boot] - - // match this new record up against records in the open - // list... - // if there's a match, merge them together - // deal with moving the old / merged record into the finalized que - - bool finalizing = item->getFinalized(); - - Mutex::Autolock _l(mLock); - - // if finalizing, we'll remove it - MediaAnalyticsItem *oitem = findItem(mOpen, item, finalizing | forcenew); - if (oitem != NULL) { - if (forcenew) { - // old one gets finalized, then we insert the new one - // so we'll have 2 records at the end of this. - // but don't finalize an empty record - if (oitem->count() == 0) { - // we're responsible for disposing of the dead record - delete oitem; - oitem = NULL; - } else { - oitem->setFinalized(true); - saveItem(mFinalized, oitem, 0); - } - // new record could itself be marked finalized... - id = item->getSessionID(); - if (finalizing) { - saveItem(mFinalized, item, 0); - mItemsFinalized++; - } else { - saveItem(mOpen, item, 1); - } - } else { - // combine the records, send it to finalized if appropriate - oitem->merge(item); - id = oitem->getSessionID(); - if (finalizing) { - saveItem(mFinalized, oitem, 0); - mItemsFinalized++; - } - - // we're responsible for disposing of the dead record - delete item; - item = NULL; - } - } else { - // nothing to merge, save the new record - id = item->getSessionID(); - if (finalizing) { - if (item->count() == 0) { - // drop empty records - delete item; - item = NULL; - } else { - saveItem(mFinalized, item, 0); - mItemsFinalized++; - } - } else { - saveItem(mOpen, item, 1); - } + if (item->count() == 0) { + // drop empty records + delete item; + item = NULL; + return MediaAnalyticsItem::SessionIDInvalid; } + + // save the new record + MediaAnalyticsItem::SessionID_t id = item->getSessionID(); + saveItem(item); + mItemsFinalized++; return id; } @@ -378,6 +312,7 @@ status_t MediaAnalyticsService::dump(int fd, const Vector& args) } Mutex::Autolock _l(mLock); + // mutex between insertion and dumping the contents mDumpProto = chosenProto; @@ -392,9 +327,9 @@ status_t MediaAnalyticsService::dump(int fd, const Vector& args) if (clear) { // remove everything from the finalized queue - while (mFinalized->size() > 0) { - MediaAnalyticsItem * oitem = *(mFinalized->begin()); - mFinalized->erase(mFinalized->begin()); + while (mItems.size() > 0) { + MediaAnalyticsItem * oitem = *(mItems.begin()); + mItems.erase(mItems.begin()); delete oitem; mItemsDiscarded++; } @@ -408,7 +343,8 @@ status_t MediaAnalyticsService::dump(int fd, const Vector& args) } // dump headers -void MediaAnalyticsService::dumpHeaders(String8 &result, nsecs_t ts_since) { +void MediaAnalyticsService::dumpHeaders(String8 &result, nsecs_t ts_since) +{ const size_t SIZE = 512; char buffer[SIZE]; @@ -425,7 +361,7 @@ void MediaAnalyticsService::dumpHeaders(String8 &result, nsecs_t ts_since) { snprintf(buffer, SIZE, "Since Boot: Submissions: %8" PRId64 - " Finalizations: %8" PRId64 "\n", + " Accepted: %8" PRId64 "\n", mItemsSubmitted, mItemsFinalized); result.append(buffer); snprintf(buffer, SIZE, @@ -433,19 +369,17 @@ void MediaAnalyticsService::dumpHeaders(String8 &result, nsecs_t ts_since) { " (by Count: %" PRId64 " by Expiration: %" PRId64 ")\n", mItemsDiscarded, mItemsDiscardedCount, mItemsDiscardedExpire); result.append(buffer); - snprintf(buffer, SIZE, - "Summary Sets Discarded: %" PRId64 "\n", mSetsDiscarded); - result.append(buffer); if (ts_since != 0) { snprintf(buffer, SIZE, - "Dumping Queue entries more recent than: %" PRId64 "\n", + "Emitting Queue entries more recent than: %" PRId64 "\n", (int64_t) ts_since); result.append(buffer); } } // the recent, detailed queues -void MediaAnalyticsService::dumpRecent(String8 &result, nsecs_t ts_since, const char * only) { +void MediaAnalyticsService::dumpRecent(String8 &result, nsecs_t ts_since, const char * only) +{ const size_t SIZE = 512; char buffer[SIZE]; @@ -456,30 +390,27 @@ void MediaAnalyticsService::dumpRecent(String8 &result, nsecs_t ts_since, const // show the recently recorded records snprintf(buffer, sizeof(buffer), "\nFinalized Metrics (oldest first):\n"); result.append(buffer); - result.append(this->dumpQueue(mFinalized, ts_since, only)); - - snprintf(buffer, sizeof(buffer), "\nIn-Progress Metrics (newest first):\n"); - result.append(buffer); - result.append(this->dumpQueue(mOpen, ts_since, only)); + result.append(this->dumpQueue(ts_since, only)); // show who is connected and injecting records? // talk about # records fed to the 'readers' // talk about # records we discarded, perhaps "discarded w/o reading" too } + // caller has locked mLock... -String8 MediaAnalyticsService::dumpQueue(List *theList) { - return dumpQueue(theList, (nsecs_t) 0, NULL); +String8 MediaAnalyticsService::dumpQueue() { + return dumpQueue((nsecs_t) 0, NULL); } -String8 MediaAnalyticsService::dumpQueue(List *theList, nsecs_t ts_since, const char * only) { +String8 MediaAnalyticsService::dumpQueue(nsecs_t ts_since, const char * only) { String8 result; int slot = 0; - if (theList->empty()) { + if (mItems.empty()) { result.append("empty\n"); } else { - List::iterator it = theList->begin(); - for (; it != theList->end(); it++) { + List::iterator it = mItems.begin(); + for (; it != mItems.end(); it++) { nsecs_t when = (*it)->getTimestamp(); if (when < ts_since) { continue; @@ -500,35 +431,25 @@ String8 MediaAnalyticsService::dumpQueue(List *theList, ns // // Our Cheap in-core, non-persistent records management. -// XXX: rewrite this to manage persistence, etc. // insert appropriately into queue -// caller should hold mLock -void MediaAnalyticsService::saveItem(List *l, MediaAnalyticsItem * item, int front) { - - if (front) { - // for non-finalized stuff, since we expect to reference it again soon, - // make it quicker to find (nearer the front of our list) - l->push_front(item); - } else { - // for finalized records, which we want to dump 'in sequence order' - l->push_back(item); - } +void MediaAnalyticsService::saveItem(MediaAnalyticsItem * item) +{ - // our reclaim process is for oldest-first queues - if (front) { - return; - } + Mutex::Autolock _l(mLock); + // mutex between insertion and dumping the contents + // we want to dump 'in FIFO order', so insert at the end + mItems.push_back(item); // keep removing old records the front until we're in-bounds (count) if (mMaxRecords > 0) { - while (l->size() > (size_t) mMaxRecords) { - MediaAnalyticsItem * oitem = *(l->begin()); + while (mItems.size() > (size_t) mMaxRecords) { + MediaAnalyticsItem * oitem = *(mItems.begin()); if (oitem == item) { break; } - l->erase(l->begin()); + mItems.erase(mItems.begin()); delete oitem; mItemsDiscarded++; mItemsDiscardedCount++; @@ -536,10 +457,11 @@ void MediaAnalyticsService::saveItem(List *l, MediaAnalyti } // keep removing old records the front until we're in-bounds (count) + // NB: expired entries aren't removed until the next insertion, which could be a while if (mMaxRecordAgeNs > 0) { nsecs_t now = systemTime(SYSTEM_TIME_REALTIME); - while (l->size() > 0) { - MediaAnalyticsItem * oitem = *(l->begin()); + while (mItems.size() > 0) { + MediaAnalyticsItem * oitem = *(mItems.begin()); nsecs_t when = oitem->getTimestamp(); if (oitem == item) { break; @@ -549,7 +471,7 @@ void MediaAnalyticsService::saveItem(List *l, MediaAnalyti // this (and the rest) are recent enough to keep break; } - l->erase(l->begin()); + mItems.erase(mItems.begin()); delete oitem; mItemsDiscarded++; mItemsDiscardedExpire++; @@ -557,79 +479,6 @@ void MediaAnalyticsService::saveItem(List *l, MediaAnalyti } } -// are they alike enough that nitem can be folded into oitem? -static bool compatibleItems(MediaAnalyticsItem * oitem, MediaAnalyticsItem * nitem) { - - // general safety - if (nitem->getUid() != oitem->getUid()) { - return false; - } - if (nitem->getPid() != oitem->getPid()) { - return false; - } - - // key -- needs to match - if (nitem->getKey() == oitem->getKey()) { - // still in the game. - } else { - return false; - } - - // session id -- empty field in new is allowed - MediaAnalyticsItem::SessionID_t osession = oitem->getSessionID(); - MediaAnalyticsItem::SessionID_t nsession = nitem->getSessionID(); - if (nsession != osession) { - // incoming '0' matches value in osession - if (nsession != 0) { - return false; - } - } - - return true; -} - -// find the incomplete record that this will overlay -// caller should hold mLock -MediaAnalyticsItem *MediaAnalyticsService::findItem(List *theList, MediaAnalyticsItem *nitem, bool removeit) { - if (nitem == NULL) { - return NULL; - } - - MediaAnalyticsItem *item = NULL; - - for (List::iterator it = theList->begin(); - it != theList->end(); it++) { - MediaAnalyticsItem *tmp = (*it); - - if (!compatibleItems(tmp, nitem)) { - continue; - } - - // we match! this is the one I want. - if (removeit) { - theList->erase(it); - } - item = tmp; - break; - } - return item; -} - - -// delete the indicated record -// caller should hold mLock -void MediaAnalyticsService::deleteItem(List *l, MediaAnalyticsItem *item) { - - for (List::iterator it = l->begin(); - it != l->end(); it++) { - if ((*it)->getSessionID() != item->getSessionID()) - continue; - delete *it; - l->erase(it); - break; - } -} - static std::string allowedKeys[] = { "audiorecord", @@ -676,7 +525,9 @@ bool MediaAnalyticsService::rateLimited(MediaAnalyticsItem *) { #define PKG_EXPIRATION_NS (30*60*1000000000ll) // 30 minutes, in nsecs // give me the package name, perhaps going to find it -void MediaAnalyticsService::setPkgInfo(MediaAnalyticsItem *item, uid_t uid, bool setName, bool setVersion) { +// manages its own mutex operations internally +void MediaAnalyticsService::setPkgInfo(MediaAnalyticsItem *item, uid_t uid, bool setName, bool setVersion) +{ ALOGV("asking for packagename to go with uid=%d", uid); if (!setName && !setVersion) { @@ -686,22 +537,26 @@ void MediaAnalyticsService::setPkgInfo(MediaAnalyticsItem *item, uid_t uid, bool nsecs_t now = systemTime(SYSTEM_TIME_REALTIME); struct UidToPkgMap mapping; - mapping.uid = (-1); - - ssize_t i = mPkgMappings.indexOfKey(uid); - if (i >= 0) { - mapping = mPkgMappings.valueAt(i); - ALOGV("Expiration? uid %d expiration %" PRId64 " now %" PRId64, - uid, mapping.expiration, now); - if (mapping.expiration < now) { - // purge our current entry and re-query - ALOGV("entry for uid %d expired, now= %" PRId64 "", uid, now); - mPkgMappings.removeItemsAt(i, 1); - // could cheat and use a goto back to the top of the routine. - // a good compiler should recognize the local tail recursion... - return setPkgInfo(item, uid, setName, setVersion); + mapping.uid = (uid_t)(-1); + + { + Mutex::Autolock _l(mLock_mappings); + int i = mPkgMappings.indexOfKey(uid); + if (i >= 0) { + mapping = mPkgMappings.valueAt(i); + ALOGV("Expiration? uid %d expiration %" PRId64 " now %" PRId64, + uid, mapping.expiration, now); + if (mapping.expiration <= now) { + // purge the stale entry and fall into re-fetching + ALOGV("entry for uid %d expired, now= %" PRId64 "", uid, now); + mPkgMappings.removeItemsAt(i); + mapping.uid = (uid_t)(-1); + } } - } else { + } + + // if we did not find it + if (mapping.uid == (uid_t)(-1)) { std::string pkg; std::string installer = ""; int64_t versionCode = 0; @@ -711,7 +566,7 @@ void MediaAnalyticsService::setPkgInfo(MediaAnalyticsItem *item, uid_t uid, bool pkg = pw->pw_name; } - // find the proper value -- should we cache this binder?? + // find the proper value sp binder = NULL; sp sm = defaultServiceManager(); diff --git a/services/mediaanalytics/MediaAnalyticsService.h b/services/mediaanalytics/MediaAnalyticsService.h index 484339c3b9..b3c902a496 100644 --- a/services/mediaanalytics/MediaAnalyticsService.h +++ b/services/mediaanalytics/MediaAnalyticsService.h @@ -53,7 +53,6 @@ class MediaAnalyticsService : public BnMediaAnalyticsService int64_t mItemsDiscarded; int64_t mItemsDiscardedExpire; int64_t mItemsDiscardedCount; - int64_t mSetsDiscarded; MediaAnalyticsItem::SessionID_t mLastSessionID; // partitioned a bit so we don't over serialize @@ -76,25 +75,15 @@ class MediaAnalyticsService : public BnMediaAnalyticsService bool contentValid(MediaAnalyticsItem *item, bool isTrusted); bool rateLimited(MediaAnalyticsItem *); - // the ones that are still open - // (newest at front) since we keep looking for them - List *mOpen; - // the ones we've finalized // (oldest at front) so it prints nicely for dumpsys - List *mFinalized; - // searching within these queues: queue, key - MediaAnalyticsItem *findItem(List *, - MediaAnalyticsItem *, bool removeit); - - void saveItem(MediaAnalyticsItem); - void saveItem(List *, MediaAnalyticsItem *, int); - void deleteItem(List *, MediaAnalyticsItem *); + List mItems; + void saveItem(MediaAnalyticsItem *); // support for generating output int mDumpProto; int mDumpProtoDefault; - String8 dumpQueue(List *); - String8 dumpQueue(List *, nsecs_t, const char *only); + String8 dumpQueue(); + String8 dumpQueue(nsecs_t, const char *only); void dumpHeaders(String8 &result, nsecs_t ts_since); void dumpSummaries(String8 &result, nsecs_t ts_since, const char * only);