Redownload AGPS every 16 hours

This commit is contained in:
Victor Shcherb 2015-03-27 01:04:07 +01:00
parent 00da1e90c6
commit e23cdb7dd3
4 changed files with 29 additions and 0 deletions

View file

@ -10,6 +10,8 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />

View file

@ -103,6 +103,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
private float[] mRotationM = new float[9];
private OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS;
private OsmandPreference<Boolean> USE_FILTER_FOR_COMPASS;
private static final long AGPS_TO_REDOWNLOAD = 16 * 60 * 60 * 1000; // 16 hours
@ -221,6 +222,13 @@ public class OsmAndLocationProvider implements SensorEventListener {
public void resumeAllUpdates() {
final LocationManager service = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
if(app.getSettings().isInternetConnectionAvailable()) {
long time = System.currentTimeMillis();
if(time - app.getSettings().AGPS_DATA_LAST_TIME_DOWNLOADED.get() > AGPS_TO_REDOWNLOAD) {
redownloadAGPS();
app.getSettings().AGPS_DATA_LAST_TIME_DOWNLOADED.set(time);
}
}
service.addGpsStatusListener(getGpsStatusListener(service));
try {
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, gpsListener);
@ -243,6 +251,18 @@ public class OsmAndLocationProvider implements SensorEventListener {
}
}
}
public void redownloadAGPS() {
try {
final LocationManager service = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
service.sendExtraCommand(LocationManager.GPS_PROVIDER,"delete_aiding_data", null);
Bundle bundle = new Bundle();
service.sendExtraCommand("gps", "force_xtra_injection", bundle);
service.sendExtraCommand("gps", "force_time_injection", bundle);
} catch (Exception e) {
e.printStackTrace();
}
}
private Listener getGpsStatusListener(final LocationManager service) {
gpsStatusListener = new Listener() {
@ -847,4 +867,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
return true;
}
}

View file

@ -1750,6 +1750,9 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME =
new BooleanPreference("show_arrival_time", true).makeGlobal();
public final OsmandPreference<Long> AGPS_DATA_LAST_TIME_DOWNLOADED =
new LongPreference("agps_data_downloaded", 0).makeGlobal();
// UI boxes
public final CommonPreference<Boolean> TRANSPARENT_MAP_THEME =

View file

@ -157,6 +157,7 @@ public class MapActivity extends AccessibleActivity {
dashboardOnMap.createDashboardView();
checkAppInitialization();
parseLaunchIntentLocation();
getMyApplication().getLocationProvider().redownloadAGPS();
mapView.setTrackBallDelegate(new OsmandMapTileView.OnTrackBallListener() {
@Override
public boolean onTrackBallEvent(MotionEvent e) {
@ -191,6 +192,7 @@ public class MapActivity extends AccessibleActivity {
if (!settings.isLastKnownMapLocation()) {
// show first time when application ran
net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation();
mapViewTrackingUtilities.setMapLinkedToLocation(true);
if (location != null) {
mapView.setLatLon(location.getLatitude(), location.getLongitude());
mapView.setIntZoom(14);