Loading media/libmediametrics/IMediaAnalyticsService.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ public: data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor()); data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor()); err = remote()->transact(GENERATE_UNIQUE_SESSIONID, data, &reply); err = remote()->transact(GENERATE_UNIQUE_SESSIONID, data, &reply); if (err != NO_ERROR) { if (err != NO_ERROR) { ALOGW("bad response from service"); ALOGW("bad response from service for generateSessionId, err=%d", err); return MediaAnalyticsItem::SessionIDInvalid; return MediaAnalyticsItem::SessionIDInvalid; } } sessionid = reply.readInt64(); sessionid = reply.readInt64(); Loading Loading @@ -94,6 +94,7 @@ public: err = remote()->transact(SUBMIT_ITEM, data, &reply); err = remote()->transact(SUBMIT_ITEM, data, &reply); if (err != NO_ERROR) { if (err != NO_ERROR) { ALOGW("bad response from service for submit, err=%d", err); return MediaAnalyticsItem::SessionIDInvalid; return MediaAnalyticsItem::SessionIDInvalid; } } Loading media/libmediametrics/MediaAnalyticsItem.cpp +36 −8 Original line number Original line Diff line number Diff line Loading @@ -820,11 +820,16 @@ bool MediaAnalyticsItem::selfrecord(bool forcenew) { sp<IMediaAnalyticsService> svc = getInstance(); sp<IMediaAnalyticsService> svc = getInstance(); if (svc != NULL) { if (svc != NULL) { svc->submit(this, forcenew); MediaAnalyticsItem::SessionID_t newid = svc->submit(this, forcenew); if (newid == SessionIDInvalid) { AString p = this->toString(); ALOGW("Failed to record: %s [forcenew=%d]", p.c_str(), forcenew); return false; } return true; return true; } else { } else { AString p = this->toString(); AString p = this->toString(); ALOGD("Unable to record: %s [forcenew=%d]", p.c_str(), forcenew); ALOGW("Unable to record: %s [forcenew=%d]", p.c_str(), forcenew); return false; return false; } } } } Loading @@ -833,6 +838,7 @@ bool MediaAnalyticsItem::selfrecord(bool forcenew) { // static // static sp<IMediaAnalyticsService> MediaAnalyticsItem::sAnalyticsService; sp<IMediaAnalyticsService> MediaAnalyticsItem::sAnalyticsService; static Mutex sInitMutex; static Mutex sInitMutex; static int remainingBindAttempts = SVC_TRIES; //static //static bool MediaAnalyticsItem::isEnabled() { bool MediaAnalyticsItem::isEnabled() { Loading @@ -850,10 +856,28 @@ bool MediaAnalyticsItem::isEnabled() { return true; return true; } } // monitor health of our connection to the metrics service class MediaMetricsDeathNotifier : public IBinder::DeathRecipient { virtual void binderDied(const wp<IBinder> &) { ALOGW("Reacquire service connection on next request"); MediaAnalyticsItem::dropInstance(); } }; static sp<MediaMetricsDeathNotifier> sNotifier = NULL; // static void MediaAnalyticsItem::dropInstance() { Mutex::Autolock _l(sInitMutex); remainingBindAttempts = SVC_TRIES; sAnalyticsService = NULL; } //static //static sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { static const char *servicename = "media.metrics"; static const char *servicename = "media.metrics"; static int tries_remaining = SVC_TRIES; int enabled = isEnabled(); int enabled = isEnabled(); if (enabled == false) { if (enabled == false) { Loading Loading @@ -885,15 +909,20 @@ sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { Mutex::Autolock _l(sInitMutex); Mutex::Autolock _l(sInitMutex); const char *badness = ""; const char *badness = ""; // think of tries_remaining as telling us whether service==NULL because // think of remainingBindAttempts as telling us whether service==NULL because // (1) we haven't tried to initialize it yet // (1) we haven't tried to initialize it yet // (2) we've tried to initialize it, but failed. // (2) we've tried to initialize it, but failed. if (sAnalyticsService == NULL && tries_remaining > 0) { if (sAnalyticsService == NULL && remainingBindAttempts > 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IServiceManager> sm = defaultServiceManager(); if (sm != NULL) { if (sm != NULL) { sp<IBinder> binder = sm->getService(String16(servicename)); sp<IBinder> binder = sm->getService(String16(servicename)); if (binder != NULL) { if (binder != NULL) { sAnalyticsService = interface_cast<IMediaAnalyticsService>(binder); sAnalyticsService = interface_cast<IMediaAnalyticsService>(binder); if (sNotifier != NULL) { sNotifier = NULL; } sNotifier = new MediaMetricsDeathNotifier(); binder->linkToDeath(sNotifier); } else { } else { badness = "did not find service"; badness = "did not find service"; } } Loading @@ -902,8 +931,8 @@ sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { } } if (sAnalyticsService == NULL) { if (sAnalyticsService == NULL) { if (tries_remaining > 0) { if (remainingBindAttempts > 0) { tries_remaining--; remainingBindAttempts--; } } if (DEBUG_SERVICEACCESS) { if (DEBUG_SERVICEACCESS) { ALOGD("Unable to bind to service %s: %s", servicename, badness); ALOGD("Unable to bind to service %s: %s", servicename, badness); Loading @@ -915,7 +944,6 @@ sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { } } } } // merge the info from 'incoming' into this record. // merge the info from 'incoming' into this record. // we finish with a union of this+incoming and special handling for collisions // we finish with a union of this+incoming and special handling for collisions bool MediaAnalyticsItem::merge(MediaAnalyticsItem *incoming) { bool MediaAnalyticsItem::merge(MediaAnalyticsItem *incoming) { Loading media/libmediametrics/include/MediaAnalyticsItem.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -42,6 +42,7 @@ class MediaAnalyticsItem { friend class IMediaAnalyticsService; friend class IMediaAnalyticsService; friend class MediaMetricsJNI; friend class MediaMetricsJNI; friend class MetricsSummarizer; friend class MetricsSummarizer; friend class MediaMetricsDeathNotifier; public: public: Loading Loading @@ -209,6 +210,7 @@ class MediaAnalyticsItem { // let's reuse a binder connection // let's reuse a binder connection static sp<IMediaAnalyticsService> sAnalyticsService; static sp<IMediaAnalyticsService> sAnalyticsService; static sp<IMediaAnalyticsService> getInstance(); static sp<IMediaAnalyticsService> getInstance(); static void dropInstance(); // tracking information // tracking information SessionID_t mSessionID; // grouping similar records SessionID_t mSessionID; // grouping similar records Loading Loading
media/libmediametrics/IMediaAnalyticsService.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ public: data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor()); data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor()); err = remote()->transact(GENERATE_UNIQUE_SESSIONID, data, &reply); err = remote()->transact(GENERATE_UNIQUE_SESSIONID, data, &reply); if (err != NO_ERROR) { if (err != NO_ERROR) { ALOGW("bad response from service"); ALOGW("bad response from service for generateSessionId, err=%d", err); return MediaAnalyticsItem::SessionIDInvalid; return MediaAnalyticsItem::SessionIDInvalid; } } sessionid = reply.readInt64(); sessionid = reply.readInt64(); Loading Loading @@ -94,6 +94,7 @@ public: err = remote()->transact(SUBMIT_ITEM, data, &reply); err = remote()->transact(SUBMIT_ITEM, data, &reply); if (err != NO_ERROR) { if (err != NO_ERROR) { ALOGW("bad response from service for submit, err=%d", err); return MediaAnalyticsItem::SessionIDInvalid; return MediaAnalyticsItem::SessionIDInvalid; } } Loading
media/libmediametrics/MediaAnalyticsItem.cpp +36 −8 Original line number Original line Diff line number Diff line Loading @@ -820,11 +820,16 @@ bool MediaAnalyticsItem::selfrecord(bool forcenew) { sp<IMediaAnalyticsService> svc = getInstance(); sp<IMediaAnalyticsService> svc = getInstance(); if (svc != NULL) { if (svc != NULL) { svc->submit(this, forcenew); MediaAnalyticsItem::SessionID_t newid = svc->submit(this, forcenew); if (newid == SessionIDInvalid) { AString p = this->toString(); ALOGW("Failed to record: %s [forcenew=%d]", p.c_str(), forcenew); return false; } return true; return true; } else { } else { AString p = this->toString(); AString p = this->toString(); ALOGD("Unable to record: %s [forcenew=%d]", p.c_str(), forcenew); ALOGW("Unable to record: %s [forcenew=%d]", p.c_str(), forcenew); return false; return false; } } } } Loading @@ -833,6 +838,7 @@ bool MediaAnalyticsItem::selfrecord(bool forcenew) { // static // static sp<IMediaAnalyticsService> MediaAnalyticsItem::sAnalyticsService; sp<IMediaAnalyticsService> MediaAnalyticsItem::sAnalyticsService; static Mutex sInitMutex; static Mutex sInitMutex; static int remainingBindAttempts = SVC_TRIES; //static //static bool MediaAnalyticsItem::isEnabled() { bool MediaAnalyticsItem::isEnabled() { Loading @@ -850,10 +856,28 @@ bool MediaAnalyticsItem::isEnabled() { return true; return true; } } // monitor health of our connection to the metrics service class MediaMetricsDeathNotifier : public IBinder::DeathRecipient { virtual void binderDied(const wp<IBinder> &) { ALOGW("Reacquire service connection on next request"); MediaAnalyticsItem::dropInstance(); } }; static sp<MediaMetricsDeathNotifier> sNotifier = NULL; // static void MediaAnalyticsItem::dropInstance() { Mutex::Autolock _l(sInitMutex); remainingBindAttempts = SVC_TRIES; sAnalyticsService = NULL; } //static //static sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { static const char *servicename = "media.metrics"; static const char *servicename = "media.metrics"; static int tries_remaining = SVC_TRIES; int enabled = isEnabled(); int enabled = isEnabled(); if (enabled == false) { if (enabled == false) { Loading Loading @@ -885,15 +909,20 @@ sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { Mutex::Autolock _l(sInitMutex); Mutex::Autolock _l(sInitMutex); const char *badness = ""; const char *badness = ""; // think of tries_remaining as telling us whether service==NULL because // think of remainingBindAttempts as telling us whether service==NULL because // (1) we haven't tried to initialize it yet // (1) we haven't tried to initialize it yet // (2) we've tried to initialize it, but failed. // (2) we've tried to initialize it, but failed. if (sAnalyticsService == NULL && tries_remaining > 0) { if (sAnalyticsService == NULL && remainingBindAttempts > 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IServiceManager> sm = defaultServiceManager(); if (sm != NULL) { if (sm != NULL) { sp<IBinder> binder = sm->getService(String16(servicename)); sp<IBinder> binder = sm->getService(String16(servicename)); if (binder != NULL) { if (binder != NULL) { sAnalyticsService = interface_cast<IMediaAnalyticsService>(binder); sAnalyticsService = interface_cast<IMediaAnalyticsService>(binder); if (sNotifier != NULL) { sNotifier = NULL; } sNotifier = new MediaMetricsDeathNotifier(); binder->linkToDeath(sNotifier); } else { } else { badness = "did not find service"; badness = "did not find service"; } } Loading @@ -902,8 +931,8 @@ sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { } } if (sAnalyticsService == NULL) { if (sAnalyticsService == NULL) { if (tries_remaining > 0) { if (remainingBindAttempts > 0) { tries_remaining--; remainingBindAttempts--; } } if (DEBUG_SERVICEACCESS) { if (DEBUG_SERVICEACCESS) { ALOGD("Unable to bind to service %s: %s", servicename, badness); ALOGD("Unable to bind to service %s: %s", servicename, badness); Loading @@ -915,7 +944,6 @@ sp<IMediaAnalyticsService> MediaAnalyticsItem::getInstance() { } } } } // merge the info from 'incoming' into this record. // merge the info from 'incoming' into this record. // we finish with a union of this+incoming and special handling for collisions // we finish with a union of this+incoming and special handling for collisions bool MediaAnalyticsItem::merge(MediaAnalyticsItem *incoming) { bool MediaAnalyticsItem::merge(MediaAnalyticsItem *incoming) { Loading
media/libmediametrics/include/MediaAnalyticsItem.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -42,6 +42,7 @@ class MediaAnalyticsItem { friend class IMediaAnalyticsService; friend class IMediaAnalyticsService; friend class MediaMetricsJNI; friend class MediaMetricsJNI; friend class MetricsSummarizer; friend class MetricsSummarizer; friend class MediaMetricsDeathNotifier; public: public: Loading Loading @@ -209,6 +210,7 @@ class MediaAnalyticsItem { // let's reuse a binder connection // let's reuse a binder connection static sp<IMediaAnalyticsService> sAnalyticsService; static sp<IMediaAnalyticsService> sAnalyticsService; static sp<IMediaAnalyticsService> getInstance(); static sp<IMediaAnalyticsService> getInstance(); static void dropInstance(); // tracking information // tracking information SessionID_t mSessionID; // grouping similar records SessionID_t mSessionID; // grouping similar records Loading