clean up a fixed size buffer
eliminate the size of a fixed length buffer for a potentially very
long record. Code was safe in that it didn't allow an overflow, but
we really wanted the information that was being truncated.
also some cleanup on parameters for "dumpsys media.metrics":
time units for "-since" and include a -help.
Bug: 34792286 34793404
Test: invoke dumpsys with assorted parameters to see output
Change-Id: If960afd52a509f277910e62c13d4ba60f9ed7e34
diff --git a/services/mediaanalytics/MediaAnalyticsService.cpp b/services/mediaanalytics/MediaAnalyticsService.cpp
index eacafdd..35c1f5b 100644
--- a/services/mediaanalytics/MediaAnalyticsService.cpp
+++ b/services/mediaanalytics/MediaAnalyticsService.cpp
@@ -280,6 +280,7 @@
nsecs_t ts_since = 0;
String16 clearOption("-clear");
String16 sinceOption("-since");
+ String16 helpOption("-help");
int n = args.size();
for (int i = 0; i < n; i++) {
String8 myarg(args[i]);
@@ -298,6 +299,16 @@
} else {
ts_since = 0;
}
+ // command line is milliseconds; internal units are nano-seconds
+ ts_since *= 1000*1000;
+ } else if (args[i] == helpOption) {
+ result.append("Recognized parameters:\n");
+ result.append("-help this help message\n");
+ result.append("-clear clears out saved records\n");
+ result.append("-since XXX include records since XXX\n");
+ result.append(" (XXX is milliseconds since the UNIX epoch)\n");
+ write(fd, result.string(), result.size());
+ return NO_ERROR;
}
}
@@ -364,8 +375,6 @@
}
String8 MediaAnalyticsService::dumpQueue(List<MediaAnalyticsItem *> *theList, nsecs_t ts_since) {
- const size_t SIZE = 512;
- char buffer[SIZE];
String8 result;
int slot = 0;
@@ -379,12 +388,7 @@
continue;
}
AString entry = (*it)->toString();
- snprintf(buffer, sizeof(buffer), "%4d: %s",
- slot, entry.c_str());
- result.append(buffer);
- buffer[0] = '\n';
- buffer[1] = '\0';
- result.append(buffer);
+ result.appendFormat("%5d: %s\n", slot, entry.c_str());
slot++;
}
}