From 2c2077e503e779898e4aba3d6644c2303fd7b6ca Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Thu, 28 Dec 2023 10:37:31 +0100 Subject: [PATCH 1/2] chore: update spotless and ktlint --- .editorconfig | 12 ++++ DEVELOPMENT.md | 8 +-- README.md | 6 +- .../AdvancedPrivacyApplication.kt | 4 +- .../e/advancedprivacy/DependencyContainer.kt | 0 .../e/advancedprivacy/KoinModule.kt | 4 +- .../e/advancedprivacy/Notifications.kt | 15 +++-- .../e/advancedprivacy/common/GraphHolder.kt | 61 ++++++++++++------- .../advancedprivacy/common/TextViewHelpers.kt | 12 +--- .../e/advancedprivacy/common/ThrottleFlow.kt | 2 +- .../e/advancedprivacy/common/WarningDialog.kt | 15 ++--- ...ository.kt => LocalStateRepositoryImpl.kt} | 0 ...ourcesGetter.kt => ResourcesRepository.kt} | 4 +- .../domain/entities/AppWithCounts.kt | 11 ++-- .../domain/entities/QuickPrivacyState.kt | 4 +- .../domain/entities/TrackerMode.kt | 4 +- .../domain/usecases/AppTrackersUseCase.kt | 2 +- .../usecases/FakeLocationStateUseCase.kt | 8 ++- .../usecases/GetQuickPrivacyStateUseCase.kt | 8 +-- .../domain/usecases/TrackerDetailsUseCase.kt | 13 +--- .../usecases/TrackersAndAppsListsUseCase.kt | 23 +++---- .../domain/usecases/TrackersStateUseCase.kt | 9 +-- .../usecases/TrackersStatisticsUseCase.kt | 41 +++++++------ .../features/dashboard/DashboardFragment.kt | 55 ++++++++++++----- .../features/dashboard/DashboardState.kt | 2 +- .../features/dashboard/DashboardViewModel.kt | 2 +- .../InternetPrivacyFragment.kt | 13 ++-- .../internetprivacy/InternetPrivacyState.kt | 2 +- .../InternetPrivacyViewModel.kt | 8 ++- .../features/location/FakeLocationFragment.kt | 16 ++--- .../features/location/FakeLocationMapView.kt | 9 ++- .../features/location/FakeLocationState.kt | 2 +- .../location/FakeLocationViewModel.kt | 2 +- .../features/trackers/ListsTabPagerAdapter.kt | 9 ++- .../trackers/TrackerControlDisclaimer.kt | 4 +- .../features/trackers/TrackersFragment.kt | 4 +- .../trackers/TrackersPeriodAdapter.kt | 17 ++++++ .../trackers/TrackersPeriodViewModel.kt | 2 +- .../trackers/apptrackers/AppTrackersState.kt | 2 +- .../apptrackers/AppTrackersViewModel.kt | 7 ++- .../apptrackers/ToggleTrackersAdapter.kt | 3 +- .../features/trackers/graph/GraphHolder.kt | 13 ++-- .../trackers/graph/PeriodMarkerView.kt | 8 ++- .../trackerdetails/TrackerAppsAdapter.kt | 2 +- .../trackerdetails/TrackerDetailsState.kt | 2 +- .../trackerdetails/TrackerDetailsViewModel.kt | 5 +- .../e/advancedprivacy/widget/Widget.kt | 20 ++---- .../widget/WidgetCommandReceiver.kt | 6 +- .../e/advancedprivacy/widget/WidgetUI.kt | 54 ++++++++++------ app/src/main/res/drawable/bg_tag.xml | 16 +++++ app/src/main/res/values-en-rUS/strings.xml | 16 +++++ build.gradle | 30 ++++----- .../core/utils/CoroutinesUtils.kt | 6 +- .../core/utils/NotificationsHelper.kt | 5 +- .../data/repositories/AppListsRepository.kt | 13 ++-- .../domain/entities/AppOpModes.kt | 2 +- .../domain/entities/ApplicationDescription.kt | 4 +- .../domain/entities/FeatureState.kt | 5 +- .../domain/entities/LocationMode.kt | 4 +- .../domain/entities/MainFeatures.kt | 2 + .../permissions/IPermissionsPrivacyModule.kt | 16 +---- .../PermissionsPrivacyModuleBase.kt | 37 +++++------ .../fakelocationdemo/MainActivity.kt | 3 +- .../services/FakeLocationService.kt | 1 - gradle/libs.versions.toml | 2 +- .../ipscrambler/OrbotSupervisor.kt | 20 ++++-- load-properties.gradle | 2 +- .../PermissionsPrivacyModuleImpl.kt | 20 ++---- .../PermissionsPrivacyModuleImpl.kt | 16 +---- settings.gradle | 1 - .../data/RemoteTrackersListRepository.kt | 8 +-- .../trackers/data/StatsDatabase.kt | 54 ++++++++-------- .../trackers/data/TrackersRepository.kt | 6 +- .../trackers/data/WhitelistRepository.kt | 6 +- .../externalinterfaces/TrackersSupervisor.kt | 2 +- .../domain/usecases/FilterHostnameUseCase.kt | 4 +- .../domain/usecases/StatisticsUseCase.kt | 5 +- .../usecases/UpdateTrackerListUseCase.kt | 2 +- .../trackers/services/UpdateTrackersWorker.kt | 5 +- .../trackers/service/DNSBlocker.kt | 6 +- .../trackers/service/TrackersSupervisorEos.kt | 2 +- .../service/VpnSupervisorUseCaseEos.kt | 2 +- .../trackers/service/Config.kt | 7 ++- .../service/TrackersSupervisorStandalone.kt | 6 +- .../trackers/service/TunLooper.kt | 23 ++++--- .../service/data/RequestDNSRepository.kt | 4 +- .../service/usecases/ResolveDNSUseCase.kt | 6 +- .../VpnSupervisorUseCaseStandalone.kt | 2 +- 88 files changed, 498 insertions(+), 408 deletions(-) create mode 100644 .editorconfig delete mode 100644 app/src/main/java/foundation/e/advancedprivacy/DependencyContainer.kt rename app/src/main/java/foundation/e/advancedprivacy/data/repositories/{LocalStateRepository.kt => LocalStateRepositoryImpl.kt} (100%) rename app/src/main/java/foundation/e/advancedprivacy/data/repositories/{ResourcesGetter.kt => ResourcesRepository.kt} (96%) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..ec953c09 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*.{kt,kts}] + +ktlint_code_style = android_studio +max_line_length = 140 + +# Disable rules ktlint can't fix itself with spotlessApply +ktlint_standard_no-wildcard-imports = disabled +ktlint_standard_comment-wrapping = disabled +ktlint_standard_property-naming = disabled +ktlint_standard_discouraged-comment-location = disabled \ No newline at end of file diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index bdc45074..218a8e9c 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -2,12 +2,12 @@ This guide contains development related information to help a developer in getting better understanding of project structure. ## Architecture -The architecture of AdvancedPrivacy is based on [clean architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html). For presentation layer, we use a MVVM design pattern, -with a unique StateFlow for each screen to simplify coherence. Our android app is having single activity multiple fragments, using Android Navigation component. +The architecture of AdvancedPrivacy is based on [clean architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html). For presentation layer, we use a MVVM design pattern, +with a unique StateFlow for each screen to simplify coherence. Our android app is having single activity multiple fragments, using Android Navigation component. The project has 2 flavors : - eOS: for /e/OS devices, with OS specific signatures, system priviledges and persistent flag - - standalone: for app's stores, without any priviledges. + - standalone: for app's stores, without any priviledges. Most of the differences between the 2 flavors are separated in distinct modules like : - permissioneos / permissionstandalone @@ -15,7 +15,7 @@ Most of the differences between the 2 flavors are separated in distinct modules ### Clean Architecture -Clean architecture is the building block of AdvancedPrivacy. It is now a common way of organizing project, +Clean architecture is the building block of AdvancedPrivacy. It is now a common way of organizing project, so it helps newcomers. It gives a framework to apply Single Responsibility Principle, having a testable project and keep files with a decent length. diff --git a/README.md b/README.md index a96700c0..3a30d873 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ You can build the apk locally by using above instructions or you can download th ### To run apk on /e/OS devices If you are running your tests on a `/test` build, the debug buildtype already sign it with the appropriate key, and without the persistant flag, to allow further updates. -But the first time, to replace the AdvancedPrivacy app, embeded in the test build, you have to use the following commands: +But the first time, to replace the AdvancedPrivacy app, embeded in the test build, you have to use the following commands: ```shell adb root && adb remount @@ -134,7 +134,7 @@ AdvancedPrivacy needs to be installed as system app and whitelisting in order to ``` 1. Allow the fake location service to run in background. Add in the file /system/etc/permissions/platform.xml . - + 1. Reboot the device ```shell adb reboot @@ -165,7 +165,7 @@ 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/. ``` diff --git a/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt b/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt index 0fc1d673..b640c9e7 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt @@ -59,14 +59,14 @@ class AdvancedPrivacyApplication : Application() { Widget.startListening( this, get(GetQuickPrivacyStateUseCase::class.java), - get(TrackersStatisticsUseCase::class.java), + get(TrackersStatisticsUseCase::class.java) ) Notifications.startListening( this, get(GetQuickPrivacyStateUseCase::class.java), get(IPermissionsPrivacyModule::class.java), - get(CoroutineScope::class.java), + get(CoroutineScope::class.java) ) get(IpScramblingStateUseCase::class.java) diff --git a/app/src/main/java/foundation/e/advancedprivacy/DependencyContainer.kt b/app/src/main/java/foundation/e/advancedprivacy/DependencyContainer.kt deleted file mode 100644 index e69de29b..00000000 diff --git a/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt b/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt index 4c7f18e3..23065911 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt @@ -21,7 +21,7 @@ import android.content.res.Resources import android.os.Process import foundation.e.advancedprivacy.core.coreModule import foundation.e.advancedprivacy.data.repositories.LocalStateRepositoryImpl -import foundation.e.advancedprivacy.data.repositories.ResourcesGetter +import foundation.e.advancedprivacy.data.repositories.ResourcesRepository import foundation.e.advancedprivacy.domain.entities.ApplicationDescription import foundation.e.advancedprivacy.domain.entities.CHANNEL_TRACKER_FLAG import foundation.e.advancedprivacy.domain.entities.NotificationContent @@ -114,7 +114,7 @@ val appModule = module { } single { CityDataSource } - single { ResourcesGetter(androidContext()) } + single { ResourcesRepository(androidContext()) } singleOf(::AppListUseCase) single { diff --git a/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt b/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt index 430e9d56..ec92ebe9 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt @@ -61,7 +61,8 @@ object Notifications { .setAutoCancel(true) NotificationManagerCompat.from(context).notify( - NOTIFICATION_FIRST_BOOT, notificationBuilder.build() + NOTIFICATION_FIRST_BOOT, + notificationBuilder.build() ) } @@ -128,10 +129,12 @@ object Notifications { permissionsPrivacyModule: IPermissionsPrivacyModule, channelId: String, @StringRes channelName: Int, - @StringRes channelDescription: Int, + @StringRes channelDescription: Int ) { val channel = NotificationChannel( - channelId, context.getString(channelName), NotificationManager.IMPORTANCE_LOW + channelId, + context.getString(channelName), + NotificationManager.IMPORTANCE_LOW ) channel.description = context.getString(channelDescription) permissionsPrivacyModule.setBlockable(channel) @@ -170,11 +173,7 @@ object Notifications { } } - private fun showFlagNotification( - context: Context, - id: Int, - content: NotificationContent, - ) { + private fun showFlagNotification(context: Context, id: Int, content: NotificationContent) { val builder = notificationBuilder(context, content) .setPriority(NotificationCompat.PRIORITY_LOW) .setOngoing(true) diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/GraphHolder.kt b/app/src/main/java/foundation/e/advancedprivacy/common/GraphHolder.kt index ca4fcb65..44fb73d3 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/common/GraphHolder.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/common/GraphHolder.kt @@ -104,7 +104,11 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov barChart.offsetTopAndBottom(0) - barChart.setXAxisRenderer(object : XAxisRenderer(barChart.viewPortHandler, barChart.xAxis, barChart.getTransformer(AxisDependency.LEFT)) { + barChart.setXAxisRenderer(object : XAxisRenderer( + barChart.viewPortHandler, + barChart.xAxis, + barChart.getTransformer(AxisDependency.LEFT) + ) { override fun renderAxisLine(c: Canvas) { mAxisLinePaint.color = mXAxis.axisLineColor mAxisLinePaint.strokeWidth = mXAxis.axisLineWidth @@ -113,8 +117,10 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov // Top line c.drawLine( mViewPortHandler.contentLeft(), - mViewPortHandler.contentTop(), mViewPortHandler.contentRight(), - mViewPortHandler.contentTop(), mAxisLinePaint + mViewPortHandler.contentTop(), + mViewPortHandler.contentRight(), + mViewPortHandler.contentTop(), + mAxisLinePaint ) // Bottom line @@ -203,9 +209,12 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov .getPixelForValues(index.toFloat(), 0f) .x val highlight = Highlight( - index.toFloat(), 0f, - xPx.toFloat(), 0f, - 0, YAxis.AxisDependency.LEFT + index.toFloat(), + 0f, + xPx.toFloat(), + 0f, + 0, + YAxis.AxisDependency.LEFT ) barChart.highlightValue(highlight, true) @@ -222,7 +231,6 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov }, "" ).apply { - val blockedColor = ContextCompat.getColor(context, R.color.accent) val leakedColor = ContextCompat.getColor(context, R.color.red_off) @@ -261,20 +269,28 @@ class PeriodMarkerView(context: Context, private val isMarkerAbove: Boolean = tr private fun showArrow(position: ArrowPosition?) { val ids = listOf( - R.id.arrow_top_left, R.id.arrow_top_center, R.id.arrow_top_right, - R.id.arrow_bottom_left, R.id.arrow_bottom_center, R.id.arrow_bottom_right + R.id.arrow_top_left, + R.id.arrow_top_center, + R.id.arrow_top_right, + R.id.arrow_bottom_left, + R.id.arrow_bottom_center, + R.id.arrow_bottom_right ) - val toShow = if (isMarkerAbove) when (position) { - ArrowPosition.LEFT -> R.id.arrow_bottom_left - ArrowPosition.CENTER -> R.id.arrow_bottom_center - ArrowPosition.RIGHT -> R.id.arrow_bottom_right - else -> null - } else when (position) { - ArrowPosition.LEFT -> R.id.arrow_top_left - ArrowPosition.CENTER -> R.id.arrow_top_center - ArrowPosition.RIGHT -> R.id.arrow_top_right - else -> null + val toShow = if (isMarkerAbove) { + when (position) { + ArrowPosition.LEFT -> R.id.arrow_bottom_left + ArrowPosition.CENTER -> R.id.arrow_bottom_center + ArrowPosition.RIGHT -> R.id.arrow_bottom_right + else -> null + } + } else { + when (position) { + ArrowPosition.LEFT -> R.id.arrow_top_left + ArrowPosition.CENTER -> R.id.arrow_top_center + ArrowPosition.RIGHT -> R.id.arrow_top_right + else -> null + } } ids.forEach { id -> @@ -321,8 +337,11 @@ class PeriodMarkerView(context: Context, private val isMarkerAbove: Boolean = tr } mOffset2.x = x - mOffset2.y = if (isMarkerAbove) -posY - else -posY + (chartView?.height?.toFloat() ?: 0f) - height + mOffset2.y = if (isMarkerAbove) { + -posY + } else { + -posY + (chartView?.height?.toFloat() ?: 0f) - height + } return mOffset2 } diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/TextViewHelpers.kt b/app/src/main/java/foundation/e/advancedprivacy/common/TextViewHelpers.kt index f87834ab..50cad5ec 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/common/TextViewHelpers.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/common/TextViewHelpers.kt @@ -29,22 +29,14 @@ import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.widget.TooltipCompat import foundation.e.advancedprivacy.R -fun setToolTipForAsterisk( - textView: TextView, - @StringRes textId: Int, - @StringRes tooltipTextId: Int -) { +fun setToolTipForAsterisk(textView: TextView, @StringRes textId: Int, @StringRes tooltipTextId: Int) { textView.text = asteriskAsInfoIconSpannable(textView.context, textId, textView.textColors) TooltipCompat.setTooltipText(textView, textView.context.getString(tooltipTextId)) textView.setOnClickListener { it.performLongClick() } } -private fun asteriskAsInfoIconSpannable( - context: Context, - @StringRes textId: Int, - tint: ColorStateList -): Spannable { +private fun asteriskAsInfoIconSpannable(context: Context, @StringRes textId: Int, tint: ColorStateList): Spannable { val spannable = SpannableString(context.getString(textId)) val index = spannable.lastIndexOf("*") if (index != -1) { diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/ThrottleFlow.kt b/app/src/main/java/foundation/e/advancedprivacy/common/ThrottleFlow.kt index e9ec060e..06fa0738 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/common/ThrottleFlow.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/common/ThrottleFlow.kt @@ -17,10 +17,10 @@ package foundation.e.advancedprivacy.common +import kotlin.time.Duration import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow -import kotlin.time.Duration @FlowPreview fun Flow.throttleFirst(windowDuration: Duration): Flow = flow { diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt b/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt index 60747e36..ecc2e4ac 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt @@ -47,11 +47,7 @@ class WarningDialog : AppCompatActivity() { companion object { private const val PARAM_FEATURE = "feature" - fun startListening( - showFeaturesWarningUseCase: ShowFeaturesWarningUseCase, - appScope: CoroutineScope, - appContext: Context - ) { + fun startListening(showFeaturesWarningUseCase: ShowFeaturesWarningUseCase, appScope: CoroutineScope, appContext: Context) { showFeaturesWarningUseCase.showWarning().map { feature -> appContext.startActivity( createIntent(context = appContext, feature = feature) @@ -59,10 +55,7 @@ class WarningDialog : AppCompatActivity() { }.launchIn(appScope) } - private fun createIntent( - context: Context, - feature: MainFeatures, - ): Intent { + private fun createIntent(context: Context, feature: MainFeatures): Intent { val intent = Intent(context, WarningDialog::class.java) intent.putExtra(PARAM_FEATURE, feature) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK @@ -133,7 +126,9 @@ class WarningDialog : AppCompatActivity() { if (vpnDisclaimerIntent != null) { isWaitingForResult = true launchAndroidVpnDisclaimer.launch(vpnDisclaimerIntent) - } else finish() + } else { + finish() + } } if (feature is MainFeatures.TrackersControl) { diff --git a/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt b/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepositoryImpl.kt similarity index 100% rename from app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt rename to app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepositoryImpl.kt diff --git a/app/src/main/java/foundation/e/advancedprivacy/data/repositories/ResourcesGetter.kt b/app/src/main/java/foundation/e/advancedprivacy/data/repositories/ResourcesRepository.kt similarity index 96% rename from app/src/main/java/foundation/e/advancedprivacy/data/repositories/ResourcesGetter.kt rename to app/src/main/java/foundation/e/advancedprivacy/data/repositories/ResourcesRepository.kt index 6902a993..23ea9b6d 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/data/repositories/ResourcesGetter.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/data/repositories/ResourcesRepository.kt @@ -21,11 +21,11 @@ import android.content.Context import android.content.res.Configuration import android.content.res.Resources import androidx.annotation.StringRes -import timber.log.Timber import java.time.format.DateTimeFormatter import java.util.Locale +import timber.log.Timber -class ResourcesGetter(private val context: Context) { +class ResourcesRepository(private val context: Context) { private val defaultResources by lazy { getLocalizedResources(context, Locale("")) } private fun getLocalizedResources(context: Context, desiredLocale: Locale?): Resources { diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/AppWithCounts.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/AppWithCounts.kt index 344e6897..244b1337 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/AppWithCounts.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/AppWithCounts.kt @@ -30,7 +30,7 @@ data class AppWithCounts( val trackersCount: Int = 0, val whiteListedTrackersCount: Int = 0, val blockedLeaks: Int = 0, - val leaks: Int = 0, + val leaks: Int = 0 ) { constructor( app: ApplicationDescription, @@ -38,7 +38,7 @@ data class AppWithCounts( trackersCount: Int, whiteListedTrackersCount: Int, blockedLeaks: Int, - leaks: Int, + leaks: Int ) : this( appDesc = app, @@ -53,6 +53,9 @@ data class AppWithCounts( leaks = leaks ) - val blockedTrackersCount get() = if (isWhitelisted) 0 - else Math.max(trackersCount - whiteListedTrackersCount, 0) + val blockedTrackersCount get() = if (isWhitelisted) { + 0 + } else { + Math.max(trackersCount - whiteListedTrackersCount, 0) + } } diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/QuickPrivacyState.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/QuickPrivacyState.kt index c21bb1d6..247e8349 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/QuickPrivacyState.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/QuickPrivacyState.kt @@ -18,7 +18,9 @@ package foundation.e.advancedprivacy.domain.entities enum class QuickPrivacyState { - DISABLED, ENABLED, FULL_ENABLED; + DISABLED, + ENABLED, + FULL_ENABLED; fun isEnabled(): Boolean = this != DISABLED } diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/TrackerMode.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/TrackerMode.kt index 2033251a..fd6ea60f 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/TrackerMode.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/TrackerMode.kt @@ -18,5 +18,7 @@ package foundation.e.advancedprivacy.domain.entities enum class TrackerMode { - DENIED, CUSTOM, VULNERABLE + DENIED, + CUSTOM, + VULNERABLE } diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/AppTrackersUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/AppTrackersUseCase.kt index 3047f33f..b156246d 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/AppTrackersUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/AppTrackersUseCase.kt @@ -30,7 +30,7 @@ class AppTrackersUseCase( private val appListsRepository: AppListsRepository, private val statsDatabase: StatsDatabase, private val trackersRepository: TrackersRepository, - private val filterHostnameUseCase: FilterHostnameUseCase, + private val filterHostnameUseCase: FilterHostnameUseCase ) { suspend fun toggleAppWhitelist(app: ApplicationDescription, trackers: List, isBlocked: Boolean) { val realApIds = appListsRepository.getRealApps(app).map { it.apId } 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 282116e7..6c948020 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 @@ -32,13 +32,13 @@ import foundation.e.advancedprivacy.domain.repositories.LocalStateRepository import foundation.e.advancedprivacy.dummy.CityDataSource import foundation.e.advancedprivacy.externalinterfaces.permissions.IPermissionsPrivacyModule import foundation.e.advancedprivacy.fakelocation.domain.usecases.FakeLocationModule +import kotlin.random.Random import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import timber.log.Timber -import kotlin.random.Random class FakeLocationStateUseCase( private val fakeLocationModule: FakeLocationModule, @@ -114,7 +114,7 @@ class FakeLocationStateUseCase( private fun computeLocationMode( isFakeLocationEnabled: Boolean, fakeLocation: Pair, - isSpecificLocation: Boolean = false, + isSpecificLocation: Boolean = false ): Triple { return Triple( when { @@ -158,7 +158,9 @@ class FakeLocationStateUseCase( return if (hasAcquireLocationPermission()) { requestLocationUpdates() true - } else false + } else { + false + } } fun stopListeningLocation() { diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt index 480d3b35..962a87ad 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt @@ -31,7 +31,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map class GetQuickPrivacyStateUseCase( - private val localStateRepository: LocalStateRepository, + private val localStateRepository: LocalStateRepository ) { val quickPrivacyState: Flow = combine( localStateRepository.blockTrackers, @@ -47,9 +47,9 @@ class GetQuickPrivacyStateUseCase( isAllTrackersBlocked && locationMode != LocationMode.REAL_LOCATION && internetPrivacyMode in listOf( - FeatureState.ON, - FeatureState.STARTING - ) -> QuickPrivacyState.FULL_ENABLED + FeatureState.ON, + FeatureState.STARTING + ) -> QuickPrivacyState.FULL_ENABLED else -> QuickPrivacyState.ENABLED } diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackerDetailsUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackerDetailsUseCase.kt index 6348d751..eb247d7b 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackerDetailsUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackerDetailsUseCase.kt @@ -28,13 +28,9 @@ class TrackerDetailsUseCase( private val trackersStateUseCase: TrackersStateUseCase, private val appListsRepository: AppListsRepository, private val statsDatabase: StatsDatabase, - private val filterHostnameUseCase: FilterHostnameUseCase, + private val filterHostnameUseCase: FilterHostnameUseCase ) { - suspend fun toggleTrackerWhitelist( - tracker: Tracker, - apps: List, - isBlocked: Boolean - ) { + suspend fun toggleTrackerWhitelist(tracker: Tracker, apps: List, isBlocked: Boolean) { whitelistRepository.setWhiteListed(tracker, !isBlocked) whitelistRepository.setWhitelistedAppsForTracker( apps.flatMap { appListsRepository.getRealApps(it) }.map { it.apId }, @@ -53,10 +49,7 @@ class TrackerDetailsUseCase( ) } - suspend fun enrichWithBlockedState( - apps: List, - tracker: Tracker - ): List> { + suspend fun enrichWithBlockedState(apps: List, tracker: Tracker): List> { return apps.map { app -> app to appListsRepository.anyForHiddenApps(app) { realApp -> !filterHostnameUseCase.isWhitelisted(realApp.uid, tracker.id) diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersAndAppsListsUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersAndAppsListsUseCase.kt index 9bff2f7e..5606d499 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersAndAppsListsUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersAndAppsListsUseCase.kt @@ -25,13 +25,13 @@ import foundation.e.advancedprivacy.features.trackers.TrackerWithAppsCount import foundation.e.advancedprivacy.trackers.data.StatsDatabase import foundation.e.advancedprivacy.trackers.data.TrackersRepository import foundation.e.advancedprivacy.trackers.domain.entities.Tracker -import kotlinx.coroutines.flow.first import java.time.Instant +import kotlinx.coroutines.flow.first class TrackersAndAppsListsUseCase( private val statsDatabase: StatsDatabase, private val trackersRepository: TrackersRepository, - private val appListsRepository: AppListsRepository, + private val appListsRepository: AppListsRepository ) { suspend fun getAppsAndTrackersCounts(period: Period): TrackersAndAppsLists { val periodStart: Instant = period.getPeriodStart() @@ -76,14 +76,15 @@ class TrackersAndAppsListsUseCase( }.distinct() } - private fun foldToCountByEntityMaps(trackersAndApps: List>): - Pair, Map> { - return trackersAndApps.fold( - mutableMapOf() to mutableMapOf() - ) { (countByApp, countByTracker), (tracker, app) -> - countByApp[app] = countByApp.getOrDefault(app, 0) + 1 - countByTracker[tracker] = countByTracker.getOrDefault(tracker, 0) + 1 - countByApp to countByTracker - } + private fun foldToCountByEntityMaps( + trackersAndApps: List> + ): Pair, Map> { + return trackersAndApps.fold( + mutableMapOf() to mutableMapOf() + ) { (countByApp, countByTracker), (tracker, app) -> + countByApp[app] = countByApp.getOrDefault(app, 0) + 1 + countByTracker[tracker] = countByTracker.getOrDefault(tracker, 0) + 1 + countByApp to countByTracker } + } } diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt index 51d69e8c..3ae3f446 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt @@ -30,7 +30,7 @@ class TrackersStateUseCase( private val whitelistRepository: WhitelistRepository, private val localStateRepository: LocalStateRepository, private val appListsRepository: AppListsRepository, - coroutineScope: CoroutineScope, + coroutineScope: CoroutineScope ) { init { coroutineScope.launch { @@ -64,12 +64,7 @@ class TrackersStateUseCase( } } -fun isWhitelisted( - app: ApplicationDescription, - appListsRepository: AppListsRepository, - whitelistRepository: WhitelistRepository - -): Boolean { +fun isWhitelisted(app: ApplicationDescription, appListsRepository: AppListsRepository, whitelistRepository: WhitelistRepository): Boolean { return appListsRepository.anyForHiddenApps( app, whitelistRepository::isAppWhiteListed diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt index 804ba381..64520a50 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt @@ -21,7 +21,7 @@ package foundation.e.advancedprivacy.domain.usecases import foundation.e.advancedprivacy.R import foundation.e.advancedprivacy.common.throttleFirst import foundation.e.advancedprivacy.data.repositories.AppListsRepository -import foundation.e.advancedprivacy.data.repositories.ResourcesGetter +import foundation.e.advancedprivacy.data.repositories.ResourcesRepository import foundation.e.advancedprivacy.domain.entities.ApplicationDescription import foundation.e.advancedprivacy.domain.entities.TrackersPeriodicStatistics import foundation.e.advancedprivacy.features.trackers.Period @@ -30,15 +30,15 @@ import foundation.e.advancedprivacy.trackers.data.TrackersRepository import foundation.e.advancedprivacy.trackers.data.WhitelistRepository import foundation.e.advancedprivacy.trackers.domain.entities.Tracker import foundation.e.advancedprivacy.trackers.domain.usecases.StatisticsUseCase +import java.time.ZonedDateTime +import java.time.temporal.ChronoUnit +import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart -import java.time.ZonedDateTime -import java.time.temporal.ChronoUnit -import kotlin.time.Duration -import kotlin.time.Duration.Companion.seconds class TrackersStatisticsUseCase( private val statisticsUseCase: StatisticsUseCase, @@ -46,29 +46,28 @@ class TrackersStatisticsUseCase( private val trackersRepository: TrackersRepository, private val appListsRepository: AppListsRepository, private val statsDatabase: StatsDatabase, - private val resourcesGetter: ResourcesGetter, + private val resourcesRepository: ResourcesRepository ) { fun initAppList() { appListsRepository.apps() } @OptIn(FlowPreview::class) - fun listenUpdates(debounce: Duration = 1.seconds) = - statsDatabase.newDataAvailable - .throttleFirst(windowDuration = debounce) - .onStart { emit(Unit) } + fun listenUpdates(debounce: Duration = 1.seconds) = statsDatabase.newDataAvailable + .throttleFirst(windowDuration = debounce) + .onStart { emit(Unit) } fun getDayStatistics(): Pair { return TrackersPeriodicStatistics( callsBlockedNLeaked = statisticsUseCase.getTrackersCallsOnPeriod(24, ChronoUnit.HOURS), periods = buildDayLabels(), trackersCount = statisticsUseCase.getActiveTrackersByPeriod(24, ChronoUnit.HOURS), - graduations = buildDayGraduations(), + graduations = buildDayGraduations() ) to statisticsUseCase.getContactedTrackersCount() } fun getNonBlockedTrackersCount(): Flow { - return if (whitelistRepository.isBlockingEnabled) + return if (whitelistRepository.isBlockingEnabled) { appListsRepository.allApps().map { apps -> val whiteListedTrackers = mutableSetOf() val whiteListedApps = whitelistRepository.getWhiteListedApp() @@ -81,7 +80,9 @@ class TrackersStatisticsUseCase( } whiteListedTrackers.size } - else flowOf(statisticsUseCase.getContactedTrackersCount()) + } else { + flowOf(statisticsUseCase.getContactedTrackersCount()) + } } fun getMostLeakedApp(): ApplicationDescription? { @@ -101,7 +102,7 @@ class TrackersStatisticsUseCase( } private fun buildDayGraduations(): List { - val formatter = resourcesGetter.getFormatter(R.string.trackers_graph_hours_period_format) + val formatter = resourcesRepository.getFormatter(R.string.trackers_graph_hours_period_format) val periods = mutableListOf() var end = ZonedDateTime.now() @@ -114,7 +115,7 @@ class TrackersStatisticsUseCase( } private fun buildMonthGraduations(): List { - val formatter = resourcesGetter.getFormatter( + val formatter = resourcesRepository.getFormatter( R.string.trackers_graph_month_graduations_format ) @@ -130,7 +131,7 @@ class TrackersStatisticsUseCase( } private fun buildYearGraduations(): List { - val formatter = resourcesGetter.getFormatter(R.string.trackers_graph_year_graduations_format) + val formatter = resourcesRepository.getFormatter(R.string.trackers_graph_year_graduations_format) val periods = mutableListOf() var end = ZonedDateTime.now() @@ -154,7 +155,7 @@ class TrackersStatisticsUseCase( } private fun buildDayLabels(): List { - val formatter = resourcesGetter.getFormatter(R.string.trackers_graph_hours_period_format) + val formatter = resourcesRepository.getFormatter(R.string.trackers_graph_hours_period_format) val periods = mutableListOf() var end = ZonedDateTime.now() @@ -167,7 +168,7 @@ class TrackersStatisticsUseCase( } private fun buildMonthLabels(): List { - val formater = resourcesGetter.getFormatter(R.string.trackers_graph_days_period_format) + val formater = resourcesRepository.getFormatter(R.string.trackers_graph_days_period_format) val periods = mutableListOf() var day = ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS) @@ -179,7 +180,7 @@ class TrackersStatisticsUseCase( } private fun buildYearLabels(): List { - val formater = resourcesGetter.getFormatter(R.string.trackers_graph_months_period_format) + val formater = resourcesRepository.getFormatter(R.string.trackers_graph_months_period_format) val periods = mutableListOf() var month = ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1) @@ -196,7 +197,7 @@ class TrackersStatisticsUseCase( periods = buildLabels(period), trackersCount = statsDatabase.getTrackersCount(period.periodsCount, period.periodUnit), trackersAllowedCount = statsDatabase.getLeakedTrackersCount(period.periodsCount, period.periodUnit), - graduations = buildGraduations(period), + graduations = buildGraduations(period) ) } diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardFragment.kt index b22e67f4..31c4d07c 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardFragment.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardFragment.kt @@ -153,8 +153,11 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { ) binding.stateIcon.setImageResource( - if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on - else R.drawable.ic_shield_off + if (state.quickPrivacyState.isEnabled()) { + R.drawable.ic_shield_on + } else { + R.drawable.ic_shield_off + } ) binding.toggleTrackers.isChecked = state.trackerMode != TrackerMode.VULNERABLE @@ -169,22 +172,31 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { binding.stateTrackers.setTextColor( getColor( requireContext(), - if (state.trackerMode == TrackerMode.VULNERABLE) R.color.red_off - else R.color.green_valid + if (state.trackerMode == TrackerMode.VULNERABLE) { + R.color.red_off + } else { + R.color.green_valid + } ) ) binding.toggleLocation.isChecked = state.isLocationHidden binding.stateGeolocation.text = getString( - if (state.isLocationHidden) R.string.dashboard_state_geolocation_on - else R.string.dashboard_state_geolocation_off + if (state.isLocationHidden) { + R.string.dashboard_state_geolocation_on + } else { + R.string.dashboard_state_geolocation_off + } ) binding.stateGeolocation.setTextColor( getColor( requireContext(), - if (state.isLocationHidden) R.color.green_valid - else R.color.red_off + if (state.isLocationHidden) { + R.color.green_valid + } else { + R.color.red_off + } ) ) @@ -195,8 +207,11 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { ) binding.stateIpAddress.text = getString( - if (state.ipScramblingMode == FeatureState.ON) R.string.dashboard_state_ipaddress_on - else R.string.dashboard_state_ipaddress_off + if (state.ipScramblingMode == FeatureState.ON) { + R.string.dashboard_state_ipaddress_on + } else { + R.string.dashboard_state_ipaddress_off + } ) binding.stateIpAddressLoader.visibility = if (isLoading) View.VISIBLE else View.GONE @@ -205,8 +220,11 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { binding.stateIpAddress.setTextColor( getColor( requireContext(), - if (state.ipScramblingMode == FeatureState.ON) R.color.green_valid - else R.color.red_off + if (state.ipScramblingMode == FeatureState.ON) { + R.color.green_valid + } else { + R.color.red_off + } ) ) @@ -241,7 +259,11 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { } if (state.allowedTrackersCount != null && state.trackersCount != null) { - binding.amITracked.subTitle = getString(R.string.dashboard_am_i_tracked_subtitle, state.trackersCount, state.allowedTrackersCount) + binding.amITracked.subTitle = getString( + R.string.dashboard_am_i_tracked_subtitle, + state.trackersCount, + state.allowedTrackersCount + ) } else { binding.amITracked.subTitle = "" } @@ -255,8 +277,11 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { ) binding.internetActivityPrivacy.subTitle = getString( - if (state.ipScramblingMode == FeatureState.ON) R.string.dashboard_internet_activity_privacy_subtitle_on - else R.string.dashboard_internet_activity_privacy_subtitle_off + if (state.ipScramblingMode == FeatureState.ON) { + R.string.dashboard_internet_activity_privacy_subtitle_on + } else { + R.string.dashboard_internet_activity_privacy_subtitle_off + } ) binding.executePendingBindings() diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardState.kt b/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardState.kt index d26c53d1..774901a8 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardState.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardState.kt @@ -33,5 +33,5 @@ data class DashboardState( val allowedTrackersCount: Int? = null, val dayStatistics: List>? = null, val dayLabels: List? = null, - val dayGraduations: List? = null, + val dayGraduations: List? = null ) diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardViewModel.kt b/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardViewModel.kt index 8259c89e..a36b24a3 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/dashboard/DashboardViewModel.kt @@ -42,7 +42,7 @@ import kotlinx.coroutines.withContext class DashboardViewModel( private val getPrivacyStateUseCase: GetQuickPrivacyStateUseCase, - private val trackersStatisticsUseCase: TrackersStatisticsUseCase, + private val trackersStatisticsUseCase: TrackersStatisticsUseCase ) : ViewModel() { private val _state = MutableStateFlow(DashboardState()) diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyFragment.kt b/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyFragment.kt index 482a7738..fb01c437 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyFragment.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyFragment.kt @@ -33,9 +33,9 @@ import foundation.e.advancedprivacy.common.ToggleAppsAdapter import foundation.e.advancedprivacy.common.setToolTipForAsterisk import foundation.e.advancedprivacy.databinding.FragmentInternetActivityPolicyBinding import foundation.e.advancedprivacy.domain.entities.FeatureState +import java.util.Locale import kotlinx.coroutines.launch import org.koin.androidx.viewmodel.ext.android.viewModel -import java.util.Locale class InternetPrivacyFragment : NavToolbarFragment(R.layout.fragment_internet_activity_policy) { @@ -92,12 +92,7 @@ class InternetPrivacyFragment : NavToolbarFragment(R.layout.fragment_internet_ac } onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected( - parentView: AdapterView<*>, - selectedItemView: View?, - position: Int, - id: Long - ) { + override fun onItemSelected(parentView: AdapterView<*>, selectedItemView: View?, position: Int, id: Long) { viewModel.submitAction( InternetPrivacyViewModel.Action.SelectLocationAction( position @@ -163,8 +158,8 @@ class InternetPrivacyFragment : NavToolbarFragment(R.layout.fragment_internet_ac ) when { - state.mode.isLoading - || state.availableApps.isEmpty() -> { + state.mode.isLoading || + state.availableApps.isEmpty() -> { binding.loader.visibility = View.VISIBLE viewIdsToHide.forEach { it.visibility = View.GONE } } diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyState.kt b/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyState.kt index 9ba716f0..4966431f 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyState.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyState.kt @@ -26,7 +26,7 @@ data class InternetPrivacyState( val bypassTorApps: Collection = emptyList(), val selectedLocation: String = "", val availableLocationIds: List = emptyList(), - val forceRedraw: Boolean = false, + val forceRedraw: Boolean = false ) { fun getApps(): List> { return availableApps.map { it to (it.packageName !in bypassTorApps) } diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyViewModel.kt b/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyViewModel.kt index b2f93c27..748ddd3a 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyViewModel.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/internetprivacy/InternetPrivacyViewModel.kt @@ -91,9 +91,11 @@ class InternetPrivacyViewModel( .map { it == FeatureState.STARTING } .debounce(WARNING_LOADING_LONG_DELAY) .collect { - if (it) _singleEvents.emit( - SingleEvent.ErrorEvent(R.string.ipscrambling_warning_starting_long) - ) + if (it) { + _singleEvents.emit( + SingleEvent.ErrorEvent(R.string.ipscrambling_warning_starting_long) + ) + } } } 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 1c629c2c..79912d8e 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 @@ -205,10 +205,7 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) } } - private fun validateCoordinate( - inputLayout: TextInputLayout, - maxValue: Float - ): Boolean { + private fun validateCoordinate(inputLayout: TextInputLayout, maxValue: Float): Boolean { return try { val value = inputLayout.editText?.text?.toString()?.toFloat()!! @@ -248,7 +245,9 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) private fun onLatTextChanged(editable: Editable?) { if (!binding.edittextLatitude.isFocused || !validateCoordinate(binding.textlayoutLatitude, 90f) - ) return + ) { + return + } updateSpecificCoordinates() } @@ -257,7 +256,9 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) private fun onLonTextChanged(editable: Editable?) { if (!binding.edittextLongitude.isFocused || !validateCoordinate(binding.textlayoutLongitude, 180f) - ) return + ) { + return + } updateSpecificCoordinates() } @@ -367,7 +368,8 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) locationComponent = mapboxMap?.locationComponent locationComponent?.activateLocationComponent( LocationComponentActivationOptions.builder( - requireContext(), loadedMapStyle + requireContext(), + loadedMapStyle ).useDefaultLocationEngine(false).build() ) locationComponent?.isLocationComponentEnabled = true diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationMapView.kt b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationMapView.kt index f80c25e5..8280426e 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationMapView.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationMapView.kt @@ -49,8 +49,7 @@ class FakeLocationMapView @JvmOverloads constructor( } } -fun FakeLocationMapView.setup(savedInstanceState: Bundle?, callback: OnMapReadyCallback) = - this.apply { - onCreate(savedInstanceState) - getMapAsync(callback) - } +fun FakeLocationMapView.setup(savedInstanceState: Bundle?, callback: OnMapReadyCallback) = this.apply { + onCreate(savedInstanceState) + getMapAsync(callback) +} 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 baa672bc..ec2eef18 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 @@ -25,5 +25,5 @@ data class FakeLocationState( val currentLocation: Location? = null, val specificLatitude: Float? = null, val specificLongitude: Float? = null, - val forceRefresh: Boolean = false, + 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 deca4c16..9962037f 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 @@ -21,6 +21,7 @@ import android.location.Location import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import foundation.e.advancedprivacy.domain.usecases.FakeLocationStateUseCase +import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.MutableSharedFlow @@ -34,7 +35,6 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import kotlin.time.Duration.Companion.milliseconds class FakeLocationViewModel( private val fakeLocationStateUseCase: FakeLocationStateUseCase diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/ListsTabPagerAdapter.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/ListsTabPagerAdapter.kt index dd665fc9..7cde6590 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/ListsTabPagerAdapter.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/ListsTabPagerAdapter.kt @@ -34,7 +34,7 @@ private const val TAB_TRACKERS = 1 class ListsTabPagerAdapter( private val context: Context, - private val viewModel: TrackersPeriodViewModel, + private val viewModel: TrackersPeriodViewModel ) : RecyclerView.Adapter() { private var uiState: TrackersPeriodState = TrackersPeriodState() @@ -109,8 +109,11 @@ class ListsTabPagerAdapter( fun onBind(uiState: TrackersPeriodState) { (binding.list.adapter as AppsAdapter).dataSet = ( - if (uiState.hideNoTrackersApps) - uiState.appsWithTrackers else uiState.allApps + if (uiState.hideNoTrackersApps) { + uiState.appsWithTrackers + } else { + uiState.allApps + } ) ?: emptyList() binding.toggleNoTrackerApps.apply { diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackerControlDisclaimer.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackerControlDisclaimer.kt index 183a5ca9..f232e0d0 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackerControlDisclaimer.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackerControlDisclaimer.kt @@ -75,7 +75,9 @@ private fun buildSpan(context: Context, onClickLearnMore: () -> Unit): Spannable onClickLearnMore.invoke() } }, - linkStartIndex, linkEndIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE + linkStartIndex, + linkEndIndex, + Spannable.SPAN_INCLUSIVE_EXCLUSIVE ) return spannable } diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersFragment.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersFragment.kt index 063458da..7663c4d8 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersFragment.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersFragment.kt @@ -143,7 +143,9 @@ class TrackersFragment : NavToolbarFragment(R.layout.fragment_trackers) { viewModel.onClickLearnMore() } }, - startIndex, endIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE + startIndex, + endIndex, + Spannable.SPAN_INCLUSIVE_EXCLUSIVE ) with(binding.trackersInfo) { diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodAdapter.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodAdapter.kt index 6afc1ba8..721791b8 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodAdapter.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodAdapter.kt @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2023 MURENA SAS + * + * 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 . + */ + package foundation.e.advancedprivacy.features.trackers import androidx.fragment.app.Fragment diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodViewModel.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodViewModel.kt index 0593e529..8b3887e3 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodViewModel.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/TrackersPeriodViewModel.kt @@ -48,7 +48,7 @@ class TrackersPeriodViewModel( Period.DAY -> R.string.trackers_graph_title_day Period.MONTH -> R.string.trackers_graph_title_month Period.YEAR -> R.string.trackers_graph_title_year - }, + } ) ) diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersState.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersState.kt index cea99a6e..ede918f3 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersState.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersState.kt @@ -28,7 +28,7 @@ data class AppTrackersState( val leaked: Int = 0, val blocked: Int = 0, val isTrackersBlockingEnabled: Boolean = false, - val isWhitelistEmpty: Boolean = true, + val isWhitelistEmpty: Boolean = true ) { fun getTrackersCount() = trackersWithBlockedList.size diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersViewModel.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersViewModel.kt index 5a079b5f..9e0af042 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersViewModel.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/AppTrackersViewModel.kt @@ -61,7 +61,7 @@ class AppTrackersViewModel( init { _state.update { it.copy( - appDesc = app, + appDesc = app ) } } @@ -141,9 +141,10 @@ class AppTrackersViewModel( s.copy( isBlockingActivated = !trackersStateUseCase.isWhitelisted(app), trackersWithBlockedList = appTrackersUseCase.enrichWithBlockedState( - app, s.trackersWithBlockedList.map { it.first } + app, + s.trackersWithBlockedList.map { it.first } ), - isWhitelistEmpty = trackersStatisticsUseCase.isWhiteListEmpty(app), + isWhitelistEmpty = trackersStatisticsUseCase.isWhiteListEmpty(app) ) } } diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/ToggleTrackersAdapter.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/ToggleTrackersAdapter.kt index 1d499059..dd20a408 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/ToggleTrackersAdapter.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/apptrackers/ToggleTrackersAdapter.kt @@ -33,14 +33,13 @@ class ToggleTrackersAdapter( ) : RecyclerView.Adapter() { class ViewHolder( private val binding: ApptrackersItemTrackerToggleBinding, - private val viewModel: AppTrackersViewModel, + private val viewModel: AppTrackersViewModel ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: Pair) { val label = item.first.label with(binding.title) { if (item.first.exodusId != null) { - setTextColor(ContextCompat.getColor(context, R.color.accent)) val spannable = SpannableString(label) spannable.setSpan(UnderlineSpan(), 0, spannable.length, 0) diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/GraphHolder.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/GraphHolder.kt index d4483c02..ed6c326c 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/GraphHolder.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/GraphHolder.kt @@ -79,7 +79,9 @@ class GraphHolder(private val binding: TrackersItemGraphBinding) { } private val xAxisRenderer = object : XAxisRenderer( - barChart.viewPortHandler, barChart.xAxis, barChart.getTransformer(AxisDependency.LEFT) + barChart.viewPortHandler, + barChart.xAxis, + barChart.getTransformer(AxisDependency.LEFT) ) { override fun renderAxisLine(c: Canvas) { mAxisLinePaint.color = mXAxis.axisLineColor @@ -180,9 +182,12 @@ class GraphHolder(private val binding: TrackersItemGraphBinding) { title.text = context.getString(state.title) val views = listOf( helperText, - legendBlockedIcon, legendBlocked, - legendAllowedIcon, legendAllowed, - trackersDetected, trackersAllowed + legendBlockedIcon, + legendBlocked, + legendAllowedIcon, + legendAllowed, + trackersDetected, + trackersAllowed ) if (state.isEmptyCalls()) { diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/PeriodMarkerView.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/PeriodMarkerView.kt index cd7730cb..be7e81bc 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/PeriodMarkerView.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/graph/PeriodMarkerView.kt @@ -56,8 +56,12 @@ class PeriodMarkerView(context: Context) : MarkerView(context, R.layout.chart_to private fun showArrow(position: ArrowPosition?) { val ids = listOf( - R.id.arrow_top_left, R.id.arrow_top_center, R.id.arrow_top_right, - R.id.arrow_bottom_left, R.id.arrow_bottom_center, R.id.arrow_bottom_right + R.id.arrow_top_left, + R.id.arrow_top_center, + R.id.arrow_top_right, + R.id.arrow_bottom_left, + R.id.arrow_bottom_center, + R.id.arrow_bottom_right ) val toShow = when (position) { diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerAppsAdapter.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerAppsAdapter.kt index d4196771..da714274 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerAppsAdapter.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerAppsAdapter.kt @@ -29,7 +29,7 @@ class TrackerAppsAdapter( class ViewHolder( private val binding: ApptrackersItemTrackerToggleBinding, - private val viewModel: TrackerDetailsViewModel, + private val viewModel: TrackerDetailsViewModel ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: Pair) { diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsState.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsState.kt index 9ae7412f..9cbc3993 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsState.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsState.kt @@ -27,5 +27,5 @@ data class TrackerDetailsState( val blockedCount: Int = 0, val leakedCount: Int = 0, val appList: List> = emptyList(), - val isTrackersBlockingEnabled: Boolean = false, + val isTrackersBlockingEnabled: Boolean = false ) diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsViewModel.kt b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsViewModel.kt index 3e3a2d59..1a87f94b 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsViewModel.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/trackers/trackerdetails/TrackerDetailsViewModel.kt @@ -108,7 +108,7 @@ class TrackerDetailsViewModel( detectedCount = appsWhitWhiteListState.size, blockedCount = blocked, leakedCount = leaked, - appList = appsWhitWhiteListState, + appList = appsWhitWhiteListState ) } } @@ -118,7 +118,8 @@ class TrackerDetailsViewModel( s.copy( isBlockAllActivated = !trackersStateUseCase.isWhitelisted(tracker), appList = trackerDetailsUseCase.enrichWithBlockedState( - s.appList.map { it.first }, tracker + s.appList.map { it.first }, + tracker ) ) } diff --git a/app/src/main/java/foundation/e/advancedprivacy/widget/Widget.kt b/app/src/main/java/foundation/e/advancedprivacy/widget/Widget.kt index a4272e21..66cf87ea 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/widget/Widget.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/widget/Widget.kt @@ -25,6 +25,7 @@ import foundation.e.advancedprivacy.domain.usecases.GetQuickPrivacyStateUseCase import foundation.e.advancedprivacy.domain.usecases.TrackersStatisticsUseCase import foundation.e.advancedprivacy.widget.State import foundation.e.advancedprivacy.widget.render +import java.time.temporal.ChronoUnit import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers @@ -43,18 +44,13 @@ import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -import java.time.temporal.ChronoUnit /** * Implementation of App Widget functionality. */ class Widget : AppWidgetProvider() { - override fun onUpdate( - context: Context, - appWidgetManager: AppWidgetManager, - appWidgetIds: IntArray - ) { + override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { render(context, state.value, appWidgetManager) } @@ -80,12 +76,11 @@ class Widget : AppWidgetProvider() { trackersStatisticsUseCase: TrackersStatisticsUseCase, coroutineScope: CoroutineScope ): StateFlow { - return combine( getPrivacyStateUseCase.quickPrivacyState, getPrivacyStateUseCase.trackerMode, getPrivacyStateUseCase.isLocationHidden, - getPrivacyStateUseCase.ipScramblingMode, + getPrivacyStateUseCase.ipScramblingMode ) { quickPrivacyState, trackerMode, isLocationHidden, ipScramblingMode -> State( @@ -124,7 +119,7 @@ class Widget : AppWidgetProvider() { fun startListening( appContext: Context, getPrivacyStateUseCase: GetQuickPrivacyStateUseCase, - trackersStatisticsUseCase: TrackersStatisticsUseCase, + trackersStatisticsUseCase: TrackersStatisticsUseCase ) { state = initState( getPrivacyStateUseCase, @@ -141,12 +136,7 @@ class Widget : AppWidgetProvider() { } } - override fun onAppWidgetOptionsChanged( - context: Context, - appWidgetManager: AppWidgetManager, - appWidgetId: Int, - newOptions: Bundle? - ) { + override fun onAppWidgetOptionsChanged(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int, newOptions: Bundle?) { super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions) if (newOptions != null) { isDarkText = newOptions.getBoolean(DARK_TEXT_KEY) diff --git a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetCommandReceiver.kt b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetCommandReceiver.kt index 917cbda3..6fe3ac54 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetCommandReceiver.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetCommandReceiver.kt @@ -28,9 +28,11 @@ class WidgetCommandReceiver : BroadcastReceiver() { val getQuickPrivacyStateUseCase = get(GetQuickPrivacyStateUseCase::class.java) val featureEnabled = intent?.extras?.let { bundle -> - if (bundle.containsKey(PARAM_FEATURE_ENABLED)) + if (bundle.containsKey(PARAM_FEATURE_ENABLED)) { bundle.getBoolean(PARAM_FEATURE_ENABLED) - else null + } else { + null + } } when (intent?.action) { ACTION_TOGGLE_TRACKERS -> getQuickPrivacyStateUseCase.toggleTrackers(featureEnabled) diff --git a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt index e3454b90..5d5a1639 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt @@ -47,14 +47,10 @@ data class State( val isLocationHidden: Boolean = false, val ipScramblingMode: FeatureState = FeatureState.STOPPING, val dayStatistics: List> = emptyList(), - val activeTrackersCount: Int = 0, + val activeTrackersCount: Int = 0 ) -fun render( - context: Context, - state: State, - appWidgetManager: AppWidgetManager, -) { +fun render(context: Context, state: State, appWidgetManager: AppWidgetManager) { val views = RemoteViews(context.packageName, R.layout.widget) applyDarkText(context, state, views) views.apply { @@ -110,8 +106,11 @@ fun render( setImageViewResource( R.id.toggle_location, - if (state.isLocationHidden) R.drawable.ic_switch_enabled - else R.drawable.ic_switch_disabled + if (state.isLocationHidden) { + R.drawable.ic_switch_enabled + } else { + R.drawable.ic_switch_disabled + } ) setOnClickPendingIntent( @@ -130,15 +129,21 @@ fun render( setTextViewText( R.id.state_geolocation, context.getString( - if (state.isLocationHidden) R.string.widget_state_geolocation_on - else R.string.widget_state_geolocation_off + if (state.isLocationHidden) { + R.string.widget_state_geolocation_on + } else { + R.string.widget_state_geolocation_off + } ) ) setImageViewResource( R.id.toggle_ipscrambling, - if (state.ipScramblingMode.isChecked) R.drawable.ic_switch_enabled - else R.drawable.ic_switch_disabled + if (state.ipScramblingMode.isChecked) { + R.drawable.ic_switch_enabled + } else { + R.drawable.ic_switch_disabled + } ) setOnClickPendingIntent( @@ -157,8 +162,11 @@ fun render( setTextViewText( R.id.state_ip_address, context.getString( - if (state.ipScramblingMode == FeatureState.ON) R.string.widget_state_ipaddress_on - else R.string.widget_state_ipaddress_off + if (state.ipScramblingMode == FeatureState.ON) { + R.string.widget_state_ipaddress_on + } else { + R.string.widget_state_ipaddress_off + } ) ) @@ -248,7 +256,7 @@ private val containerBarIds = listOf( R.id.widget_graph_bar_container_20, R.id.widget_graph_bar_container_21, R.id.widget_graph_bar_container_22, - R.id.widget_graph_bar_container_23, + R.id.widget_graph_bar_container_23 ) private val blockedBarIds = listOf( @@ -317,7 +325,7 @@ fun applyDarkText(context: Context, state: State, views: RemoteViews) { listOf( R.id.state_label, R.id.graph_legend_blocked, - R.id.graph_legend_allowed, + R.id.graph_legend_allowed ) .forEach { @@ -371,11 +379,17 @@ fun applyDarkText(context: Context, state: State, views: RemoteViews) { setImageViewResource( R.id.state_icon, if (isDarkText) { - if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_light - else R.drawable.ic_shield_off_light + if (state.quickPrivacyState.isEnabled()) { + R.drawable.ic_shield_on_light + } else { + R.drawable.ic_shield_off_light + } } else { - if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_white - else R.drawable.ic_shield_off_white + if (state.quickPrivacyState.isEnabled()) { + R.drawable.ic_shield_on_white + } else { + R.drawable.ic_shield_off_white + } } ) } diff --git a/app/src/main/res/drawable/bg_tag.xml b/app/src/main/res/drawable/bg_tag.xml index 5243140a..018c0eba 100644 --- a/app/src/main/res/drawable/bg_tag.xml +++ b/app/src/main/res/drawable/bg_tag.xml @@ -1,4 +1,20 @@ + diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index 426be81b..152bb92d 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -1,4 +1,20 @@ + HH:mm MMMM d - EEE diff --git a/build.gradle b/build.gradle index 50427ef2..2397a9e4 100644 --- a/build.gradle +++ b/build.gradle @@ -65,26 +65,22 @@ allprojects { -subprojects { - apply plugin: 'com.diffplug.spotless' - spotless { - kotlin { - target '**/*.kt' - targetExclude("$buildDir/**/*.kt") - targetExclude('bin/**/*.kt') - targetExclude '**/spotless/*.kt' - ktlint("0.40.0") - } - format 'misc', { - // define the files to apply `misc` to - target '*.gradle', '*.md', '.gitignore' +spotless { + kotlin { + target("**/*.kt") + ktlint("1.0.1") + } + format 'misc', { + // define the files to apply `misc` to + target '*.gradle', '*.md', '.gitignore' - // define the steps to apply to those files - trimTrailingWhitespace() - endWithNewline() - } + // define the steps to apply to those files + trimTrailingWhitespace() + endWithNewline() } +} +subprojects { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { // Treat all Kotlin warnings as errors diff --git a/core/src/main/java/foundation/e/advancedprivacy/core/utils/CoroutinesUtils.kt b/core/src/main/java/foundation/e/advancedprivacy/core/utils/CoroutinesUtils.kt index 5344c6a9..cbc77872 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/core/utils/CoroutinesUtils.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/core/utils/CoroutinesUtils.kt @@ -17,10 +17,10 @@ package foundation.e.advancedprivacy.core.utils -import kotlinx.coroutines.CancellationException import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract +import kotlinx.coroutines.CancellationException @OptIn(ExperimentalContracts::class) inline fun runSuspendCatching(block: () -> T): Result { @@ -35,9 +35,7 @@ inline fun runSuspendCatching(block: () -> T): Result { } } -inline fun Result.recoverSuspendCatching( - transform: (exception: Throwable) -> R -): Result { +inline fun Result.recoverSuspendCatching(transform: (exception: Throwable) -> R): Result { return when (val exception = exceptionOrNull()) { null -> this else -> runSuspendCatching { transform(exception) } diff --git a/core/src/main/java/foundation/e/advancedprivacy/core/utils/NotificationsHelper.kt b/core/src/main/java/foundation/e/advancedprivacy/core/utils/NotificationsHelper.kt index 29721b0b..47703ad2 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/core/utils/NotificationsHelper.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/core/utils/NotificationsHelper.kt @@ -20,10 +20,7 @@ import android.content.Context import androidx.core.app.NotificationCompat import foundation.e.advancedprivacy.domain.entities.NotificationContent -fun notificationBuilder( - context: Context, - content: NotificationContent -): NotificationCompat.Builder { +fun notificationBuilder(context: Context, content: NotificationContent): NotificationCompat.Builder { val builder = NotificationCompat.Builder(context, content.channelId) .setSmallIcon(content.icon) .setPriority(NotificationCompat.PRIORITY_LOW) diff --git a/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt b/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt index b44e96ed..6241d874 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt @@ -49,7 +49,9 @@ class AppListsRepository( private const val PNAME_MICROG_SERVICES_CORE = "com.google.android.gms" val compatibiltyPNames = setOf( - PNAME_PWAPLAYER, PNAME_INTENT_VERIFICATION, PNAME_MICROG_SERVICES_CORE + PNAME_PWAPLAYER, + PNAME_INTENT_VERIFICATION, + PNAME_MICROG_SERVICES_CORE ) } @@ -91,10 +93,7 @@ class AppListsRepository( ) } - private fun recycleIcons( - newApps: List, - fetchMissingIcons: Boolean - ): List { + private fun recycleIcons(newApps: List, fetchMissingIcons: Boolean): List { val oldVisibleApps = allProfilesAppDescriptions.value.first return newApps.map { app -> app.copy( @@ -177,7 +176,9 @@ class AppListsRepository( getHiddenSystemApps().any { test(it) } } else if (app == dummyCompatibilityApp) { getCompatibilityApps().any { test(it) } - } else test(app) + } else { + test(app) + } } fun getRealApps(app: ApplicationDescription): List { diff --git a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/AppOpModes.kt b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/AppOpModes.kt index 3e0a2611..66fa2a8c 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/AppOpModes.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/AppOpModes.kt @@ -37,7 +37,7 @@ enum class AppOpModes(val modeValue: Int) { ALLOWED.modeValue to ALLOWED, IGNORED.modeValue to IGNORED, ERRORED.modeValue to ERRORED, - DEFAULT.modeValue to DEFAULT, + DEFAULT.modeValue to DEFAULT ) fun getByModeValue(modeValue: Int): AppOpModes { diff --git a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/ApplicationDescription.kt b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/ApplicationDescription.kt index 90b637f1..8f7b4ef4 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/ApplicationDescription.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/ApplicationDescription.kt @@ -46,5 +46,7 @@ data class ApplicationDescription( } enum class ProfileType { - MAIN, WORK, OTHER + MAIN, + WORK, + OTHER } diff --git a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/FeatureState.kt b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/FeatureState.kt index c756f4af..75b88068 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/FeatureState.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/FeatureState.kt @@ -17,7 +17,10 @@ package foundation.e.advancedprivacy.domain.entities enum class FeatureState { - OFF, ON, STARTING, STOPPING; + OFF, + ON, + STARTING, + STOPPING; val isChecked get() = this == ON || this == STARTING diff --git a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/LocationMode.kt b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/LocationMode.kt index 62581ebc..512080e3 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/LocationMode.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/LocationMode.kt @@ -18,5 +18,7 @@ package foundation.e.advancedprivacy.domain.entities enum class LocationMode { - REAL_LOCATION, RANDOM_LOCATION, SPECIFIC_LOCATION + REAL_LOCATION, + RANDOM_LOCATION, + SPECIFIC_LOCATION } diff --git a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/MainFeatures.kt b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/MainFeatures.kt index 1af2ae03..335565fe 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/domain/entities/MainFeatures.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/domain/entities/MainFeatures.kt @@ -24,8 +24,10 @@ import kotlinx.parcelize.Parcelize sealed class MainFeatures : Parcelable { @Parcelize data class TrackersControl(val startVpnDisclaimer: Intent? = null) : MainFeatures() + @Parcelize object FakeLocation : MainFeatures() + @Parcelize data class IpScrambling(val startVpnDisclaimer: Intent? = null) : MainFeatures() } diff --git a/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/IPermissionsPrivacyModule.kt b/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/IPermissionsPrivacyModule.kt index da11769e..2b6ffcee 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/IPermissionsPrivacyModule.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/IPermissionsPrivacyModule.kt @@ -37,9 +37,7 @@ interface IPermissionsPrivacyModule { profileType: ProfileType = ProfileType.MAIN ): ApplicationDescription - fun getApplications( - filter: ((PackageInfo) -> Boolean)?, - ): List + fun getApplications(filter: ((PackageInfo) -> Boolean)?): List /** * List of permissions names used by an app, specified by its [packageName]. @@ -85,11 +83,7 @@ interface IPermissionsPrivacyModule { * @return true if the permission is or has just been granted, false if * user has to do it himself. */ - fun toggleDangerousPermission( - appDesc: ApplicationDescription, - permissionName: String, - grant: Boolean - ): Boolean + fun toggleDangerousPermission(appDesc: ApplicationDescription, permissionName: String, grant: Boolean): Boolean /** * Change the appOp Mode for the specified appOpPermission and application. @@ -98,11 +92,7 @@ interface IPermissionsPrivacyModule { * @return true if the mode has been changed, false if * user has to do it himself. */ - fun setAppOpMode( - appDesc: ApplicationDescription, - appOpPermissionName: String, - status: AppOpModes - ): Boolean + fun setAppOpMode(appDesc: ApplicationDescription, appOpPermissionName: String, status: AppOpModes): Boolean /** * Return true if the application is flagged Dangerous. diff --git a/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleBase.kt b/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleBase.kt index 27ba17f5..69f5a7a6 100644 --- a/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleBase.kt +++ b/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleBase.kt @@ -83,23 +83,21 @@ abstract class PermissionsPrivacyModuleBase(protected val context: Context) : IP // on google version, work only for the current package. @Suppress("DEPRECATION") - override fun getAppOpMode( - appDesc: ApplicationDescription, - appOpPermissionName: String - ): AppOpModes { - + override fun getAppOpMode(appDesc: ApplicationDescription, appOpPermissionName: String): AppOpModes { val appOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager val mode = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { appOps.checkOpNoThrow( appOpPermissionName, - appDesc.uid, appDesc.packageName + appDesc.uid, + appDesc.packageName ) } else { appOps.unsafeCheckOpNoThrow( appOpPermissionName, - appDesc.uid, appDesc.packageName + appDesc.uid, + appDesc.packageName ) } @@ -130,21 +128,16 @@ abstract class PermissionsPrivacyModuleBase(protected val context: Context) : IP } } - override fun buildApplicationDescription( - appInfo: ApplicationInfo, - profileId: Int, - profileType: ProfileType - ): - ApplicationDescription { - return ApplicationDescription( - packageName = appInfo.packageName, - uid = appInfo.uid, - label = getAppLabel(appInfo), - icon = null, - profileId = profileId, - profileType = profileType, - ) - } + override fun buildApplicationDescription(appInfo: ApplicationInfo, profileId: Int, profileType: ProfileType): ApplicationDescription { + return ApplicationDescription( + packageName = appInfo.packageName, + uid = appInfo.uid, + label = getAppLabel(appInfo), + icon = null, + profileId = profileId, + profileType = profileType + ) + } private fun getAppLabel(appInfo: ApplicationInfo): CharSequence { return context.packageManager.getApplicationLabel(appInfo) diff --git a/fakelocation/fakelocationdemo/src/main/java/foundation/e/privacymodules/fakelocationdemo/MainActivity.kt b/fakelocation/fakelocationdemo/src/main/java/foundation/e/privacymodules/fakelocationdemo/MainActivity.kt index c105ceb0..78543e61 100644 --- a/fakelocation/fakelocationdemo/src/main/java/foundation/e/privacymodules/fakelocationdemo/MainActivity.kt +++ b/fakelocation/fakelocationdemo/src/main/java/foundation/e/privacymodules/fakelocationdemo/MainActivity.kt @@ -163,7 +163,8 @@ class MainActivity : AppCompatActivity() { @Suppress("UNUSED_PARAMETER") fun onClickPermission(view: View?) { val isGranted = permissionsModule.setAppOpMode( - appDesc, AppOpsManager.OPSTR_MOCK_LOCATION, + appDesc, + AppOpsManager.OPSTR_MOCK_LOCATION, AppOpModes.ALLOWED ) 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 6eaae549..f431b05c 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 @@ -64,7 +64,6 @@ class FakeLocationService : Service() { intent?.let { when (it.action?.let { str -> Actions.valueOf(str) }) { Actions.START_FAKE_LOCATION -> { - fakeLocation = Pair( it.getDoubleExtra(PARAM_LATITUDE, 0.0), it.getDoubleExtra(PARAM_LONGITUDE, 0.0) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f15f10dc..001efbec 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -55,4 +55,4 @@ androidx-navigation-safeargs = { id = "androidx.navigation.safeargs.kotlin", ver benmanes-versions = { id = "com.github.ben-manes.versions", version = "0.38.0" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } -spotless = { id = "com.diffplug.spotless", version = "5.12.4" } +spotless = { id = "com.diffplug.spotless", version = "6.23.3" } diff --git a/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotSupervisor.kt b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotSupervisor.kt index 0edc7106..8f8a6be1 100644 --- a/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotSupervisor.kt +++ b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotSupervisor.kt @@ -30,6 +30,8 @@ import android.os.Looper import android.os.Message import foundation.e.advancedprivacy.domain.entities.FeatureState import foundation.e.advancedprivacy.externalinterfaces.servicesupervisors.FeatureSupervisor +import java.security.InvalidParameterException +import java.util.function.Function import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -44,22 +46,27 @@ import org.torproject.android.service.OrbotConstants.ACTION_STOP_FOREGROUND_TASK import org.torproject.android.service.OrbotService import org.torproject.android.service.util.Prefs import timber.log.Timber -import java.security.InvalidParameterException -import java.util.function.Function @SuppressLint("CommitPrefEdits") class OrbotSupervisor( private val context: Context, - private val coroutineScope: CoroutineScope, + private val coroutineScope: CoroutineScope ) : FeatureSupervisor { private val _state = MutableStateFlow(FeatureState.OFF) override val state: StateFlow = _state enum class Status { - OFF, ON, STARTING, STOPPING, START_DISABLED + OFF, + ON, + STARTING, + STOPPING, + START_DISABLED } companion object { - private val EXIT_COUNTRY_CODES = setOf("DE", "AT", "SE", "CH", "IS", "CA", "US", "ES", "FR", "BG", "PL", "AU", "BR", "CZ", "DK", "FI", "GB", "HU", "NL", "JP", "RO", "RU", "SG", "SK") + private val EXIT_COUNTRY_CODES = setOf( + "DE", "AT", "SE", "CH", "IS", "CA", "US", "ES", "FR", "BG", "PL", "AU", + "BR", "CZ", "DK", "FI", "GB", "HU", "NL", "JP", "RO", "RU", "SG", "SK" + ) // Key where exit country is stored by orbot service. private const val PREFS_KEY_EXIT_NODES = "pref_exit_nodes" @@ -191,7 +198,8 @@ class OrbotSupervisor( private fun saveTorifiedApps(packageNames: Collection) { packageNames.joinToString("|") Prefs.getSharedPrefs(context).edit().putString( - OrbotConstants.PREFS_KEY_TORIFIED, packageNames.joinToString("|") + OrbotConstants.PREFS_KEY_TORIFIED, + packageNames.joinToString("|") ).commit() if (isServiceRunning()) { diff --git a/load-properties.gradle b/load-properties.gradle index d9f90342..89092707 100644 --- a/load-properties.gradle +++ b/load-properties.gradle @@ -30,4 +30,4 @@ if (localPropertiesFile.exists()) { } else { ext["MAPBOX_KEY"] = System.getenv('MAPBOX_KEY') ext["SENTRY_DSN"] = System.getenv('SENTRY_DSN') -} \ No newline at end of file +} diff --git a/permissionseos/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleImpl.kt b/permissionseos/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleImpl.kt index 0d32bce6..dc50b478 100644 --- a/permissionseos/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleImpl.kt +++ b/permissionseos/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/PermissionsPrivacyModuleImpl.kt @@ -53,11 +53,7 @@ class PermissionsPrivacyModuleImpl(context: Context) : PermissionsPrivacyModuleB * @see IPermissionsPrivacyModule.toggleDangerousPermission * Always return true, permission is set using privileged capacities. */ - override fun toggleDangerousPermission( - appDesc: ApplicationDescription, - permissionName: String, - grant: Boolean - ): Boolean { + override fun toggleDangerousPermission(appDesc: ApplicationDescription, permissionName: String, grant: Boolean): Boolean { try { if (grant) { context.packageManager.grantRuntimePermission( @@ -80,11 +76,7 @@ class PermissionsPrivacyModuleImpl(context: Context) : PermissionsPrivacyModuleB return true } - override fun setAppOpMode( - appDesc: ApplicationDescription, - appOpPermissionName: String, - status: AppOpModes - ): Boolean { + override fun setAppOpMode(appDesc: ApplicationDescription, appOpPermissionName: String, status: AppOpModes): Boolean { val op = strOpToOp(appOpPermissionName) if (op != OP_NONE) { appOpsManager.setMode(op, appDesc.uid, appDesc.packageName, status.modeValue) @@ -92,9 +84,7 @@ class PermissionsPrivacyModuleImpl(context: Context) : PermissionsPrivacyModuleB return true } - override fun getApplications( - filter: ((PackageInfo) -> Boolean)? - ): List { + override fun getApplications(filter: ((PackageInfo) -> Boolean)?): List { val pm = context.packageManager val mainUserId = UserHandle.myUserId() val workProfileId = getWorkProfile()?.id @@ -123,7 +113,9 @@ class PermissionsPrivacyModuleImpl(context: Context) : PermissionsPrivacyModuleB pm.getUserBadgedIcon(it, workProfile.getUserHandle()) } } - } else getApplicationIcon(app.packageName) + } else { + getApplicationIcon(app.packageName) + } } override fun setBlockable(notificationChannel: NotificationChannel) { diff --git a/permissionsstandalone/src/main/java/foundation/e/advancedprivacy/permissions/externalinterfaces/PermissionsPrivacyModuleImpl.kt b/permissionsstandalone/src/main/java/foundation/e/advancedprivacy/permissions/externalinterfaces/PermissionsPrivacyModuleImpl.kt index d31bdf44..142e34ea 100644 --- a/permissionsstandalone/src/main/java/foundation/e/advancedprivacy/permissions/externalinterfaces/PermissionsPrivacyModuleImpl.kt +++ b/permissionsstandalone/src/main/java/foundation/e/advancedprivacy/permissions/externalinterfaces/PermissionsPrivacyModuleImpl.kt @@ -30,9 +30,7 @@ import foundation.e.advancedprivacy.externalinterfaces.permissions.PermissionsPr * Implements [IPermissionsPrivacyModule] using only API authorized on the PlayStore. */ class PermissionsPrivacyModuleImpl(context: Context) : PermissionsPrivacyModuleBase(context) { - override fun getApplications( - filter: ((PackageInfo) -> Boolean)? - ): List { + override fun getApplications(filter: ((PackageInfo) -> Boolean)?): List { return context.packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS) .filter { filter?.invoke(it) == true } .map { buildApplicationDescription(it.applicationInfo) } @@ -46,17 +44,9 @@ class PermissionsPrivacyModuleImpl(context: Context) : PermissionsPrivacyModuleB * @see IPermissionsPrivacyModule.toggleDangerousPermission * Return an ManualAction to go toggle manually the permission in the ap page of the settings. */ - override fun toggleDangerousPermission( - appDesc: ApplicationDescription, - permissionName: String, - grant: Boolean - ): Boolean = false + override fun toggleDangerousPermission(appDesc: ApplicationDescription, permissionName: String, grant: Boolean): Boolean = false - override fun setAppOpMode( - appDesc: ApplicationDescription, - appOpPermissionName: String, - status: AppOpModes - ): Boolean = false + override fun setAppOpMode(appDesc: ApplicationDescription, appOpPermissionName: String, status: AppOpModes): Boolean = false override fun setVpnPackageAuthorization(packageName: String): Boolean { return false diff --git a/settings.gradle b/settings.gradle index 2ae18aeb..705504d9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -31,4 +31,3 @@ dependencyResolutionManagement { maven { url "https://raw.githubusercontent.com/guardianproject/gpmaven/master" } } } - diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/RemoteTrackersListRepository.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/RemoteTrackersListRepository.kt index 64477b7e..cf142b82 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/RemoteTrackersListRepository.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/RemoteTrackersListRepository.kt @@ -17,14 +17,14 @@ package foundation.e.advancedprivacy.data.repositories -import retrofit2.Retrofit -import retrofit2.converter.scalars.ScalarsConverterFactory -import retrofit2.http.GET -import timber.log.Timber import java.io.File import java.io.FileWriter import java.io.IOException import java.io.PrintWriter +import retrofit2.Retrofit +import retrofit2.converter.scalars.ScalarsConverterFactory +import retrofit2.http.GET +import timber.log.Timber class RemoteTrackersListRepository { diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/StatsDatabase.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/StatsDatabase.kt index dc726db3..238de4e6 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/StatsDatabase.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/StatsDatabase.kt @@ -32,17 +32,17 @@ import foundation.e.advancedprivacy.trackers.data.StatsDatabase.AppTrackerEntry. import foundation.e.advancedprivacy.trackers.data.StatsDatabase.AppTrackerEntry.COLUMN_NAME_TRACKER import foundation.e.advancedprivacy.trackers.data.StatsDatabase.AppTrackerEntry.TABLE_NAME import foundation.e.advancedprivacy.trackers.domain.entities.Tracker -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.SharedFlow -import kotlinx.coroutines.withContext -import timber.log.Timber import java.time.Instant import java.time.ZonedDateTime import java.time.format.DateTimeFormatter import java.time.temporal.ChronoUnit import java.time.temporal.TemporalUnit import java.util.concurrent.TimeUnit +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.withContext +import timber.log.Timber class StatsDatabase( context: Context, @@ -110,11 +110,7 @@ class StatsDatabase( } } - private fun getCallsByPeriod( - periodsCount: Int, - periodUnit: TemporalUnit, - sqlitePeriodFormat: String - ): Map> { + private fun getCallsByPeriod(periodsCount: Int, periodUnit: TemporalUnit, sqlitePeriodFormat: String): Map> { synchronized(lock) { val minTimestamp = getPeriodStartTs(periodsCount, periodUnit) val db = readableDatabase @@ -163,10 +159,7 @@ class StatsDatabase( return calls } - fun getTrackersCallsOnPeriod( - periodsCount: Int, - periodUnit: TemporalUnit - ): List> { + fun getTrackersCallsOnPeriod(periodsCount: Int, periodUnit: TemporalUnit): List> { var sqlitePeriodFormat = "%Y%m" var javaPeriodFormat = "yyyyMM" if (periodUnit === ChronoUnit.MONTHS) { @@ -462,19 +455,27 @@ class StatsDatabase( if (cursor.count > 0) { cursor.moveToFirst() val entry = cursorToEntry(cursor) - if (blocked) values.put( - COLUMN_NAME_NUMBER_BLOCKED, - entry.sum_blocked + 1 - ) else values.put(COLUMN_NAME_NUMBER_BLOCKED, entry.sum_blocked) + if (blocked) { + values.put( + COLUMN_NAME_NUMBER_BLOCKED, + entry.sum_blocked + 1 + ) + } else { + values.put(COLUMN_NAME_NUMBER_BLOCKED, entry.sum_blocked) + } values.put(COLUMN_NAME_NUMBER_CONTACTED, entry.sum_contacted + 1) db.update(TABLE_NAME, values, selection, selectionArg) // db.execSQL(query, new String[]{""+hour, ""+day, ""+month, ""+year, ""+appUid, ""+trackerId}); } else { - if (blocked) values.put( - COLUMN_NAME_NUMBER_BLOCKED, - 1 - ) else values.put(COLUMN_NAME_NUMBER_BLOCKED, 0) + if (blocked) { + values.put( + COLUMN_NAME_NUMBER_BLOCKED, + 1 + ) + } else { + values.put(COLUMN_NAME_NUMBER_BLOCKED, 0) + } values.put(COLUMN_NAME_NUMBER_CONTACTED, 1) db.insert(TABLE_NAME, null, values) } @@ -578,10 +579,7 @@ class StatsDatabase( return System.currentTimeMillis() / hourInMs * hourInS } - private fun getPeriodStartTs( - periodsCount: Int, - periodUnit: TemporalUnit - ): Long { + private fun getPeriodStartTs(periodsCount: Int, periodUnit: TemporalUnit): Long { var start = ZonedDateTime.now() .minus(periodsCount.toLong(), periodUnit) .plus(1, periodUnit) @@ -607,6 +605,8 @@ class StatsDatabase( val columnIndex = getColumnIndex(columnName) return if (columnIndex >= 0) { getStringOrNull(columnIndex) ?: "" - } else "" + } else { + "" + } } } diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/TrackersRepository.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/TrackersRepository.kt index fc57a8ef..bc6a6267 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/TrackersRepository.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/TrackersRepository.kt @@ -20,13 +20,13 @@ package foundation.e.advancedprivacy.trackers.data import android.content.Context import com.google.gson.Gson import foundation.e.advancedprivacy.trackers.domain.entities.Tracker +import java.io.File +import java.io.FileInputStream +import java.io.InputStreamReader import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import timber.log.Timber -import java.io.File -import java.io.FileInputStream -import java.io.InputStreamReader class TrackersRepository( private val context: Context, diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/WhitelistRepository.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/WhitelistRepository.kt index 76116b14..618c4113 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/WhitelistRepository.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/data/WhitelistRepository.kt @@ -23,10 +23,10 @@ import android.content.SharedPreferences import foundation.e.advancedprivacy.data.repositories.AppListsRepository import foundation.e.advancedprivacy.domain.entities.ApplicationDescription import foundation.e.advancedprivacy.trackers.domain.entities.Tracker +import java.io.File import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext -import java.io.File class WhitelistRepository( context: Context, @@ -87,7 +87,9 @@ class WhitelistRepository( try { val uid = it.toInt() appListsRepository.getApp(uid)?.apId - } catch (e: Exception) { null } + } catch (e: Exception) { + null + } }?.toSet() ?: HashSet() editorV2.putStringSet(KEY_APPS_WHITELIST, apIds) diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/externalinterfaces/TrackersSupervisor.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/externalinterfaces/TrackersSupervisor.kt index a0c7935f..ca4e1eb1 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/externalinterfaces/TrackersSupervisor.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/externalinterfaces/TrackersSupervisor.kt @@ -17,8 +17,8 @@ package foundation.e.advancedprivacy.trackers.domain.externalinterfaces import foundation.e.advancedprivacy.externalinterfaces.servicesupervisors.FeatureSupervisor -import org.pcap4j.packet.DnsPacket import java.util.function.Function +import org.pcap4j.packet.DnsPacket interface TrackersSupervisor : FeatureSupervisor { fun isRunning(): Boolean diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/FilterHostnameUseCase.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/FilterHostnameUseCase.kt index e0fae43f..f8c351c7 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/FilterHostnameUseCase.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/FilterHostnameUseCase.kt @@ -24,13 +24,13 @@ import foundation.e.advancedprivacy.domain.entities.ApplicationDescription import foundation.e.advancedprivacy.trackers.data.StatsDatabase import foundation.e.advancedprivacy.trackers.data.TrackersRepository import foundation.e.advancedprivacy.trackers.data.WhitelistRepository +import java.util.concurrent.LinkedBlockingQueue import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import timber.log.Timber -import java.util.concurrent.LinkedBlockingQueue class FilterHostnameUseCase( private val trackersRepository: TrackersRepository, @@ -38,7 +38,7 @@ class FilterHostnameUseCase( context: Context, private val appDesc: ApplicationDescription, private val database: StatsDatabase, - private val appListsRepository: AppListsRepository, + private val appListsRepository: AppListsRepository ) { private var eBrowserAppUid = -1 diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/StatisticsUseCase.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/StatisticsUseCase.kt index 22bd8fce..d629b801 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/StatisticsUseCase.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/StatisticsUseCase.kt @@ -28,10 +28,7 @@ class StatisticsUseCase( private val database: StatsDatabase, private val appListsRepository: AppListsRepository ) { - fun getTrackersCallsOnPeriod( - periodsCount: Int, - periodUnit: TemporalUnit - ): List> { + fun getTrackersCallsOnPeriod(periodsCount: Int, periodUnit: TemporalUnit): List> { return database.getTrackersCallsOnPeriod(periodsCount, periodUnit) } diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/UpdateTrackerListUseCase.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/UpdateTrackerListUseCase.kt index fa60431c..2645e60d 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/UpdateTrackerListUseCase.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/domain/usecases/UpdateTrackerListUseCase.kt @@ -27,7 +27,7 @@ import timber.log.Timber class UpdateTrackerListUseCase( private val remoteTrackersListRepository: RemoteTrackersListRepository, private val trackersRepository: TrackersRepository, - private val coroutineScope: CoroutineScope, + private val coroutineScope: CoroutineScope ) { fun updateTrackers() = coroutineScope.launch { diff --git a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/services/UpdateTrackersWorker.kt b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/services/UpdateTrackersWorker.kt index 50aa082d..6b3d5d64 100644 --- a/trackers/src/main/java/foundation/e/advancedprivacy/trackers/services/UpdateTrackersWorker.kt +++ b/trackers/src/main/java/foundation/e/advancedprivacy/trackers/services/UpdateTrackersWorker.kt @@ -26,8 +26,8 @@ import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager import androidx.work.WorkerParameters import foundation.e.advancedprivacy.trackers.domain.usecases.UpdateTrackerListUseCase -import org.koin.java.KoinJavaComponent.get import java.util.concurrent.TimeUnit +import org.koin.java.KoinJavaComponent.get class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters) : CoroutineWorker(appContext, workerParams) { @@ -46,7 +46,8 @@ class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters) fun periodicUpdate(context: Context) { val request = PeriodicWorkRequestBuilder( - 7, TimeUnit.DAYS + 7, + TimeUnit.DAYS ) .setConstraints(constraints).build() diff --git a/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/DNSBlocker.kt b/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/DNSBlocker.kt index 6a2b2189..2da4fdb2 100644 --- a/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/DNSBlocker.kt +++ b/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/DNSBlocker.kt @@ -24,6 +24,9 @@ import android.system.Os import android.system.OsConstants import foundation.e.advancedprivacy.core.utils.runSuspendCatching import foundation.e.advancedprivacy.trackers.domain.usecases.FilterHostnameUseCase +import java.io.BufferedReader +import java.io.InputStreamReader +import java.io.PrintWriter import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -31,9 +34,6 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import timber.log.Timber -import java.io.BufferedReader -import java.io.InputStreamReader -import java.io.PrintWriter class DNSBlocker( val filterHostnameUseCase: FilterHostnameUseCase diff --git a/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorEos.kt b/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorEos.kt index 71a4fc4d..4580389a 100644 --- a/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorEos.kt +++ b/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorEos.kt @@ -64,7 +64,7 @@ val trackerServiceModule = module { trackersSupervisor = get(), appDesc = get(named("AdvancedPrivacy")), permissionsPrivacyModule = get(), - scope = get(), + scope = get() ) } } diff --git a/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/VpnSupervisorUseCaseEos.kt b/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/VpnSupervisorUseCaseEos.kt index 976a2b71..1aa7d47a 100644 --- a/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/VpnSupervisorUseCaseEos.kt +++ b/trackersserviceeos/src/main/java/foundation/e/advancedprivacy/trackers/service/VpnSupervisorUseCaseEos.kt @@ -38,7 +38,7 @@ class VpnSupervisorUseCaseEos( private val trackersSupervisor: TrackersSupervisor, private val appDesc: ApplicationDescription, private val permissionsPrivacyModule: IPermissionsPrivacyModule, - private val scope: CoroutineScope, + private val scope: CoroutineScope ) : VpnSupervisorUseCase { override fun listenSettings() { diff --git a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/Config.kt b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/Config.kt index d079e22e..9420e0e9 100644 --- a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/Config.kt +++ b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/Config.kt @@ -36,9 +36,12 @@ internal object Config { const val MAX_RESOLVER_COUNT = 100 val DNS_SERVER_TO_CATCH_IPV4 = listOf( - "8.8.8.8", "8.8.4.4", "1.1.1.1" + "8.8.8.8", + "8.8.4.4", + "1.1.1.1" ) val DNS_SERVER_TO_CATCH_IPV6 = listOf( - "2001:4860:4860::8888", "2001:4860:4860::8844" + "2001:4860:4860::8888", + "2001:4860:4860::8844" ) } diff --git a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorStandalone.kt b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorStandalone.kt index ac06ced4..6b7dc0c9 100644 --- a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorStandalone.kt +++ b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TrackersSupervisorStandalone.kt @@ -25,6 +25,7 @@ import foundation.e.advancedprivacy.trackers.service.data.NetworkDNSAddressRepos import foundation.e.advancedprivacy.trackers.service.data.RequestDNSRepository import foundation.e.advancedprivacy.trackers.service.usecases.ResolveDNSUseCase import foundation.e.advancedprivacy.trackers.service.usecases.VpnSupervisorUseCaseStandalone +import java.util.function.Function import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -32,7 +33,6 @@ import org.koin.core.module.dsl.bind import org.koin.core.module.dsl.singleOf import org.koin.dsl.module import org.pcap4j.packet.DnsPacket -import java.util.function.Function class TrackersSupervisorStandalone( private val context: Context, @@ -47,7 +47,9 @@ class TrackersSupervisorStandalone( val intent = Intent(context, TrackersService::class.java) context.startService(intent) true - } else false + } else { + false + } } override fun stop(): Boolean { diff --git a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TunLooper.kt b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TunLooper.kt index bb349ebe..97bef835 100644 --- a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TunLooper.kt +++ b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/TunLooper.kt @@ -18,6 +18,12 @@ package foundation.e.advancedprivacy.trackers.service import android.os.ParcelFileDescriptor import foundation.e.advancedprivacy.trackers.service.usecases.ResolveDNSUseCase +import java.io.DataOutputStream +import java.io.FileInputStream +import java.io.FileOutputStream +import java.io.IOException +import java.net.Inet6Address +import java.util.Arrays import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -33,15 +39,9 @@ import org.pcap4j.packet.UdpPacket import org.pcap4j.packet.namednumber.IpNumber import org.pcap4j.packet.namednumber.UdpPort import timber.log.Timber -import java.io.DataOutputStream -import java.io.FileInputStream -import java.io.FileOutputStream -import java.io.IOException -import java.net.Inet6Address -import java.util.Arrays class TunLooper( - private val resolveDNSUseCase: ResolveDNSUseCase, + private val resolveDNSUseCase: ResolveDNSUseCase ) { private var vpnInterface: ParcelFileDescriptor? = null private var fileInputStream: FileInputStream? = null @@ -58,10 +58,7 @@ class TunLooper( vpnInterface = null } - fun listenJob( - vpnInterface: ParcelFileDescriptor, - scope: CoroutineScope - ): Job = scope.launch(Dispatchers.IO) { + fun listenJob(vpnInterface: ParcelFileDescriptor, scope: CoroutineScope): Job = scope.launch(Dispatchers.IO) { this@TunLooper.vpnInterface = vpnInterface val fis = FileInputStream(vpnInterface.fileDescriptor) this@TunLooper.fileInputStream = fis @@ -151,7 +148,9 @@ class TunLooper( .dstAddr(ipPacket.getHeader().getSrcAddr() as Inet6Address) .payloadBuilder(udpBuilder) .build() - } else null + } else { + null + } respPacket?.let { try { diff --git a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/data/RequestDNSRepository.kt b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/data/RequestDNSRepository.kt index d9370be5..05fff3c9 100644 --- a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/data/RequestDNSRepository.kt +++ b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/data/RequestDNSRepository.kt @@ -17,12 +17,12 @@ package foundation.e.advancedprivacy.trackers.service.data import foundation.e.advancedprivacy.core.utils.runSuspendCatching +import java.net.DatagramPacket +import java.net.DatagramSocket import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.pcap4j.packet.DnsPacket import timber.log.Timber -import java.net.DatagramPacket -import java.net.DatagramSocket class RequestDNSRepository { diff --git a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/ResolveDNSUseCase.kt b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/ResolveDNSUseCase.kt index b74b9cb0..c0938e05 100644 --- a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/ResolveDNSUseCase.kt +++ b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/ResolveDNSUseCase.kt @@ -20,13 +20,13 @@ import foundation.e.advancedprivacy.core.utils.runSuspendCatching import foundation.e.advancedprivacy.trackers.domain.usecases.FilterHostnameUseCase import foundation.e.advancedprivacy.trackers.service.data.NetworkDNSAddressRepository import foundation.e.advancedprivacy.trackers.service.data.RequestDNSRepository +import java.net.DatagramPacket import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import org.pcap4j.packet.DnsPacket import org.pcap4j.packet.namednumber.DnsRCode import timber.log.Timber -import java.net.DatagramPacket @OptIn(DelicateCoroutinesApi::class) class ResolveDNSUseCase( @@ -50,7 +50,9 @@ class ResolveDNSUseCase( dnsRequest.builder .rCode(DnsRCode.NX_DOMAIN) .response(true).build() - } else null + } else { + null + } }.onFailure { Timber.e(it, "Can't find host") }.getOrNull() diff --git a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/VpnSupervisorUseCaseStandalone.kt b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/VpnSupervisorUseCaseStandalone.kt index 683f886d..d7bba5ee 100644 --- a/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/VpnSupervisorUseCaseStandalone.kt +++ b/trackersservicestandalone/src/main/java/foundation/e/advancedprivacy/trackers/service/usecases/VpnSupervisorUseCaseStandalone.kt @@ -36,7 +36,7 @@ class VpnSupervisorUseCaseStandalone( private val localStateRepository: LocalStateRepository, private val trackersSupervisor: TrackersSupervisor, private val orbotSupervisor: OrbotSupervisor, - private val scope: CoroutineScope, + private val scope: CoroutineScope ) : VpnSupervisorUseCase { private var applySettingJob: Job? = null -- GitLab From b0de73aec9d2e55bce09877b84e243c64d1b3792 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Wed, 3 Jan 2024 18:36:13 +0100 Subject: [PATCH 2/2] chore: Add detekt code quality tool. --- .gitlab-ci.yml | 5 +++++ build.gradle | 19 +++++++++++++++++++ detekt.yml | 22 ++++++++++++++++++++++ gradle/libs.versions.toml | 2 ++ 4 files changed, 48 insertions(+) create mode 100644 detekt.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aa2dc510..5264174d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,11 +24,16 @@ lint: stage: lint script: - ./gradlew spotlessCheck + - ./gradlew detekt rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" when: on_success - if: $CI_COMMIT_BRANCH == "main" when: on_success + artifacts: + paths: + - build/reports/detekt/ + # No unit tests yet. #unit-test: diff --git a/build.gradle b/build.gradle index 2397a9e4..0c8404e7 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,7 @@ buildscript { plugins { alias libs.plugins.spotless + alias libs.plugins.detekt alias libs.plugins.benmanes.versions alias libs.plugins.kotlin.android apply false alias libs.plugins.android.application apply false @@ -90,6 +91,24 @@ subprojects { jvmTarget = "17" } } + + detekt { + toolVersion = libs.versions.detekt + + source = files( + "src/main/java" + ) + + config.setFrom("detekt.yml") + baseline = file("detekt-baseline.xml") + parallel = false + buildUponDefaultConfig = true + allRules = false + disableDefaultRuleSets = false + debug = false + ignoreFailures = false + basePath = projectDir + } } Object propOrDef(String propertyName, Object defaultValue) { diff --git a/detekt.yml b/detekt.yml new file mode 100644 index 00000000..4efb8651 --- /dev/null +++ b/detekt.yml @@ -0,0 +1,22 @@ +# Naming rules +naming: + + ConstructorParameterNaming: + active: false + + VariableNaming: + active: false + + +# Style rules +style: + + ForbiddenComment: + active: false + + +# Complexity rules +complexity: + + TooManyFunctions: + ignorePrivate: true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 001efbec..24bcc501 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,6 @@ [versions] agp = "8.2.0" +detekt = "1.23.1" koin = "3.4.3" kotlinx-coroutines = "1.7.3" kotlin = "1.9.21" @@ -53,6 +54,7 @@ android-application = { id = "com.android.application", version.ref = "agp" } android-library = { id = "com.android.library", version.ref = "agp" } androidx-navigation-safeargs = { id = "androidx.navigation.safeargs.kotlin", version.ref = "androidx-navigation" } benmanes-versions = { id = "com.github.ben-manes.versions", version = "0.38.0" } +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } spotless = { id = "com.diffplug.spotless", version = "6.23.3" } -- GitLab