diff options
5 files changed, 40 insertions, 26 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt index cba1548..42979f0 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt @@ -28,7 +28,7 @@ import android.util.Log import foundation.e.privacycentralapp.data.repositories.LocalStateRepository import foundation.e.privacycentralapp.domain.entities.LocationMode import foundation.e.privacycentralapp.dummy.CityDataSource -import foundation.e.privacymodules.fakelocation.FakeLocationModule +import foundation.e.privacymodules.location.IFakeLocationModule import foundation.e.privacymodules.permissions.PermissionsPrivacyModule import foundation.e.privacymodules.permissions.data.AppOpModes import foundation.e.privacymodules.permissions.data.ApplicationDescription @@ -40,7 +40,7 @@ import kotlinx.coroutines.launch import kotlin.random.Random class FakeLocationStateUseCase( - private val fakeLocationModule: FakeLocationModule, + private val fakeLocationModule: IFakeLocationModule, private val permissionsModule: PermissionsPrivacyModule, private val localStateRepository: LocalStateRepository, private val citiesRepository: CityDataSource, diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt index 75a9c4a..3d8f809 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt @@ -24,7 +24,6 @@ import android.view.View import android.widget.Toast import androidx.core.os.bundleOf import androidx.core.view.isVisible -import androidx.fragment.app.commit import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -69,12 +68,9 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val appUid = requireArguments().getInt(PARAM_APP_UID, -1) - if (appUid == -1) { - activity?.supportFragmentManager?.commit(allowStateLoss = true) { - remove(this@AppTrackersFragment) - } - return + if (arguments == null || + requireArguments().getInt(PARAM_APP_UID, Int.MIN_VALUE) == Int.MIN_VALUE) { + activity?.supportFragmentManager?.popBackStack() } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt index eef75a4..bc591bf 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt @@ -42,7 +42,7 @@ class AppTrackersViewModel( private val getQuickPrivacyStateUseCase: GetQuickPrivacyStateUseCase ) : ViewModel() { companion object { - private const val exodusBaseUrl = "https://reports.exodus-privacy.eu.org/fr/trackers/" + private const val exodusBaseUrl = "https://reports.exodus-privacy.eu.org/trackers/" } private val _state = MutableStateFlow(AppTrackersState()) diff --git a/fakelocation/build.gradle b/fakelocation/build.gradle index ea28e44..945cb66 100644 --- a/fakelocation/build.gradle +++ b/fakelocation/build.gradle @@ -51,4 +51,6 @@ dependencies { Libs.AndroidX.coreKtx, Libs.Coroutines.core ) + implementation project(':privacymodule-api') + } diff --git a/fakelocation/src/main/java/foundation/e/privacymodules/fakelocation/FakeLocationModule.kt b/fakelocation/src/main/java/foundation/e/privacymodules/fakelocation/FakeLocationModule.kt index 43a4545..cd01e95 100644 --- a/fakelocation/src/main/java/foundation/e/privacymodules/fakelocation/FakeLocationModule.kt +++ b/fakelocation/src/main/java/foundation/e/privacymodules/fakelocation/FakeLocationModule.kt @@ -19,12 +19,15 @@ package foundation.e.privacymodules.fakelocation import android.content.Context import android.content.Context.LOCATION_SERVICE -import android.location.Criteria import android.location.Location import android.location.LocationManager +import android.location.LocationManager.GPS_PROVIDER +import android.location.LocationManager.NETWORK_PROVIDER +import android.location.provider.ProviderProperties import android.os.Build import android.os.SystemClock import android.util.Log +import foundation.e.privacymodules.location.IFakeLocationModule /** * Implementation of the functionality of fake location. @@ -32,12 +35,10 @@ import android.util.Log * * @param context an Android context, to retrieve system services for example. */ -class FakeLocationModule(protected val context: Context) { - - /** - * List of all the Location provider that will be mocked. - */ - private val providers = listOf(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER) +class FakeLocationModule(private val context: Context): IFakeLocationModule { + companion object { + private const val TAG = "FakeLocationModule" + } /** * Handy accessor to the locationManager service. @@ -47,17 +48,24 @@ class FakeLocationModule(protected val context: Context) { context.getSystemService(LOCATION_SERVICE) as LocationManager /** + * List of all the Location provider that will be mocked. + */ + private val providers = locationManager.allProviders + .intersect(listOf(GPS_PROVIDER, NETWORK_PROVIDER)) + + /** * @see IFakeLocationModule.startFakeLocation */ @Synchronized - fun startFakeLocation() { + override fun startFakeLocation() { providers.forEach { provider -> try { locationManager.removeTestProvider(provider) } catch(e: Exception) { - Log.d("FakeLocationModule", "Test provider $provider already removed.") + Log.w(TAG, "Test provider $provider already removed.") } + locationManager.addTestProvider( provider, false, @@ -67,12 +75,17 @@ class FakeLocationModule(protected val context: Context) { false, true, true, - Criteria.POWER_LOW, Criteria.ACCURACY_FINE) - locationManager.setTestProviderEnabled(provider, true) + ProviderProperties.POWER_USAGE_LOW, + ProviderProperties.ACCURACY_FINE) + try { + locationManager.setTestProviderEnabled(provider, true) + } catch (e: Exception) { + Log.e(TAG, "Can't enable test $provider", e) + } } } - fun setFakeLocation(latitude: Double, longitude: Double) { + override fun setFakeLocation(latitude: Double, longitude: Double) { context.startService(FakeLocationService.buildFakeLocationIntent(context, latitude, longitude)) } @@ -95,22 +108,25 @@ class FakeLocationModule(protected val context: Context) { location.verticalAccuracyMeters = 0.1f location.speedAccuracyMetersPerSecond = 0.01f } - - locationManager.setTestProviderLocation(provider, location) + try { + locationManager.setTestProviderLocation(provider, location) + } catch (e: Exception) { + Log.e(TAG, "Can't set location for test provider $provider", e) + } } } /** * @see IFakeLocationModule.stopFakeLocation */ - fun stopFakeLocation() { + override fun stopFakeLocation() { context.stopService(FakeLocationService.buildStopIntent(context)) providers.forEach { provider -> try { locationManager.setTestProviderEnabled(provider, false) locationManager.removeTestProvider(provider) } catch (e: Exception) { - Log.d("FakeLocationModule", "Test provider $provider already removed.") + Log.d(TAG, "Test provider $provider already removed.") } } } |