From 007f9fb51bca1f0a953589b9b511ed3ec98094f6 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 21 May 2018 12:02:21 +0300 Subject: [PATCH 1/3] Surround library crash with try-catch --- .../net/osmand/plus/voice/AbstractPrologCommandPlayer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java index 15eac5021e..219010b4be 100644 --- a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java @@ -126,7 +126,11 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat @Override public void stateChanged(ApplicationMode change) { if(prologSystem != null) { - prologSystem.getTheoryManager().retract(new Struct("appMode", new Var())); + try { + prologSystem.getTheoryManager().retract(new Struct("appMode", new Var())); + } catch (Exception e) { + log.error("Retract error: ", e); + } prologSystem.getTheoryManager() .assertA( new Struct("appMode", new Struct(ctx.getSettings().APPLICATION_MODE.get().getStringKey() From aa7339d8b842dd85caa49dcdb4e49ae5e634783e Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 21 May 2018 12:19:09 +0300 Subject: [PATCH 2/3] Restore cancelled subscription holding period --- OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java index 428627128f..3a482749a2 100644 --- a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java +++ b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java @@ -39,7 +39,7 @@ public class InAppPurchaseHelper { private static final String TAG = InAppPurchaseHelper.class.getSimpleName(); boolean mDebugLog = true; - public static final long SUBSCRIPTION_HOLDING_TIME_MSEC = 1000 * 60;// * 60 * 24 * 3; // 3 days + public static final long SUBSCRIPTION_HOLDING_TIME_MSEC = 1000 * 60 * 60 * 24 * 3; // 3 days private long lastValidationCheckTime; private String liveUpdatesPrice; From 9d5f1b3bfe93e7ea437ddfeeeb7ce345fc4ab488 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 21 May 2018 14:04:11 +0300 Subject: [PATCH 3/3] Fix #5071 --- .../osmand/plus/CurrentPositionHelper.java | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index e465cc6b5b..ae9fa3fbe7 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -1,8 +1,8 @@ package net.osmand.plus; -import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.util.LongSparseArray; import net.osmand.Location; import net.osmand.PlatformUtil; @@ -20,6 +20,8 @@ import net.osmand.router.RoutingConfiguration; import net.osmand.router.RoutingContext; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -27,6 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; public class CurrentPositionHelper { @@ -37,18 +40,15 @@ public class CurrentPositionHelper { private OsmandApplication app; private ApplicationMode am; private List usedReaders = new ArrayList<>(); - private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(CurrentPositionHelper.class); - private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); + private static final Log log = PlatformUtil.getLog(CurrentPositionHelper.class); - public CurrentPositionHelper(OsmandApplication app) { + private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); + private LongSparseArray requestNumbersMap = new LongSparseArray<>(); + + CurrentPositionHelper(OsmandApplication app) { this.app = app; } - - - public Location getLastAskedLocation() { - return lastAskedLocation; - } - + public boolean getRouteSegment(Location loc, @Nullable ApplicationMode appMode, ResultMatcher result) { return scheduleRouteSegmentFind(loc, false, true, null, result, appMode); @@ -80,9 +80,13 @@ public class CurrentPositionHelper { } return null; } - ///////////////////////// PRIVATE IMPLEMENTATION ////////////////////////// + + private long getRequestNumberKey(boolean storeFound, boolean allowEmptyNames) { + return (storeFound ? 0x2 : 0x0) | (allowEmptyNames ? 0x1 : 0x0); + } + private boolean scheduleRouteSegmentFind(final Location loc, final boolean storeFound, final boolean allowEmptyNames, @@ -91,18 +95,20 @@ public class CurrentPositionHelper { @Nullable final ApplicationMode appMode) { boolean res = false; if (loc != null) { - new AsyncTask() { + long requestKey = getRequestNumberKey(storeFound, allowEmptyNames); + AtomicInteger requestNumber = requestNumbersMap.get(requestKey); + if (requestNumber == null) { + requestNumber = new AtomicInteger(); + requestNumbersMap.put(requestKey, requestNumber); + } + final int request = requestNumber.incrementAndGet(); + final AtomicInteger finalRequestNumber = requestNumber; + singleThreadExecutor.submit(new Runnable() { @Override - protected Void doInBackground(Void... params) { - try { - processGeocoding(loc, geoCoding, storeFound, allowEmptyNames, result, appMode); - } catch (Exception e) { - log.error("Error processing geocoding", e); - e.printStackTrace(); - } - return null; + public void run() { + processGeocoding(loc, geoCoding, storeFound, allowEmptyNames, result, appMode, request, finalRequestNumber); } - }.executeOnExecutor(singleThreadExecutor, (Void) null); + }); res = true; } return res; @@ -147,7 +153,13 @@ public class CurrentPositionHelper { boolean storeFound, boolean allowEmptyNames, @Nullable final ResultMatcher result, - @Nullable ApplicationMode appMode) throws IOException { + @Nullable ApplicationMode appMode, + int request, + @NonNull AtomicInteger requestNumber) { + + if (request != requestNumber.get()) { + return; + } final List gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude(), geoCoding != null, allowEmptyNames, appMode); @@ -170,7 +182,7 @@ public class CurrentPositionHelper { private List runUpdateInThread(double lat, double lon, boolean geocoding, boolean allowEmptyNames, - @Nullable ApplicationMode appMode) throws IOException { + @Nullable ApplicationMode appMode) { List checkReaders = checkReaders(lat, lon, usedReaders); if (appMode == null) { @@ -185,7 +197,7 @@ public class CurrentPositionHelper { try { return new GeocodingUtilities().reverseGeocodingSearch(geocoding ? defCtx : ctx, lat, lon, allowEmptyNames); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception happened during runUpdateInThread", e); return null; } } @@ -240,7 +252,6 @@ public class CurrentPositionHelper { minBuildingDistance, result); } catch (IOException e) { log.error("Exception happened during reverse geocoding", e); - e.printStackTrace(); } if (justified != null && !justified.isEmpty()) { double md = justified.get(0).getDistance(); @@ -295,10 +306,4 @@ public class CurrentPositionHelper { } return d; } - - - - - - }