Skip to content
Snippets Groups Projects
Commit 8e357b48 authored by Zhanghao's avatar Zhanghao Committed by Zhanghao Wen
Browse files

Add event logs for GnssMeasurement Provider

Test: atest GnssMeasurementValueTest
Bug: 268070943
Change-Id: I45f01488bd57f7c7ff9a88d9635865c009085e3e
parent f8827b1a
No related branches found
No related tags found
No related merge requests found
...@@ -135,8 +135,12 @@ public final class GnssMeasurementRequest implements Parcelable { ...@@ -135,8 +135,12 @@ public final class GnssMeasurementRequest implements Parcelable {
public String toString() { public String toString() {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
s.append("GnssMeasurementRequest["); s.append("GnssMeasurementRequest[");
s.append("@"); if (mIntervalMillis == PASSIVE_INTERVAL) {
TimeUtils.formatDuration(mIntervalMillis, s); s.append("passive");
} else {
s.append("@");
TimeUtils.formatDuration(mIntervalMillis, s);
}
if (mFullTracking) { if (mFullTracking) {
s.append(", FullTracking"); s.append(", FullTracking");
} }
......
...@@ -1549,6 +1549,18 @@ public class LocationManagerService extends ILocationManager.Stub implements ...@@ -1549,6 +1549,18 @@ public class LocationManagerService extends ILocationManager.Stub implements
} }
ipw.decreaseIndent(); ipw.decreaseIndent();
ipw.println("Historical Aggregate Gnss Measurement Provider Data:");
ipw.increaseIndent();
ArrayMap<CallerIdentity, LocationEventLog.GnssMeasurementAggregateStats>
gnssAggregateStats = EVENT_LOG.copyGnssMeasurementAggregateStats();
for (int i = 0; i < gnssAggregateStats.size(); i++) {
ipw.print(gnssAggregateStats.keyAt(i));
ipw.print(": ");
gnssAggregateStats.valueAt(i).updateTotals();
ipw.println(gnssAggregateStats.valueAt(i));
}
ipw.decreaseIndent();
if (mGnssManagerService != null) { if (mGnssManagerService != null) {
ipw.println("GNSS Manager:"); ipw.println("GNSS Manager:");
ipw.increaseIndent(); ipw.increaseIndent();
......
...@@ -30,6 +30,7 @@ import static java.lang.Math.min; ...@@ -30,6 +30,7 @@ import static java.lang.Math.min;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.location.GnssMeasurementRequest;
import android.location.LocationRequest; import android.location.LocationRequest;
import android.location.provider.ProviderRequest; import android.location.provider.ProviderRequest;
import android.location.util.identity.CallerIdentity; import android.location.util.identity.CallerIdentity;
...@@ -58,21 +59,25 @@ public class LocationEventLog extends LocalEventLog<Object> { ...@@ -58,21 +59,25 @@ public class LocationEventLog extends LocalEventLog<Object> {
private static int getLocationsLogSize() { private static int getLocationsLogSize() {
if (D) { if (D) {
return 200; return 400;
} else { } else {
return 100; return 200;
} }
} }
@GuardedBy("mAggregateStats") @GuardedBy("mAggregateStats")
private final ArrayMap<String, ArrayMap<CallerIdentity, AggregateStats>> mAggregateStats; private final ArrayMap<String, ArrayMap<CallerIdentity, AggregateStats>> mAggregateStats;
@GuardedBy("mGnssMeasAggregateStats")
private final ArrayMap<CallerIdentity, GnssMeasurementAggregateStats> mGnssMeasAggregateStats;
@GuardedBy("this") @GuardedBy("this")
private final LocationsEventLog mLocationsLog; private final LocationsEventLog mLocationsLog;
private LocationEventLog() { private LocationEventLog() {
super(getLogSize(), Object.class); super(getLogSize(), Object.class);
mAggregateStats = new ArrayMap<>(4); mAggregateStats = new ArrayMap<>(4);
mGnssMeasAggregateStats = new ArrayMap<>();
mLocationsLog = new LocationsEventLog(getLocationsLogSize()); mLocationsLog = new LocationsEventLog(getLocationsLogSize());
} }
...@@ -105,6 +110,29 @@ public class LocationEventLog extends LocalEventLog<Object> { ...@@ -105,6 +110,29 @@ public class LocationEventLog extends LocalEventLog<Object> {
} }
} }
/** Copies out gnss measurement aggregated stats. */
public ArrayMap<CallerIdentity, GnssMeasurementAggregateStats>
copyGnssMeasurementAggregateStats() {
synchronized (mGnssMeasAggregateStats) {
ArrayMap<CallerIdentity, GnssMeasurementAggregateStats> copy = new ArrayMap<>(
mGnssMeasAggregateStats);
return copy;
}
}
private GnssMeasurementAggregateStats getGnssMeasurementAggregateStats(
CallerIdentity identity) {
synchronized (mGnssMeasAggregateStats) {
CallerIdentity aggregate = CallerIdentity.forAggregation(identity);
GnssMeasurementAggregateStats stats = mGnssMeasAggregateStats.get(aggregate);
if (stats == null) {
stats = new GnssMeasurementAggregateStats();
mGnssMeasAggregateStats.put(aggregate, stats);
}
return stats;
}
}
/** Logs a user switched event. */ /** Logs a user switched event. */
public void logUserSwitched(int userIdFrom, int userIdTo) { public void logUserSwitched(int userIdFrom, int userIdTo) {
addLog(new UserSwitchedEvent(userIdFrom, userIdTo)); addLog(new UserSwitchedEvent(userIdFrom, userIdTo));
...@@ -221,6 +249,29 @@ public class LocationEventLog extends LocalEventLog<Object> { ...@@ -221,6 +249,29 @@ public class LocationEventLog extends LocalEventLog<Object> {
addLog(new LocationPowerSaveModeEvent(locationPowerSaveMode)); addLog(new LocationPowerSaveModeEvent(locationPowerSaveMode));
} }
/** Logs a new client registration for a GNSS Measurement. */
public void logGnssMeasurementClientRegistered(CallerIdentity identity,
GnssMeasurementRequest request) {
addLog(new GnssMeasurementClientRegisterEvent(true, identity, request));
getGnssMeasurementAggregateStats(identity).markRequestAdded(request.getIntervalMillis(),
request.isFullTracking());
}
/** Logs a new client unregistration for a GNSS Measurement. */
public void logGnssMeasurementClientUnregistered(CallerIdentity identity) {
addLog(new GnssMeasurementClientRegisterEvent(false, identity, null));
getGnssMeasurementAggregateStats(identity).markRequestRemoved();
}
/** Logs a GNSS measurement event deliver for a client. */
public void logGnssMeasurementsDelivered(int numGnssMeasurements,
CallerIdentity identity) {
synchronized (this) {
mLocationsLog.logDeliveredGnssMeasurements(numGnssMeasurements, identity);
}
getGnssMeasurementAggregateStats(identity).markGnssMeasurementDelivered();
}
private void addLog(Object logEvent) { private void addLog(Object logEvent) {
addLog(SystemClock.elapsedRealtime(), logEvent); addLog(SystemClock.elapsedRealtime(), logEvent);
} }
...@@ -528,6 +579,50 @@ public class LocationEventLog extends LocalEventLog<Object> { ...@@ -528,6 +579,50 @@ public class LocationEventLog extends LocalEventLog<Object> {
} }
} }
private static final class GnssMeasurementClientRegisterEvent{
private final boolean mRegistered;
private final CallerIdentity mIdentity;
@Nullable
private final GnssMeasurementRequest mGnssMeasurementRequest;
GnssMeasurementClientRegisterEvent(boolean registered,
CallerIdentity identity, @Nullable GnssMeasurementRequest measurementRequest) {
mRegistered = registered;
mIdentity = identity;
mGnssMeasurementRequest = measurementRequest;
}
@Override
public String toString() {
if (mRegistered) {
return "gnss measurements +registration " + mIdentity + " -> "
+ mGnssMeasurementRequest;
} else {
return "gnss measurements -registration " + mIdentity;
}
}
}
private static final class GnssMeasurementDeliverEvent {
private final int mNumGnssMeasurements;
@Nullable
private final CallerIdentity mIdentity;
GnssMeasurementDeliverEvent(int numGnssMeasurements,
@Nullable CallerIdentity identity) {
mNumGnssMeasurements = numGnssMeasurements;
mIdentity = identity;
}
@Override
public String toString() {
return "gnss measurements delivered GnssMeasurements[" + mNumGnssMeasurements + "]"
+ " to " + mIdentity;
}
}
private static final class LocationsEventLog extends LocalEventLog<Object> { private static final class LocationsEventLog extends LocalEventLog<Object> {
LocationsEventLog(int size) { LocationsEventLog(int size) {
...@@ -538,6 +633,11 @@ public class LocationEventLog extends LocalEventLog<Object> { ...@@ -538,6 +633,11 @@ public class LocationEventLog extends LocalEventLog<Object> {
addLog(new ProviderReceiveLocationEvent(provider, numLocations)); addLog(new ProviderReceiveLocationEvent(provider, numLocations));
} }
public void logDeliveredGnssMeasurements(int numGnssMeasurements,
CallerIdentity identity) {
addLog(new GnssMeasurementDeliverEvent(numGnssMeasurements, identity));
}
public void logProviderDeliveredLocations(String provider, int numLocations, public void logProviderDeliveredLocations(String provider, int numLocations,
CallerIdentity identity) { CallerIdentity identity) {
addLog(new ProviderDeliverLocationEvent(provider, numLocations, identity)); addLog(new ProviderDeliverLocationEvent(provider, numLocations, identity));
...@@ -668,4 +768,89 @@ public class LocationEventLog extends LocalEventLog<Object> { ...@@ -668,4 +768,89 @@ public class LocationEventLog extends LocalEventLog<Object> {
} }
} }
} }
/**
* Aggregate statistics for GNSS measurements.
*/
public static final class GnssMeasurementAggregateStats {
@GuardedBy("this")
private int mAddedRequestCount;
@GuardedBy("this")
private int mReceivedMeasurementEventCount;
@GuardedBy("this")
private long mAddedTimeTotalMs;
@GuardedBy("this")
private long mAddedTimeLastUpdateRealtimeMs;
@GuardedBy("this")
private long mFastestIntervalMs = Long.MAX_VALUE;
@GuardedBy("this")
private long mSlowestIntervalMs = 0;
@GuardedBy("this")
private boolean mHasFullTracking;
@GuardedBy("this")
private boolean mHasDutyCycling;
GnssMeasurementAggregateStats() {
}
synchronized void markRequestAdded(long intervalMillis, boolean fullTracking) {
if (mAddedRequestCount++ == 0) {
mAddedTimeLastUpdateRealtimeMs = SystemClock.elapsedRealtime();
}
if (fullTracking) {
mHasFullTracking = true;
} else {
mHasDutyCycling = true;
}
mFastestIntervalMs = min(intervalMillis, mFastestIntervalMs);
mSlowestIntervalMs = max(intervalMillis, mSlowestIntervalMs);
}
synchronized void markRequestRemoved() {
updateTotals();
--mAddedRequestCount;
Preconditions.checkState(mAddedRequestCount >= 0);
}
synchronized void markGnssMeasurementDelivered() {
mReceivedMeasurementEventCount++;
}
public synchronized void updateTotals() {
if (mAddedRequestCount > 0) {
long realtimeMs = SystemClock.elapsedRealtime();
mAddedTimeTotalMs += realtimeMs - mAddedTimeLastUpdateRealtimeMs;
mAddedTimeLastUpdateRealtimeMs = realtimeMs;
}
}
@Override
public synchronized String toString() {
return "min/max interval = "
+ intervalToString(mFastestIntervalMs) + "/"
+ intervalToString(mSlowestIntervalMs)
+ ", total duration = " + formatDuration(mAddedTimeTotalMs)
+ ", tracking mode = " + trackingModeToString() + ", GNSS measurement events = "
+ mReceivedMeasurementEventCount;
}
private static String intervalToString(long intervalMs) {
if (intervalMs == GnssMeasurementRequest.PASSIVE_INTERVAL) {
return "passive";
} else {
return MILLISECONDS.toSeconds(intervalMs) + "s";
}
}
@GuardedBy("this")
private String trackingModeToString() {
if (mHasFullTracking && mHasDutyCycling) {
return "mixed tracking mode";
} else if (mHasFullTracking) {
return "always full-tracking";
} else {
return "always duty-cycling";
}
}
}
} }
...@@ -18,6 +18,7 @@ package com.android.server.location.gnss; ...@@ -18,6 +18,7 @@ package com.android.server.location.gnss;
import static android.app.AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION; import static android.app.AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION;
import static com.android.server.location.eventlog.LocationEventLog.EVENT_LOG;
import static com.android.server.location.gnss.GnssManagerService.D; import static com.android.server.location.gnss.GnssManagerService.D;
import static com.android.server.location.gnss.GnssManagerService.TAG; import static com.android.server.location.gnss.GnssManagerService.TAG;
...@@ -62,11 +63,17 @@ public final class GnssMeasurementsProvider extends ...@@ -62,11 +63,17 @@ public final class GnssMeasurementsProvider extends
@Override @Override
protected void onRegister() { protected void onRegister() {
super.onRegister(); super.onRegister();
EVENT_LOG.logGnssMeasurementClientRegistered(getIdentity(), getRequest());
executeOperation(listener -> listener.onStatusChanged( executeOperation(listener -> listener.onStatusChanged(
GnssMeasurementsEvent.Callback.STATUS_READY)); GnssMeasurementsEvent.Callback.STATUS_READY));
} }
@Override
protected void onUnregister() {
EVENT_LOG.logGnssMeasurementClientUnregistered(getIdentity());
super.onUnregister();
}
@Nullable @Nullable
@Override @Override
protected void onActive() { protected void onActive() {
...@@ -250,6 +257,8 @@ public final class GnssMeasurementsProvider extends ...@@ -250,6 +257,8 @@ public final class GnssMeasurementsProvider extends
deliverToListeners(registration -> { deliverToListeners(registration -> {
if (mAppOpsHelper.noteOpNoThrow(AppOpsManager.OP_FINE_LOCATION, if (mAppOpsHelper.noteOpNoThrow(AppOpsManager.OP_FINE_LOCATION,
registration.getIdentity())) { registration.getIdentity())) {
EVENT_LOG.logGnssMeasurementsDelivered(event.getMeasurements().size(),
registration.getIdentity());
return listener -> listener.onGnssMeasurementsReceived(event); return listener -> listener.onGnssMeasurementsReceived(event);
} else { } else {
return null; return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment