summaryrefslogtreecommitdiff
path: root/fakelocation/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'fakelocation/src/main')
-rw-r--r--fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/domain/usecases/FakeLocationModule.kt16
-rw-r--r--fakelocation/src/main/java/foundation/e/advancedprivacy/fakelocation/services/FakeLocationService.kt38
2 files changed, 41 insertions, 13 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 7424f38..9036a92 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
@@ -95,11 +95,11 @@ class FakeLocationModule(private val context: Context) {
context.stopService(FakeLocationService.buildStopIntent(context))
}
- fun setFakeLocation(altitude: Double, speed: Float, jitter: Float, latitude: Double, longitude: Double) {
- context.startService(FakeLocationService.buildFakeLocationIntent(context, altitude, speed, jitter, latitude, longitude))
+ fun setFakeLocation(altitude: Double, speed: Float, bearing: Float, jitter: Float, jitterAltitude: Double, jitterSpeed: Float, jitterBearing: Float, latitude: Double, longitude: Double) {
+ context.startService(FakeLocationService.buildFakeLocationIntent(context, altitude, speed, bearing, jitter, jitterAltitude, jitterSpeed, jitterBearing, latitude, longitude))
}
- internal fun setTestProviderLocation(altitude: Double, speed: Float, jitter: Float, latitude: Double, longitude: Double) {
+ internal fun setTestProviderLocation(altitude: Double, speed: Float, bearing: Float, accuracy: Float, accuracyAltitude: Float, accuracySpeed: Float, accuracyBearing: Float, latitude: Double, longitude: Double) {
providers.forEach { provider ->
val location = Location(provider)
location.latitude = latitude
@@ -109,14 +109,14 @@ class FakeLocationModule(private val context: Context) {
location.altitude = altitude
location.time = System.currentTimeMillis()
location.speed = speed
- location.bearing = 1f
- location.accuracy = jitter
+ location.bearing = bearing
+ location.accuracy = accuracy
location.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- location.bearingAccuracyDegrees = jitter / 10.0f
- location.verticalAccuracyMeters = jitter / 10.0f
- location.speedAccuracyMetersPerSecond = jitter / 100.0f
+ location.bearingAccuracyDegrees = accuracyBearing
+ location.verticalAccuracyMeters = accuracyAltitude
+ location.speedAccuracyMetersPerSecond = accuracySpeed
}
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 f9a3c52..41784a1 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
@@ -45,18 +45,26 @@ class FakeLocationService : Service() {
private const val PARAM_ALTITUDE = "PARAM_ALTITUDE"
private const val PARAM_SPEED = "PARAM_SPEED"
+ private const val PARAM_BEARING = "PARAM_BEARING"
private const val PARAM_JITTER = "PARAM_JITTER"
+ private const val PARAM_JITTER_ALTITUDE = "PARAM_JITTER_ALTITUDE"
+ private const val PARAM_JITTER_SPEED = "PARAM_JITTER_SPEED"
+ private const val PARAM_JITTER_BEARING = "PARAM_JITTER_BEARING"
private const val PARAM_LATITUDE = "PARAM_LATITUDE"
private const val PARAM_LONGITUDE = "PARAM_LONGITUDE"
private const val PARAM_ROUTE = "PARAM_ROUTE"
private const val PARAM_ROUTE_LOOP = "PARAM_ROUTE_LOOP"
- fun buildFakeLocationIntent(context: Context, altitude: Double, speed: Float, jitter: Float, latitude: Double, longitude: Double): Intent {
+ fun buildFakeLocationIntent(context: Context, altitude: Double, speed: Float, bearing: Float, jitter: Float, jitterAltitude: Double, jitterSpeed: Float, jitterBearing: 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_BEARING, bearing)
putExtra(PARAM_JITTER, jitter)
+ putExtra(PARAM_JITTER_ALTITUDE, jitterAltitude)
+ putExtra(PARAM_JITTER_SPEED, jitterSpeed)
+ putExtra(PARAM_JITTER_BEARING, jitterBearing)
putExtra(PARAM_LATITUDE, latitude)
putExtra(PARAM_LONGITUDE, longitude)
}
@@ -81,7 +89,11 @@ class FakeLocationService : Service() {
private var altitude: Double? = null
private var speed: Float? = null
+ private var bearing: Float? = null
private var jitter: Float? = null
+ private var jitterAltitude: Double? = null
+ private var jitterSpeed: Float? = null
+ private var jitterBearing: Float? = null
private var fakeLocation: Pair<Double, Double>? = null
@@ -100,7 +112,11 @@ class FakeLocationService : Service() {
Actions.START_FAKE_LOCATION -> {
altitude = it.getDoubleExtra(PARAM_ALTITUDE, 3.0)
speed = it.getFloatExtra(PARAM_SPEED, 1.0f)
+ bearing = it.getFloatExtra(PARAM_BEARING, 0.0f)
jitter = it.getFloatExtra(PARAM_JITTER, 3.0f)
+ jitterAltitude = it.getDoubleExtra(PARAM_JITTER_ALTITUDE, 3.0)
+ jitterSpeed = it.getFloatExtra(PARAM_JITTER_SPEED, 0.1f)
+ jitterBearing = it.getFloatExtra(PARAM_JITTER_BEARING, 10.0f)
fakeLocation = Pair(
it.getDoubleExtra(PARAM_LATITUDE, 0.0),
it.getDoubleExtra(PARAM_LONGITUDE, 0.0)
@@ -131,14 +147,22 @@ class FakeLocationService : Service() {
override fun onTick(millisUntilFinished: Long) {
var altitude_buf: Double = altitude ?: return
var speed_buf: Float = speed ?: return
+ var bearing_buf: Float = bearing ?: return
var jitter_buf: Float = jitter ?: return
+ var jitterAltitude_buf: Double = jitterAltitude ?: return
+ var jitterSpeed_buf: Float = jitterSpeed ?: return
+ var jitterBearing_buf: Float = jitterBearing ?: return
var fakeLocation_buf: Pair<Double, Double> = fakeLocation ?: return
if(fakeLocation != null && altitude != null && speed != null && jitter != null) {
try {
fakeLocationModule.setTestProviderLocation(
- (altitude_buf + ((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f))).toDouble(),
- speed_buf + ((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f)),
+ (altitude_buf + ((Random.nextFloat() * jitterAltitude_buf) - (jitterAltitude_buf * 0.5f))).toDouble(),
+ speed_buf + ((Random.nextFloat() * jitterSpeed_buf) - (jitterSpeed_buf * 0.5f)),
+ bearing_buf + ((Random.nextFloat() * jitterBearing_buf) - (jitterBearing_buf * 0.5f)),
jitter_buf,
+ jitterAltitude_buf.toFloat(),
+ jitterSpeed_buf,
+ jitterBearing_buf,
(fakeLocation_buf.first + (((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f)) / 111139.0f)).toDouble(),
(fakeLocation_buf.second + (((Random.nextFloat() * jitter_buf) - (jitter_buf * 0.5f)) / 111139.0f)).toDouble()
)
@@ -212,9 +236,13 @@ class FakeLocationService : Service() {
}
try {
fakeLocationModule.setTestProviderLocation(
- (coord.first.altitude + ((Random.nextFloat() * coord.first.jitter) - (coord.first.jitter * 0.5f))).toDouble(),
- coord.first.speed + ((Random.nextFloat() * coord.first.jitter) - (coord.first.jitter * 0.5f)),
+ (coord.first.altitude + ((Random.nextFloat() * coord.first.jitterAltitude) - (coord.first.jitterAltitude * 0.5f))).toDouble(),
+ coord.first.speed + ((Random.nextFloat() * coord.first.jitterSpeed) - (coord.first.jitterSpeed * 0.5f)),
+ coord.first.bearing + ((Random.nextFloat() * coord.first.jitterBearing) - (coord.first.jitterBearing * 0.5f)),
coord.first.jitter,
+ coord.first.jitterAltitude,
+ coord.first.jitterSpeed,
+ coord.first.jitterBearing,
(coord.second.first + (((Random.nextFloat() * coord.first.jitter) - (coord.first.jitter * 0.5f)) / 111139.0f)).toDouble(),
(coord.second.second + (((Random.nextFloat() * coord.first.jitter) - (coord.first.jitter * 0.5f)) / 111139.0f)).toDouble()
)