GPS power metrics

Power metrics is added to GPS metrics

BUG:72383800

Test: Manual
Change-Id: I6b01c04984b750c6e079e26b2ad4730d647be382
This commit is contained in:
Siddharth Ray
2018-01-20 18:57:58 -08:00
parent 8a972cf380
commit d679a767b4
2 changed files with 70 additions and 3 deletions

View File

@@ -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;
@@ -312,6 +331,38 @@ public class GnssMetrics {
mLastAverageCn0 = -100.0;
}
/**
* 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.
@@ -347,4 +398,4 @@ public class GnssMetrics {
return GnssMetrics.GPS_SIGNAL_QUALITY_POOR;
}
}
}
}

View File

@@ -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;
}
// 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;
}