diff options
author | Guillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com> | 2022-10-07 08:45:15 +0200 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com> | 2022-10-26 14:01:43 +0200 |
commit | 5f02fd142ca438a48423340aeb9a36b017a6be83 (patch) | |
tree | 793326be63e878c880298f075f9c0de3413bb6e4 /app | |
parent | f8d19823ea9be0c8700a69a215fac7d3af4d6d87 (diff) |
Fix lint.
Diffstat (limited to 'app')
28 files changed, 193 insertions, 196 deletions
diff --git a/app/build.gradle b/app/build.gradle index 42bf90d..6b57002 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -115,6 +115,10 @@ android { dataBinding true viewBinding true } + + lintOptions { + disable 'MissingTranslation' + } } dependencies { @@ -130,6 +134,8 @@ dependencies { implementation 'foundation.e:privacymodule.tor:1.2.0-orbot-16.6.2' + implementation 'foundation.e:elib:0.0.1-alpha11' + implementation ( Libs.Kotlin.stdlib, Libs.AndroidX.coreKtx, @@ -150,9 +156,6 @@ dependencies { debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1' testImplementation 'junit:junit:4.+' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - implementation 'foundation.e:elib:0.0.1-alpha11' } static def log(Object val) { diff --git a/app/src/androidTest/java/foundation/e/privacycentralapp/ExampleInstrumentedTest.kt b/app/src/androidTest/java/foundation/e/privacycentralapp/ExampleInstrumentedTest.kt deleted file mode 100644 index f42f093..0000000 --- a/app/src/androidTest/java/foundation/e/privacycentralapp/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2021 E FOUNDATION - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -package foundation.e.privacycentralapp - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - Assert.assertEquals("foundation.e.privacycentralapp", appContext.packageName) - } -} diff --git a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt index 2e24d4c..670b81e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt @@ -106,15 +106,17 @@ class DependencyContainer(val app: Application) { ) } - val viewModelsFactory by lazy { ViewModelsFactory( - getQuickPrivacyStateUseCase = getQuickPrivacyStateUseCase, - trackersStatisticsUseCase = trackersStatisticsUseCase, - trackersStateUseCase = trackersStateUseCase, - fakeLocationStateUseCase = fakeLocationStateUseCase, - ipScramblerModule = ipScramblerModule, - ipScramblingStateUseCase = ipScramblingStateUseCase, - appListUseCase = appListUseCase - ) } + val viewModelsFactory by lazy { + ViewModelsFactory( + getQuickPrivacyStateUseCase = getQuickPrivacyStateUseCase, + trackersStatisticsUseCase = trackersStatisticsUseCase, + trackersStateUseCase = trackersStateUseCase, + fakeLocationStateUseCase = fakeLocationStateUseCase, + ipScramblerModule = ipScramblerModule, + ipScramblingStateUseCase = ipScramblingStateUseCase, + appListUseCase = appListUseCase + ) + } // Background fun initBackgroundSingletons() { @@ -140,15 +142,15 @@ class ViewModelsFactory( private val ipScramblerModule: IIpScramblerModule, private val ipScramblingStateUseCase: IpScramblingStateUseCase, private val appListUseCase: AppListUseCase -): ViewModelProvider.Factory { +) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T { return when (modelClass) { AppTrackersViewModel::class.java -> { val fallbackUid = android.os.Process.myPid() - val appUid = extras[DEFAULT_ARGS_KEY]?. - getInt(AppTrackersFragment.PARAM_APP_UID, fallbackUid)?: fallbackUid + val appUid = extras[DEFAULT_ARGS_KEY] + ?.getInt(AppTrackersFragment.PARAM_APP_UID, fallbackUid) ?: fallbackUid AppTrackersViewModel( appUid = appUid, diff --git a/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt b/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt index b23be3d..28e96e0 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt @@ -19,14 +19,12 @@ package foundation.e.privacycentralapp import android.app.Application import com.mapbox.mapboxsdk.Mapbox -import kotlinx.coroutines.FlowPreview class PrivacyCentralApplication : Application() { // Initialize the dependency container. val dependencyContainer: DependencyContainer by lazy { DependencyContainer(this) } - override fun onCreate() { super.onCreate() Mapbox.getTelemetry()?.setUserTelemetryRequestState(false) diff --git a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt index c83d8f9..13511da 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt @@ -45,8 +45,9 @@ class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters) fun periodicUpdate(context: Context) { val request = PeriodicWorkRequestBuilder<UpdateTrackersWorker>( - 7, TimeUnit.DAYS) - .setConstraints(constraints).build() + 7, TimeUnit.DAYS + ) + .setConstraints(constraints).build() WorkManager.getInstance(context).enqueueUniquePeriodicWork( UpdateTrackersWorker::class.qualifiedName ?: "", diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt index 25a3633..d85f4a7 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt @@ -60,4 +60,4 @@ private fun asteriskAsInfoIconSpannable( } } return spannable -}
\ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt index ae70ba3..9f057be 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt @@ -19,4 +19,4 @@ package foundation.e.privacycentralapp.domain.entities enum class TrackerMode { DENIED, CUSTOM, VULNERABLE -}
\ No newline at end of file +} 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 1426891..e9da855 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 @@ -67,8 +67,8 @@ class FakeLocationStateUseCase( get() = appContext.getSystemService(Context.LOCATION_SERVICE) as LocationManager private fun hasAcquireLocationPermission(): Boolean { - return (appContext.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) - || permissionsModule.toggleDangerousPermission(appDesc, android.Manifest.permission.ACCESS_FINE_LOCATION, true) + return (appContext.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) || + permissionsModule.toggleDangerousPermission(appDesc, android.Manifest.permission.ACCESS_FINE_LOCATION, true) } private fun applySettings(isQuickPrivacyEnabled: Boolean, fakeLocation: Pair<Float, Float>?, isSpecificLocation: Boolean = false) { @@ -85,8 +85,8 @@ class FakeLocationStateUseCase( } private fun hasAcquireMockLocationPermission(): Boolean { - return (permissionsModule.getAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION) == AppOpModes.ALLOWED) - || permissionsModule.setAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION, AppOpModes.ALLOWED) + return (permissionsModule.getAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION) == AppOpModes.ALLOWED) || + permissionsModule.setAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION, AppOpModes.ALLOWED) } fun setSpecificLocation(latitude: Float, longitude: Float) { @@ -140,7 +140,8 @@ class FakeLocationStateUseCase( override fun onLocationChanged(location: Location) { currentLocation.update { previous -> if ((previous?.time ?: 0) + 1800 < location.time || - (previous?.accuracy ?: Float.MAX_VALUE) > location.accuracy) { + (previous?.accuracy ?: Float.MAX_VALUE) > location.accuracy + ) { location } else { previous @@ -193,10 +194,10 @@ class FakeLocationStateUseCase( ) - locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)?: - locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)?.let { - localListener.onLocationChanged(it) - } + locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) + ?: locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)?.let { + localListener.onLocationChanged(it) + } } catch (se: SecurityException) { Log.e(TAG, "Missing permission", se) } diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt index 688bdc4..46e054e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt @@ -108,5 +108,4 @@ class GetQuickPrivacyStateUseCase( } val otherVpnRunning: SharedFlow<ApplicationDescription> = localStateRepository.otherVpnRunning - } diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt index a0003eb..947e8e9 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt @@ -129,13 +129,13 @@ class IpScramblingStateUseCase( val mode = localStateRepository.internetPrivacyMode.value when { isQuickPrivacyEnabled && isIpScramblingEnabled && - mode in setOf(InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING) -> + mode in setOf(InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING) -> applyStartIpScrambling() mode in setOf(InternetPrivacyMode.HIDE_IP, InternetPrivacyMode.HIDE_IP_LOADING) -> ipScramblerModule.stop() else -> {} - } + } } private fun applyStartIpScrambling() { @@ -149,8 +149,7 @@ class IpScramblingStateUseCase( ) } localStateRepository.setIpScramblingSetting(enabled = false) - - }?: run { + } ?: run { ipScramblerModule.start(enableNotification = false) } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt index 10c1ad0..17e5096 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt @@ -20,7 +20,6 @@ package foundation.e.privacycentralapp.domain.usecases import foundation.e.privacycentralapp.data.repositories.AppListsRepository import foundation.e.privacycentralapp.data.repositories.LocalStateRepository import foundation.e.privacycentralapp.data.repositories.TrackersRepository -import foundation.e.privacymodules.permissions.PermissionsPrivacyModule import foundation.e.privacymodules.permissions.data.ApplicationDescription import foundation.e.privacymodules.trackers.api.IBlockTrackersPrivacyModule import foundation.e.privacymodules.trackers.api.ITrackTrackersPrivacyModule @@ -63,8 +62,9 @@ class TrackersStateUseCase( return appListsRepository.getApplicationDescription(appUid) } - fun isWhitelisted(appUid: Int) - = isWhitelisted(appUid, appListsRepository, blockTrackersPrivacyModule) + fun isWhitelisted(appUid: Int): Boolean { + return isWhitelisted(appUid, appListsRepository, blockTrackersPrivacyModule) + } fun getTrackersWhitelistIds(appUid: Int): List<String> { return if (appUid == appListsRepository.dummySystemApp.uid) { @@ -108,7 +108,6 @@ class TrackersStateUseCase( } } - fun isWhitelisted( appUid: Int, appListsRepository: AppListsRepository, diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt index 0a47bc5..57ab1a4 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt @@ -166,17 +166,15 @@ class TrackersStatisticsUseCase( acc.addAll(blockTrackersPrivacyModule.getWhiteList(app.uid).map { it.id }) acc } - } else { trackers = trackTrackersPrivacyModule.getTrackersForApp(appUid) whiteListedTrackersIds = blockTrackersPrivacyModule.getWhiteList(appUid) .map { it.id }.toSet() } - return trackers.sortedBy { it.label.lowercase() }.map { tracker -> tracker to whiteListedTrackersIds.any { tracker.id == it }} + return trackers.sortedBy { it.label.lowercase() }.map { tracker -> tracker to whiteListedTrackersIds.any { tracker.id == it } } } - fun getCalls(appUid: Int): Pair<Int, Int> { return if (appUid == appListsRepository.dummySystemApp.uid) { appListsRepository.getHiddenSystemApps().map { @@ -211,10 +209,12 @@ class TrackersStatisticsUseCase( blockTrackersPrivacyModule.getWhiteList(app.uid).size }, blockedLeaks = appListsRepository.foldForHiddenSystemApp(app.uid) { - appUid -> callsByApp.getOrDefault(appUid, 0 to 0).first + appUid -> + callsByApp.getOrDefault(appUid, 0 to 0).first }, leaks = appListsRepository.foldForHiddenSystemApp(app.uid) { - appUid -> callsByApp.getOrDefault(appUid, 0 to 0).second + appUid -> + callsByApp.getOrDefault(appUid, 0 to 0).second } ) }.sortedWith(mostLeakedAppsComparator) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt index 21950a4..6cd259e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt @@ -163,7 +163,8 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { } } is SingleEvent.ToastMessageSingleEvent -> - Toast.makeText(requireContext(), + Toast.makeText( + requireContext(), getString(event.message, *event.args.toTypedArray()), Toast.LENGTH_LONG ).show() @@ -202,11 +203,13 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { binding.togglePrivacyCentral.isChecked = state.quickPrivacyState.isEnabled() - binding.stateTrackers.text = getString(when(state.trackerMode) { - TrackerMode.DENIED -> R.string.dashboard_state_trackers_on - TrackerMode.VULNERABLE -> R.string.dashboard_state_trackers_off - TrackerMode.CUSTOM -> R.string.dashboard_state_trackers_custom - }) + binding.stateTrackers.text = getString( + when (state.trackerMode) { + TrackerMode.DENIED -> R.string.dashboard_state_trackers_on + TrackerMode.VULNERABLE -> R.string.dashboard_state_trackers_off + TrackerMode.CUSTOM -> R.string.dashboard_state_trackers_custom + } + ) binding.stateTrackers.setTextColor( getColor( requireContext(), diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt index fb00f07..04b7ae8 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt @@ -33,4 +33,4 @@ data class DashboardState( val dayStatistics: List<Pair<Int, Int>>? = null, val dayLabels: List<String>? = null, val showQuickPrivacyDisabledMessage: Boolean = false -)
\ No newline at end of file +) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt index a2fca86..d7d74c6 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt @@ -77,10 +77,12 @@ class DashboardViewModel( _state.update { s -> s.copy(showQuickPrivacyDisabledMessage = it) } }, getPrivacyStateUseCase.otherVpnRunning.map { - _singleEvents.emit(SingleEvent.ToastMessageSingleEvent( - R.string.ipscrambling_error_always_on_vpn_already_running, - listOf(it.label?: "") - )) + _singleEvents.emit( + SingleEvent.ToastMessageSingleEvent( + R.string.ipscrambling_error_always_on_vpn_already_running, + listOf(it.label ?: "") + ) + ) } ).collect {} } @@ -122,9 +124,11 @@ class DashboardViewModel( val isFirstActivation = getPrivacyStateUseCase.toggleReturnIsFirstActivation() fetchStatistics().first() - if (isFirstActivation) _singleEvents.emit(SingleEvent.ToastMessageSingleEvent( - message = R.string.dashboard_first_ipscrambling_activation - )) + if (isFirstActivation) _singleEvents.emit( + SingleEvent.ToastMessageSingleEvent( + message = R.string.dashboard_first_ipscrambling_activation + ) + ) } private suspend fun actionShowMostLeakedApp() = withContext(Dispatchers.IO) { @@ -142,7 +146,8 @@ class DashboardViewModel( object NavigateToPermissionsSingleEvent : SingleEvent() data class NavigateToAppDetailsEvent(val appDesc: ApplicationDescription) : SingleEvent() data class ToastMessageSingleEvent( - @StringRes val message: Int, val args: List<Any> = emptyList() + @StringRes val message: Int, + val args: List<Any> = emptyList() ) : SingleEvent() } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt index 25e911f..6991196 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt @@ -34,4 +34,4 @@ data class InternetPrivacyState( } val selectedLocationPosition get() = availableLocationIds.indexOf(selectedLocation) -}
\ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt index 8bdb16e..be6cd4d 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt @@ -55,20 +55,20 @@ class InternetPrivacyViewModel( private val _singleEvents = MutableSharedFlow<SingleEvent>() val singleEvents = _singleEvents.asSharedFlow() - - val availablesLocationsIds = listOf("", *ipScramblerModule.getAvailablesLocations().sorted().toTypedArray()) init { viewModelScope.launch(Dispatchers.IO) { - _state.update { it.copy( - mode = ipScramblingStateUseCase.internetPrivacyMode.value, - availableLocationIds = availablesLocationsIds, - selectedLocation = ipScramblerModule.exitCountry) } + _state.update { + it.copy( + mode = ipScramblingStateUseCase.internetPrivacyMode.value, + availableLocationIds = availablesLocationsIds, + selectedLocation = ipScramblerModule.exitCountry + ) + } } } - @OptIn(FlowPreview::class) suspend fun doOnStartedState() = withContext(Dispatchers.IO) { launch { @@ -77,23 +77,26 @@ class InternetPrivacyViewModel( _state.update { s -> s.copy(showQuickPrivacyDisabledMessage = it) } }, appListUseCase.getAppsUsingInternet().map { apps -> - _state.update { s -> s.copy( - availableApps = apps, - bypassTorApps = ipScramblingStateUseCase.bypassTorApps - ) } + _state.update { s -> + s.copy( + availableApps = apps, + bypassTorApps = ipScramblingStateUseCase.bypassTorApps + ) + } }, if (getQuickPrivacyStateUseCase.isQuickPrivacyEnabled) ipScramblingStateUseCase.internetPrivacyMode.map { _state.update { s -> s.copy(mode = it) } } else ipScramblingStateUseCase.configuredMode.map { - _state.update { s -> s.copy( - mode = if (it) InternetPrivacyMode.HIDE_IP - else InternetPrivacyMode.REAL_IP - ) } + _state.update { s -> + s.copy( + mode = if (it) InternetPrivacyMode.HIDE_IP + else InternetPrivacyMode.REAL_IP + ) + } } ).collect {} - } launch { @@ -109,12 +112,13 @@ class InternetPrivacyViewModel( launch { getQuickPrivacyStateUseCase.otherVpnRunning.collect { - _singleEvents.emit(SingleEvent.ErrorEvent( - R.string.ipscrambling_error_always_on_vpn_already_running, - listOf(it.label?: "")) + _singleEvents.emit( + SingleEvent.ErrorEvent( + R.string.ipscrambling_error_always_on_vpn_already_running, + listOf(it.label ?: "") + ) ) - _state.update { it.copy(forceRedraw = !it.forceRedraw)} - + _state.update { it.copy(forceRedraw = !it.forceRedraw) } } } } @@ -153,8 +157,9 @@ class InternetPrivacyViewModel( sealed class SingleEvent { data class ErrorEvent( - @StringRes val errorResId: Int, val args: List<Any> = emptyList() - ): SingleEvent() + @StringRes val errorResId: Int, + val args: List<Any> = emptyList() + ) : SingleEvent() } sealed class Action { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt index 2e014e2..537d0b6 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt @@ -86,8 +86,8 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) private val locationPermissionRequest = registerForActivityResult( ActivityResultContracts.RequestMultiplePermissions() ) { permissions -> - if (permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) - || permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) + if (permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) || + permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) ) { viewModel.submitAction(Action.StartListeningLocation) } // TODO: else. @@ -167,10 +167,12 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) } is FakeLocationViewModel.SingleEvent.RequestLocationPermission -> { // TODO for standalone: rationale dialog - locationPermissionRequest.launch(arrayOf( - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION - )) + locationPermissionRequest.launch( + arrayOf( + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION + ) + ) } is FakeLocationViewModel.SingleEvent.LocationUpdatedEvent -> { // Nothing here, another collect linked to mapbox view. diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt index c7bcd98..9513f77 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt @@ -27,4 +27,4 @@ data class FakeLocationState( val specificLongitude: Float? = null, val forceRefresh: Boolean = false, val showQuickPrivacyDisabledMessage: Boolean = false -)
\ No newline at end of file +) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt index afba3d0..8db3537 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt @@ -58,28 +58,32 @@ class FakeLocationViewModel( launch { merge( fakeLocationStateUseCase.configuredLocationMode.map { (mode, lat, lon) -> - _state.update { s -> s.copy( - mode = mode, - specificLatitude = lat, - specificLongitude = lon - ) } + _state.update { s -> + s.copy( + mode = mode, + specificLatitude = lat, + specificLongitude = lon + ) + } }, getQuickPrivacyStateUseCase.showQuickPrivacyDisabledMessage.map { _state.update { s -> s.copy(showQuickPrivacyDisabledMessage = it) } }, specificLocationInputFlow .debounce(SET_SPECIFIC_LOCATION_DELAY).map { action -> - fakeLocationStateUseCase.setSpecificLocation(action.latitude, action.longitude) - } + fakeLocationStateUseCase.setSpecificLocation(action.latitude, action.longitude) + } ).collect {} } launch { fakeLocationStateUseCase.currentLocation.collect { location -> - _singleEvents.emit(SingleEvent.LocationUpdatedEvent( - mode = _state.value.mode, - location = location - )) + _singleEvents.emit( + SingleEvent.LocationUpdatedEvent( + mode = _state.value.mode, + location = location + ) + ) } } } @@ -110,7 +114,7 @@ class FakeLocationViewModel( sealed class SingleEvent { data class LocationUpdatedEvent(val mode: LocationMode, val location: Location?) : SingleEvent() - object RequestLocationPermission: SingleEvent() + object RequestLocationPermission : SingleEvent() data class ErrorEvent(val error: String) : SingleEvent() } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt index f51ff18..2437366 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt @@ -26,4 +26,4 @@ data class TrackersState( val yearStatistics: TrackersPeriodicStatistics? = null, val apps: List<AppWithCounts>? = null, val showQuickPrivacyDisabledMessage: Boolean = false -)
\ No newline at end of file +) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt index f49152e..3869c39 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt @@ -52,11 +52,13 @@ class TrackersViewModel( trackersStatisticsUseCase.listenUpdates().map { trackersStatisticsUseCase.getDayMonthYearStatistics() .let { (day, month, year) -> - _state.update { s -> s.copy( + _state.update { s -> + s.copy( dayStatistics = day, monthStatistics = month, yearStatistics = year - ) } + ) + } } }, trackersStatisticsUseCase.getAppsWithCounts().map { @@ -74,7 +76,7 @@ class TrackersViewModel( } } - suspend private fun actionClickApp(action: Action.ClickAppAction) { + private suspend fun actionClickApp(action: Action.ClickAppAction) { state.value.apps?.find { it.packageName == action.packageName }?.let { _singleEvents.emit(SingleEvent.OpenAppDetailsEvent(it)) } 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 69e520c..cd4f6b2 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 @@ -68,7 +68,8 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (arguments == null || - requireArguments().getInt(PARAM_APP_UID, Int.MIN_VALUE) == Int.MIN_VALUE) { + requireArguments().getInt(PARAM_APP_UID, Int.MIN_VALUE) == Int.MIN_VALUE + ) { activity?.supportFragmentManager?.popBackStack() } } @@ -150,7 +151,6 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { binding.blockAllToggle.isChecked = state.isBlockingActivated - val trackersStatus = state.getTrackersStatus() if (!trackersStatus.isNullOrEmpty()) { binding.trackersListTitle.isVisible = state.isBlockingActivated diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt index ffa1f36..d6d0858 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt @@ -29,11 +29,12 @@ data class AppTrackersState( val isQuickPrivacyEnabled: Boolean = false, val showQuickPrivacyDisabledMessage: Boolean = false, ) { - fun getTrackersStatus(): List<Pair<Tracker, Boolean>>? - = trackersWithWhiteList?.map { it.first to !it.second } + fun getTrackersStatus(): List<Pair<Tracker, Boolean>>? { + return trackersWithWhiteList?.map { it.first to !it.second } + } fun getTrackersCount() = trackersWithWhiteList?.size ?: 0 fun getBlockedTrackersCount(): Int = if (isQuickPrivacyEnabled && isBlockingActivated) - trackersWithWhiteList?.count { !it.second }?: 0 + trackersWithWhiteList?.count { !it.second } ?: 0 else 0 -}
\ No newline at end of file +} 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 4a81b2c..52ef2c4 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 @@ -54,11 +54,13 @@ class AppTrackersViewModel( init { viewModelScope.launch(Dispatchers.IO) { - _state.update { it.copy( - appDesc = trackersStateUseCase.getApplicationDescription(appUid), - isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid), - trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), - ) } + _state.update { + it.copy( + appDesc = trackersStateUseCase.getApplicationDescription(appUid), + isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid), + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), + ) + } } } @@ -75,54 +77,67 @@ class AppTrackersViewModel( } fun submitAction(action: Action) = viewModelScope.launch { - when (action) { - is Action.BlockAllToggleAction -> blockAllToggleAction(action) - is Action.ToggleTrackerAction -> toggleTrackerAction(action) - is Action.ClickTracker ->actionClickTracker(action) - is Action.CloseQuickPrivacyDisabledMessage -> - getQuickPrivacyStateUseCase.resetQuickPrivacyDisabledMessage() - } + when (action) { + is Action.BlockAllToggleAction -> blockAllToggleAction(action) + is Action.ToggleTrackerAction -> toggleTrackerAction(action) + is Action.ClickTracker -> actionClickTracker(action) + is Action.CloseQuickPrivacyDisabledMessage -> + getQuickPrivacyStateUseCase.resetQuickPrivacyDisabledMessage() + } } - private suspend fun blockAllToggleAction(action: Action.BlockAllToggleAction) - = withContext(Dispatchers.IO) { - trackersStateUseCase.toggleAppWhitelist(appUid, !action.isBlocked) - _state.update { it.copy( - isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid) - ) } + private suspend fun blockAllToggleAction(action: Action.BlockAllToggleAction) { + withContext(Dispatchers.IO) { + trackersStateUseCase.toggleAppWhitelist(appUid, !action.isBlocked) + _state.update { + it.copy( + isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid) + ) + } + } } - private suspend fun toggleTrackerAction(action: Action.ToggleTrackerAction) - = withContext(Dispatchers.IO) { - if (state.value.isBlockingActivated) { - trackersStateUseCase.blockTracker(appUid, action.tracker, action.isBlocked) - _state.update { it.copy( - trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid) - ) } + private suspend fun toggleTrackerAction(action: Action.ToggleTrackerAction) { + withContext(Dispatchers.IO) { + if (state.value.isBlockingActivated) { + trackersStateUseCase.blockTracker(appUid, action.tracker, action.isBlocked) + _state.update { + it.copy( + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList( + appUid + ) + ) + } + } } } - private suspend fun actionClickTracker(action: Action.ClickTracker) - = withContext(Dispatchers.IO) { - action.tracker.exodusId?.let { - try { - _singleEvents.emit(SingleEvent.OpenUrl( - Uri.parse(exodusBaseUrl + it) - )) - } catch (e: Exception) {} + private suspend fun actionClickTracker(action: Action.ClickTracker) { + withContext(Dispatchers.IO) { + action.tracker.exodusId?.let { + try { + _singleEvents.emit( + SingleEvent.OpenUrl( + Uri.parse(exodusBaseUrl + it) + ) + ) + } catch (e: Exception) { + } + } } } private fun fetchStatistics() { val (blocked, leaked) = trackersStatisticsUseCase.getCalls(appUid) - return _state.update { s -> s.copy( - trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), - leaked = leaked, - blocked = blocked, - ) } + return _state.update { s -> + s.copy( + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), + leaked = leaked, + blocked = blocked, + ) + } } - sealed class SingleEvent { data class ErrorEvent(@StringRes val errorResId: Int) : SingleEvent() data class OpenUrl(val url: Uri) : SingleEvent() diff --git a/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt b/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt index 63ec27f..58ac797 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt @@ -28,7 +28,6 @@ import foundation.e.privacycentralapp.PrivacyCentralApplication import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.features.dashboard.DashboardFragment import foundation.e.privacycentralapp.features.trackers.TrackersFragment -import kotlinx.coroutines.FlowPreview open class MainActivity : FragmentActivity(R.layout.activity_main) { override fun onPostCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt index e886cd8..ddfcc2e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt @@ -141,7 +141,6 @@ class Widget : AppWidgetProvider() { } } - override fun onAppWidgetOptionsChanged( context: Context, appWidgetManager: AppWidgetManager, diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt index 27589a8..682e5cc 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt @@ -29,8 +29,8 @@ import android.widget.RemoteViews import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.Widget import foundation.e.privacycentralapp.Widget.Companion.isDarkText -import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState import foundation.e.privacycentralapp.common.extensions.dpToPxF +import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState import foundation.e.privacycentralapp.domain.entities.TrackerMode import foundation.e.privacycentralapp.main.MainActivity import foundation.e.privacycentralapp.widget.WidgetCommandReceiver.Companion.ACTION_TOGGLE_PRIVACY @@ -44,7 +44,6 @@ data class State( val activeTrackersCount: Int = 0, ) - fun render( context: Context, state: State, @@ -93,7 +92,7 @@ fun render( setTextViewText( R.id.state_trackers, context.getString( - when(state.trackerMode) { + when (state.trackerMode) { TrackerMode.DENIED -> R.string.widget_state_trackers_on TrackerMode.VULNERABLE -> R.string.widget_state_trackers_off TrackerMode.CUSTOM -> R.string.widget_state_trackers_custom @@ -277,7 +276,7 @@ fun applyDarkText(context: Context, state: State, views: RemoteViews) { R.id.graph_legend_blocked, R.id.graph_legend_allowed, - ) + ) .forEach { setTextColor( it, |