From a0fdd6ddc3a40ed856e1b647b644d037eb30152a Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 18 Apr 2021 03:52:41 +0530 Subject: app: configure Hilt and desugaring Signed-off-by: Harsh Shandilya --- app/build.gradle.kts | 6 ++++++ app/src/main/java/dev/msfjarvis/aps/Application.kt | 2 ++ .../aps/injection/password/PasswordModule.kt | 15 +++++++++++++++ .../dev/msfjarvis/aps/injection/totp/TotpModule.kt | 19 +++++++++++++++++++ .../java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt | 3 ++- 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/dev/msfjarvis/aps/injection/password/PasswordModule.kt create mode 100644 app/src/main/java/dev/msfjarvis/aps/injection/totp/TotpModule.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5901b7f3..41c561f4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -7,6 +7,8 @@ import com.android.build.gradle.internal.api.BaseVariantOutputImpl plugins { id("com.android.application") kotlin("android") + kotlin("kapt") + id("dagger.hilt.android.plugin") `versioning-plugin` `aps-plugin` `crowdin-plugin` @@ -22,6 +24,7 @@ android { } } } + compileOptions { isCoreLibraryDesugaringEnabled = true } defaultConfig { applicationId = "dev.msfjarvis.aps" @@ -42,7 +45,9 @@ android { } dependencies { + kapt(libs.dagger.hilt.compiler) compileOnly(libs.androidx.annotation) + coreLibraryDesugaring(libs.android.desugarJdkLibs) implementation(projects.autofillParser) implementation(projects.openpgpKtx) implementation(libs.androidx.activityKtx) @@ -60,6 +65,7 @@ dependencies { implementation(libs.androidx.recyclerviewSelection) implementation(libs.androidx.security) implementation(libs.androidx.swiperefreshlayout) + implementation(libs.dagger.hilt.android) implementation(libs.kotlin.coroutines.android) implementation(libs.kotlin.coroutines.core) diff --git a/app/src/main/java/dev/msfjarvis/aps/Application.kt b/app/src/main/java/dev/msfjarvis/aps/Application.kt index d7d4c7a7..013b6b21 100644 --- a/app/src/main/java/dev/msfjarvis/aps/Application.kt +++ b/app/src/main/java/dev/msfjarvis/aps/Application.kt @@ -12,6 +12,7 @@ import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES import com.github.ajalt.timberkt.Timber.DebugTree import com.github.ajalt.timberkt.Timber.plant +import dagger.hilt.android.HiltAndroidApp import dev.msfjarvis.aps.util.extensions.getString import dev.msfjarvis.aps.util.extensions.sharedPrefs import dev.msfjarvis.aps.util.git.sshj.setUpBouncyCastleForSshj @@ -20,6 +21,7 @@ import dev.msfjarvis.aps.util.settings.PreferenceKeys import dev.msfjarvis.aps.util.settings.runMigrations @Suppress("Unused") +@HiltAndroidApp class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener { private val prefs by lazy { sharedPrefs } diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/password/PasswordModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/password/PasswordModule.kt new file mode 100644 index 00000000..dd795d14 --- /dev/null +++ b/app/src/main/java/dev/msfjarvis/aps/injection/password/PasswordModule.kt @@ -0,0 +1,15 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.injection.password + +import dagger.assisted.AssistedFactory +import dev.msfjarvis.aps.data.passfile.PasswordEntry +import kotlinx.coroutines.CoroutineScope + +@AssistedFactory +interface PasswordEntryFactory { + fun create(scope: CoroutineScope, bytes: ByteArray): PasswordEntry +} diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/totp/TotpModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/totp/TotpModule.kt new file mode 100644 index 00000000..e02a3b86 --- /dev/null +++ b/app/src/main/java/dev/msfjarvis/aps/injection/totp/TotpModule.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.injection.totp + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ActivityComponent +import dev.msfjarvis.aps.util.totp.TotpFinder +import dev.msfjarvis.aps.util.totp.UriTotpFinder + +@Module +@InstallIn(ActivityComponent::class) +interface TotpModule { + @Binds abstract fun bindTotpFinder(totpFinder: UriTotpFinder): TotpFinder +} diff --git a/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt b/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt index fa3ff28a..2e954804 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/totp/UriTotpFinder.kt @@ -6,9 +6,10 @@ package dev.msfjarvis.aps.util.totp import android.net.Uri +import javax.inject.Inject /** [Uri] backed TOTP URL parser. */ -class UriTotpFinder : TotpFinder { +class UriTotpFinder @Inject constructor() : TotpFinder { override fun findSecret(content: String): String? { content.split("\n".toRegex()).forEach { line -> -- cgit v1.2.3