Skip to content

Commit

Permalink
[android] Removed "Continue detecting your location?" dialog
Browse files Browse the repository at this point in the history
User now explicitly controls if location search should be disabled by pressing rotating radar icon

Signed-off-by: Alexander Borsuk <[email protected]>
  • Loading branch information
biodranik authored and rtsisyk committed Feb 6, 2024
1 parent 618e420 commit d0f3a6d
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 188 deletions.
24 changes: 0 additions & 24 deletions android/app/src/main/cpp/app/organicmaps/LocationState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ static void LocationStateModeChanged(location::EMyPositionMode mode,
"onMyPositionModeChanged", "(I)V"), static_cast<jint>(mode));
}

static void LocationPendingTimeout(std::shared_ptr<jobject> const & listener)
{
JNIEnv * env = jni::GetEnv();
env->CallVoidMethod(*listener, jni::GetMethodID(env, *listener.get(),
"onLocationPendingTimeout", "()V"));
}

// public static void nativeSwitchToNextMode();
JNIEXPORT void JNICALL
Java_app_organicmaps_location_LocationState_nativeSwitchToNextMode(JNIEnv * env, jclass clazz)
Expand Down Expand Up @@ -59,23 +52,6 @@ Java_app_organicmaps_location_LocationState_nativeRemoveListener(JNIEnv * env, j
g_framework->SetMyPositionModeListener(location::TMyPositionModeChanged());
}

JNIEXPORT void JNICALL
Java_app_organicmaps_location_LocationState_nativeSetLocationPendingTimeoutListener(
JNIEnv * env, jclass clazz, jobject listener)
{
ASSERT(g_framework, ());
g_framework->NativeFramework()->SetMyPositionPendingTimeoutListener(
std::bind(&LocationPendingTimeout, jni::make_global_ref(listener)));
}

JNIEXPORT void JNICALL
Java_app_organicmaps_location_LocationState_nativeRemoveLocationPendingTimeoutListener(
JNIEnv * env, jclass)
{
ASSERT(g_framework, ());
g_framework->NativeFramework()->SetMyPositionPendingTimeoutListener(nullptr);
}

JNIEXPORT void JNICALL
Java_app_organicmaps_location_LocationState_nativeOnLocationError(JNIEnv * env, jclass clazz, int errorCode)
{
Expand Down
50 changes: 0 additions & 50 deletions android/app/src/main/java/app/organicmaps/MwmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,6 @@ protected void onResume()
mNavigationController.refresh();
refreshLightStatusBar();

LocationState.nativeSetLocationPendingTimeoutListener(this::onLocationPendingTimeout);
SensorHelper.from(this).addListener(this);
}

Expand All @@ -1058,7 +1057,6 @@ protected void onPause()
{
if (mOnmapDownloader != null)
mOnmapDownloader.onPause();
LocationState.nativeRemoveLocationPendingTimeoutListener();
SensorHelper.from(this).removeListener(this);
dismissLocationErrorDialog();
dismissAlertDialog();
Expand Down Expand Up @@ -1951,54 +1949,6 @@ public void onLocationDisabled()
mLocationErrorDialog = builder.show();
}

/**
* Called by the core when location updates were not received after the 30 second deadline.
*/
@UiThread
private void onLocationPendingTimeout()
{
// Sic: the callback can be called after the activity is destroyed because of being queued.
if (isDestroyed())
{
Logger.w(LOCATION_TAG, "Ignore late callback from core because activity is already destroyed");
return;
}

if (LocationState.getMode() == LocationState.NOT_FOLLOW_NO_POSITION)
{
Logger.d(LOCATION_TAG, "Don't show 'location timeout' error dialog in NOT_FOLLOW_NO_POSITION mode");
return;
}

Logger.d(LOCATION_TAG, "services = " + LocationUtils.areLocationServicesTurnedOn(this));

//
// For all cases below we don't stop location provider until user explicitly clicks "Stop" in the dialog.
//

if (mLocationErrorDialog != null && mLocationErrorDialog.isShowing())
{
Logger.d(LOCATION_TAG, "Don't show 'location timeout' error dialog because another dialog is in progress");
return;
}

mLocationErrorDialog = new MaterialAlertDialogBuilder(this, R.style.MwmTheme_AlertDialog)
.setTitle(R.string.current_location_unknown_title)
.setMessage(R.string.current_location_unknown_message)
.setOnDismissListener(dialog -> mLocationErrorDialog = null)
.setNegativeButton(R.string.current_location_unknown_stop_button, (dialog, which) ->
{
Logger.w(LOCATION_TAG, "Disabled by user");
// Calls onMyPositionModeChanged(NOT_FOLLOW_NO_POSITION).
LocationState.nativeOnLocationError(LocationState.ERROR_GPS_OFF);
})
.setPositiveButton(R.string.current_location_unknown_continue_button, (dialog, which) ->
{
// Do nothing - provider will continue to search location.
})
.show();
}

@Override
public void onUseMyPositionAsStart()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ public interface ModeChangeListener
void onMyPositionModeChanged(int newMode);
}

// Used by JNI.
@Keep
@SuppressWarnings("unused")
public interface PendingTimeoutListener
{
void onLocationPendingTimeout();
}

@Retention(RetentionPolicy.SOURCE)
@IntDef({ PENDING_POSITION, NOT_FOLLOW_NO_POSITION, NOT_FOLLOW, FOLLOW, FOLLOW_AND_ROTATE})
@interface Value {}
Expand All @@ -55,9 +47,6 @@ public interface PendingTimeoutListener
public static native void nativeSetListener(@NonNull ModeChangeListener listener);
public static native void nativeRemoveListener();

public static native void nativeSetLocationPendingTimeoutListener(@NonNull PendingTimeoutListener listener);
public static native void nativeRemoveLocationPendingTimeoutListener();

public static native void nativeOnLocationError(int errorCode);

static native void nativeLocationUpdated(long time, double lat, double lon, float accuracy,
Expand Down
33 changes: 15 additions & 18 deletions docs/ANDROID_LOCATION_TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,38 @@ implementation on Android.
appears on the top of splash screen;
- Grant "Precise" or "Approximately" (doesn't matter) permissions
for "Only this time".
- [fdroid only] Initial map download dialog should appear and suggest to
- [FDroid only] Initial map download dialog should appear and suggest to
download map of your area (a check box);
- The main map screen should start with cool animation to your current location.

1. GPS cold start

- Disable Wi-Fi, disable Cellular Data, enable Location;
- Get under a roof and away from the open sky and any windows;
- Restart device, start the app, and wait 1 minute until
"Continue detecting your current location?" appears;
- Don't tap any buttons in the dialog - the search for a location
should continue in the background until "Stop" is explicitly taped;
- Go out to have the open sky and wait 1-5 minutes GPS to find satellites
without locking device and switching to another apps.
- "Continue detecting your current location?" should disappear
automatically when location is found;
- Restart device, start the app
- Wait until location is detected, or go outside to have the open sky and wait
for a few minutes so the device can find GPS satellites, without locking device
and switching to another apps.
- The screen should be automatically on all the time during the process.

This test-case should work with the same behavior regardless of
"Google Play Services" option in the app settings.
"Google Play Services" option in the app settings.

2. Location disabled by user

- Follow instructions from (1) until the dialog appears,
but press "Stop" button in the dialog;
- Follow first 3 steps from (1) above but stop detecting location by pressing
the location "rotating radar" button;
- Check that location icon is crossed out;
- Switch to some other app and back;
- Check that location icon is crossed out;
- Kill the app and start it again;
- Check that location icon is crossed out;
- Tap on location icon;
- Tap on location button;
- Ensure that location search has started;
- Wait until location is found under the open sky.

This test-case should work with the same behavior regardless of
"Google Play Services" option in the app settings.
"Google Play Services" option in the app settings.

3. Google location dialog (positive case)

Expand Down Expand Up @@ -99,16 +95,17 @@ This test-case should work with the same behavior regardless of
- Disable system Location by swiping down from Android's menu bar
to disable location via "Quick settings" panel WITHOUT switching
to Settings or any other apps;
- "Please enable Location Services" or "For better experiences..."
- "Please enable Location Services" or "For better experiences..."
dialog should appear immediately, depending in Google Play Service
availability;
- Further taps on location button will lead to (4) or (5).

7. Pending location mode
7. Pending (searching) location mode

- Disable Wi-Fi, disable cellular data, and enable location.
- Move your phone away from the open sky and any windows to make sure that GPS can't be acquired.
- If the location search hasn't already begun, press the location button to start it.
- The location icon MUST be "locating" while searching for a GPS signal.
- Press the location button multiple time - the icon MUST NOT change from the "locating" mode.
- The location icon MUST be "locating" while searching for a GPS signal, and location icon should be displayed in the system tray.
- Touch, drag or try to zoom in and zoom out the map - the icon MUST NOT change from "locating" mode.
- Press the location button to disable location search, its icon should change, and system location icon disappear after a few seconds.
- Press the location button again to start searching for location.
12 changes: 0 additions & 12 deletions drape_frontend/drape_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ DrapeEngine::DrapeEngine(Params && params)
std::bind(&DrapeEngine::ModelViewChanged, this, _1),
std::bind(&DrapeEngine::TapEvent, this, _1),
std::bind(&DrapeEngine::UserPositionChanged, this, _1, _2),
std::bind(&DrapeEngine::UserPositionPendingTimeout, this),
make_ref(m_requestedTiles),
std::move(params.m_overlaysShowStatsCallback),
params.m_allow3dBuildings,
Expand Down Expand Up @@ -469,12 +468,6 @@ void DrapeEngine::UserPositionChanged(m2::PointD const & position, bool hasPosit
m_userPositionChangedHandler(position, hasPosition);
}

void DrapeEngine::UserPositionPendingTimeout()
{
if (m_userPositionPendingTimeoutHandler != nullptr)
m_userPositionPendingTimeoutHandler();
}

void DrapeEngine::ResizeImpl(int w, int h)
{
gui::DrapeGui::Instance().SetSurfaceSize(m2::PointF(w, h));
Expand Down Expand Up @@ -555,11 +548,6 @@ void DrapeEngine::SetUserPositionListener(UserPositionChangedHandler && fn)
m_userPositionChangedHandler = std::move(fn);
}

void DrapeEngine::SetUserPositionPendingTimeoutListener(UserPositionPendingTimeoutHandler && fn)
{
m_userPositionPendingTimeoutHandler = std::move(fn);
}

void DrapeEngine::SelectObject(SelectionShape::ESelectedObject obj, m2::PointD const & pt,
FeatureID const & featureId, bool isAnim,
bool isGeometrySelectionAllowed, bool isSelectionShapeVisible)
Expand Down
4 changes: 0 additions & 4 deletions drape_frontend/drape_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ class DrapeEngine
void SetTapEventInfoListener(TapEventInfoHandler && fn);
using UserPositionChangedHandler = FrontendRenderer::UserPositionChangedHandler;
void SetUserPositionListener(UserPositionChangedHandler && fn);
using UserPositionPendingTimeoutHandler = FrontendRenderer::UserPositionPendingTimeoutHandler;
void SetUserPositionPendingTimeoutListener(UserPositionPendingTimeoutHandler && fn);

void SelectObject(SelectionShape::ESelectedObject obj, m2::PointD const & pt,
FeatureID const & featureID, bool isAnim, bool isGeometrySelectionAllowed,
Expand Down Expand Up @@ -258,7 +256,6 @@ class DrapeEngine
void MyPositionModeChanged(location::EMyPositionMode mode, bool routingActive);
void TapEvent(TapInfo const & tapInfo);
void UserPositionChanged(m2::PointD const & position, bool hasPosition);
void UserPositionPendingTimeout();

void ResizeImpl(int w, int h);
void RecacheGui(bool needResetOldGui);
Expand All @@ -282,7 +279,6 @@ class DrapeEngine
ModelViewChangedHandler m_modelViewChangedHandler;
TapEventInfoHandler m_tapEventInfoHandler;
UserPositionChangedHandler m_userPositionChangedHandler;
UserPositionPendingTimeoutHandler m_userPositionPendingTimeoutHandler;

gui::TWidgetsInitInfo m_widgetsInfo;
gui::TWidgetsLayoutInfo m_widgetsLayout;
Expand Down
7 changes: 0 additions & 7 deletions drape_frontend/frontend_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ FrontendRenderer::FrontendRenderer(Params && params)
, m_modelViewChangedHandler(std::move(params.m_modelViewChangedHandler))
, m_tapEventInfoHandler(std::move(params.m_tapEventHandler))
, m_userPositionChangedHandler(std::move(params.m_positionChangedHandler))
, m_userPositionPendingTimeoutHandler(std::move(params.m_userPositionPendingTimeoutHandler))
, m_requestedTiles(params.m_requestedTiles)
, m_maxGeneration(0)
, m_maxUserMarksGeneration(0)
Expand All @@ -194,7 +193,6 @@ FrontendRenderer::FrontendRenderer(Params && params)
ASSERT(m_modelViewChangedHandler, ());
ASSERT(m_tapEventInfoHandler, ());
ASSERT(m_userPositionChangedHandler, ());
ASSERT(m_userPositionPendingTimeoutHandler, ());

m_gpsTrackRenderer = make_unique_dp<GpsTrackRenderer>([this](uint32_t pointsCount)
{
Expand Down Expand Up @@ -2482,11 +2480,6 @@ void FrontendRenderer::PositionChanged(m2::PointD const & position, bool hasPosi
m_userPositionChangedHandler(position, hasPosition);
}

void FrontendRenderer::PositionPendingTimeout()
{
m_userPositionPendingTimeoutHandler();
}

void FrontendRenderer::ChangeModelView(m2::PointD const & center, int zoomLevel,
TAnimationCreator const & parallelAnimCreator)
{
Expand Down
6 changes: 0 additions & 6 deletions drape_frontend/frontend_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class FrontendRenderer : public BaseRenderer,
using GraphicsReadyHandler = std::function<void()>;
using TapEventInfoHandler = std::function<void(TapInfo const &)>;
using UserPositionChangedHandler = std::function<void(m2::PointD const & pt, bool hasPosition)>;
using UserPositionPendingTimeoutHandler = std::function<void()>;

struct Params : BaseRenderer::Params
{
Expand All @@ -92,7 +91,6 @@ class FrontendRenderer : public BaseRenderer,
MyPositionController::Params && myPositionParams, dp::Viewport viewport,
ModelViewChangedHandler && modelViewChangedHandler, TapEventInfoHandler && tapEventHandler,
UserPositionChangedHandler && positionChangedHandler,
UserPositionPendingTimeoutHandler && userPositionPendingTimeoutHandler,
ref_ptr<RequestedTiles> requestedTiles,
OverlaysShowStatsCallback && overlaysShowStatsCallback,
bool allow3dBuildings, bool trafficEnabled, bool blockTapEvents,
Expand All @@ -104,7 +102,6 @@ class FrontendRenderer : public BaseRenderer,
, m_modelViewChangedHandler(std::move(modelViewChangedHandler))
, m_tapEventHandler(std::move(tapEventHandler))
, m_positionChangedHandler(std::move(positionChangedHandler))
, m_userPositionPendingTimeoutHandler(std::move(userPositionPendingTimeoutHandler))
, m_requestedTiles(requestedTiles)
, m_overlaysShowStatsCallback(std::move(overlaysShowStatsCallback))
, m_allow3dBuildings(allow3dBuildings)
Expand All @@ -118,7 +115,6 @@ class FrontendRenderer : public BaseRenderer,
ModelViewChangedHandler m_modelViewChangedHandler;
TapEventInfoHandler m_tapEventHandler;
UserPositionChangedHandler m_positionChangedHandler;
UserPositionPendingTimeoutHandler m_userPositionPendingTimeoutHandler;
ref_ptr<RequestedTiles> m_requestedTiles;
OverlaysShowStatsCallback m_overlaysShowStatsCallback;
bool m_allow3dBuildings;
Expand All @@ -136,7 +132,6 @@ class FrontendRenderer : public BaseRenderer,

// MyPositionController::Listener
void PositionChanged(m2::PointD const & position, bool hasPosition) override;
void PositionPendingTimeout() override;
void ChangeModelView(m2::PointD const & center, int zoomLevel,
TAnimationCreator const & parallelAnimCreator) override;
void ChangeModelView(double azimuth, TAnimationCreator const & parallelAnimCreator) override;
Expand Down Expand Up @@ -342,7 +337,6 @@ class FrontendRenderer : public BaseRenderer,
ModelViewChangedHandler m_modelViewChangedHandler;
TapEventInfoHandler m_tapEventInfoHandler;
UserPositionChangedHandler m_userPositionChangedHandler;
UserPositionPendingTimeoutHandler m_userPositionPendingTimeoutHandler;

ScreenBase m_lastReadedModelView;
TTilesCollection m_notFinishedTiles;
Expand Down
Loading

0 comments on commit d0f3a6d

Please sign in to comment.