Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix location crash #5084

Merged
merged 23 commits into from
Jan 31, 2022
Merged

Fix location crash #5084

merged 23 commits into from
Jan 31, 2022

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Jan 27, 2022

When the user want to share their location and then disable the location on their device, there was a crash on Android < R.

Now the user get a dialog and can safely close the screen.

Update

I use the same PR to fix more implementation issue:

  • Some lifecycle method was not called.
  • Add a ProgressBar when the user wait to see his location. It can take several seconds on my device
  • Move some logic to the ViewModel.
  • pin was not rendered if the user has no avatar
  • fix race condition between map ready / location update
  • NEW Give priority to GPS provider over the other ones

There is still some problems:

  • a regression from this PR: In a timeline, it there are several location events, the pin is not displayed on each item. I am pretty sure it's a stupid bug, I will investigate later.
  • In the timeline we do not cleanup properly the maps, I think it can lead to bug due to bad releasing of resources.
  • Same problem in the bottomsheet (message detail)

`LocationListener` does not have default implementation for some methods for Android versions below R
@bmarty bmarty requested a review from onurays January 27, 2022 15:31
@bmarty bmarty mentioned this pull request Jan 27, 2022
56 tasks
Copy link
Contributor

@onurays onurays left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised, approved, thanks a lot for testing.

@github-actions
Copy link

github-actions bot commented Jan 27, 2022

Unit Test Results

  76 files  +4    76 suites  +4   54s ⏱️ -1s
143 tests +2  143 ✔️ +2  0 💤 ±0  0 ±0 
448 runs  +8  448 ✔️ +8  0 💤 ±0  0 ±0 

Results for commit 8ee23c1. ± Comparison against base commit a6ae709.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 27, 2022

Matrix SDK

Integration Tests Results:

  • [org.matrix.android.sdk.session]
    passed="21" failures="0" errors="0" skipped="2"
  • [org.matrix.android.sdk.account]
    passed="5" failures="0" errors="0" skipped="2"
  • [org.matrix.android.sdk.internal]
    passed="158" failures="1" errors="0" skipped="38"
  • [org.matrix.android.sdk.ordering]
    passed="16" failures="0" errors="0" skipped="0"
  • [org.matrix.android.sdk.PermalinkParserTest]
    passed="2" failures="0" errors="0" skipped="0"

@bmarty bmarty requested a review from onurays January 27, 2022 21:33
errorDrawable ?: return
val pinDrawable = createPinDrawable(errorDrawable)
cache[userId] = pinDrawable
callback(pinDrawable)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the issue when the user does not have an avatar

@@ -18,15 +18,9 @@ package im.vector.app.features.location

import android.graphics.drawable.Drawable

interface VectorMapView {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface was implemented but not really used as a type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tried to be flexible in case of changing the map library but has problems with epoxy.

style
)
pendingState?.let { render(it) }
pendingState = null
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to fix race condition here

return map?.cameraPosition?.zoom
}

override fun onClick(callback: () -> Unit) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was not used

android:layout_marginEnd="@dimen/layout_horizontal_margin"
app:layout_constraintBottom_toBottomOf="@id/shareLocationContainer"
app:layout_constraintEnd_toEndOf="@id/shareLocationContainer"
app:layout_constraintTop_toTopOf="@id/shareLocationContainer" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@bmarty bmarty requested a review from ouchadam January 28, 2022 08:39
callback?.onLocationUpdate(lastKnownLocation.toLocationData())
}

locationManager.requestLocationUpdates(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK to call this multiple times this fun and call only once locationManager?.removeUpdates(this) in onStop? Maybe yes but I want to be sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can see the location icon on Status Bar is disappearing when fragment is destroyed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah didn't notice that. It does not disappear on my side

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I have to put the entire app into bg to make it disappear to be more precise.

Copy link
Contributor

@ouchadam ouchadam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

working well in my local test

@DoM1niC
Copy link

DoM1niC commented Jan 28, 2022

for me the Marker is there but no Map Render in Timeline but the rest to seems work now :)

@bmarty
Copy link
Member Author

bmarty commented Jan 28, 2022

for me the Marker is there but no Map Render in Timeline but the rest to seems work now :)

Thanks for your feedback!

Loading images in the timeline can take a few seconds but is working here.

@bmarty bmarty requested a review from ouchadam January 28, 2022 21:55
append(keyParam)
if (!resources.getBoolean(R.bool.is_rtl)) {
// On LTR languages we want the legal mentions to be displayed on the bottom left of the image
append("&attribution=bottomleft")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

Copy link
Contributor

@onurays onurays left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great collaboration!

@DoM1niC
Copy link

DoM1niC commented Jan 29, 2022

OS: Oxygen OS 11 based on Android 11
Mhhh... I wait more then 30 Sec without luck here 🥺
Video
https://user-images.githubusercontent.com/1436958/151638693-96a96509-34dd-4470-b334-5a014820ff02.mp4

for me the Marker is there but no Map Render in Timeline but the rest to seems work now :)

Thanks for your feedback!

Loading images in the timeline can take a few seconds but is working here.

@bmarty
Copy link
Member Author

bmarty commented Jan 29, 2022

@DoM1niC any chance that you put a breakpoint here and get the URL location, then try to open it from the browser of your device? The image should be displayed.

}

@Test
fun invalidCases() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks for the test cases!

@onurays
Copy link
Contributor

onurays commented Jan 31, 2022

@DoM1niC any chance that you put a breakpoint here and get the URL location, then try to open it from the browser of your device? The image should be displayed.

I can reproduce it

val locationUrl = state.timelineEvent()?.root?.getClearContent()
?.toModel<MessageLocationContent>(catchError = true)
?.toLocationData()
?.let { urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, 1200, 800) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is it worth extracting these to width/height constants or using named params?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and I think the values are not correct (since not related to the actual ImageView size). Anyway, could be improved later, this is not a big issue, Glide will crop the image anyway (I think)
Thanks for the review!

@bmarty bmarty merged commit 91e444c into develop Jan 31, 2022
@bmarty bmarty deleted the feature/bma/location_crash branch January 31, 2022 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants