summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Siddharth Ray <siddharthr@google.com> 2018-01-20 18:57:58 -0800
committer Siddharth Ray <siddharthr@google.com> 2018-01-30 10:12:15 -0800
commitd679a767b49ea4bd4aee83a4bc2425fdce67b950 (patch)
treec2edc4372f2a7b26c67ea61679a68ee6d8c407e4
parent8a972cf38091f36e98a522743216998c4915d24e (diff)
GPS power metrics
Power metrics is added to GPS metrics BUG:72383800 Test: Manual Change-Id: I6b01c04984b750c6e079e26b2ad4730d647be382
-rw-r--r--location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java55
-rw-r--r--proto/src/gnss.proto18
2 files changed, 70 insertions, 3 deletions
diff --git a/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java b/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java
index 603926f4fe4d..98e67c21c1a1 100644
--- a/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java
+++ b/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java
@@ -17,7 +17,9 @@
package com.android.internal.location.gnssmetrics;
import android.os.SystemClock;
+import android.os.connectivity.GpsBatteryStats;
+import android.text.format.DateUtils;
import android.util.Base64;
import android.util.Log;
import android.util.TimeUtils;
@@ -26,6 +28,7 @@ import java.util.Arrays;
import com.android.internal.app.IBatteryStats;
import com.android.internal.location.nano.GnssLogsProto.GnssLog;
+import com.android.internal.location.nano.GnssLogsProto.PowerMetrics;
/**
* GnssMetrics: Is used for logging GNSS metrics
@@ -171,6 +174,7 @@ public class GnssMetrics {
msg.standardDeviationTopFourAverageCn0DbHz
= topFourAverageCn0Statistics.getStandardDeviation();
}
+ msg.powerMetrics = mGnssPowerMetrics.buildProto();
String s = Base64.encodeToString(GnssLog.toByteArray(msg), Base64.DEFAULT);
reset();
return s;
@@ -218,6 +222,21 @@ public class GnssMetrics {
topFourAverageCn0Statistics.getStandardDeviation()).append("\n");
}
s.append("GNSS_KPI_END").append("\n");
+ GpsBatteryStats stats = mGnssPowerMetrics.getGpsBatteryStats();
+ if (stats != null) {
+ s.append("Power Metrics").append('\n');
+ long[] t = stats.getTimeInGpsSignalQualityLevel();
+ if (t != null && t.length == NUM_GPS_SIGNAL_QUALITY_LEVELS) {
+ s.append(" Amount of time (while on battery) Top 4 Avg CN0 > " +
+ Double.toString(GnssPowerMetrics.POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ) +
+ " dB-Hz (min): ").append(t[1] / ((double) DateUtils.MINUTE_IN_MILLIS)).append("\n");
+ s.append(" Amount of time (while on battery) Top 4 Avg CN0 <= " +
+ Double.toString(GnssPowerMetrics.POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ) +
+ " dB-Hz (min): ").append(t[0] / ((double) DateUtils.MINUTE_IN_MILLIS)).append("\n");
+ }
+ s.append(" Energy consumed while on battery (mAh): ").append(
+ stats.getEnergyConsumedMaMs() / ((double) DateUtils.HOUR_IN_MILLIS)).append("\n");
+ }
return s.toString();
}
@@ -294,7 +313,7 @@ public class GnssMetrics {
private class GnssPowerMetrics {
/* Threshold for Top Four Average CN0 below which GNSS signal quality is declared poor */
- private static final double POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ = 20.0;
+ public static final double POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ = 20.0;
/* Minimum change in Top Four Average CN0 needed to trigger a report */
private static final double REPORTING_THRESHOLD_DB_HZ = 1.0;
@@ -313,6 +332,38 @@ public class GnssMetrics {
}
/**
+ * Builds power metrics proto buf. This is included in the gnss proto buf.
+ * @return PowerMetrics
+ */
+ public PowerMetrics buildProto() {
+ PowerMetrics p = new PowerMetrics();
+ GpsBatteryStats stats = mGnssPowerMetrics.getGpsBatteryStats();
+ if (stats != null) {
+ p.loggingDurationMs = stats.getLoggingDurationMs();
+ p.energyConsumedMah = stats.getEnergyConsumedMaMs() / ((double) DateUtils.HOUR_IN_MILLIS);
+ long[] t = stats.getTimeInGpsSignalQualityLevel();
+ p.timeInSignalQualityLevelMs = new long[t.length];
+ for (int i = 0; i < t.length; i++) {
+ p.timeInSignalQualityLevelMs[i] = t[i];
+ }
+ }
+ return p;
+ }
+
+ /**
+ * Returns the GPS power stats
+ * @return GpsBatteryStats
+ */
+ public GpsBatteryStats getGpsBatteryStats() {
+ try {
+ return mBatteryStats.getGpsBatteryStats();
+ } catch (Exception e) {
+ Log.w(TAG, "Exception", e);
+ return null;
+ }
+ }
+
+ /**
* Reports signal quality to BatteryStats. Signal quality is based on Top four average CN0. If
* the number of SVs seen is less than 4, then signal quality is the average CN0.
* Changes are reported only if the average CN0 changes by more than REPORTING_THRESHOLD_DB_HZ.
@@ -347,4 +398,4 @@ public class GnssMetrics {
return GnssMetrics.GPS_SIGNAL_QUALITY_POOR;
}
}
-} \ No newline at end of file
+}
diff --git a/proto/src/gnss.proto b/proto/src/gnss.proto
index c54ddadd07df..016839232255 100644
--- a/proto/src/gnss.proto
+++ b/proto/src/gnss.proto
@@ -42,4 +42,20 @@ message GnssLog {
// Standard deviation of top 4 average CN0 (dB-Hz)
optional double standard_deviation_top_four_average_cn0_db_hz = 11;
-} \ No newline at end of file
+
+ // Power metrics
+ optional PowerMetrics power_metrics = 12;
+}
+
+// Power metrics
+message PowerMetrics {
+
+ // Duration of power log (ms)
+ optional int64 logging_duration_ms = 1;
+
+ // Energy consumed (mAh)
+ optional double energy_consumed_mah = 2;
+
+ // Time spent in signal quality level (ms)
+ repeated int64 time_in_signal_quality_level_ms = 3;
+}