treewide: switch to logging via timberkt

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-04-21 13:30:42 +05:30
parent 72166c6912
commit 500ab60973
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
11 changed files with 70 additions and 56 deletions

View file

@ -11,8 +11,9 @@ import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.github.ajalt.timberkt.Timber.DebugTree
import com.github.ajalt.timberkt.Timber.plant
import com.haroldadmin.whatthestack.WhatTheStack import com.haroldadmin.whatthestack.WhatTheStack
import timber.log.Timber
@Suppress("Unused") @Suppress("Unused")
class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener { class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener {
@ -20,7 +21,7 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
Timber.plant(Timber.DebugTree()) plant(DebugTree())
if (BuildConfig.ENABLE_DEBUG_FEATURES) { if (BuildConfig.ENABLE_DEBUG_FEATURES) {
WhatTheStack(this).init() WhatTheStack(this).init()
} }

View file

@ -17,6 +17,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.github.ajalt.timberkt.d
import com.zeapo.pwdstore.utils.ClipboardUtils import com.zeapo.pwdstore.utils.ClipboardUtils
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -26,7 +27,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import timber.log.Timber
class ClipboardService : Service() { class ClipboardService : Service() {
@ -92,7 +92,7 @@ class ClipboardService : Service() {
ClipboardUtils.clearClipboard(clipboardManager, deepClear) ClipboardUtils.clearClipboard(clipboardManager, deepClear)
} }
} else { } else {
Timber.tag("ClipboardService").d("Cannot get clipboard manager service") d { "Cannot get clipboard manager service" }
} }
} }
@ -144,7 +144,7 @@ class ClipboardService : Service() {
if (manager != null) { if (manager != null) {
manager.createNotificationChannel(serviceChannel) manager.createNotificationChannel(serviceChannel)
} else { } else {
Timber.tag("ClipboardService").d("Failed to create notification channel") d { "Failed to create notification channel" }
} }
} }
} }

View file

@ -35,6 +35,11 @@ import androidx.fragment.app.FragmentManager
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.observe import androidx.lifecycle.observe
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.e
import com.github.ajalt.timberkt.i
import com.github.ajalt.timberkt.w
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
@ -64,7 +69,6 @@ import org.apache.commons.io.FilenameUtils
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.api.errors.GitAPIException
import org.eclipse.jgit.revwalk.RevCommit import org.eclipse.jgit.revwalk.RevCommit
import timber.log.Timber
class PasswordStore : AppCompatActivity() { class PasswordStore : AppCompatActivity() {
@ -334,7 +338,7 @@ class PasswordStore : AppCompatActivity() {
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
if (!localDir.delete()) { if (!localDir.delete()) {
Timber.tag(TAG).d("Failed to delete local repository") tag(TAG).d { "Failed to delete local repository" }
} }
return return
} }
@ -381,7 +385,7 @@ class PasswordStore : AppCompatActivity() {
val fragmentManager = supportFragmentManager val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction() val fragmentTransaction = fragmentManager.beginTransaction()
if (localDir != null && settings.getBoolean("repository_initialized", false)) { if (localDir != null && settings.getBoolean("repository_initialized", false)) {
Timber.tag(TAG).d("Check, dir: ${localDir.absolutePath}") tag(TAG).d { "Check, dir: ${localDir.absolutePath}" }
// do not push the fragment if we already have it // do not push the fragment if we already have it
if (fragmentManager.findFragmentByTag("PasswordsList") == null || if (fragmentManager.findFragmentByTag("PasswordsList") == null ||
settings.getBoolean("repo_changed", false)) { settings.getBoolean("repo_changed", false)) {
@ -424,7 +428,7 @@ class PasswordStore : AppCompatActivity() {
val repoPath = getRepositoryDirectory(this) val repoPath = getRepositoryDirectory(this)
val repository = getRepository(repoPath) val repository = getRepository(repoPath)
if (repository == null) { if (repository == null) {
Timber.tag(TAG).d("getLastChangedTimestamp: No git repository") tag(TAG).d { "getLastChangedTimestamp: No git repository" }
return File(fullPath).lastModified() return File(fullPath).lastModified()
} }
val git = Git(repository) val git = Git(repository)
@ -433,11 +437,11 @@ class PasswordStore : AppCompatActivity() {
iterator = try { iterator = try {
git.log().addPath(relativePath).call().iterator() git.log().addPath(relativePath).call().iterator()
} catch (e: GitAPIException) { } catch (e: GitAPIException) {
Timber.tag(TAG).e(e, "getLastChangedTimestamp: GITAPIException") tag(TAG).e(e) { "getLastChangedTimestamp: GITAPIException" }
return -1 return -1
} }
if (!iterator.hasNext()) { if (!iterator.hasNext()) {
Timber.tag(TAG).w("getLastChangedTimestamp: No commits for file: $relativePath") tag(TAG).w { "getLastChangedTimestamp: No commits for file: $relativePath" }
return -1 return -1
} }
return iterator.next().commitTime.toLong() * 1000 return iterator.next().commitTime.toLong() * 1000
@ -509,7 +513,7 @@ class PasswordStore : AppCompatActivity() {
fun createPassword() { fun createPassword() {
if (!validateState()) return if (!validateState()) return
val currentDir = currentDir val currentDir = currentDir
Timber.tag(TAG).i("Adding file to : ${currentDir.absolutePath}") tag(TAG).i { "Adding file to : ${currentDir.absolutePath}" }
val intent = Intent(this, PgpActivity::class.java) val intent = Intent(this, PgpActivity::class.java)
intent.putExtra("FILE_PATH", currentDir.absolutePath) intent.putExtra("FILE_PATH", currentDir.absolutePath)
intent.putExtra("REPO_PATH", getRepositoryDirectory(applicationContext).absolutePath) intent.putExtra("REPO_PATH", getRepositoryDirectory(applicationContext).absolutePath)
@ -649,24 +653,26 @@ class PasswordStore : AppCompatActivity() {
startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE) startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE)
} }
REQUEST_CODE_SELECT_FOLDER -> { REQUEST_CODE_SELECT_FOLDER -> {
Timber.tag(TAG) val intentData = data ?: return
.d("Moving passwords to ${data!!.getStringExtra("SELECTED_FOLDER_PATH")}") tag(TAG).d {
Timber.tag(TAG).d( "Moving passwords to ${intentData.getStringExtra("SELECTED_FOLDER_PATH")}"
TextUtils.join(", ", requireNotNull(data.getStringArrayListExtra("Files"))) }
) tag(TAG).d {
TextUtils.join(", ", requireNotNull(intentData.getStringArrayListExtra("Files")))
}
val target = File(requireNotNull(data.getStringExtra("SELECTED_FOLDER_PATH"))) val target = File(requireNotNull(intentData.getStringExtra("SELECTED_FOLDER_PATH")))
val repositoryPath = getRepositoryDirectory(applicationContext).absolutePath val repositoryPath = getRepositoryDirectory(applicationContext).absolutePath
if (!target.isDirectory) { if (!target.isDirectory) {
Timber.tag(TAG).e("Tried moving passwords to a non-existing folder.") tag(TAG).e { "Tried moving passwords to a non-existing folder." }
return return
} }
// TODO move this to an async task // TODO move this to an async task
for (fileString in requireNotNull(data.getStringArrayListExtra("Files"))) { for (fileString in requireNotNull(intentData.getStringArrayListExtra("Files"))) {
val source = File(fileString) val source = File(fileString)
if (!source.exists()) { if (!source.exists()) {
Timber.tag(TAG).e("Tried moving something that appears non-existent.") tag(TAG).e { "Tried moving something that appears non-existent." }
continue continue
} }
val destinationFile = File(target.absolutePath + "/" + source.name) val destinationFile = File(target.absolutePath + "/" + source.name)
@ -674,7 +680,7 @@ class PasswordStore : AppCompatActivity() {
val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename) val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename)
val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename) val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename)
if (destinationFile.exists()) { if (destinationFile.exists()) {
Timber.tag(TAG).e("Trying to move a file that already exists.") tag(TAG).e { "Trying to move a file that already exists." }
// TODO: Add option to cancel overwrite. Will be easier once this is an async task. // TODO: Add option to cancel overwrite. Will be easier once this is an async task.
MaterialAlertDialogBuilder(this) MaterialAlertDialogBuilder(this)
.setTitle(resources.getString(R.string.password_exists_title)) .setTitle(resources.getString(R.string.password_exists_title))
@ -697,7 +703,7 @@ class PasswordStore : AppCompatActivity() {
} }
if (!source.renameTo(destinationFile)) { if (!source.renameTo(destinationFile)) {
// TODO this should show a warning to the user // TODO this should show a warning to the user
Timber.tag(TAG).e("Something went wrong while moving.") tag(TAG).e { "Something went wrong while moving." }
} else { } else {
AutofillMatcher.updateMatches(this, sourceDestinationMap) AutofillMatcher.updateMatches(this, sourceDestinationMap)
commitChange(this.resources commitChange(this.resources
@ -803,7 +809,7 @@ class PasswordStore : AppCompatActivity() {
fun commitChange(activity: Activity, message: String, finishWithResultOnEnd: Intent? = null) { fun commitChange(activity: Activity, message: String, finishWithResultOnEnd: Intent? = null) {
object : GitOperation(getRepositoryDirectory(activity), activity) { object : GitOperation(getRepositoryDirectory(activity), activity) {
override fun execute() { override fun execute() {
Timber.tag(TAG).d("Committing with message $message") tag(TAG).d { "Committing with message $message" }
val git = Git(repository) val git = Git(repository)
val tasks = GitAsyncTask(activity, true, this, finishWithResultOnEnd) val tasks = GitAsyncTask(activity, true, this, finishWithResultOnEnd)
tasks.execute( tasks.execute(

View file

@ -33,6 +33,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.d import com.github.ajalt.timberkt.d
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
@ -59,7 +60,6 @@ import java.util.HashSet
import java.util.TimeZone import java.util.TimeZone
import me.msfjarvis.openpgpktx.util.OpenPgpUtils import me.msfjarvis.openpgpktx.util.OpenPgpUtils
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import timber.log.Timber
typealias ClickListener = Preference.OnPreferenceClickListener typealias ClickListener = Preference.OnPreferenceClickListener
typealias ChangeListener = Preference.OnPreferenceChangeListener typealias ChangeListener = Preference.OnPreferenceChangeListener
@ -643,7 +643,7 @@ class UserPreference : AppCompatActivity() {
SELECT_GIT_DIRECTORY -> { SELECT_GIT_DIRECTORY -> {
val uri = data.data val uri = data.data
Timber.tag(TAG).d { "Selected repository URI is $uri" } tag(TAG).d { "Selected repository URI is $uri" }
// TODO: This is fragile. Workaround until PasswordItem is backed by DocumentFile // TODO: This is fragile. Workaround until PasswordItem is backed by DocumentFile
val docId = DocumentsContract.getTreeDocumentId(uri) val docId = DocumentsContract.getTreeDocumentId(uri)
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
@ -651,7 +651,7 @@ class UserPreference : AppCompatActivity() {
val repoPath = "${Environment.getExternalStorageDirectory()}/$path" val repoPath = "${Environment.getExternalStorageDirectory()}/$path"
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext) val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
Timber.tag(TAG).d {"Selected repository path is $repoPath" } tag(TAG).d { "Selected repository path is $repoPath" }
if (Environment.getExternalStorageDirectory().path == repoPath) { if (Environment.getExternalStorageDirectory().path == repoPath) {
MaterialAlertDialogBuilder(this) MaterialAlertDialogBuilder(this)
@ -714,7 +714,7 @@ class UserPreference : AppCompatActivity() {
val repositoryDirectory = requireNotNull(PasswordRepository.getRepositoryDirectory(applicationContext)) val repositoryDirectory = requireNotNull(PasswordRepository.getRepositoryDirectory(applicationContext))
val sourcePassDir = DocumentFile.fromFile(repositoryDirectory) val sourcePassDir = DocumentFile.fromFile(repositoryDirectory)
Timber.tag(TAG).d { "Copying ${repositoryDirectory.path} to $targetDirectory" } tag(TAG).d { "Copying ${repositoryDirectory.path} to $targetDirectory" }
val dateString = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val dateString = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LocalDateTime LocalDateTime

View file

@ -12,10 +12,11 @@ import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit import androidx.core.content.edit
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.e
import com.zeapo.pwdstore.PasswordStore import com.zeapo.pwdstore.PasswordStore
import com.zeapo.pwdstore.utils.splitLines import com.zeapo.pwdstore.utils.splitLines
import org.eclipse.jgit.util.StringUtils import org.eclipse.jgit.util.StringUtils
import timber.log.Timber
// blank activity started by service for calling startIntentSenderForResult // blank activity started by service for calling startIntentSenderForResult
class AutofillActivity : AppCompatActivity() { class AutofillActivity : AppCompatActivity() {
@ -29,7 +30,7 @@ class AutofillActivity : AppCompatActivity() {
val pi = extras.getParcelable<PendingIntent>("pending_intent") ?: return val pi = extras.getParcelable<PendingIntent>("pending_intent") ?: return
startIntentSenderForResult(pi.intentSender, REQUEST_CODE_DECRYPT_AND_VERIFY, null, 0, 0, 0) startIntentSenderForResult(pi.intentSender, REQUEST_CODE_DECRYPT_AND_VERIFY, null, 0, 0, 0)
} catch (e: IntentSender.SendIntentException) { } catch (e: IntentSender.SendIntentException) {
Timber.tag(AutofillService.Constants.TAG).e(e, "SendIntentException") tag(AutofillService.Constants.TAG).e(e) { "SendIntentException" }
} }
} else if (extras != null && extras.containsKey("pick")) { } else if (extras != null && extras.containsKey("pick")) {
val intent = Intent(applicationContext, PasswordStore::class.java) val intent = Intent(applicationContext, PasswordStore::class.java)

View file

@ -24,6 +24,9 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.e
import com.github.ajalt.timberkt.i
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.PasswordEntry import com.zeapo.pwdstore.PasswordEntry
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
@ -48,7 +51,6 @@ import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import org.openintents.openpgp.IOpenPgpService2 import org.openintents.openpgp.IOpenPgpService2
import org.openintents.openpgp.OpenPgpError import org.openintents.openpgp.OpenPgpError
import timber.log.Timber
class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope(Dispatchers.Default) { class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope(Dispatchers.Default) {
private var serviceConnection: OpenPgpServiceConnection? = null private var serviceConnection: OpenPgpServiceConnection? = null
@ -522,11 +524,11 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L
} }
} catch (e: UnsupportedEncodingException) { } catch (e: UnsupportedEncodingException) {
Timber.tag(Constants.TAG).e(e) tag(Constants.TAG).e(e)
} }
} }
OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED -> { OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED -> {
Timber.tag("PgpHandler").i("RESULT_CODE_USER_INTERACTION_REQUIRED") tag("PgpHandler").i { "RESULT_CODE_USER_INTERACTION_REQUIRED" }
val pi = result.getParcelableExtra<PendingIntent>(OpenPgpApi.RESULT_INTENT) val pi = result.getParcelableExtra<PendingIntent>(OpenPgpApi.RESULT_INTENT)
// need to start a blank activity to call startIntentSenderForResult // need to start a blank activity to call startIntentSenderForResult
val intent = Intent(applicationContext, AutofillActivity::class.java) val intent = Intent(applicationContext, AutofillActivity::class.java)
@ -538,8 +540,8 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
val error = result.getParcelableExtra<OpenPgpError>(OpenPgpApi.RESULT_ERROR) val error = result.getParcelableExtra<OpenPgpError>(OpenPgpApi.RESULT_ERROR)
if (error != null) { if (error != null) {
withContext(Dispatchers.Main) { Toast.makeText(applicationContext, "Error from OpenKeyChain : ${error.message}", Toast.LENGTH_LONG).show() } withContext(Dispatchers.Main) { Toast.makeText(applicationContext, "Error from OpenKeyChain : ${error.message}", Toast.LENGTH_LONG).show() }
Timber.tag(Constants.TAG).e("onError getErrorId: ${error.errorId}") tag(Constants.TAG).e { "onError getErrorId: ${error.errorId}" }
Timber.tag(Constants.TAG).e("onError getMessage: ${error.message}") tag(Constants.TAG).e { "onError getMessage: ${error.message}" }
} }
} }
} }

View file

@ -38,6 +38,9 @@ import androidx.core.widget.doOnTextChanged
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.github.ajalt.timberkt.Timber.e
import com.github.ajalt.timberkt.Timber.i
import com.github.ajalt.timberkt.Timber.tag
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.ClipboardService import com.zeapo.pwdstore.ClipboardService
@ -71,7 +74,6 @@ import org.apache.commons.io.FileUtils
import org.apache.commons.io.FilenameUtils import org.apache.commons.io.FilenameUtils
import org.openintents.openpgp.IOpenPgpService2 import org.openintents.openpgp.IOpenPgpService2
import org.openintents.openpgp.OpenPgpError import org.openintents.openpgp.OpenPgpError
import timber.log.Timber
class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private val clipboard by lazy { getSystemService<ClipboardManager>() } private val clipboard by lazy { getSystemService<ClipboardManager>() }
@ -116,7 +118,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE) window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
Timber.tag(TAG) tag(TAG)
// some persistence // some persistence
_keyIDs = settings.getStringSet("openpgp_key_ids_set", null) ?: emptySet() _keyIDs = settings.getStringSet("openpgp_key_ids_set", null) ?: emptySet()
@ -318,7 +320,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
* @param requestCode The code we'd like to use to identify the behaviour * @param requestCode The code we'd like to use to identify the behaviour
*/ */
private fun handleUserInteractionRequest(result: Intent, requestCode: Int) { private fun handleUserInteractionRequest(result: Intent, requestCode: Int) {
Timber.i("RESULT_CODE_USER_INTERACTION_REQUIRED") i { "RESULT_CODE_USER_INTERACTION_REQUIRED" }
val pi: PendingIntent? = result.getParcelableExtra(RESULT_INTENT) val pi: PendingIntent? = result.getParcelableExtra(RESULT_INTENT)
try { try {
@ -327,7 +329,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
null, 0, 0, 0 null, 0, 0, 0
) )
} catch (e: IntentSender.SendIntentException) { } catch (e: IntentSender.SendIntentException) {
Timber.e(e, "SendIntentException") e(e) { "SendIntentException" }
} }
} }
@ -346,8 +348,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val error: OpenPgpError? = result.getParcelableExtra(RESULT_ERROR) val error: OpenPgpError? = result.getParcelableExtra(RESULT_ERROR)
if (error != null) { if (error != null) {
showSnackbar("Error from OpenKeyChain : " + error.message) showSnackbar("Error from OpenKeyChain : " + error.message)
Timber.e("onError getErrorId: ${error.errorId}") e { "onError getErrorId: ${error.errorId}" }
Timber.e("onError getMessage: ${error.message}") e { "onError getMessage: ${error.message}" }
} }
} }
@ -524,7 +526,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
copyPasswordToClipBoard() copyPasswordToClipBoard()
} }
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e, "An Exception occurred") e(e) { "An Exception occurred" }
} }
} }
RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_DECRYPT) RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_DECRYPT)
@ -624,7 +626,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
setResult(RESULT_OK, returnIntent) setResult(RESULT_OK, returnIntent)
finish() finish()
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e, "An Exception occurred") e(e) { "An Exception occurred" }
} }
} }
RESULT_CODE_ERROR -> handleError(result) RESULT_CODE_ERROR -> handleError(result)
@ -730,7 +732,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
setResult(RESULT_OK) setResult(RESULT_OK)
finish() finish()
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e, "An Exception occurred") e(e) { "An Exception occurred" }
} }
} }
RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID) RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID)

View file

@ -14,6 +14,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit import androidx.core.content.edit
import androidx.core.text.isDigitsOnly import androidx.core.text.isDigitsOnly
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.e
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.git.config.ConnectionMode import com.zeapo.pwdstore.git.config.ConnectionMode
import com.zeapo.pwdstore.git.config.Protocol import com.zeapo.pwdstore.git.config.Protocol
@ -23,7 +25,6 @@ import com.zeapo.pwdstore.utils.getEncryptedPrefs
import java.io.File import java.io.File
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.URI import java.net.URI
import timber.log.Timber
/** /**
* Abstract AppCompatActivity that holds some information that is commonly shared across git-related * Abstract AppCompatActivity that holds some information that is commonly shared across git-related
@ -172,7 +173,7 @@ abstract class BaseGitActivity : AppCompatActivity() {
REQUEST_RESET -> ResetToRemoteOperation(localDir, this).setCommands() REQUEST_RESET -> ResetToRemoteOperation(localDir, this).setCommands()
SshApiSessionFactory.POST_SIGNATURE -> return SshApiSessionFactory.POST_SIGNATURE -> return
else -> { else -> {
Timber.tag(TAG).e("Operation not recognized : $operation") tag(TAG).e { "Operation not recognized : $operation" }
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
finish() finish()
return return

View file

@ -18,12 +18,12 @@ import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.edit import androidx.core.content.edit
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.github.ajalt.timberkt.Timber.tag
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.pwgen.PasswordGenerator import com.zeapo.pwdstore.pwgen.PasswordGenerator
import com.zeapo.pwdstore.pwgenxkpwd.CapsType import com.zeapo.pwdstore.pwgenxkpwd.CapsType
import com.zeapo.pwdstore.pwgenxkpwd.PasswordBuilder import com.zeapo.pwdstore.pwgenxkpwd.PasswordBuilder
import timber.log.Timber
/** A placeholder fragment containing a simple view. */ /** A placeholder fragment containing a simple view. */
class XkPasswordGeneratorDialogFragment : DialogFragment() { class XkPasswordGeneratorDialogFragment : DialogFragment() {
@ -66,7 +66,7 @@ class XkPasswordGeneratorDialogFragment : DialogFragment() {
val previousStoredCapStyle: String = try { val previousStoredCapStyle: String = try {
prefs.getString(PREF_KEY_CAPITALS_STYLE, DEFAULT_CAPS_STYLE)!! prefs.getString(PREF_KEY_CAPITALS_STYLE, DEFAULT_CAPS_STYLE)!!
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag("xkpw").e(e) tag("xkpw").e(e)
DEFAULT_CAPS_STYLE DEFAULT_CAPS_STYLE
} }
spinnerCapsType = view.findViewById(R.id.xkCapType) spinnerCapsType = view.findViewById(R.id.xkCapType)
@ -76,7 +76,7 @@ class XkPasswordGeneratorDialogFragment : DialogFragment() {
lastCapitalsStyleIndex = try { lastCapitalsStyleIndex = try {
CapsType.valueOf(previousStoredCapStyle).ordinal CapsType.valueOf(previousStoredCapStyle).ordinal
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag("xkpw").e(e) tag("xkpw").e(e)
DEFAULT_CAPS_INDEX DEFAULT_CAPS_INDEX
} }
spinnerCapsType.setSelection(lastCapitalsStyleIndex) spinnerCapsType.setSelection(lastCapitalsStyleIndex)
@ -126,7 +126,7 @@ class XkPasswordGeneratorDialogFragment : DialogFragment() {
.setCapitalization(CapsType.valueOf(spinnerCapsType.selectedItem.toString())).create() .setCapitalization(CapsType.valueOf(spinnerCapsType.selectedItem.toString())).create()
} catch (e: PasswordGenerator.PasswordGeneratorExeption) { } catch (e: PasswordGenerator.PasswordGeneratorExeption) {
Toast.makeText(requireActivity(), e.message, Toast.LENGTH_SHORT).show() Toast.makeText(requireActivity(), e.message, Toast.LENGTH_SHORT).show()
Timber.tag("xkpw").e(e, "failure generating xkpasswd") tag("xkpw").e(e, "failure generating xkpasswd")
passwordText.text = FALLBACK_ERROR_PASS passwordText.text = FALLBACK_ERROR_PASS
} }
} }

View file

@ -6,14 +6,14 @@ package com.zeapo.pwdstore.utils
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import com.github.ajalt.timberkt.d
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import timber.log.Timber
object ClipboardUtils { object ClipboardUtils {
suspend fun clearClipboard(clipboard: ClipboardManager, deepClear: Boolean = false) { suspend fun clearClipboard(clipboard: ClipboardManager, deepClear: Boolean = false) {
Timber.d("Clearing the clipboard") d { "Clearing the clipboard" }
val clip = ClipData.newPlainText("pgp_handler_result_pm", "") val clip = ClipData.newPlainText("pgp_handler_result_pm", "")
clipboard.setPrimaryClip(clip) clipboard.setPrimaryClip(clip)
if (deepClear) { if (deepClear) {

View file

@ -8,8 +8,9 @@ import android.os.Handler
import androidx.biometric.BiometricManager import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt import androidx.biometric.BiometricPrompt
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.d
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import timber.log.Timber
internal class Authenticator( internal class Authenticator(
private val fragmentActivity: FragmentActivity, private val fragmentActivity: FragmentActivity,
@ -22,19 +23,19 @@ internal class Authenticator(
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString) super.onAuthenticationError(errorCode, errString)
Timber.tag(TAG).d("Error: $errorCode: $errString") tag(TAG).d { "Error: $errorCode: $errString" }
callback(AuthenticationResult.UnrecoverableError(errorCode, errString)) callback(AuthenticationResult.UnrecoverableError(errorCode, errString))
} }
override fun onAuthenticationFailed() { override fun onAuthenticationFailed() {
super.onAuthenticationFailed() super.onAuthenticationFailed()
Timber.tag(TAG).d("Failed") tag(TAG).d { "Failed" }
callback(AuthenticationResult.Failure) callback(AuthenticationResult.Failure)
} }
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result) super.onAuthenticationSucceeded(result)
Timber.tag(TAG).d("Success") tag(TAG).d { "Success" }
callback(AuthenticationResult.Success(result.cryptoObject)) callback(AuthenticationResult.Success(result.cryptoObject))
} }
} }