Skip to content

Commit

Permalink
Fix NPE when PlatformUtil.getOsmandRegions is not ready
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Nov 19, 2024
1 parent 5641b51 commit 7fc188b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions OsmAnd/src/net/osmand/plus/auto/NavigationSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import net.osmand.util.GeoPointParserUtil;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -704,8 +705,12 @@ public void onProgress(@NonNull AppInitializer init, @NonNull AppInitEvents even
}
}
if (event == ROUTING_CONFIG_INITIALIZED) {
if (app.getRegions() != null) {
restoreNavigationHelper.checkRestoreRoutingMode();
try {
if (PlatformUtil.getOsmandRegions() != null) {
restoreNavigationHelper.checkRestoreRoutingMode();
}
} catch (IOException e) {
LOG.warn("NavigateSession getOsmandRegions failed", e);
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions OsmAnd/src/net/osmand/plus/routing/RouteRecalculationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.annotation.NonNull;

import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
Expand All @@ -15,6 +16,9 @@
import net.osmand.router.RouteCalculationProgress;
import net.osmand.util.Algorithms;

import org.apache.commons.logging.Log;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -30,6 +34,7 @@
import java.util.concurrent.TimeUnit;

class RouteRecalculationHelper {
private static final Log LOG = PlatformUtil.getLog(RouteRecalculationHelper.class);

private static final int RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE = 3;
private static final int RECALCULATE_THRESHOLD_CAUSING_FULL_RECALCULATE_INTERVAL = 2 * 60 * 1000;
Expand Down Expand Up @@ -217,6 +222,16 @@ public void recalculateRouteInBackground(Location start, LatLon end, List<LatLon
if (start == null || end == null) {
return;
}
try {
if (PlatformUtil.getOsmandRegions() == null || !app.getAppInitializer().isRoutingConfigInitialized()) {
String awaitInitializationMessage = app.getString(R.string.waiting_for_route_calculation);
app.runInUIThread(() -> app.showToastMessage(awaitInitializationMessage));
LOG.warn("recalculateRouteInBackground requires getOsmandRegions");
return; // will be retried automatically
}
} catch (IOException e) {
LOG.warn("recalculateRouteInBackground getOsmandRegions failed", e);
}
// do not evaluate very often
if ((!isRouteBeingCalculated() && System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval)
|| paramsChanged || !onlyStartPointChanged) {
Expand Down

0 comments on commit 7fc188b

Please sign in to comment.