mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Don't crash the app if the node sends a bogus lat > 90 deg
This commit is contained in:
parent
1bff4d8178
commit
12ef3d4d7b
2 changed files with 23 additions and 1 deletions
|
|
@ -89,7 +89,11 @@ data class NodeInfo(
|
|||
/// return the position if it is valid, else null
|
||||
val validPosition: Position?
|
||||
get() {
|
||||
return position?.takeIf { it.latitude != 0.0 || it.longitude != 0.0 }
|
||||
return position?.takeIf {
|
||||
(it.latitude <= 90.0 && it.latitude >= -90) && // If GPS gives a crap position don't crash our app
|
||||
it.latitude != 0.0 &&
|
||||
it.longitude != 0.0
|
||||
}
|
||||
}
|
||||
|
||||
/// @return distance in meters to some other node (or null if unknown)
|
||||
|
|
|
|||
18
app/src/test/java/com/geeksville/mesh/PositionTest.kt
Normal file
18
app/src/test/java/com/geeksville/mesh/PositionTest.kt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package com.geeksville.mesh
|
||||
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class PositionTest {
|
||||
@Test
|
||||
fun degGood() {
|
||||
Assert.assertEquals(Position.degI(89.0), 890000000)
|
||||
Assert.assertEquals(Position.degI(-89.0), -890000000)
|
||||
|
||||
Assert.assertEquals(Position.degD(Position.degI(89.0)), 89.0, 0.01)
|
||||
Assert.assertEquals(Position.degD(Position.degI(-89.0)), -89.0, 0.01)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue