Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 500ab60

Browse files
committed
treewide: switch to logging via timberkt
Signed-off-by: Harsh Shandilya <[email protected]>
1 parent 72166c6 commit 500ab60

File tree

11 files changed

+70
-56
lines changed

11 files changed

+70
-56
lines changed

app/src/main/java/com/zeapo/pwdstore/Application.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
1111
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
1212
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
1313
import androidx.preference.PreferenceManager
14+
import com.github.ajalt.timberkt.Timber.DebugTree
15+
import com.github.ajalt.timberkt.Timber.plant
1416
import com.haroldadmin.whatthestack.WhatTheStack
15-
import timber.log.Timber
1617

1718
@Suppress("Unused")
1819
class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener {
1920
private var prefs: SharedPreferences? = null
2021

2122
override fun onCreate() {
2223
super.onCreate()
23-
Timber.plant(Timber.DebugTree())
24+
plant(DebugTree())
2425
if (BuildConfig.ENABLE_DEBUG_FEATURES) {
2526
WhatTheStack(this).init()
2627
}

app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.core.app.NotificationCompat
1717
import androidx.core.content.getSystemService
1818
import androidx.localbroadcastmanager.content.LocalBroadcastManager
1919
import androidx.preference.PreferenceManager
20+
import com.github.ajalt.timberkt.d
2021
import com.zeapo.pwdstore.utils.ClipboardUtils
2122
import kotlinx.coroutines.CoroutineScope
2223
import kotlinx.coroutines.Dispatchers
@@ -26,7 +27,6 @@ import kotlinx.coroutines.delay
2627
import kotlinx.coroutines.isActive
2728
import kotlinx.coroutines.launch
2829
import kotlinx.coroutines.withContext
29-
import timber.log.Timber
3030

3131
class ClipboardService : Service() {
3232

@@ -92,7 +92,7 @@ class ClipboardService : Service() {
9292
ClipboardUtils.clearClipboard(clipboardManager, deepClear)
9393
}
9494
} else {
95-
Timber.tag("ClipboardService").d("Cannot get clipboard manager service")
95+
d { "Cannot get clipboard manager service" }
9696
}
9797
}
9898

@@ -144,7 +144,7 @@ class ClipboardService : Service() {
144144
if (manager != null) {
145145
manager.createNotificationChannel(serviceChannel)
146146
} else {
147-
Timber.tag("ClipboardService").d("Failed to create notification channel")
147+
d { "Failed to create notification channel" }
148148
}
149149
}
150150
}

app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ import androidx.fragment.app.FragmentManager
3535
import androidx.lifecycle.ViewModelProvider
3636
import androidx.lifecycle.observe
3737
import androidx.preference.PreferenceManager
38+
import com.github.ajalt.timberkt.Timber.tag
39+
import com.github.ajalt.timberkt.d
40+
import com.github.ajalt.timberkt.e
41+
import com.github.ajalt.timberkt.i
42+
import com.github.ajalt.timberkt.w
3843
import com.google.android.material.dialog.MaterialAlertDialogBuilder
3944
import com.google.android.material.snackbar.Snackbar
4045
import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
@@ -64,7 +69,6 @@ import org.apache.commons.io.FilenameUtils
6469
import org.eclipse.jgit.api.Git
6570
import org.eclipse.jgit.api.errors.GitAPIException
6671
import org.eclipse.jgit.revwalk.RevCommit
67-
import timber.log.Timber
6872

6973
class PasswordStore : AppCompatActivity() {
7074

@@ -334,7 +338,7 @@ class PasswordStore : AppCompatActivity() {
334338
} catch (e: Exception) {
335339
e.printStackTrace()
336340
if (!localDir.delete()) {
337-
Timber.tag(TAG).d("Failed to delete local repository")
341+
tag(TAG).d { "Failed to delete local repository" }
338342
}
339343
return
340344
}
@@ -381,7 +385,7 @@ class PasswordStore : AppCompatActivity() {
381385
val fragmentManager = supportFragmentManager
382386
val fragmentTransaction = fragmentManager.beginTransaction()
383387
if (localDir != null && settings.getBoolean("repository_initialized", false)) {
384-
Timber.tag(TAG).d("Check, dir: ${localDir.absolutePath}")
388+
tag(TAG).d { "Check, dir: ${localDir.absolutePath}" }
385389
// do not push the fragment if we already have it
386390
if (fragmentManager.findFragmentByTag("PasswordsList") == null ||
387391
settings.getBoolean("repo_changed", false)) {
@@ -424,7 +428,7 @@ class PasswordStore : AppCompatActivity() {
424428
val repoPath = getRepositoryDirectory(this)
425429
val repository = getRepository(repoPath)
426430
if (repository == null) {
427-
Timber.tag(TAG).d("getLastChangedTimestamp: No git repository")
431+
tag(TAG).d { "getLastChangedTimestamp: No git repository" }
428432
return File(fullPath).lastModified()
429433
}
430434
val git = Git(repository)
@@ -433,11 +437,11 @@ class PasswordStore : AppCompatActivity() {
433437
iterator = try {
434438
git.log().addPath(relativePath).call().iterator()
435439
} catch (e: GitAPIException) {
436-
Timber.tag(TAG).e(e, "getLastChangedTimestamp: GITAPIException")
440+
tag(TAG).e(e) { "getLastChangedTimestamp: GITAPIException" }
437441
return -1
438442
}
439443
if (!iterator.hasNext()) {
440-
Timber.tag(TAG).w("getLastChangedTimestamp: No commits for file: $relativePath")
444+
tag(TAG).w { "getLastChangedTimestamp: No commits for file: $relativePath" }
441445
return -1
442446
}
443447
return iterator.next().commitTime.toLong() * 1000
@@ -509,7 +513,7 @@ class PasswordStore : AppCompatActivity() {
509513
fun createPassword() {
510514
if (!validateState()) return
511515
val currentDir = currentDir
512-
Timber.tag(TAG).i("Adding file to : ${currentDir.absolutePath}")
516+
tag(TAG).i { "Adding file to : ${currentDir.absolutePath}" }
513517
val intent = Intent(this, PgpActivity::class.java)
514518
intent.putExtra("FILE_PATH", currentDir.absolutePath)
515519
intent.putExtra("REPO_PATH", getRepositoryDirectory(applicationContext).absolutePath)
@@ -649,32 +653,34 @@ class PasswordStore : AppCompatActivity() {
649653
startActivityForResult(intent, BaseGitActivity.REQUEST_CLONE)
650654
}
651655
REQUEST_CODE_SELECT_FOLDER -> {
652-
Timber.tag(TAG)
653-
.d("Moving passwords to ${data!!.getStringExtra("SELECTED_FOLDER_PATH")}")
654-
Timber.tag(TAG).d(
655-
TextUtils.join(", ", requireNotNull(data.getStringArrayListExtra("Files")))
656-
)
656+
val intentData = data ?: return
657+
tag(TAG).d {
658+
"Moving passwords to ${intentData.getStringExtra("SELECTED_FOLDER_PATH")}"
659+
}
660+
tag(TAG).d {
661+
TextUtils.join(", ", requireNotNull(intentData.getStringArrayListExtra("Files")))
662+
}
657663

658-
val target = File(requireNotNull(data.getStringExtra("SELECTED_FOLDER_PATH")))
664+
val target = File(requireNotNull(intentData.getStringExtra("SELECTED_FOLDER_PATH")))
659665
val repositoryPath = getRepositoryDirectory(applicationContext).absolutePath
660666
if (!target.isDirectory) {
661-
Timber.tag(TAG).e("Tried moving passwords to a non-existing folder.")
667+
tag(TAG).e { "Tried moving passwords to a non-existing folder." }
662668
return
663669
}
664670

665671
// TODO move this to an async task
666-
for (fileString in requireNotNull(data.getStringArrayListExtra("Files"))) {
672+
for (fileString in requireNotNull(intentData.getStringArrayListExtra("Files"))) {
667673
val source = File(fileString)
668674
if (!source.exists()) {
669-
Timber.tag(TAG).e("Tried moving something that appears non-existent.")
675+
tag(TAG).e { "Tried moving something that appears non-existent." }
670676
continue
671677
}
672678
val destinationFile = File(target.absolutePath + "/" + source.name)
673679
val basename = FilenameUtils.getBaseName(source.absolutePath)
674680
val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename)
675681
val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename)
676682
if (destinationFile.exists()) {
677-
Timber.tag(TAG).e("Trying to move a file that already exists.")
683+
tag(TAG).e { "Trying to move a file that already exists." }
678684
// TODO: Add option to cancel overwrite. Will be easier once this is an async task.
679685
MaterialAlertDialogBuilder(this)
680686
.setTitle(resources.getString(R.string.password_exists_title))
@@ -697,7 +703,7 @@ class PasswordStore : AppCompatActivity() {
697703
}
698704
if (!source.renameTo(destinationFile)) {
699705
// TODO this should show a warning to the user
700-
Timber.tag(TAG).e("Something went wrong while moving.")
706+
tag(TAG).e { "Something went wrong while moving." }
701707
} else {
702708
AutofillMatcher.updateMatches(this, sourceDestinationMap)
703709
commitChange(this.resources
@@ -803,7 +809,7 @@ class PasswordStore : AppCompatActivity() {
803809
fun commitChange(activity: Activity, message: String, finishWithResultOnEnd: Intent? = null) {
804810
object : GitOperation(getRepositoryDirectory(activity), activity) {
805811
override fun execute() {
806-
Timber.tag(TAG).d("Committing with message $message")
812+
tag(TAG).d { "Committing with message $message" }
807813
val git = Git(repository)
808814
val tasks = GitAsyncTask(activity, true, this, finishWithResultOnEnd)
809815
tasks.execute(

app/src/main/java/com/zeapo/pwdstore/UserPreference.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import androidx.preference.Preference
3333
import androidx.preference.PreferenceFragmentCompat
3434
import androidx.preference.PreferenceManager
3535
import androidx.preference.SwitchPreferenceCompat
36+
import com.github.ajalt.timberkt.Timber.tag
3637
import com.github.ajalt.timberkt.d
3738
import com.google.android.material.dialog.MaterialAlertDialogBuilder
3839
import com.google.android.material.snackbar.Snackbar
@@ -59,7 +60,6 @@ import java.util.HashSet
5960
import java.util.TimeZone
6061
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
6162
import org.apache.commons.io.FileUtils
62-
import timber.log.Timber
6363

6464
typealias ClickListener = Preference.OnPreferenceClickListener
6565
typealias ChangeListener = Preference.OnPreferenceChangeListener
@@ -643,15 +643,15 @@ class UserPreference : AppCompatActivity() {
643643
SELECT_GIT_DIRECTORY -> {
644644
val uri = data.data
645645

646-
Timber.tag(TAG).d { "Selected repository URI is $uri" }
646+
tag(TAG).d { "Selected repository URI is $uri" }
647647
// TODO: This is fragile. Workaround until PasswordItem is backed by DocumentFile
648648
val docId = DocumentsContract.getTreeDocumentId(uri)
649649
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
650650
val path = if (split.isNotEmpty()) split[1] else split[0]
651651
val repoPath = "${Environment.getExternalStorageDirectory()}/$path"
652652
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
653653

654-
Timber.tag(TAG).d {"Selected repository path is $repoPath" }
654+
tag(TAG).d { "Selected repository path is $repoPath" }
655655

656656
if (Environment.getExternalStorageDirectory().path == repoPath) {
657657
MaterialAlertDialogBuilder(this)
@@ -714,7 +714,7 @@ class UserPreference : AppCompatActivity() {
714714
val repositoryDirectory = requireNotNull(PasswordRepository.getRepositoryDirectory(applicationContext))
715715
val sourcePassDir = DocumentFile.fromFile(repositoryDirectory)
716716

717-
Timber.tag(TAG).d { "Copying ${repositoryDirectory.path} to $targetDirectory" }
717+
tag(TAG).d { "Copying ${repositoryDirectory.path} to $targetDirectory" }
718718

719719
val dateString = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
720720
LocalDateTime

app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import android.content.SharedPreferences
1212
import android.os.Bundle
1313
import androidx.appcompat.app.AppCompatActivity
1414
import androidx.core.content.edit
15+
import com.github.ajalt.timberkt.Timber.tag
16+
import com.github.ajalt.timberkt.e
1517
import com.zeapo.pwdstore.PasswordStore
1618
import com.zeapo.pwdstore.utils.splitLines
1719
import org.eclipse.jgit.util.StringUtils
18-
import timber.log.Timber
1920

2021
// blank activity started by service for calling startIntentSenderForResult
2122
class AutofillActivity : AppCompatActivity() {
@@ -29,7 +30,7 @@ class AutofillActivity : AppCompatActivity() {
2930
val pi = extras.getParcelable<PendingIntent>("pending_intent") ?: return
3031
startIntentSenderForResult(pi.intentSender, REQUEST_CODE_DECRYPT_AND_VERIFY, null, 0, 0, 0)
3132
} catch (e: IntentSender.SendIntentException) {
32-
Timber.tag(AutofillService.Constants.TAG).e(e, "SendIntentException")
33+
tag(AutofillService.Constants.TAG).e(e) { "SendIntentException" }
3334
}
3435
} else if (extras != null && extras.containsKey("pick")) {
3536
val intent = Intent(applicationContext, PasswordStore::class.java)

app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import android.widget.Toast
2424
import androidx.appcompat.app.AlertDialog
2525
import androidx.core.os.bundleOf
2626
import androidx.preference.PreferenceManager
27+
import com.github.ajalt.timberkt.Timber.tag
28+
import com.github.ajalt.timberkt.e
29+
import com.github.ajalt.timberkt.i
2730
import com.google.android.material.dialog.MaterialAlertDialogBuilder
2831
import com.zeapo.pwdstore.PasswordEntry
2932
import com.zeapo.pwdstore.R
@@ -48,7 +51,6 @@ import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
4851
import org.apache.commons.io.FileUtils
4952
import org.openintents.openpgp.IOpenPgpService2
5053
import org.openintents.openpgp.OpenPgpError
51-
import timber.log.Timber
5254

5355
class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope(Dispatchers.Default) {
5456
private var serviceConnection: OpenPgpServiceConnection? = null
@@ -522,11 +524,11 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
522524
lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L
523525
}
524526
} catch (e: UnsupportedEncodingException) {
525-
Timber.tag(Constants.TAG).e(e)
527+
tag(Constants.TAG).e(e)
526528
}
527529
}
528530
OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED -> {
529-
Timber.tag("PgpHandler").i("RESULT_CODE_USER_INTERACTION_REQUIRED")
531+
tag("PgpHandler").i { "RESULT_CODE_USER_INTERACTION_REQUIRED" }
530532
val pi = result.getParcelableExtra<PendingIntent>(OpenPgpApi.RESULT_INTENT)
531533
// need to start a blank activity to call startIntentSenderForResult
532534
val intent = Intent(applicationContext, AutofillActivity::class.java)
@@ -538,8 +540,8 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
538540
val error = result.getParcelableExtra<OpenPgpError>(OpenPgpApi.RESULT_ERROR)
539541
if (error != null) {
540542
withContext(Dispatchers.Main) { Toast.makeText(applicationContext, "Error from OpenKeyChain : ${error.message}", Toast.LENGTH_LONG).show() }
541-
Timber.tag(Constants.TAG).e("onError getErrorId: ${error.errorId}")
542-
Timber.tag(Constants.TAG).e("onError getMessage: ${error.message}")
543+
tag(Constants.TAG).e { "onError getErrorId: ${error.errorId}" }
544+
tag(Constants.TAG).e { "onError getMessage: ${error.message}" }
543545
}
544546
}
545547
}

app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import androidx.core.widget.doOnTextChanged
3838
import androidx.lifecycle.lifecycleScope
3939
import androidx.localbroadcastmanager.content.LocalBroadcastManager
4040
import androidx.preference.PreferenceManager
41+
import com.github.ajalt.timberkt.Timber.e
42+
import com.github.ajalt.timberkt.Timber.i
43+
import com.github.ajalt.timberkt.Timber.tag
4144
import com.google.android.material.dialog.MaterialAlertDialogBuilder
4245
import com.google.android.material.snackbar.Snackbar
4346
import com.zeapo.pwdstore.ClipboardService
@@ -71,7 +74,6 @@ import org.apache.commons.io.FileUtils
7174
import org.apache.commons.io.FilenameUtils
7275
import org.openintents.openpgp.IOpenPgpService2
7376
import org.openintents.openpgp.OpenPgpError
74-
import timber.log.Timber
7577

7678
class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
7779
private val clipboard by lazy { getSystemService<ClipboardManager>() }
@@ -116,7 +118,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
116118
override fun onCreate(savedInstanceState: Bundle?) {
117119
super.onCreate(savedInstanceState)
118120
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
119-
Timber.tag(TAG)
121+
tag(TAG)
120122

121123
// some persistence
122124
_keyIDs = settings.getStringSet("openpgp_key_ids_set", null) ?: emptySet()
@@ -318,7 +320,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
318320
* @param requestCode The code we'd like to use to identify the behaviour
319321
*/
320322
private fun handleUserInteractionRequest(result: Intent, requestCode: Int) {
321-
Timber.i("RESULT_CODE_USER_INTERACTION_REQUIRED")
323+
i { "RESULT_CODE_USER_INTERACTION_REQUIRED" }
322324

323325
val pi: PendingIntent? = result.getParcelableExtra(RESULT_INTENT)
324326
try {
@@ -327,7 +329,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
327329
null, 0, 0, 0
328330
)
329331
} catch (e: IntentSender.SendIntentException) {
330-
Timber.e(e, "SendIntentException")
332+
e(e) { "SendIntentException" }
331333
}
332334
}
333335

@@ -346,8 +348,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
346348
val error: OpenPgpError? = result.getParcelableExtra(RESULT_ERROR)
347349
if (error != null) {
348350
showSnackbar("Error from OpenKeyChain : " + error.message)
349-
Timber.e("onError getErrorId: ${error.errorId}")
350-
Timber.e("onError getMessage: ${error.message}")
351+
e { "onError getErrorId: ${error.errorId}" }
352+
e { "onError getMessage: ${error.message}" }
351353
}
352354
}
353355

@@ -524,7 +526,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
524526
copyPasswordToClipBoard()
525527
}
526528
} catch (e: Exception) {
527-
Timber.e(e, "An Exception occurred")
529+
e(e) { "An Exception occurred" }
528530
}
529531
}
530532
RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_DECRYPT)
@@ -624,7 +626,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
624626
setResult(RESULT_OK, returnIntent)
625627
finish()
626628
} catch (e: Exception) {
627-
Timber.e(e, "An Exception occurred")
629+
e(e) { "An Exception occurred" }
628630
}
629631
}
630632
RESULT_CODE_ERROR -> handleError(result)
@@ -730,7 +732,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
730732
setResult(RESULT_OK)
731733
finish()
732734
} catch (e: Exception) {
733-
Timber.e(e, "An Exception occurred")
735+
e(e) { "An Exception occurred" }
734736
}
735737
}
736738
RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID)

0 commit comments

Comments
 (0)