media.metrics changes AString -> std::string

change from AString to std::string for how media.metrics handles
strings.  This severs the dependency on libstagefright_foundation,
where AString is implemented, so we can integrate into places
which do not want to introduce a dependency on libstagefright_foundation.

Bug: 70805723
Test: compilation/linking, CTS subset
Change-Id: I66de971b6ec354444e06112607a2d7614084cef8
gugelfrei
Ray Essick 7 years ago
parent 734d186db7
commit 783bd0d74d

@ -46,7 +46,7 @@ status_t reportMetricsGroup(const MetricsGroup& metricsGroup,
// Report the package name. // Report the package name.
if (metricsGroup.has_app_package_name()) { if (metricsGroup.has_app_package_name()) {
AString app_package_name(metricsGroup.app_package_name().c_str(), std::string app_package_name(metricsGroup.app_package_name().c_str(),
metricsGroup.app_package_name().size()); metricsGroup.app_package_name().size());
analyticsItem.setPkgName(app_package_name); analyticsItem.setPkgName(app_package_name);
} }

@ -49,7 +49,6 @@ cc_library_shared {
"libaudiomanager", "libaudiomanager",
"libmedia_helper", "libmedia_helper",
"libmediametrics", "libmediametrics",
"libstagefright_foundation",
], ],
export_shared_lib_headers: ["libbinder"], export_shared_lib_headers: ["libbinder"],

@ -29,8 +29,6 @@
#include <utils/SortedVector.h> #include <utils/SortedVector.h>
#include <utils/threads.h> #include <utils/threads.h>
#include <media/stagefright/foundation/AString.h>
#include <binder/IServiceManager.h> #include <binder/IServiceManager.h>
#include <media/IMediaAnalyticsService.h> #include <media/IMediaAnalyticsService.h>
#include <media/MediaAnalyticsItem.h> #include <media/MediaAnalyticsItem.h>
@ -205,15 +203,11 @@ uid_t MediaAnalyticsItem::getUid() const {
return mUid; return mUid;
} }
MediaAnalyticsItem &MediaAnalyticsItem::setPkgName(AString pkgName) { MediaAnalyticsItem &MediaAnalyticsItem::setPkgName(const std::string &pkgName) {
mPkgName = pkgName; mPkgName = pkgName;
return *this; return *this;
} }
AString MediaAnalyticsItem::getPkgName() const {
return mPkgName;
}
MediaAnalyticsItem &MediaAnalyticsItem::setPkgVersionCode(int64_t pkgVersionCode) { MediaAnalyticsItem &MediaAnalyticsItem::setPkgVersionCode(int64_t pkgVersionCode) {
mPkgVersionCode = pkgVersionCode; mPkgVersionCode = pkgVersionCode;
return *this; return *this;
@ -727,11 +721,11 @@ int32_t MediaAnalyticsItem::writeToParcel(Parcel *data) {
} }
AString MediaAnalyticsItem::toString() { std::string MediaAnalyticsItem::toString() {
return toString(-1); return toString(-1);
} }
AString MediaAnalyticsItem::toString(int version) { std::string MediaAnalyticsItem::toString(int version) {
// v0 : released with 'o' // v0 : released with 'o'
// v1 : bug fix (missing pid/finalized separator), // v1 : bug fix (missing pid/finalized separator),
@ -744,7 +738,7 @@ AString MediaAnalyticsItem::toString(int version) {
version = PROTO_LAST; version = PROTO_LAST;
} }
AString result; std::string result;
char buffer[512]; char buffer[512];
if (version == PROTO_V0) { if (version == PROTO_V0) {
@ -841,7 +835,7 @@ bool MediaAnalyticsItem::selfrecord() {
bool MediaAnalyticsItem::selfrecord(bool forcenew) { bool MediaAnalyticsItem::selfrecord(bool forcenew) {
if (DEBUG_API) { if (DEBUG_API) {
AString p = this->toString(); std::string p = this->toString();
ALOGD("selfrecord of: %s [forcenew=%d]", p.c_str(), forcenew); ALOGD("selfrecord of: %s [forcenew=%d]", p.c_str(), forcenew);
} }
@ -850,13 +844,13 @@ bool MediaAnalyticsItem::selfrecord(bool forcenew) {
if (svc != NULL) { if (svc != NULL) {
MediaAnalyticsItem::SessionID_t newid = svc->submit(this, forcenew); MediaAnalyticsItem::SessionID_t newid = svc->submit(this, forcenew);
if (newid == SessionIDInvalid) { if (newid == SessionIDInvalid) {
AString p = this->toString(); std::string p = this->toString();
ALOGW("Failed to record: %s [forcenew=%d]", p.c_str(), forcenew); ALOGW("Failed to record: %s [forcenew=%d]", p.c_str(), forcenew);
return false; return false;
} }
return true; return true;
} else { } else {
AString p = this->toString(); std::string p = this->toString();
ALOGW("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;
} }

@ -18,6 +18,7 @@
#define ANDROID_MEDIA_MEDIAANALYTICSITEM_H #define ANDROID_MEDIA_MEDIAANALYTICSITEM_H
#include <cutils/properties.h> #include <cutils/properties.h>
#include <string>
#include <sys/types.h> #include <sys/types.h>
#include <utils/Errors.h> #include <utils/Errors.h>
#include <utils/KeyedVector.h> #include <utils/KeyedVector.h>
@ -25,13 +26,10 @@
#include <utils/StrongPointer.h> #include <utils/StrongPointer.h>
#include <utils/Timers.h> #include <utils/Timers.h>
#include <media/stagefright/foundation/AString.h>
namespace android { namespace android {
class IMediaAnalyticsService; class IMediaAnalyticsService;
class Parcel;
// the class interface // the class interface
// //
@ -66,7 +64,7 @@ class MediaAnalyticsItem {
// values can be "component/component" // values can be "component/component"
// basic values: "video", "audio", "drm" // basic values: "video", "audio", "drm"
// XXX: need to better define the format // XXX: need to better define the format
typedef AString Key; typedef std::string Key;
static const Key kKeyNone; // "" static const Key kKeyNone; // ""
static const Key kKeyAny; // "*" static const Key kKeyAny; // "*"
@ -170,8 +168,8 @@ class MediaAnalyticsItem {
MediaAnalyticsItem &setUid(uid_t); MediaAnalyticsItem &setUid(uid_t);
uid_t getUid() const; uid_t getUid() const;
MediaAnalyticsItem &setPkgName(AString); MediaAnalyticsItem &setPkgName(const std::string &pkgName);
AString getPkgName() const; std::string getPkgName() const { return mPkgName; }
MediaAnalyticsItem &setPkgVersionCode(int64_t); MediaAnalyticsItem &setPkgVersionCode(int64_t);
int64_t getPkgVersionCode() const; int64_t getPkgVersionCode() const;
@ -180,8 +178,8 @@ class MediaAnalyticsItem {
int32_t writeToParcel(Parcel *); int32_t writeToParcel(Parcel *);
int32_t readFromParcel(const Parcel&); int32_t readFromParcel(const Parcel&);
AString toString(); std::string toString();
AString toString(int version); std::string toString(int version);
// are we collecting analytics data // are we collecting analytics data
static bool isEnabled(); static bool isEnabled();
@ -204,7 +202,7 @@ class MediaAnalyticsItem {
// to help validate that A doesn't mess with B's records // to help validate that A doesn't mess with B's records
pid_t mPid; pid_t mPid;
uid_t mUid; uid_t mUid;
AString mPkgName; std::string mPkgName;
int64_t mPkgVersionCode; int64_t mPkgVersionCode;
// let's reuse a binder connection // let's reuse a binder connection

@ -389,7 +389,7 @@ status_t MediaAnalyticsService::dump(int fd, const Vector<String16>& args)
nsecs_t ts_since = 0; nsecs_t ts_since = 0;
String16 helpOption("-help"); String16 helpOption("-help");
String16 onlyOption("-only"); String16 onlyOption("-only");
AString only; std::string only;
int n = args.size(); int n = args.size();
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
@ -553,7 +553,7 @@ void MediaAnalyticsService::dumpSummaries(String8 &result, nsecs_t ts_since, con
if (only != NULL && strcmp(only, (*it)->getKey()) != 0) { if (only != NULL && strcmp(only, (*it)->getKey()) != 0) {
ALOGV("Told to omit '%s'", (*it)->getKey()); ALOGV("Told to omit '%s'", (*it)->getKey());
} }
AString distilled = (*it)->dumpSummary(slot, only); std::string distilled = (*it)->dumpSummary(slot, only);
result.append(distilled.c_str()); result.append(distilled.c_str());
} }
} }
@ -605,7 +605,7 @@ String8 MediaAnalyticsService::dumpQueue(List<MediaAnalyticsItem *> *theList, ns
ALOGV("Omit '%s', it's not '%s'", (*it)->getKey().c_str(), only); ALOGV("Omit '%s', it's not '%s'", (*it)->getKey().c_str(), only);
continue; continue;
} }
AString entry = (*it)->toString(mDumpProto); std::string entry = (*it)->toString(mDumpProto);
result.appendFormat("%5d: %s\n", slot, entry.c_str()); result.appendFormat("%5d: %s\n", slot, entry.c_str());
slot++; slot++;
} }
@ -746,7 +746,7 @@ void MediaAnalyticsService::deleteItem(List<MediaAnalyticsItem *> *l, MediaAnaly
} }
} }
static AString allowedKeys[] = static std::string allowedKeys[] =
{ {
"codec", "codec",
"extractor" "extractor"
@ -760,7 +760,7 @@ bool MediaAnalyticsService::contentValid(MediaAnalyticsItem *item, bool isTruste
// untrusted uids can only send us a limited set of keys // untrusted uids can only send us a limited set of keys
if (isTrusted == false) { if (isTrusted == false) {
// restrict to a specific set of keys // restrict to a specific set of keys
AString key = item->getKey(); std::string key = item->getKey();
size_t i; size_t i;
for(i = 0; i < nAllowedKeys; i++) { for(i = 0; i < nAllowedKeys; i++) {
@ -854,7 +854,7 @@ void MediaAnalyticsService::setPkgInfo(MediaAnalyticsItem *item, uid_t uid, bool
return setPkgInfo(item, uid, setName, setVersion); return setPkgInfo(item, uid, setName, setVersion);
} }
} else { } else {
AString pkg; std::string pkg;
std::string installer = ""; std::string installer = "";
int64_t versionCode = 0; int64_t versionCode = 0;
@ -896,7 +896,7 @@ void MediaAnalyticsService::setPkgInfo(MediaAnalyticsItem *item, uid_t uid, bool
} }
// strip any leading "shared:" strings that came back // strip any leading "shared:" strings that came back
if (pkg.startsWith("shared:")) { if (pkg.compare(0, 7, "shared:") == 0) {
pkg.erase(0, 7); pkg.erase(0, 7);
} }

@ -136,8 +136,8 @@ class MediaAnalyticsService : public BnMediaAnalyticsService
// mapping uids to package names // mapping uids to package names
struct UidToPkgMap { struct UidToPkgMap {
uid_t uid; uid_t uid;
AString pkg; std::string pkg;
AString installer; std::string installer;
int64_t versionCode; int64_t versionCode;
nsecs_t expiration; nsecs_t expiration;
}; };

@ -19,6 +19,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <string>
#include <inttypes.h> #include <inttypes.h>
#include <utils/threads.h> #include <utils/threads.h>
@ -87,21 +88,21 @@ bool MetricsSummarizer::isMine(MediaAnalyticsItem &item)
{ {
if (mKey == NULL) if (mKey == NULL)
return true; return true;
AString itemKey = item.getKey(); std::string itemKey = item.getKey();
if (strcmp(mKey, itemKey.c_str()) != 0) { if (strcmp(mKey, itemKey.c_str()) != 0) {
return false; return false;
} }
return true; return true;
} }
AString MetricsSummarizer::dumpSummary(int &slot) std::string MetricsSummarizer::dumpSummary(int &slot)
{ {
return dumpSummary(slot, NULL); return dumpSummary(slot, NULL);
} }
AString MetricsSummarizer::dumpSummary(int &slot, const char *only) std::string MetricsSummarizer::dumpSummary(int &slot, const char *only)
{ {
AString value = ""; std::string value;
List<MediaAnalyticsItem *>::iterator it = mSummaries->begin(); List<MediaAnalyticsItem *>::iterator it = mSummaries->begin();
if (it != mSummaries->end()) { if (it != mSummaries->end()) {
@ -110,7 +111,7 @@ AString MetricsSummarizer::dumpSummary(int &slot, const char *only)
if (only != NULL && strcmp(only, (*it)->getKey().c_str()) != 0) { if (only != NULL && strcmp(only, (*it)->getKey().c_str()) != 0) {
continue; continue;
} }
AString entry = (*it)->toString(); std::string entry = (*it)->toString();
snprintf(buf, sizeof(buf), "%5d: ", slot); snprintf(buf, sizeof(buf), "%5d: ", slot);
value.append(buf); value.append(buf);
value.append(entry.c_str()); value.append(entry.c_str());

@ -18,10 +18,10 @@
#ifndef ANDROID_METRICSSUMMARIZER_H #ifndef ANDROID_METRICSSUMMARIZER_H
#define ANDROID_METRICSSUMMARIZER_H #define ANDROID_METRICSSUMMARIZER_H
#include <string>
#include <utils/threads.h> #include <utils/threads.h>
#include <utils/Errors.h> #include <utils/Errors.h>
#include <utils/KeyedVector.h> #include <utils/KeyedVector.h>
#include <utils/String8.h>
#include <utils/List.h> #include <utils/List.h>
#include <media/IMediaAnalyticsService.h> #include <media/IMediaAnalyticsService.h>
@ -49,8 +49,8 @@ class MetricsSummarizer
virtual void mergeRecord(MediaAnalyticsItem &have, MediaAnalyticsItem &incoming); virtual void mergeRecord(MediaAnalyticsItem &have, MediaAnalyticsItem &incoming);
// dump the summarized records (for dumpsys) // dump the summarized records (for dumpsys)
AString dumpSummary(int &slot); std::string dumpSummary(int &slot);
AString dumpSummary(int &slot, const char *only); std::string dumpSummary(int &slot, const char *only);
void setIgnorables(const char **); void setIgnorables(const char **);
const char **getIgnorables(); const char **getIgnorables();

Loading…
Cancel
Save