diff options
author | Leonard Kugis <leonard@kug.is> | 2024-01-04 02:39:04 +0100 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2024-01-04 02:39:04 +0100 |
commit | aa93b37883deb00c6ca74ad72a5464284fe9171f (patch) | |
tree | bcbc0792e914059a763a04182bbe0f2538b3a5b4 /app/src/main/java/foundation/e/advancedprivacy | |
parent | cb28d70fb5d220953dec337885601597c654e4fd (diff) |
Added additional fake location parameters
Bearing, Bearing jitter, Speed jitter, Altitude jitter
Diffstat (limited to 'app/src/main/java/foundation/e/advancedprivacy')
5 files changed, 140 insertions, 4 deletions
diff --git a/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt b/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt index 9643899..b1f5ec3 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt @@ -41,7 +41,11 @@ class LocalStateRepositoryImpl(context: Context) : LocalStateRepository { private const val KEY_IP_SCRAMBLING = "ipScrambling" private const val KEY_FAKE_ALTITUDE = "fakeAltitude" private const val KEY_FAKE_SPEED = "fakeSpeed" + private const val KEY_FAKE_BEARING = "fakeBearing" private const val KEY_FAKE_JITTER = "fakeJitter" + private const val KEY_FAKE_JITTER_ALTITUDE = "fakeJitterAltitude" + private const val KEY_FAKE_JITTER_SPEED = "fakeJitterSpeed" + private const val KEY_FAKE_JITTER_BEARING = "fakeJitterBearing" private const val KEY_LOCATION_MODE = "locationMode" private const val KEY_LOCATION_ROUTE = "locationRoute" private const val KEY_LOCATION_ROUTE_LOOP = "locationRouteLoop" @@ -82,6 +86,14 @@ class LocalStateRepositoryImpl(context: Context) : LocalStateRepository { .apply() } + override var fakeBearing: Float + get() = sharedPref.getFloat(KEY_FAKE_BEARING, 0.0f) + set(value) { + sharedPref.edit() + .putFloat(KEY_FAKE_BEARING, value) + .apply() + } + override var fakeJitter: Float get() = sharedPref.getFloat(KEY_FAKE_JITTER, 3.0f) set(value) { @@ -90,6 +102,30 @@ class LocalStateRepositoryImpl(context: Context) : LocalStateRepository { .apply() } + override var fakeJitterAltitude: Float + get() = sharedPref.getFloat(KEY_FAKE_JITTER_ALTITUDE, 3.0f) + set(value) { + sharedPref.edit() + .putFloat(KEY_FAKE_JITTER_ALTITUDE, value) + .apply() + } + + override var fakeJitterSpeed: Float + get() = sharedPref.getFloat(KEY_FAKE_JITTER_SPEED, 0.1f) + set(value) { + sharedPref.edit() + .putFloat(KEY_FAKE_JITTER_SPEED, value) + .apply() + } + + override var fakeJitterBearing: Float + get() = sharedPref.getFloat(KEY_FAKE_JITTER_BEARING, 10.0f) + set(value) { + sharedPref.edit() + .putFloat(KEY_FAKE_JITTER_BEARING, value) + .apply() + } + override var fakeLocation: Pair<Float, Float> get() = Pair( // Initial default value is Quezon City diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt index b7743df..1f92554 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt @@ -54,7 +54,7 @@ class FakeLocationStateUseCase( coroutineScope: CoroutineScope ) { private val _configuredLocationMode = MutableStateFlow<FakeLocationState>( - FakeLocationState(LocationMode.REAL_LOCATION, null, null, null, null, null, null, false, null, false, false) + FakeLocationState(LocationMode.REAL_LOCATION, null, null, null, null, null, null, null, null, null, null, false, null, false, false) ) val configuredLocationMode: StateFlow<FakeLocationState> = _configuredLocationMode @@ -120,6 +120,10 @@ class FakeLocationStateUseCase( null, null, null, + null, + null, + null, + null, false, localStateRepository.route, isEnabled, @@ -129,13 +133,17 @@ class FakeLocationStateUseCase( localStateRepository.routeLoopEnabled = isEnabled } - fun setFakeLocationParameters(altitude: Float, speed: Float, jitter: Float) { + fun setFakeLocationParameters(altitude: Float, speed: Float, bearing: Float, jitter: Float, jitterAltitude: Float, jitterSpeed: Float, jitterBearing: Float) { _configuredLocationMode.value = FakeLocationState( LocationMode.SPECIFIC_LOCATION, null, altitude, speed, + bearing, jitter, + jitterAltitude, + jitterSpeed, + jitterBearing, localStateRepository.fakeLocation.first, localStateRepository.fakeLocation.second, false, @@ -146,7 +154,11 @@ class FakeLocationStateUseCase( localStateRepository.fakeAltitude = altitude localStateRepository.fakeSpeed = speed + localStateRepository.fakeBearing = bearing localStateRepository.fakeJitter = jitter + localStateRepository.fakeJitterAltitude = jitterAltitude + localStateRepository.fakeJitterSpeed = jitterSpeed + localStateRepository.fakeJitterBearing = jitterBearing } fun useRealLocation() { @@ -158,6 +170,10 @@ class FakeLocationStateUseCase( null, null, null, + null, + null, + null, + null, false, null, false, @@ -183,7 +199,11 @@ class FakeLocationStateUseCase( null, localStateRepository.fakeAltitude, localStateRepository.fakeSpeed, + localStateRepository.fakeBearing, localStateRepository.fakeJitter, + localStateRepository.fakeJitterAltitude, + localStateRepository.fakeJitterSpeed, + localStateRepository.fakeJitterBearing, location.first, location.second, false, @@ -197,7 +217,11 @@ class FakeLocationStateUseCase( localStateRepository.setLocationMode(LocationMode.SPECIFIC_LOCATION) fakeLocationModule.setFakeLocation(localStateRepository.fakeAltitude.toDouble(), localStateRepository.fakeSpeed, + localStateRepository.fakeBearing, localStateRepository.fakeJitter, + localStateRepository.fakeJitterAltitude.toDouble(), + localStateRepository.fakeJitterSpeed, + localStateRepository.fakeJitterBearing, localStateRepository.fakeLocation.first.toDouble(), localStateRepository.fakeLocation.second.toDouble()) } else { @@ -215,6 +239,10 @@ class FakeLocationStateUseCase( null, null, null, + null, + null, + null, + null, false, route ?: localStateRepository.route, localStateRepository.routeLoopEnabled, @@ -235,6 +263,10 @@ class FakeLocationStateUseCase( null, null, null, + null, + null, + null, + null, false, route, localStateRepository.routeLoopEnabled, @@ -253,6 +285,10 @@ class FakeLocationStateUseCase( null, null, null, + null, + null, + null, + null, false, localStateRepository.route, localStateRepository.routeLoopEnabled, diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt index 33884f7..f1288cb 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt @@ -284,7 +284,11 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) Action.UpdateMockLocationParameters( binding.edittextAltitude.text.toString().toFloat(), binding.edittextSpeed.text.toString().toFloat(), + binding.edittextBearing.text.toString().toFloat(), binding.edittextJitter.text.toString().toFloat(), + binding.edittextJitterAltitude.text.toString().toFloat(), + binding.edittextJitterSpeed.text.toString().toFloat(), + binding.edittextJitterBearing.text.toString().toFloat(), ) ) } catch (e: NumberFormatException) { @@ -305,12 +309,36 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) } @Suppress("UNUSED_PARAMETER") + private fun onBearingTextChanged(editable: Editable?) { + if(!validateBounds(binding.textlayoutBearing, 0.0f, 360.0f)) return + updateMockLocationParameters() + } + + @Suppress("UNUSED_PARAMETER") private fun onJitterTextChanged(editable: Editable?) { if(!validateBounds(binding.textlayoutJitter, 0.0f, 10000000.0f)) return updateMockLocationParameters() } @Suppress("UNUSED_PARAMETER") + private fun onJitterAltitudeTextChanged(editable: Editable?) { + if(!validateBounds(binding.textlayoutJitterAltitude, -100000.0f, 100000.0f)) return + updateMockLocationParameters() + } + + @Suppress("UNUSED_PARAMETER") + private fun onJitterSpeedTextChanged(editable: Editable?) { + if(!validateBounds(binding.textlayoutJitterSpeed, 0.0f, 299792458.0f)) return + updateMockLocationParameters() + } + + @Suppress("UNUSED_PARAMETER") + private fun onJitterBearingTextChanged(editable: Editable?) { + if(!validateBounds(binding.textlayoutJitterBearing, 0.0f, 360.0f)) return + updateMockLocationParameters() + } + + @Suppress("UNUSED_PARAMETER") private fun onLatTextChanged(editable: Editable?) { if (!binding.edittextLatitude.isFocused || !validateCoordinate(binding.textlayoutLatitude, 90f) @@ -406,12 +434,20 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) binding.edittextAltitude.addTextChangedListener(afterTextChanged = ::onAltitudeTextChanged) binding.edittextSpeed.addTextChangedListener(afterTextChanged = ::onSpeedTextChanged) + binding.edittextBearing.addTextChangedListener(afterTextChanged = ::onBearingTextChanged) binding.edittextJitter.addTextChangedListener(afterTextChanged = ::onJitterTextChanged) + binding.edittextJitterAltitude.addTextChangedListener(afterTextChanged = ::onJitterAltitudeTextChanged) + binding.edittextJitterSpeed.addTextChangedListener(afterTextChanged = ::onJitterSpeedTextChanged) + binding.edittextJitterBearing.addTextChangedListener(afterTextChanged = ::onJitterBearingTextChanged) binding.edittextLatitude.addTextChangedListener(afterTextChanged = ::onLatTextChanged) binding.edittextLongitude.addTextChangedListener(afterTextChanged = ::onLonTextChanged) binding.edittextAltitude.onFocusChangeListener = latLonOnFocusChangeListener binding.edittextSpeed.onFocusChangeListener = latLonOnFocusChangeListener + binding.edittextBearing.onFocusChangeListener = latLonOnFocusChangeListener binding.edittextJitter.onFocusChangeListener = latLonOnFocusChangeListener + binding.edittextJitterAltitude.onFocusChangeListener = latLonOnFocusChangeListener + binding.edittextJitterSpeed.onFocusChangeListener = latLonOnFocusChangeListener + binding.edittextJitterBearing.onFocusChangeListener = latLonOnFocusChangeListener binding.edittextLatitude.onFocusChangeListener = latLonOnFocusChangeListener binding.edittextLongitude.onFocusChangeListener = latLonOnFocusChangeListener @@ -435,7 +471,11 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) binding.textlayoutAltitude.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION binding.textlayoutSpeed.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION + binding.textlayoutBearing.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION binding.textlayoutJitter.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION + binding.textlayoutJitterAltitude.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION + binding.textlayoutJitterSpeed.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION + binding.textlayoutJitterBearing.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION binding.buttonLocationRoutePathSelect.isVisible = state.mode == LocationMode.ROUTE binding.locationRoutePath.isVisible = state.mode == LocationMode.ROUTE @@ -455,9 +495,21 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) if(!binding.edittextSpeed.isFocused) binding.edittextSpeed.setText(state.speed?.toString()) + if(!binding.edittextBearing.isFocused) + binding.edittextBearing.setText(state.bearing?.toString()) + if(!binding.edittextJitter.isFocused) binding.edittextJitter.setText(state.jitter?.toString()) + if(!binding.edittextJitterAltitude.isFocused) + binding.edittextJitterAltitude.setText(state.jitterAltitude?.toString()) + + if(!binding.edittextJitterSpeed.isFocused) + binding.edittextJitterSpeed.setText(state.jitterSpeed?.toString()) + + if(!binding.edittextJitterBearing.isFocused) + binding.edittextJitterBearing.setText(state.jitterBearing?.toString()) + if (state.mode == LocationMode.SPECIFIC_LOCATION) { binding.mapLoader.isVisible = false binding.mapOverlay.isVisible = false diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationState.kt b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationState.kt index 56acdfd..41e1402 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationState.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationState.kt @@ -27,7 +27,11 @@ data class FakeLocationState( val currentLocation: Location? = null, val altitude: Float? = null, val speed: Float? = null, + val bearing: Float? = null, val jitter: Float? = null, + val jitterAltitude: Float? = null, + val jitterSpeed: Float? = null, + val jitterBearing: Float? = null, val specificLatitude: Float? = null, val specificLongitude: Float? = null, val forceRefresh: Boolean = false, diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationViewModel.kt b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationViewModel.kt index 049c707..17d8c98 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationViewModel.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationViewModel.kt @@ -72,7 +72,11 @@ class FakeLocationViewModel( mode = ss.mode, altitude = ss.altitude, speed = ss.speed, + bearing = ss.bearing, jitter = ss.jitter, + jitterAltitude = ss.jitterAltitude, + jitterSpeed = ss.jitterSpeed, + jitterBearing = ss.jitterBearing, specificLatitude = ss.specificLatitude, specificLongitude = ss.specificLongitude, route = ss.route, @@ -86,7 +90,7 @@ class FakeLocationViewModel( }, mockLocationParametersInputFlow .debounce(SET_MOCK_LOCATION_PARAMETERS_DELAY).map { action -> - fakeLocationStateUseCase.setFakeLocationParameters(action.altitude, action.speed, action.jitter) + fakeLocationStateUseCase.setFakeLocationParameters(action.altitude, action.speed, action.bearing, action.jitter, action.jitterAltitude, action.jitterSpeed, action.jitterBearing) }, routeInputFlow .debounce(SET_ROUTE_DELAY).map { action -> @@ -154,7 +158,11 @@ class FakeLocationViewModel( data class UpdateMockLocationParameters( val altitude: Float, val speed: Float, - val jitter: Float + val bearing: Float, + val jitter: Float, + val jitterAltitude: Float, + val jitterSpeed: Float, + val jitterBearing: Float ) : Action() data class SetSpecificLocationAction( val latitude: Float, |