Sorting Historical Location Request Stats in Dumpsys

Per longstanding 'by provider' header
Also fixing timezone offset for recently added history

Bug: 141716920
Test: Verified on device, with adb shell dumpsys location
Change-Id: Ic211827f63d9224510ab35cd0128e2bc0d5bd38c
This commit is contained in:
WyattRiley
2019-12-30 18:12:50 -08:00
parent f85d48c900
commit d6b82a6ceb
2 changed files with 17 additions and 4 deletions

View File

@@ -123,6 +123,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
@@ -2996,10 +2997,12 @@ public class LocationManagerService extends ILocationManager.Stub {
ipw.println("Historical Records by Provider:");
ipw.increaseIndent();
TreeMap<PackageProviderKey, PackageStatistics> sorted = new TreeMap<>();
sorted.putAll(mRequestStatistics.statistics);
for (Map.Entry<PackageProviderKey, PackageStatistics> entry
: mRequestStatistics.statistics.entrySet()) {
: sorted.entrySet()) {
PackageProviderKey key = entry.getKey();
ipw.println(key.packageName + ": " + key.providerName + ": " + entry.getValue());
ipw.println(key.providerName + ": " + key.packageName + ": " + entry.getValue());
}
ipw.decreaseIndent();

View File

@@ -92,7 +92,7 @@ public class LocationRequestStatistics {
/**
* A key that holds both package and provider names.
*/
public static class PackageProviderKey {
public static class PackageProviderKey implements Comparable<PackageProviderKey> {
/**
* Name of package requesting location.
*/
@@ -107,6 +107,16 @@ public class LocationRequestStatistics {
this.providerName = providerName;
}
@Override
public int compareTo(PackageProviderKey other) {
final int providerCompare = providerName.compareTo(other.providerName);
if (providerCompare != 0) {
return providerCompare;
} else {
return packageName.compareTo(other.packageName);
}
}
@Override
public boolean equals(Object other) {
if (!(other instanceof PackageProviderKey)) {
@@ -211,7 +221,7 @@ public class LocationRequestStatistics {
void dump(IndentingPrintWriter ipw, long systemElapsedOffsetMillis) {
StringBuilder s = new StringBuilder();
long systemTimeMillis = systemElapsedOffsetMillis + mElapsedRealtimeMillis;
s.append("At ").append(TimeUtils.formatForLogging(systemTimeMillis)).append(": ")
s.append("At ").append(TimeUtils.logTimeOfDay(systemTimeMillis)).append(": ")
.append(mIntervalMillis == REQUEST_ENDED_INTERVAL ? "- " : "+ ")
.append(String.format("%7s", mProviderName)).append(" request from ")
.append(mPackageName);