mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +03:00
BIT-1283 Clear the clipboard after the settings interval (#891)
This commit is contained in:
parent
fc3cdeb798
commit
24806c4920
6 changed files with 57 additions and 1 deletions
|
@ -97,6 +97,11 @@ The following is a list of all third-party dependencies included as part of the
|
|||
- Purpose: Safely manage keys and encrypt files and sharedpreferences.
|
||||
- License: Apache 2.0
|
||||
|
||||
- **AndroidX WorkManager**
|
||||
- https://developer.android.com/jetpack/androidx/releases/work
|
||||
- Purpose: The WorkManager is used to schedule deferrable, asynchronous tasks that must be run reliably.
|
||||
- License: Apache 2.0
|
||||
|
||||
- **Core SplashScreen**
|
||||
- https://developer.android.com/jetpack/androidx/releases/core
|
||||
- Purpose: Backwards compatible SplashScreen API implementation.
|
||||
|
|
|
@ -173,6 +173,7 @@ dependencies {
|
|||
implementation(libs.androidx.room.runtime)
|
||||
implementation(libs.androidx.security.crypto)
|
||||
implementation(libs.androidx.splashscreen)
|
||||
implementation(libs.androidx.work.runtime.ktx)
|
||||
implementation(libs.bitwarden.sdk)
|
||||
implementation(libs.bumptech.glide)
|
||||
implementation(libs.google.hilt.android)
|
||||
|
|
|
@ -8,10 +8,15 @@ import android.widget.Toast
|
|||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.os.persistableBundleOf
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkManager
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
||||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.toAnnotatedString
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Default implementation of the [BitwardenClipboardManager] interface.
|
||||
|
@ -19,9 +24,13 @@ import com.x8bit.bitwarden.ui.platform.base.util.toAnnotatedString
|
|||
@OmitFromCoverage
|
||||
class BitwardenClipboardManagerImpl(
|
||||
private val context: Context,
|
||||
private val settingsRepository: SettingsRepository,
|
||||
) : BitwardenClipboardManager {
|
||||
private val clipboardManager: ClipboardManager = requireNotNull(context.getSystemService())
|
||||
|
||||
private val clearClipboardFrequencySeconds: Int?
|
||||
get() = settingsRepository.clearClipboardFrequency.frequencySeconds
|
||||
|
||||
override fun setText(
|
||||
text: AnnotatedString,
|
||||
isSensitive: Boolean,
|
||||
|
@ -46,6 +55,19 @@ class BitwardenClipboardManagerImpl(
|
|||
)
|
||||
.show()
|
||||
}
|
||||
|
||||
val frequency = clearClipboardFrequencySeconds ?: return
|
||||
val clearClipboardRequest: OneTimeWorkRequest =
|
||||
OneTimeWorkRequest
|
||||
.Builder(ClearClipboardWorker::class.java)
|
||||
.setInitialDelay(frequency.toLong(), TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance(context).enqueueUniqueWork(
|
||||
"ClearClipboard",
|
||||
ExistingWorkPolicy.REPLACE,
|
||||
clearClipboardRequest,
|
||||
)
|
||||
}
|
||||
|
||||
override fun setText(text: String, isSensitive: Boolean, toastDescriptorOverride: String?) {
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.x8bit.bitwarden.data.platform.manager.clipboard
|
||||
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Context.CLIPBOARD_SERVICE
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
|
||||
/**
|
||||
* A worker to clear the clipboard manager.
|
||||
*/
|
||||
class ClearClipboardWorker(appContext: Context, workerParams: WorkerParameters) :
|
||||
Worker(appContext, workerParams) {
|
||||
|
||||
private val clipboardManager =
|
||||
appContext.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
|
||||
|
||||
override fun doWork(): Result {
|
||||
clipboardManager.clearPrimaryClip()
|
||||
return Result.success()
|
||||
}
|
||||
}
|
|
@ -83,7 +83,11 @@ object PlatformManagerModule {
|
|||
@Singleton
|
||||
fun provideBitwardenClipboardManager(
|
||||
@ApplicationContext context: Context,
|
||||
): BitwardenClipboardManager = BitwardenClipboardManagerImpl(context)
|
||||
settingsRepository: SettingsRepository,
|
||||
): BitwardenClipboardManager = BitwardenClipboardManagerImpl(
|
||||
context,
|
||||
settingsRepository,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
|
|
@ -26,6 +26,7 @@ androidXSecurityCrypto = "1.1.0-alpha06"
|
|||
androidxSplash = "1.1.0-alpha02"
|
||||
androidXAppCompat = "1.6.1"
|
||||
androdixAutofill = "1.1.0"
|
||||
androidxWork = "2.9.0"
|
||||
bitwardenSdk = "0.4.0-20240131.132449-88"
|
||||
crashlytics = "2.9.9"
|
||||
detekt = "1.23.1"
|
||||
|
@ -82,6 +83,7 @@ androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "androidx
|
|||
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidxRoom" }
|
||||
androidx-security-crypto = { module = "androidx.security:security-crypto", version.ref = "androidXSecurityCrypto" }
|
||||
androidx-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "androidxSplash" }
|
||||
androidx-work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "androidxWork" }
|
||||
bitwarden-sdk = { module = "com.bitwarden:sdk-android", version.ref = "bitwardenSdk" }
|
||||
bumptech-glide = { module = "com.github.bumptech.glide:compose", version.ref = "glide" }
|
||||
detekt-detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
|
||||
|
|
Loading…
Reference in a new issue