From befffb651109480e5d19fe55a4ff3202301fdc8c Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 11 Nov 2020 23:49:20 +0100 Subject: [PATCH] Fix #10148 --- .../src/net/osmand/plus/AppInitializer.java | 7 +--- .../net/osmand/plus/OsmandApplication.java | 42 ++++++++++++------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index b172d08242..d89238f4f3 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -85,6 +85,7 @@ import java.util.Map; import java.util.Random; import btools.routingapp.BRouterServiceConnection; +import btools.routingapp.IBRouterService; import static net.osmand.plus.AppVersionUpgradeOnInit.LAST_APP_VERSION; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent; @@ -422,13 +423,9 @@ public class AppInitializer implements IProgress { osmandSettings.APPLICATION_MODE.set(osmandSettings.DEFAULT_APPLICATION_MODE.get()); } startTime = System.currentTimeMillis(); - try { - app.bRouterServiceConnection = startupInit(BRouterServiceConnection.connect(app), BRouterServiceConnection.class); - } catch (Exception e) { - e.printStackTrace(); - } getLazyRoutingConfig(); app.applyTheme(app); + startupInit(app.reconnectToBRouter(), IBRouterService.class); app.inAppPurchaseHelper = startupInit(new InAppPurchaseHelperImpl(app), InAppPurchaseHelperImpl.class); app.poiTypes = startupInit(MapPoiTypes.getDefaultNoInit(), MapPoiTypes.class); app.transportRoutingHelper = startupInit(new TransportRoutingHelper(app), TransportRoutingHelper.class); diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 539db520ae..42a227ebcf 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -109,17 +109,16 @@ public class OsmandApplication extends MultiDexApplication { private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class); final AppInitializer appInitializer = new AppInitializer(this); - OsmandSettings osmandSettings = null; + Handler uiHandler; + OsmandSettings osmandSettings; OsmAndAppCustomization appCustomization; + NavigationService navigationService; + DownloadService downloadService; + OsmandAidlApi aidlApi; + private final SQLiteAPI sqliteAPI = new SQLiteAPIImpl(this); private final OsmAndTaskManager taskManager = new OsmAndTaskManager(this); private final UiUtilities iconsCache = new UiUtilities(this); - Handler uiHandler; - - NavigationService navigationService; - DownloadService downloadService; - - OsmandAidlApi aidlApi; // start variables ResourceManager resourceManager; @@ -157,10 +156,8 @@ public class OsmandApplication extends MultiDexApplication { QuickActionRegistry quickActionRegistry; private Resources localizedResources; - private Map customRoutingConfigs = new ConcurrentHashMap<>(); - - private Locale preferredLocale = null; + private Locale preferredLocale; private Locale defaultLocale; private File externalStorageDirectory; private boolean externalStorageDirectoryReadOnly; @@ -591,8 +588,7 @@ public class OsmandApplication extends MultiDexApplication { while (getNavigationService() != null) { try { Thread.sleep(100); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { } } @@ -782,12 +778,28 @@ public class OsmandApplication extends MultiDexApplication { setLanguage(c); c.setTheme(themeResId); } - + + IBRouterService reconnectToBRouter() { + try { + bRouterServiceConnection = BRouterServiceConnection.connect(this); + if (bRouterServiceConnection != null) { + return bRouterServiceConnection.getBrouterService(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + public IBRouterService getBRouterService() { - if(bRouterServiceConnection == null) { + if (bRouterServiceConnection == null) { return null; } - return bRouterServiceConnection.getBrouterService(); + IBRouterService s = bRouterServiceConnection.getBrouterService(); + if (s != null && !s.asBinder().isBinderAlive()) { + s = reconnectToBRouter(); + } + return s; } public void setLanguage(Context context) {