diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-03-05 21:05:50 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-05 21:05:50 +0530 |
| commit | 73058d10a8e28fe4e7636ad5c73eeb8651369cdb (patch) | |
| tree | f5d15b6dc45eb3d2ac5f2e33a5e4362e4b84285d /app/src/main/java/com/zeapo/pwdstore/utils | |
| parent | addefdc9a3eac4124d304ee4f810daaeed419996 (diff) | |
| download | HardenedPass-73058d10a8e28fe4e7636ad5c73eeb8651369cdb.tar.gz HardenedPass-73058d10a8e28fe4e7636ad5c73eeb8651369cdb.zip | |
Resolve various memory leaks (#637)
This migrates the clipboard clear logic into a foreground service that allows us to also provide a notification that runs the clear task immediately on click, rather than wait for the timeout.
Co-authored-by: Aditya Wasan <adityawasan55@gmail.com>
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/ClipboardUtils.kt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/ClipboardUtils.kt b/app/src/main/java/com/zeapo/pwdstore/utils/ClipboardUtils.kt new file mode 100644 index 00000000..d173a519 --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/utils/ClipboardUtils.kt @@ -0,0 +1,28 @@ +/* + * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ +package com.zeapo.pwdstore.utils + +import android.content.ClipData +import android.content.ClipboardManager +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import timber.log.Timber + +object ClipboardUtils { + + suspend fun clearClipboard(clipboard: ClipboardManager, deepClear: Boolean = false) { + Timber.d("Clearing the clipboard") + val clip = ClipData.newPlainText("pgp_handler_result_pm", "") + clipboard.primaryClip = clip + if (deepClear) { + withContext(Dispatchers.IO) { + repeat(20) { + val count = (it * 500).toString() + clipboard.primaryClip = ClipData.newPlainText(count, count) + } + } + } + } +} |
