Merge "Improve Location dump Timestamps" into qt-dev

am: f4496e18e0

Change-Id: I2c357c12a5adbecf02cfb2236e7a97c61a084eb6
This commit is contained in:
WyattRiley
2019-04-22 08:30:32 -07:00
committed by android-build-merger
2 changed files with 45 additions and 7 deletions

View File

@@ -88,6 +88,7 @@ import android.util.ArraySet;
import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
import android.util.TimeUtils;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.PackageMonitor;
@@ -3567,6 +3568,10 @@ public class LocationManagerService extends ILocationManager.Stub {
return;
}
pw.println("Current Location Manager state:");
pw.print(" Current System Time: "
+ TimeUtils.logTimeOfDay(System.currentTimeMillis()));
pw.println(", Current Elapsed Time: "
+ TimeUtils.formatDuration(SystemClock.elapsedRealtime()));
pw.println(" Current user: " + mCurrentUserId + " " + Arrays.toString(
mCurrentUserProfiles));
pw.println(" Location mode: " + isLocationEnabled());

View File

@@ -66,6 +66,7 @@ import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.Log;
import android.util.StatsLog;
import android.util.TimeUtils;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IBatteryStats;
@@ -332,9 +333,16 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
// true if low power mode for the GNSS chipset is part of the latest request.
private boolean mLowPowerMode = false;
// true if we started navigation
// true if we started navigation in the HAL, only change value of this in setStarted
private boolean mStarted;
// for logging of latest change, and warning of ongoing location after a stop
private long mStartedChangedElapsedRealtime;
// threshold for delay in GNSS engine turning off before warning & error
private static final long LOCATION_OFF_DELAY_THRESHOLD_WARN_MILLIS = 2 * 1000;
private static final long LOCATION_OFF_DELAY_THRESHOLD_ERROR_MILLIS = 15 * 1000;
// capabilities reported through the top level IGnssCallback.hal
private volatile int mTopHalCapabilities;
@@ -1192,7 +1200,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
if (DEBUG) Log.d(TAG, "startNavigating");
mTimeToFirstFix = 0;
mLastFixTime = 0;
mStarted = true;
setStarted(true);
mPositionMode = GPS_POSITION_MODE_STANDALONE;
// Notify about suppressed output, if speed limit was previously exceeded.
// Elsewhere, we check again with every speed output reported.
@@ -1230,12 +1238,12 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
mLowPowerMode = mProviderRequest.lowPowerMode;
if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC,
interval, 0, 0, mLowPowerMode)) {
mStarted = false;
setStarted(false);
Log.e(TAG, "set_position_mode failed in startNavigating()");
return;
}
if (!native_start()) {
mStarted = false;
setStarted(false);
Log.e(TAG, "native_start failed in startNavigating()");
return;
}
@@ -1258,7 +1266,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
private void stopNavigating() {
if (DEBUG) Log.d(TAG, "stopNavigating");
if (mStarted) {
mStarted = false;
setStarted(false);
native_stop();
mLastFixTime = 0;
// native_stop() may reset the position mode in hardware.
@@ -1270,6 +1278,13 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
}
}
private void setStarted(boolean started) {
if (mStarted != started) {
mStarted = started;
mStartedChangedElapsedRealtime = SystemClock.elapsedRealtime();
}
}
private void hibernate() {
// stop GPS until our next fix interval arrives
stopNavigating();
@@ -1319,6 +1334,21 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes);
}
}
} else {
// Warn or error about long delayed GNSS engine shutdown as this generally wastes
// power and sends location when not expected.
long locationAfterStartedFalseMillis =
SystemClock.elapsedRealtime() - mStartedChangedElapsedRealtime;
if (locationAfterStartedFalseMillis > LOCATION_OFF_DELAY_THRESHOLD_WARN_MILLIS) {
String logMessage = "Unexpected GNSS Location report "
+ TimeUtils.formatDuration(locationAfterStartedFalseMillis)
+ " after location turned off";
if (locationAfterStartedFalseMillis > LOCATION_OFF_DELAY_THRESHOLD_ERROR_MILLIS) {
Log.e(TAG, logMessage);
} else {
Log.w(TAG, logMessage);
}
}
}
mLastFixTime = SystemClock.elapsedRealtime();
@@ -1538,7 +1568,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
private void restartLocationRequest() {
if (DEBUG) Log.d(TAG, "restartLocationRequest");
mStarted = false;
setStarted(false);
updateRequirements();
}
@@ -2152,7 +2182,10 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
StringBuilder s = new StringBuilder();
s.append(" mStarted=").append(mStarted).append('\n');
s.append(" mStarted=").append(mStarted).append(" (changed ");
TimeUtils.formatDuration(SystemClock.elapsedRealtime()
- mStartedChangedElapsedRealtime, s);
s.append(" ago)").append('\n');
s.append(" mFixInterval=").append(mFixInterval).append('\n');
s.append(" mLowPowerMode=").append(mLowPowerMode).append('\n');
s.append(" mGnssMeasurementsProvider.isRegistered()=")