Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ dependencies {
exclude(group = "org.apache.httpcomponents", module = "httpclient")
}
implementation(libs.thirdparty.kotlinResult)
implementation(libs.thirdparty.logcat)
implementation(libs.thirdparty.modernAndroidPrefs)
implementation(libs.thirdparty.plumber)
implementation(libs.thirdparty.sshauth)
implementation(libs.thirdparty.sshj)
implementation(libs.thirdparty.timber)
implementation(libs.thirdparty.timberkt)

if (isSnapshot()) {
implementation(libs.thirdparty.whatthestack)
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/dev/msfjarvis/aps/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import com.github.ajalt.timberkt.Timber.DebugTree
import com.github.ajalt.timberkt.Timber.plant
import dagger.hilt.android.HiltAndroidApp
import dev.msfjarvis.aps.injection.context.FilesDirPath
import dev.msfjarvis.aps.injection.prefs.SettingsPreferences
Expand All @@ -25,6 +23,7 @@ import dev.msfjarvis.aps.util.settings.GitSettings
import dev.msfjarvis.aps.util.settings.PreferenceKeys
import dev.msfjarvis.aps.util.settings.runMigrations
import javax.inject.Inject
import logcat.AndroidLogcatLogger

@Suppress("Unused")
@HiltAndroidApp
Expand All @@ -41,7 +40,7 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
if (BuildConfig.ENABLE_DEBUG_FEATURES ||
prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false)
) {
plant(DebugTree())
AndroidLogcatLogger.installOnDebuggableApp(this)
StrictMode.setVmPolicy(VmPolicy.Builder().detectAll().penaltyLog().build())
StrictMode.setThreadPolicy(ThreadPolicy.Builder().detectAll().penaltyLog().build())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import androidx.activity.result.contract.ActivityResultContracts.StartIntentSend
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.e
import com.github.androidpasswordstore.autofillparser.AutofillAction
import com.github.androidpasswordstore.autofillparser.Credentials
import com.github.michaelbull.result.getOrElse
Expand All @@ -31,6 +29,7 @@ import dev.msfjarvis.aps.util.autofill.AutofillPreferences
import dev.msfjarvis.aps.util.autofill.AutofillResponseBuilder
import dev.msfjarvis.aps.util.autofill.DirectoryStructure
import dev.msfjarvis.aps.util.extensions.OPENPGP_PROVIDER
import dev.msfjarvis.aps.util.extensions.asLog
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.InputStream
Expand All @@ -43,6 +42,9 @@ import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import logcat.LogPriority.ERROR
import logcat.asLog
import logcat.logcat
import me.msfjarvis.openpgpktx.util.OpenPgpApi
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
import org.openintents.openpgp.IOpenPgpService2
Expand Down Expand Up @@ -108,21 +110,21 @@ class AutofillDecryptActivity : AppCompatActivity() {
val filePath =
intent?.getStringExtra(EXTRA_FILE_PATH)
?: run {
e { "AutofillDecryptActivity started without EXTRA_FILE_PATH" }
logcat(ERROR) { "AutofillDecryptActivity started without EXTRA_FILE_PATH" }
finish()
return
}
val clientState =
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE)
?: run {
e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
logcat(ERROR) { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
finish()
return
}
val isSearchAction = intent?.getBooleanExtra(EXTRA_SEARCH_ACTION, true)!!
val action = if (isSearchAction) AutofillAction.Search else AutofillAction.Match
directoryStructure = AutofillPreferences.directoryStructure(this)
d { action.toString() }
logcat { action.toString() }
lifecycleScope.launch {
val credentials = decryptCredential(File(filePath))
if (credentials == null) {
Expand Down Expand Up @@ -183,14 +185,14 @@ class AutofillDecryptActivity : AppCompatActivity() {
val command = resumeIntent ?: Intent().apply { action = OpenPgpApi.ACTION_DECRYPT_VERIFY }
runCatching { file.inputStream() }
.onFailure { e ->
e(e) { "File to decrypt not found" }
logcat(ERROR) { e.asLog("File to decrypt not found") }
return null
}
.onSuccess { encryptedInput ->
val decryptedOutput = ByteArrayOutputStream()
runCatching { executeOpenPgpApi(command, encryptedInput, decryptedOutput) }
.onFailure { e ->
e(e) { "OpenPgpApi ACTION_DECRYPT_VERIFY failed" }
logcat(ERROR) { e.asLog("OpenPgpApi ACTION_DECRYPT_VERIFY failed") }
return null
}
.onSuccess { result ->
Expand All @@ -212,7 +214,7 @@ class AutofillDecryptActivity : AppCompatActivity() {
)
}
.getOrElse { e ->
e(e) { "Failed to parse password entry" }
logcat(ERROR) { e.asLog("Failed to parse password entry") }
return null
}
}
Expand All @@ -232,7 +234,9 @@ class AutofillDecryptActivity : AppCompatActivity() {
decryptCredential(file, intentToResume)
}
.getOrElse { e ->
e(e) { "OpenPgpApi ACTION_DECRYPT_VERIFY failed with user interaction" }
logcat(ERROR) {
e.asLog("OpenPgpApi ACTION_DECRYPT_VERIFY failed with user interaction")
}
return null
}
}
Expand All @@ -247,14 +251,14 @@ class AutofillDecryptActivity : AppCompatActivity() {
)
.show()
}
e {
logcat(ERROR) {
"OpenPgpApi ACTION_DECRYPT_VERIFY failed (${error.errorId}): ${error.message}"
}
}
null
}
else -> {
e { "Unrecognized OpenPgpApi result: $resultCode" }
logcat(ERROR) { "Unrecognized OpenPgpApi result: $resultCode" }
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import android.view.autofill.AutofillManager
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.e
import com.github.androidpasswordstore.autofillparser.AutofillAction
import com.github.androidpasswordstore.autofillparser.Credentials
import com.github.michaelbull.result.getOrElse
Expand All @@ -29,11 +27,15 @@ import dev.msfjarvis.aps.ui.crypto.DecryptActivityV2
import dev.msfjarvis.aps.util.autofill.AutofillPreferences
import dev.msfjarvis.aps.util.autofill.AutofillResponseBuilder
import dev.msfjarvis.aps.util.autofill.DirectoryStructure
import dev.msfjarvis.aps.util.extensions.asLog
import java.io.File
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import logcat.LogPriority.ERROR
import logcat.asLog
import logcat.logcat

@RequiresApi(Build.VERSION_CODES.O)
@AndroidEntryPoint
Expand Down Expand Up @@ -80,21 +82,21 @@ class AutofillDecryptActivityV2 : AppCompatActivity() {
val filePath =
intent?.getStringExtra(EXTRA_FILE_PATH)
?: run {
e { "AutofillDecryptActivityV2 started without EXTRA_FILE_PATH" }
logcat(ERROR) { "AutofillDecryptActivityV2 started without EXTRA_FILE_PATH" }
finish()
return
}
val clientState =
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE)
?: run {
e { "AutofillDecryptActivityV2 started without EXTRA_CLIENT_STATE" }
logcat(ERROR) { "AutofillDecryptActivityV2 started without EXTRA_CLIENT_STATE" }
finish()
return
}
val isSearchAction = intent?.getBooleanExtra(EXTRA_SEARCH_ACTION, true)!!
val action = if (isSearchAction) AutofillAction.Search else AutofillAction.Match
directoryStructure = AutofillPreferences.directoryStructure(this)
d { action.toString() }
logcat { action.toString() }
lifecycleScope.launch {
val credentials = decryptCredential(File(filePath))
if (credentials == null) {
Expand All @@ -121,7 +123,7 @@ class AutofillDecryptActivityV2 : AppCompatActivity() {
private suspend fun decryptCredential(file: File): Credentials? {
runCatching { file.inputStream() }
.onFailure { e ->
e(e) { "File to decrypt not found" }
logcat(ERROR) { e.asLog("File to decrypt not found") }
return null
}
.onSuccess { encryptedInput ->
Expand All @@ -136,7 +138,7 @@ class AutofillDecryptActivityV2 : AppCompatActivity() {
}
}
.onFailure { e ->
e(e) { "Decryption failed" }
logcat(ERROR) { e.asLog("Decryption failed") }
return null
}
.onSuccess { result ->
Expand All @@ -145,7 +147,7 @@ class AutofillDecryptActivityV2 : AppCompatActivity() {
AutofillPreferences.credentialsFromStoreEntry(this, file, entry, directoryStructure)
}
.getOrElse { e ->
e(e) { "Failed to parse password entry" }
logcat(ERROR) { e.asLog("Failed to parse password entry") }
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.core.widget.addTextChangedListener
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.ajalt.timberkt.e
import com.github.androidpasswordstore.autofillparser.FormOrigin
import dev.msfjarvis.aps.R
import dev.msfjarvis.aps.data.password.PasswordItem
Expand All @@ -39,6 +38,8 @@ import dev.msfjarvis.aps.util.viewmodel.ListMode
import dev.msfjarvis.aps.util.viewmodel.SearchMode
import dev.msfjarvis.aps.util.viewmodel.SearchableRepositoryAdapter
import dev.msfjarvis.aps.util.viewmodel.SearchableRepositoryViewModel
import logcat.LogPriority.ERROR
import logcat.logcat

@TargetApi(Build.VERSION_CODES.O)
class AutofillFilterView : AppCompatActivity() {
Expand Down Expand Up @@ -102,7 +103,7 @@ class AutofillFilterView : AppCompatActivity() {
window.attributes = params

if (intent?.hasExtra(AutofillManager.EXTRA_CLIENT_STATE) != true) {
e { "AutofillFilterActivity started without EXTRA_CLIENT_STATE" }
logcat(ERROR) { "AutofillFilterActivity started without EXTRA_CLIENT_STATE" }
finish()
return
}
Expand All @@ -115,7 +116,7 @@ class AutofillFilterView : AppCompatActivity() {
FormOrigin.App(intent!!.getStringExtra(EXTRA_FORM_ORIGIN_APP)!!)
}
else -> {
e {
logcat(ERROR) {
"AutofillFilterActivity started without EXTRA_FORM_ORIGIN_WEB or EXTRA_FORM_ORIGIN_APP"
}
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import android.text.format.DateUtils
import android.view.View
import android.view.autofill.AutofillManager
import androidx.appcompat.app.AppCompatActivity
import com.github.ajalt.timberkt.e
import com.github.androidpasswordstore.autofillparser.FormOrigin
import com.github.androidpasswordstore.autofillparser.computeCertificatesHash
import com.github.michaelbull.result.onFailure
Expand All @@ -26,7 +25,10 @@ import dev.msfjarvis.aps.R
import dev.msfjarvis.aps.databinding.ActivityOreoAutofillPublisherChangedBinding
import dev.msfjarvis.aps.util.autofill.AutofillMatcher
import dev.msfjarvis.aps.util.autofill.AutofillPublisherChangedException
import dev.msfjarvis.aps.util.extensions.asLog
import dev.msfjarvis.aps.util.extensions.viewBinding
import logcat.LogPriority.ERROR
import logcat.logcat

@TargetApi(Build.VERSION_CODES.O)
class AutofillPublisherChangedActivity : AppCompatActivity() {
Expand Down Expand Up @@ -69,7 +71,7 @@ class AutofillPublisherChangedActivity : AppCompatActivity() {
appPackage =
intent.getStringExtra(EXTRA_APP_PACKAGE)
?: run {
e { "AutofillPublisherChangedActivity started without EXTRA_PACKAGE_NAME" }
logcat(ERROR) { "AutofillPublisherChangedActivity started without EXTRA_PACKAGE_NAME" }
finish()
return
}
Expand Down Expand Up @@ -117,7 +119,7 @@ class AutofillPublisherChangedActivity : AppCompatActivity() {
}
}
.onFailure { e ->
e(e) { "Failed to retrieve package info for $appPackage" }
logcat(ERROR) { e.asLog("Failed to retrieve package info for $appPackage") }
finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.activity.result.contract.ActivityResultContracts.StartActivityFo
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import com.github.ajalt.timberkt.e
import com.github.androidpasswordstore.autofillparser.AutofillAction
import com.github.androidpasswordstore.autofillparser.Credentials
import com.github.androidpasswordstore.autofillparser.FormOrigin
Expand All @@ -26,6 +25,8 @@ import dev.msfjarvis.aps.util.autofill.AutofillPreferences
import dev.msfjarvis.aps.util.autofill.AutofillResponseBuilder
import dev.msfjarvis.aps.util.extensions.unsafeLazy
import java.io.File
import logcat.LogPriority.ERROR
import logcat.logcat

@RequiresApi(Build.VERSION_CODES.O)
class AutofillSaveActivity : AppCompatActivity() {
Expand Down Expand Up @@ -131,7 +132,7 @@ class AutofillSaveActivity : AppCompatActivity() {
val clientState =
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE)
?: run {
e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
logcat(ERROR) { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
finish()
return@registerForActivityResult
}
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/dev/msfjarvis/aps/ui/crypto/BasePgpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import android.view.WindowManager
import androidx.annotation.CallSuper
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.e
import com.github.ajalt.timberkt.i
import com.github.michaelbull.result.getOr
import com.github.michaelbull.result.runCatching
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand All @@ -29,6 +26,7 @@ import dev.msfjarvis.aps.R
import dev.msfjarvis.aps.injection.prefs.SettingsPreferences
import dev.msfjarvis.aps.util.FeatureFlags
import dev.msfjarvis.aps.util.extensions.OPENPGP_PROVIDER
import dev.msfjarvis.aps.util.extensions.asLog
import dev.msfjarvis.aps.util.extensions.clipboard
import dev.msfjarvis.aps.util.extensions.getString
import dev.msfjarvis.aps.util.extensions.snackbar
Expand All @@ -37,6 +35,9 @@ import dev.msfjarvis.aps.util.services.ClipboardService
import dev.msfjarvis.aps.util.settings.PreferenceKeys
import java.io.File
import javax.inject.Inject
import logcat.LogPriority.ERROR
import logcat.LogPriority.INFO
import logcat.logcat
import me.msfjarvis.openpgpktx.util.OpenPgpApi
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
import org.openintents.openpgp.IOpenPgpService2
Expand Down Expand Up @@ -82,7 +83,6 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
tag(TAG)
}

/**
Expand Down Expand Up @@ -121,7 +121,7 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
* super.
*/
override fun onError(e: Exception) {
e(e) { "Callers must handle their own exceptions" }
logcat(ERROR) { e.asLog("Callers must handle their own exceptions") }
throw e
}

Expand Down Expand Up @@ -176,7 +176,7 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
* @param result The intent returned by OpenKeychain
*/
fun getUserInteractionRequestIntent(result: Intent): IntentSender {
i { "RESULT_CODE_USER_INTERACTION_REQUIRED" }
logcat(INFO) { "RESULT_CODE_USER_INTERACTION_REQUIRED" }
return result.getParcelableExtra<PendingIntent>(OpenPgpApi.RESULT_INTENT)!!.intentSender
}

Expand All @@ -196,8 +196,8 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
}
else -> {
snackbar(message = getString(R.string.openpgp_error_unknown, error.message))
e { "onError getErrorId: ${error.errorId}" }
e { "onError getMessage: ${error.message}" }
logcat(ERROR) { "onError getErrorId: ${error.errorId}" }
logcat(ERROR) { "onError getMessage: ${error.message}" }
}
}
}
Expand Down
Loading