Skip to content

Commit

Permalink
feat: Request full tracking for raw measurements (S and higher)
Browse files Browse the repository at this point in the history
Closes #490
  • Loading branch information
barbeau committed Jun 28, 2021
1 parent b604094 commit 593fb04
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
14 changes: 13 additions & 1 deletion GPSTest/src/main/java/com/android/gpstest/GpsTestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.android.gpstest.util.IOUtils.writeGnssMeasurementToAndroidStudio;
import static com.android.gpstest.util.IOUtils.writeNavMessageToAndroidStudio;
import static com.android.gpstest.util.IOUtils.writeNmeaToAndroidStudio;
import static com.android.gpstest.util.SatelliteUtils.isForceFullGnssMeasurementsSupported;

import android.Manifest;
import android.annotation.SuppressLint;
Expand All @@ -52,6 +53,7 @@
import android.hardware.SensorManager;
import android.location.GnssAntennaInfo;
import android.location.GnssMeasurement;
import android.location.GnssMeasurementRequest;
import android.location.GnssMeasurementsEvent;
import android.location.GnssNavigationMessage;
import android.location.GnssStatus;
Expand Down Expand Up @@ -1229,7 +1231,17 @@ public void onStatusChanged(int status) {
handleLegacyMeasurementStatus(status);
}
};
mLocationManager.registerGnssMeasurementsCallback(mGnssMeasurementsListener);
if (isForceFullGnssMeasurementsSupported()) {
boolean forceFullMeasurements = Application.getPrefs().getBoolean(getString(R.string.pref_key_force_full_gnss_measurements), true);
Log.d(TAG,"Force full GNSS measurements = " + forceFullMeasurements);
// Request "force full GNSS measurements" explicitly (on <= Android R this is a manual developer setting)
GnssMeasurementRequest request = new GnssMeasurementRequest.Builder()
.setFullTracking(forceFullMeasurements)
.build();
mLocationManager.registerGnssMeasurementsCallback(request, getApplication().getMainExecutor(), mGnssMeasurementsListener);
} else {
mLocationManager.registerGnssMeasurementsCallback(mGnssMeasurementsListener);
}
}

@RequiresApi(api = Build.VERSION_CODES.S)
Expand Down
11 changes: 11 additions & 0 deletions GPSTest/src/main/java/com/android/gpstest/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.android.gpstest;

import static com.android.gpstest.util.SatelliteUtils.isForceFullGnssMeasurementsSupported;

import android.content.Context;
import android.content.SharedPreferences;
import android.location.LocationManager;
Expand All @@ -42,6 +44,8 @@
public class Preferences extends PreferenceActivity implements
SharedPreferences.OnSharedPreferenceChangeListener {

CheckBoxPreference forceFullGnssMeasurements;

EditTextPreference txtMinTime;

EditTextPreference txtMinDistance;
Expand Down Expand Up @@ -77,6 +81,13 @@ public void onCreate(Bundle savedInstanceState) {

UIUtils.resetActivityTitle(this);

forceFullGnssMeasurements = (CheckBoxPreference) this
.findPreference(getString(R.string.pref_key_force_full_gnss_measurements));

if (!isForceFullGnssMeasurementsSupported()) {
forceFullGnssMeasurements.setEnabled(false);
}

txtMinTime = (EditTextPreference) this
.findPreference(getString(R.string.pref_key_gps_min_time));
txtMinTime.getEditText()
Expand Down
26 changes: 17 additions & 9 deletions GPSTest/src/main/java/com/android/gpstest/util/SatelliteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@

package com.android.gpstest.util;

import static com.android.gpstest.model.GnssType.BEIDOU;
import static com.android.gpstest.model.GnssType.GALILEO;
import static com.android.gpstest.model.GnssType.GLONASS;
import static com.android.gpstest.model.GnssType.IRNSS;
import static com.android.gpstest.model.GnssType.NAVSTAR;
import static com.android.gpstest.model.GnssType.QZSS;
import static com.android.gpstest.model.GnssType.SBAS;
import static com.android.gpstest.model.GnssType.UNKNOWN;

import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.Sensor;
Expand All @@ -33,15 +42,6 @@
import com.android.gpstest.model.SatelliteStatus;
import com.android.gpstest.model.SbasType;

import static com.android.gpstest.model.GnssType.BEIDOU;
import static com.android.gpstest.model.GnssType.GALILEO;
import static com.android.gpstest.model.GnssType.GLONASS;
import static com.android.gpstest.model.GnssType.IRNSS;
import static com.android.gpstest.model.GnssType.NAVSTAR;
import static com.android.gpstest.model.GnssType.QZSS;
import static com.android.gpstest.model.GnssType.SBAS;
import static com.android.gpstest.model.GnssType.UNKNOWN;

/**
* Utilities to manage GNSS signal and satellite information
*/
Expand Down Expand Up @@ -317,6 +317,14 @@ public static boolean isGnssAntennaInfoSupported(LocationManager manager) {
}
}

/**
* Returns true if "force full GNSS measurements" can be programmatically invoked, and false if not
* @return true if "force full GNSS measurements" can be programmatically invoked, and false if not
*/
public static boolean isForceFullGnssMeasurementsSupported() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;
}

/**
* Returns true if the platform supports GNSS measurements, false if it does not.
* @return true if the platform supports GNSS measurements, false if it does not
Expand Down
1 change: 1 addition & 0 deletions GPSTest/src/main/res/values/do_not_translate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<string name="pref_key_preferred_distance_units_v2">preference_distance_units_v2</string>
<string name="pref_key_preferred_speed_units_v2">preference_speed_units_v2</string>
<string name="pref_key_language">preference_language</string>
<string name="pref_key_force_full_gnss_measurements">preference_force_full_gnss_measurements</string>

<!-- Default preference values -->
<string name="pref_gps_min_time_default_sec">1</string>
Expand Down
4 changes: 4 additions & 0 deletions GPSTest/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@
</string>

<string name="pref_gps_category_title">GNSS</string>

<string name="pref_force_full_gnss_measurements_title">Force full GNSS Measurements</string>
<string name="pref_force_full_gnss_measurements_summary">Available on Android 12 and higher. If checked, GNSS chipset switches off duty cycling so that no clock discontinuities are expected, and when supported, carrier phase should be continuous in good signal conditions. If unchecked, GNSS chipset optimizes power via duty cycling, constellations and frequency limits, etc.</string>

<string name="pref_auto_start_gps_title">Auto-Start GNSS</string>
<string name="pref_auto_start_gps_summary">Start GNSS when the app starts</string>

Expand Down
5 changes: 5 additions & 0 deletions GPSTest/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
android:title="@string/pref_auto_start_gps_title"
android:summary="@string/pref_auto_start_gps_summary"
android:defaultValue="true" />
<CheckBoxPreference
android:key="@string/pref_key_force_full_gnss_measurements"
android:title="@string/pref_force_full_gnss_measurements_title"
android:summary="@string/pref_force_full_gnss_measurements_summary"
android:defaultValue="true" />
<EditTextPreference
android:key="@string/pref_key_gps_min_time"
android:title="@string/pref_gps_min_time_title"
Expand Down

0 comments on commit 593fb04

Please sign in to comment.