From b0c1464a31aed5b7018f80b6ba93deb2c467002a Mon Sep 17 00:00:00 2001 From: Alexander Marchuk Date: Tue, 17 May 2016 13:41:40 +0300 Subject: [PATCH] [android] fix: Crash on accessing uninitialized framework. --- android/src/com/mapswithme/maps/LocationState.java | 12 +++++++++--- android/src/com/mapswithme/maps/MwmActivity.java | 6 +++--- .../com/mapswithme/maps/location/LocationHelper.java | 4 ++-- .../mapswithme/maps/location/LocationPredictor.java | 2 +- .../mapswithme/maps/routing/ResultCodesHelper.java | 2 +- .../maps/widget/menu/MyPositionButton.java | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/android/src/com/mapswithme/maps/LocationState.java b/android/src/com/mapswithme/maps/LocationState.java index ed00f92d20..83852e9f0e 100644 --- a/android/src/com/mapswithme/maps/LocationState.java +++ b/android/src/com/mapswithme/maps/LocationState.java @@ -18,7 +18,7 @@ public enum LocationState public static final int FOLLOW_AND_ROTATE = 4; public native void nativeSwitchToNextMode(); - public native int nativeGetMode(); + private native int nativeGetMode(); public native void nativeSetListener(ModeChangeListener listener); public native void nativeRemoveListener(); @@ -26,8 +26,14 @@ public enum LocationState /** * Checks if location state on the map is active (so its not turned off or pending). */ - public boolean isTurnedOn() + public static boolean isTurnedOn() { - return nativeGetMode() > NOT_FOLLOW_NO_POSITION; + return getMode() > NOT_FOLLOW_NO_POSITION; + } + + public static int getMode() + { + MwmApplication.get().initNativeCore(); + return INSTANCE.nativeGetMode(); } } diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 4a50e3d95d..d8ffbe5148 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -920,7 +920,7 @@ public class MwmActivity extends BaseMwmFragmentActivity { super.onResume(); LocationState.INSTANCE.nativeSetListener(this); - mMainMenu.getMyPositionButton().update(LocationState.INSTANCE.nativeGetMode()); + mMainMenu.getMyPositionButton().update(LocationState.getMode()); resumeLocation(); mSearchController.refreshToolbar(); mMainMenu.onResume(new Runnable() @@ -964,13 +964,13 @@ public class MwmActivity extends BaseMwmFragmentActivity mFirstStart = FirstStartFragment.showOn(this); if (mFirstStart) { - if (LocationState.INSTANCE.isTurnedOn()) + if (LocationState.isTurnedOn()) addTask(new MwmActivity.MapTask() { @Override public boolean run(MwmActivity target) { - if (LocationState.INSTANCE.isTurnedOn()) + if (LocationState.isTurnedOn()) LocationState.INSTANCE.nativeSwitchToNextMode(); return false; } diff --git a/android/src/com/mapswithme/maps/location/LocationHelper.java b/android/src/com/mapswithme/maps/location/LocationHelper.java index 9be461c35e..58a32a51d6 100644 --- a/android/src/com/mapswithme/maps/location/LocationHelper.java +++ b/android/src/com/mapswithme/maps/location/LocationHelper.java @@ -151,7 +151,7 @@ public enum LocationHelper implements SensorEventListener @Nullable public MapObject getMyPosition() { - if (!LocationState.INSTANCE.isTurnedOn()) + if (!LocationState.isTurnedOn()) { mMyPosition = null; return null; @@ -342,7 +342,7 @@ public enum LocationHelper implements SensorEventListener return; } - int mode = LocationState.INSTANCE.nativeGetMode(); + int mode = LocationState.getMode(); switch (mode) { default: diff --git a/android/src/com/mapswithme/maps/location/LocationPredictor.java b/android/src/com/mapswithme/maps/location/LocationPredictor.java index 155673486d..00630c6d1d 100644 --- a/android/src/com/mapswithme/maps/location/LocationPredictor.java +++ b/android/src/com/mapswithme/maps/location/LocationPredictor.java @@ -37,7 +37,7 @@ public class LocationPredictor public void resume() { - myPositionModeChanged(LocationState.INSTANCE.nativeGetMode()); + myPositionModeChanged(LocationState.getMode()); } public void pause() diff --git a/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java b/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java index 1fa134d088..e8e1b0651d 100644 --- a/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java +++ b/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java @@ -34,7 +34,7 @@ class ResultCodesHelper switch (errorCode) { case NO_POSITION: - if (LocationState.INSTANCE.nativeGetMode() == LocationState.NOT_FOLLOW_NO_POSITION) + if (LocationState.getMode() == LocationState.NOT_FOLLOW_NO_POSITION) { titleRes = R.string.dialog_routing_location_turn_on; messages.add(resources.getString(R.string.dialog_routing_location_unknown_turn_on)); diff --git a/android/src/com/mapswithme/maps/widget/menu/MyPositionButton.java b/android/src/com/mapswithme/maps/widget/menu/MyPositionButton.java index b0b0160b75..48261fd966 100644 --- a/android/src/com/mapswithme/maps/widget/menu/MyPositionButton.java +++ b/android/src/com/mapswithme/maps/widget/menu/MyPositionButton.java @@ -27,7 +27,7 @@ public class MyPositionButton { Statistics.INSTANCE.trackEvent(Statistics.EventName.TOOLBAR_MY_POSITION); AlohaHelper.logClick(AlohaHelper.TOOLBAR_MY_POSITION); - if (!LocationState.INSTANCE.isTurnedOn()) + if (!LocationState.isTurnedOn()) { LocationHelper.INSTANCE.setShouldResolveErrors(true); LocationHelper.INSTANCE.restart(); // restart to check location settings again.