Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba6072f2 authored by WyattRiley's avatar WyattRiley
Browse files

Improve Location dump Timestamps

Adding a few more for debug clarity

Bug: 122850257
Bug: 130802682
Test: On device, dumpsys location, logcat
Change-Id: Ib73b0b564782ba028c60c273de63450edaaa9af3
parent 7757b14c
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -88,6 +88,7 @@ import android.util.ArraySet;
import android.util.EventLog;
import android.util.EventLog;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
import android.util.Slog;
import android.util.TimeUtils;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.PackageMonitor;
import com.android.internal.content.PackageMonitor;
@@ -3567,6 +3568,10 @@ public class LocationManagerService extends ILocationManager.Stub {
                return;
                return;
            }
            }
            pw.println("Current Location Manager state:");
            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(
            pw.println("  Current user: " + mCurrentUserId + " " + Arrays.toString(
                    mCurrentUserProfiles));
                    mCurrentUserProfiles));
            pw.println("  Location mode: " + isLocationEnabled());
            pw.println("  Location mode: " + isLocationEnabled());
+40 −7
Original line number Original line Diff line number Diff line
@@ -66,6 +66,7 @@ import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.util.StatsLog;
import android.util.StatsLog;
import android.util.TimeUtils;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IBatteryStats;
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.
    // true if low power mode for the GNSS chipset is part of the latest request.
    private boolean mLowPowerMode = false;
    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;
    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
    // capabilities reported through the top level IGnssCallback.hal
    private volatile int mTopHalCapabilities;
    private volatile int mTopHalCapabilities;


@@ -1191,7 +1199,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
            if (DEBUG) Log.d(TAG, "startNavigating");
            if (DEBUG) Log.d(TAG, "startNavigating");
            mTimeToFirstFix = 0;
            mTimeToFirstFix = 0;
            mLastFixTime = 0;
            mLastFixTime = 0;
            mStarted = true;
            setStarted(true);
            mPositionMode = GPS_POSITION_MODE_STANDALONE;
            mPositionMode = GPS_POSITION_MODE_STANDALONE;
            // Notify about suppressed output, if speed limit was previously exceeded.
            // Notify about suppressed output, if speed limit was previously exceeded.
            // Elsewhere, we check again with every speed output reported.
            // Elsewhere, we check again with every speed output reported.
@@ -1229,12 +1237,12 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
            mLowPowerMode = mProviderRequest.lowPowerMode;
            mLowPowerMode = mProviderRequest.lowPowerMode;
            if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC,
            if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC,
                    interval, 0, 0, mLowPowerMode)) {
                    interval, 0, 0, mLowPowerMode)) {
                mStarted = false;
                setStarted(false);
                Log.e(TAG, "set_position_mode failed in startNavigating()");
                Log.e(TAG, "set_position_mode failed in startNavigating()");
                return;
                return;
            }
            }
            if (!native_start()) {
            if (!native_start()) {
                mStarted = false;
                setStarted(false);
                Log.e(TAG, "native_start failed in startNavigating()");
                Log.e(TAG, "native_start failed in startNavigating()");
                return;
                return;
            }
            }
@@ -1257,7 +1265,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
    private void stopNavigating() {
    private void stopNavigating() {
        if (DEBUG) Log.d(TAG, "stopNavigating");
        if (DEBUG) Log.d(TAG, "stopNavigating");
        if (mStarted) {
        if (mStarted) {
            mStarted = false;
            setStarted(false);
            native_stop();
            native_stop();
            mLastFixTime = 0;
            mLastFixTime = 0;
            // native_stop() may reset the position mode in hardware.
            // native_stop() may reset the position mode in hardware.
@@ -1269,6 +1277,13 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
        }
        }
    }
    }


    private void setStarted(boolean started) {
        if (mStarted != started) {
            mStarted = started;
            mStartedChangedElapsedRealtime = SystemClock.elapsedRealtime();
        }
    }

    private void hibernate() {
    private void hibernate() {
        // stop GPS until our next fix interval arrives
        // stop GPS until our next fix interval arrives
        stopNavigating();
        stopNavigating();
@@ -1318,6 +1333,21 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
                    mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes);
                    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();
        mLastFixTime = SystemClock.elapsedRealtime();
@@ -1530,7 +1560,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements


    private void restartLocationRequest() {
    private void restartLocationRequest() {
        if (DEBUG) Log.d(TAG, "restartLocationRequest");
        if (DEBUG) Log.d(TAG, "restartLocationRequest");
        mStarted = false;
        setStarted(false);
        updateRequirements();
        updateRequirements();
    }
    }


@@ -2144,7 +2174,10 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
    @Override
    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        StringBuilder s = new StringBuilder();
        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("  mFixInterval=").append(mFixInterval).append('\n');
        s.append("  mLowPowerMode=").append(mLowPowerMode).append('\n');
        s.append("  mLowPowerMode=").append(mLowPowerMode).append('\n');
        s.append("  mGnssMeasurementsProvider.isRegistered()=")
        s.append("  mGnssMeasurementsProvider.isRegistered()=")