diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-06-12 14:58:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-12 20:28:15 +0530 |
| commit | d8231e112afb501c43041a6f839ab8285f400f77 (patch) | |
| tree | 6785a8d0c6a70a3017ce5d62fe6b8234d5564f07 /app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt | |
| parent | bf33fb2c88a208931340201e95a524b274d70b31 (diff) | |
| download | HardenedPass-d8231e112afb501c43041a6f839ab8285f400f77.tar.gz HardenedPass-d8231e112afb501c43041a6f839ab8285f400f77.zip | |
Break down PGP Activity into focused sections (#776)
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt b/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt index 5349d6c3..ceb84020 100644 --- a/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt +++ b/app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt @@ -8,17 +8,16 @@ import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.app.Service -import android.content.ClipboardManager +import android.content.ClipData import android.content.Intent import android.content.SharedPreferences import android.os.Build import android.os.IBinder import androidx.core.app.NotificationCompat import androidx.core.content.getSystemService -import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.preference.PreferenceManager import com.github.ajalt.timberkt.d -import com.zeapo.pwdstore.utils.ClipboardUtils +import com.zeapo.pwdstore.utils.clipboard import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -60,7 +59,6 @@ class ClipboardService : Service() { startTimer(time) } withContext(Dispatchers.Main) { - emitBroadcast() clearClipboard() stopForeground(true) stopSelf() @@ -85,11 +83,21 @@ class ClipboardService : Service() { private fun clearClipboard() { val deepClear = settings.getBoolean("clear_clipboard_20x", false) - val clipboardManager = getSystemService<ClipboardManager>() + val clipboard = clipboard - if (clipboardManager is ClipboardManager) { + if (clipboard != null) { scope.launch { - ClipboardUtils.clearClipboard(clipboardManager, deepClear) + d { "Clearing the clipboard" } + val clip = ClipData.newPlainText("pgp_handler_result_pm", "") + clipboard.setPrimaryClip(clip) + if (deepClear) { + withContext(Dispatchers.IO) { + repeat(20) { + val count = (it * 500).toString() + clipboard.setPrimaryClip(ClipData.newPlainText(count, count)) + } + } + } } } else { d { "Cannot get clipboard manager service" } @@ -105,12 +113,6 @@ class ClipboardService : Service() { } } - private fun emitBroadcast() { - val localBroadcastManager = LocalBroadcastManager.getInstance(this) - val clearIntent = Intent(ACTION_CLEAR) - localBroadcastManager.sendBroadcast(clearIntent) - } - private fun createNotification() { createNotificationChannel() val clearIntent = Intent(this, ClipboardService::class.java) @@ -151,7 +153,7 @@ class ClipboardService : Service() { companion object { private const val ACTION_CLEAR = "ACTION_CLEAR_CLIPBOARD" - private const val ACTION_START = "ACTION_START_CLIPBOARD_TIMER" + const val ACTION_START = "ACTION_START_CLIPBOARD_TIMER" private const val CHANNEL_ID = "NotificationService" } } |
