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

Commit 82a074b1 authored by Andy Hung's avatar Andy Hung
Browse files

MediaMetrics: Add const correctness for items in service

Allows multithreaded use of items without lock.

Test: mediametrics dumpsys, atest mediametrics_tests
Bug: 138583596
Change-Id: Ieb901076b9acc33a89737b320a4fc8ce82f2608d
parent 1efc9c6f
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -140,12 +140,12 @@ status_t MediaAnalyticsService::submitInternal(MediaAnalyticsItem *item, bool re
        return BAD_VALUE;
    }

    // send to statsd
    extern bool dump2Statsd(MediaAnalyticsItem *item);  // extern hook
    (void)dump2Statsd(item);  // failure should be logged in function.
    // now attach either the item or its dup to a const shared pointer
    std::shared_ptr<const MediaAnalyticsItem> sitem(release ? item : item->dup());

    if (!release) item = item->dup();
    saveItem(item);
    extern bool dump2Statsd(const std::shared_ptr<const MediaAnalyticsItem>& item);
    (void)dump2Statsd(sitem);  // failure should be logged in function.
    saveItem(sitem);
    return NO_ERROR;
}

@@ -325,7 +325,7 @@ void MediaAnalyticsService::dumpQueue_l(

// if item != NULL, it's the item we just inserted
// true == more items eligible to be recovered
bool MediaAnalyticsService::expirations_l(MediaAnalyticsItem *item)
bool MediaAnalyticsService::expirations_l(const std::shared_ptr<const MediaAnalyticsItem>& item)
{
    bool more = false;

@@ -348,7 +348,7 @@ bool MediaAnalyticsService::expirations_l(MediaAnalyticsItem *item)
        for (; i < mItems.size(); ++i) {
            auto &oitem = mItems[i];
            nsecs_t when = oitem->getTimestamp();
            if (oitem.get() == item) {
            if (oitem.get() == item.get()) {
                break;
            }
            if (now > when && (now - when) <= mMaxRecordAgeNs) {
@@ -384,7 +384,7 @@ void MediaAnalyticsService::processExpirations()
    } while (more);
}

void MediaAnalyticsService::saveItem(MediaAnalyticsItem *item)
void MediaAnalyticsService::saveItem(const std::shared_ptr<const MediaAnalyticsItem>& item)
{
    std::lock_guard _l(mLock);
    // we assume the items are roughly in time order.
+2 −2
Original line number Diff line number Diff line
@@ -66,10 +66,10 @@ private:
    // input validation after arrival from client
    static bool isContentValid(const MediaAnalyticsItem *item, bool isTrusted);
    bool isRateLimited(MediaAnalyticsItem *) const;
    void saveItem(MediaAnalyticsItem *);
    void saveItem(const std::shared_ptr<const MediaAnalyticsItem>& item);

    // The following methods are GUARDED_BY(mLock)
    bool expirations_l(MediaAnalyticsItem *);
    bool expirations_l(const std::shared_ptr<const MediaAnalyticsItem>& item);

    // support for generating output
    void dumpQueue_l(String8 &result, int dumpProto);
+4 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <pthread.h>
#include <unistd.h>

#include <memory>
#include <string.h>
#include <pwd.h>

@@ -48,7 +49,7 @@ bool enabled_statsd = true;

struct statsd_hooks {
    const char *key;
    bool (*handler)(MediaAnalyticsItem *);
    bool (*handler)(const MediaAnalyticsItem *);
};

// keep this sorted, so we can do binary searches
@@ -69,7 +70,7 @@ static constexpr struct statsd_hooks statsd_handlers[] =
};

// give me a record, i'll look at the type and upload appropriately
bool dump2Statsd(MediaAnalyticsItem *item) {
bool dump2Statsd(const std::shared_ptr<const MediaAnalyticsItem>& item) {
    if (item == NULL) return false;

    // get the key
@@ -82,7 +83,7 @@ bool dump2Statsd(MediaAnalyticsItem *item) {

    for (const auto &statsd_handler : statsd_handlers) {
        if (key == statsd_handler.key) {
            return statsd_handler.handler(item);
            return statsd_handler.handler(item.get());
        }
    }
    return false;
+11 −11
Original line number Diff line number Diff line
@@ -19,17 +19,17 @@ namespace android {
extern bool enabled_statsd;

// component specific dumpers
extern bool statsd_audiopolicy(MediaAnalyticsItem *);
extern bool statsd_audiorecord(MediaAnalyticsItem *);
extern bool statsd_audiothread(MediaAnalyticsItem *);
extern bool statsd_audiotrack(MediaAnalyticsItem *);
extern bool statsd_codec(MediaAnalyticsItem *);
extern bool statsd_extractor(MediaAnalyticsItem *);
extern bool statsd_nuplayer(MediaAnalyticsItem *);
extern bool statsd_recorder(MediaAnalyticsItem *);
extern bool statsd_audiopolicy(const MediaAnalyticsItem *);
extern bool statsd_audiorecord(const MediaAnalyticsItem *);
extern bool statsd_audiothread(const MediaAnalyticsItem *);
extern bool statsd_audiotrack(const MediaAnalyticsItem *);
extern bool statsd_codec(const MediaAnalyticsItem *);
extern bool statsd_extractor(const MediaAnalyticsItem *);
extern bool statsd_nuplayer(const MediaAnalyticsItem *);
extern bool statsd_recorder(const MediaAnalyticsItem *);

extern bool statsd_mediadrm(MediaAnalyticsItem *);
extern bool statsd_widevineCDM(MediaAnalyticsItem *);
extern bool statsd_drmmanager(MediaAnalyticsItem *);
extern bool statsd_mediadrm(const MediaAnalyticsItem *);
extern bool statsd_widevineCDM(const MediaAnalyticsItem *);
extern bool statsd_drmmanager(const MediaAnalyticsItem *);

} // namespace android
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@

namespace android {

bool statsd_audiopolicy(MediaAnalyticsItem *item)
bool statsd_audiopolicy(const MediaAnalyticsItem *item)
{
    if (item == NULL) return false;

Loading