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

Commit 58e944d9 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge changes I76cdcce4,Ide5e9218

* changes:
  MediaMetrics: Update to use fluent style recording
  MediaMetrics: Make submit one-way
parents cd75394e aeef788a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ void DrmManager::reportEngineMetrics(
    IDrmEngine& engine = mPlugInManager.getPlugIn(plugInId);

    std::unique_ptr<MediaAnalyticsItem> item(MediaAnalyticsItem::create("drmmanager"));
    item->generateSessionID();
    item->setUid(IPCThreadState::self()->getCallingUid());
    item->setCString("function_name", func);
    item->setCString("plugin_id", plugInId.getPathLeaf().getBasePath().c_str());
+0 −1
Original line number Diff line number Diff line
@@ -1598,7 +1598,6 @@ void DrmHal::writeByteArray(Parcel &obj, hidl_vec<uint8_t> const &vec)
void DrmHal::reportFrameworkMetrics() const
{
    std::unique_ptr<MediaAnalyticsItem> item(MediaAnalyticsItem::create("mediadrm"));
    item->generateSessionID();
    item->setPkgName(mMetrics.GetAppPackageName().c_str());
    String8 vendor;
    String8 description;
+1 −3
Original line number Diff line number Diff line
@@ -35,8 +35,6 @@ status_t reportVendorMetrics(const std::string& metrics,
                             const String8& name,
                             const String8& appPackageName) {
    std::unique_ptr<MediaAnalyticsItem> analyticsItem(MediaAnalyticsItem::create(name.c_str()));
    analyticsItem->generateSessionID();

    std::string app_package_name(appPackageName.c_str(), appPackageName.size());
    analyticsItem->setPkgName(app_package_name);
    if (metrics.size() > 0) {
@@ -44,7 +42,7 @@ status_t reportVendorMetrics(const std::string& metrics,
    }

    if (!analyticsItem->selfrecord()) {
      ALOGE("selfrecord() returned false. sessioId %" PRId64, analyticsItem->getSessionID());
      ALOGE("%s: selfrecord() returned false", __func__);
    }

    return OK;
+24 −93
Original line number Diff line number Diff line
@@ -32,15 +32,10 @@
#include <media/MediaAnalyticsItem.h>
#include <media/IMediaAnalyticsService.h>

#define DEBUGGING               0
#define DEBUGGING_FLOW          0
#define DEBUGGING_RETURNS       0

namespace android {

enum {
    GENERATE_UNIQUE_SESSIONID = IBinder::FIRST_CALL_TRANSACTION,
    SUBMIT_ITEM,
    SUBMIT_ITEM_ONEWAY = IBinder::FIRST_CALL_TRANSACTION,
};

class BpMediaAnalyticsService: public BpInterface<IMediaAnalyticsService>
@@ -51,61 +46,23 @@ public:
    {
    }

    virtual MediaAnalyticsItem::SessionID_t generateUniqueSessionID() {
        Parcel data, reply;
        status_t err;
        MediaAnalyticsItem::SessionID_t sessionid =
                        MediaAnalyticsItem::SessionIDInvalid;

        data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor());
        err = remote()->transact(GENERATE_UNIQUE_SESSIONID, data, &reply);
        if (err != NO_ERROR) {
            ALOGW("bad response from service for generateSessionId, err=%d", err);
            return MediaAnalyticsItem::SessionIDInvalid;
        }
        sessionid = reply.readInt64();
        if (DEBUGGING_RETURNS) {
            ALOGD("the caller gets a sessionid of %" PRId64 " back", sessionid);
        }
        return sessionid;
    }

    virtual MediaAnalyticsItem::SessionID_t submit(MediaAnalyticsItem *item, bool forcenew)
    status_t submit(MediaAnalyticsItem *item) override
    {
        // have this record submit itself
        // this will be a binder call with appropriate timing
        // return value is the uuid that the system generated for it.
        // the return value 0 and -1 are reserved.
        // -1 to indicate that there was a problem recording...

        Parcel data, reply;
        status_t err;

        if (item == NULL) {
                return MediaAnalyticsItem::SessionIDInvalid;
        if (item == nullptr) {
            return BAD_VALUE;
        }
        ALOGV("%s: (ONEWAY) item=%s", __func__, item->toString().c_str());

        Parcel data;
        data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor());
        if(DEBUGGING_FLOW) {
            ALOGD("client offers record: %s", item->toString().c_str());
        }
        data.writeBool(forcenew);
        item->writeToParcel(&data);

        err = remote()->transact(SUBMIT_ITEM, data, &reply);
        if (err != NO_ERROR) {
            ALOGW("bad response from service for submit, err=%d", err);
            return MediaAnalyticsItem::SessionIDInvalid;
        }

        // get an answer out of 'reply'
        int64_t sessionid = reply.readInt64();
        if (DEBUGGING_RETURNS) {
            ALOGD("the caller gets sessionid=%" PRId64 "", sessionid);
        status_t err = remote()->transact(
                SUBMIT_ITEM_ONEWAY, data, nullptr /* reply */, IBinder::FLAG_ONEWAY);
        ALOGW_IF(err != NO_ERROR, "%s: bad response from service for submit, err=%d",
                __func__, err);
        return err;
    }
        return sessionid;
    }

};

IMPLEMENT_META_INTERFACE(MediaAnalyticsService, "android.media.IMediaAnalyticsService");
@@ -115,44 +72,18 @@ IMPLEMENT_META_INTERFACE(MediaAnalyticsService, "android.media.IMediaAnalyticsSe
status_t BnMediaAnalyticsService::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{


    // get calling pid/tid
    IPCThreadState *ipc = IPCThreadState::self();
    int clientPid = ipc->getCallingPid();
    // permission checking

    if(DEBUGGING_FLOW) {
        ALOGD("running in service, code %d, pid %d; called from pid %d",
            code, getpid(), clientPid);
    }
    const int clientPid = IPCThreadState::self()->getCallingPid();

    switch (code) {

        case GENERATE_UNIQUE_SESSIONID: {
    case SUBMIT_ITEM_ONEWAY: {
        CHECK_INTERFACE(IMediaAnalyticsService, data, reply);

            MediaAnalyticsItem::SessionID_t sessionid = generateUniqueSessionID();
            reply->writeInt64(sessionid);

            return NO_ERROR;
        } break;

        case SUBMIT_ITEM: {
            CHECK_INTERFACE(IMediaAnalyticsService, data, reply);

            bool forcenew;
            MediaAnalyticsItem *item = MediaAnalyticsItem::create();

            data.readBool(&forcenew);
            item->readFromParcel(data);

        MediaAnalyticsItem * const item = MediaAnalyticsItem::create();
        if (item->readFromParcel(data) < 0) {
            return BAD_VALUE;
        }
        item->setPid(clientPid);

            // submit() takes over ownership of 'item'
            MediaAnalyticsItem::SessionID_t sessionid = submit(item, forcenew);
            reply->writeInt64(sessionid);

        const status_t status __unused = submitInternal(item, true /* release */);
        return NO_ERROR;
    } break;

Loading