summaryrefslogtreecommitdiff
path: root/fakelocation/src/main
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2023-12-23 00:52:30 +0100
committerLeonard Kugis <leonard@kug.is>2023-12-23 00:52:30 +0100
commiteab77a885f6cca1d785ca57c4cd9182dc1a898cf (patch)
tree7dba714b870895220d815368d7762212ff10c5eb /fakelocation/src/main
parent98df413858d1ac577f9c510a9490f382b3f848b4 (diff)
Implemented altitude/speed/jitter parameters
Diffstat (limited to 'fakelocation/src/main')
-rw-r--r--fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/domain/usecases/FakeLocationModule.kt18
-rw-r--r--fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/services/FakeLocationService.kt32
2 files changed, 36 insertions, 14 deletions
diff --git a/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/domain/usecases/FakeLocationModule.kt b/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/domain/usecases/FakeLocationModule.kt
index c9aac0a..4934899 100644
--- a/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/domain/usecases/FakeLocationModule.kt
+++ b/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/domain/usecases/FakeLocationModule.kt
@@ -85,28 +85,28 @@ class FakeLocationModule(private val context: Context) {
}
}
- fun setFakeLocation(latitude: Double, longitude: Double) {
- context.startService(FakeLocationService.buildFakeLocationIntent(context, latitude, longitude))
+ fun setFakeLocation(altitude: Double, speed: Float, jitter: Float, latitude: Double, longitude: Double) {
+ context.startService(FakeLocationService.buildFakeLocationIntent(context, altitude, speed, jitter, latitude, longitude))
}
- internal fun setTestProviderLocation(latitude: Double, longitude: Double) {
+ internal fun setTestProviderLocation(altitude: Double, speed: Float, jitter: Float, latitude: Double, longitude: Double) {
providers.forEach { provider ->
val location = Location(provider)
location.latitude = latitude
location.longitude = longitude
// Set default value for all the other required fields.
- location.altitude = 3.0
+ location.altitude = altitude
location.time = System.currentTimeMillis()
- location.speed = 0.01f
+ location.speed = speed
location.bearing = 1f
- location.accuracy = 3f
+ location.accuracy = jitter
location.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- location.bearingAccuracyDegrees = 0.1f
- location.verticalAccuracyMeters = 0.1f
- location.speedAccuracyMetersPerSecond = 0.01f
+ location.bearingAccuracyDegrees = jitter / 10.0f
+ location.verticalAccuracyMeters = jitter / 10.0f
+ location.speedAccuracyMetersPerSecond = jitter / 100.0f
}
try {
locationManager.setTestProviderLocation(provider, location)
diff --git a/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/services/FakeLocationService.kt b/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/services/FakeLocationService.kt
index 6eaae54..af3b397 100644
--- a/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/services/FakeLocationService.kt
+++ b/fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/services/FakeLocationService.kt
@@ -25,6 +25,8 @@ import android.os.IBinder
import android.util.Log
import foundation.e.advancedprivacy.fakelocation.domain.usecases.FakeLocationModule
+import kotlin.random.Random
+
class FakeLocationService : Service() {
enum class Actions {
@@ -35,12 +37,18 @@ class FakeLocationService : Service() {
private const val PERIOD_LOCATION_UPDATE = 1000L
private const val PERIOD_UPDATES_SERIE = 2 * 60 * 1000L
+ private const val PARAM_ALTITUDE = "PARAM_ALTITUDE"
+ private const val PARAM_SPEED = "PARAM_SPEED"
+ private const val PARAM_JITTER = "PARAM_JITTER"
private const val PARAM_LATITUDE = "PARAM_LATITUDE"
private const val PARAM_LONGITUDE = "PARAM_LONGITUDE"
- fun buildFakeLocationIntent(context: Context, latitude: Double, longitude: Double): Intent {
+ fun buildFakeLocationIntent(context: Context, altitude: Double, speed: Float, jitter: Float, latitude: Double, longitude: Double): Intent {
return Intent(context, FakeLocationService::class.java).apply {
action = Actions.START_FAKE_LOCATION.name
+ putExtra(PARAM_ALTITUDE, altitude)
+ putExtra(PARAM_SPEED, speed)
+ putExtra(PARAM_JITTER, jitter)
putExtra(PARAM_LATITUDE, latitude)
putExtra(PARAM_LONGITUDE, longitude)
}
@@ -53,6 +61,10 @@ class FakeLocationService : Service() {
private var countDownTimer: CountDownTimer? = null
+ private var altitude: Double? = null
+ private var speed: Float? = null
+ private var jitter: Float? = null
+
private var fakeLocation: Pair<Double, Double>? = null
override fun onCreate() {
@@ -64,7 +76,9 @@ class FakeLocationService : Service() {
intent?.let {
when (it.action?.let { str -> Actions.valueOf(str) }) {
Actions.START_FAKE_LOCATION -> {
-
+ altitude = it.getDoubleExtra(PARAM_ALTITUDE, 3.0)
+ speed = it.getFloatExtra(PARAM_ALTITUDE, 1.0f)
+ jitter = it.getFloatExtra(PARAM_ALTITUDE, 3.0f)
fakeLocation = Pair(
it.getDoubleExtra(PARAM_LATITUDE, 0.0),
it.getDoubleExtra(PARAM_LONGITUDE, 0.0)
@@ -87,11 +101,19 @@ class FakeLocationService : Service() {
countDownTimer?.cancel()
countDownTimer = object : CountDownTimer(PERIOD_UPDATES_SERIE, PERIOD_LOCATION_UPDATE) {
override fun onTick(millisUntilFinished: Long) {
- fakeLocation?.let {
+ var altitude_buf: Double = altitude ?: return
+ var speed_buf: Float = speed ?: return
+ var jitter_buf: Float = jitter ?: return
+ var fakeLocation_buf: Pair<Double, Double> = fakeLocation ?: return
+ if(fakeLocation != null && altitude != null && speed != null && jitter != null) {
+ // buffer
try {
fakeLocationModule.setTestProviderLocation(
- it.first,
- it.second
+ altitude_buf + ((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f)),
+ speed_buf + ((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f)),
+ jitter_buf,
+ fakeLocation_buf.first + (((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f)) / 111139.0f),
+ fakeLocation_buf.second + (((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f)) / 111139.0f)
)
} catch (e: Exception) {
Log.d("FakeLocationService", "setting fake location", e)