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

Commit 39e6f112 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Log constellation types in GnssMetrics"

parents e202838e ae7e07ab
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.location;

import android.annotation.IntDef;
import android.annotation.NonNull;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -44,6 +45,8 @@ public final class GnssStatus {
    public static final int CONSTELLATION_GALILEO = 6;
    /** Constellation type constant for IRNSS. */
    public static final int CONSTELLATION_IRNSS = 7;
    /** @hide */
    public static final int CONSTELLATION_COUNT = 8;

    /** @hide */
    public static final int GNSS_SV_FLAGS_NONE = 0;
@@ -251,4 +254,36 @@ public final class GnssStatus {
    public float getCarrierFrequencyHz(int satIndex) {
        return mCarrierFrequencies[satIndex];
    }

    /**
     * Returns the string representation of a constellation type. For example,
     * {@link #CONSTELLATION_GPS} is represented by the string GPS.
     *
     * @param constellationType the constellation type.
     * @return the string representation.
     * @hide
     */
    @NonNull
    public static String constellationTypeToString(@ConstellationType int constellationType) {
        switch (constellationType) {
            case CONSTELLATION_UNKNOWN:
                return "UNKNOWN";
            case CONSTELLATION_GPS:
                return "GPS";
            case CONSTELLATION_SBAS:
                return "SBAS";
            case CONSTELLATION_GLONASS:
                return "GLONASS";
            case CONSTELLATION_QZSS:
                return "QZSS";
            case CONSTELLATION_BEIDOU:
                return "BEIDOU";
            case CONSTELLATION_GALILEO:
                return "GALILEO";
            case CONSTELLATION_IRNSS:
                return "IRNSS";
            default:
                return Integer.toString(constellationType);
        }
    }
}
+35 −5
Original line number Diff line number Diff line
@@ -16,26 +16,26 @@

package com.android.internal.location.gnssmetrics;

import android.location.GnssStatus;
import android.os.SystemClock;
import android.os.connectivity.GpsBatteryStats;
import android.os.SystemProperties;

import android.os.connectivity.GpsBatteryStats;
import android.server.location.ServerLocationProtoEnums;

import android.text.format.DateUtils;
import android.util.Base64;
import android.util.Log;
import android.util.StatsLog;
import android.util.TimeUtils;

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;

import java.util.Arrays;

/**
 * GnssMetrics: Is used for logging GNSS metrics
 *
 * @hide
 */
public class GnssMetrics {
@@ -66,6 +66,11 @@ public class GnssMetrics {
  /* GNSS power metrics */
  private GnssPowerMetrics mGnssPowerMetrics;

    /**
     * A boolean array indicating whether the constellation types have been used in fix.
     */
    private boolean[] mConstellationTypes;

  /** Constructor */
  public GnssMetrics(IBatteryStats stats) {
    mGnssPowerMetrics = new GnssPowerMetrics(stats);
@@ -156,6 +161,18 @@ public class GnssMetrics {
    return;
  }


    /**
     * Logs that a constellation type has been observed.
     */
    public void logConstellationType(int constellationType) {
        if (constellationType >= mConstellationTypes.length) {
            Log.e(TAG, "Constellation type " + constellationType + " is not valid.");
            return;
        }
        mConstellationTypes[constellationType] = true;
    }

  /**
   * Dumps GNSS metrics as a proto string
   * @return
@@ -232,6 +249,13 @@ public class GnssMetrics {
      s.append("  Top 4 Avg CN0 standard deviation (dB-Hz): ").append(
          topFourAverageCn0Statistics.getStandardDeviation()).append("\n");
    }
        s.append("  Used-in-fix constellation types: ");
        for (int i = 0; i < mConstellationTypes.length; i++) {
            if (mConstellationTypes[i]) {
                s.append(GnssStatus.constellationTypeToString(i)).append(" ");
            }
        }
        s.append("\n");
    s.append("GNSS_KPI_END").append("\n");
    GpsBatteryStats stats = mGnssPowerMetrics.getGpsBatteryStats();
    if (stats != null) {
@@ -320,9 +344,15 @@ public class GnssMetrics {
    timeToFirstFixSecStatistics.reset();
    positionAccuracyMeterStatistics.reset();
    topFourAverageCn0Statistics.reset();
        resetConstellationTypes();
    return;
  }

    /** Resets {@link #mConstellationTypes} as an all-false boolean array. */
    public void resetConstellationTypes() {
        mConstellationTypes = new boolean[GnssStatus.CONSTELLATION_COUNT];
    }

  /* Class for handling GNSS power related metrics */
  private class GnssPowerMetrics {

+8 −0
Original line number Diff line number Diff line
@@ -495,6 +495,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
    @Override
    public void onUpdateSatelliteBlacklist(int[] constellations, int[] svids) {
        mHandler.post(() -> mGnssConfiguration.setSatelliteBlacklist(constellations, svids));
        mGnssMetrics.resetConstellationTypes();
    }

    private void subscriptionOrCarrierConfigChanged(Context context) {
@@ -1443,6 +1444,13 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
                                GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0
                                ? "" : "F"));
            }

            if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) {
                int constellationType =
                        (info.mSvidWithFlags[i] >> GnssStatus.CONSTELLATION_TYPE_SHIFT_WIDTH)
                                & GnssStatus.CONSTELLATION_TYPE_MASK;
                mGnssMetrics.logConstellationType(constellationType);
            }
        }
        if (usedInFixCount > 0) {
            meanCn0 /= usedInFixCount;