From 39bac02dc3b2513a8c22b305242c638c290ec429 Mon Sep 17 00:00:00 2001 From: Dmitry Yunitsky Date: Wed, 11 May 2016 13:03:40 +0300 Subject: [PATCH] [android] Fixed crash with RoutingController attaching listeners before framework is initialized. --- android/jni/com/mapswithme/maps/Framework.cpp | 2 ++ .../com/mapswithme/maps/MwmApplication.java | 2 ++ .../maps/routing/RoutingController.java | 22 +++++++++---------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 69c0e38f34..471760c9cb 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -826,12 +826,14 @@ Java_com_mapswithme_maps_Framework_nativeShowCountry(JNIEnv * env, jclass, jstri JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeSetRoutingListener(JNIEnv * env, jclass, jobject listener) { + CHECK(g_framework, ("Framework isn't created yet!")); frm()->SetRouteBuildingListener(bind(&CallRoutingListener, jni::make_global_ref(listener), _1, _2)); } JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeSetRouteProgressListener(JNIEnv * env, jclass, jobject listener) { + CHECK(g_framework, ("Framework isn't created yet!")); frm()->SetRouteProgressListener(bind(&CallRouteProgressListener, jni::make_global_ref(listener), _1)); } diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java index f4731589f1..ff1780e27f 100644 --- a/android/src/com/mapswithme/maps/MwmApplication.java +++ b/android/src/com/mapswithme/maps/MwmApplication.java @@ -23,6 +23,7 @@ import com.mapswithme.maps.downloader.CountryItem; import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.editor.Editor; import com.mapswithme.maps.location.TrackRecorder; +import com.mapswithme.maps.routing.RoutingController; import com.mapswithme.maps.sound.TtsPlayer; import com.mapswithme.util.Config; import com.mapswithme.util.Constants; @@ -131,6 +132,7 @@ public class MwmApplication extends Application BookmarkManager.nativeLoadBookmarks(); TtsPlayer.INSTANCE.init(this); ThemeSwitcher.restart(); + RoutingController.get().initialize(); mIsFrameworkInitialized = true; } diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index 99148d13b7..44d10d921d 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -141,6 +141,11 @@ public class RoutingController } }; + public static RoutingController get() + { + return sInstance; + } + private void processRoutingEvent() { if (!mContainsCachedResult || @@ -164,17 +169,6 @@ public class RoutingController fragment.show(mContainer.getActivity().getSupportFragmentManager(), RoutingErrorDialogFragment.class.getSimpleName()); } - private RoutingController() - { - Framework.nativeSetRoutingListener(mRoutingListener); - Framework.nativeSetRouteProgressListener(mRoutingProgressListener); - } - - public static RoutingController get() - { - return sInstance; - } - private void setState(State newState) { Log.d(TAG, "[S] State: " + mState + " -> " + newState + ", BuildState: " + mBuildState); @@ -217,6 +211,12 @@ public class RoutingController mContainer = container; } + public void initialize() + { + Framework.nativeSetRoutingListener(mRoutingListener); + Framework.nativeSetRouteProgressListener(mRoutingProgressListener); + } + public void detach() { mContainer = null;