Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migration togs to Timber so we won't post logs in release app #2283

Merged
merged 4 commits into from
Jan 16, 2024
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
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ dependencies {
implementation "com.appmattus.crypto:cryptohash:0.10.1" //black2b hash for dot icon
implementation "io.coil-kt:coil-compose:$coilVersion"
implementation "io.coil-kt:coil-svg:$coilVersion"
implementation 'com.jakewharton.timber:timber:5.0.1'
testImplementation 'junit:junit:4.13.2'
testImplementation "org.mockito:mockito-core:5.8.0"
testImplementation "androidx.test:core:1.5.0"
Expand Down
10 changes: 8 additions & 2 deletions android/src/main/java/io/parity/signer/PolkadotVaultApp.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.parity.signer

import android.app.Application
import android.util.Log
import io.parity.signer.dependencygraph.ServiceLocator
import io.parity.signer.domain.submitErrorState
import io.parity.signer.uniffi.ErrorDisplayed
import io.parity.signer.uniffi.initLogging
import timber.log.Timber
import timber.log.Timber.*
import java.lang.Thread.UncaughtExceptionHandler


class PolkadotVaultApp : Application() {
override fun onCreate() {
super.onCreate()
Expand All @@ -16,6 +18,10 @@ class PolkadotVaultApp : Application() {

initLogging("SIGNER_RUST_LOG")

if (BuildConfig.DEBUG) {
Timber.plant(DebugTree())
}

val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(
RootExceptionHandler(defaultHandler)
Expand All @@ -34,7 +40,7 @@ class RootExceptionHandler(
override fun uncaughtException(t: Thread, e: Throwable) {
val rustStr = findErrorDisplayedStr(e)
if (rustStr != null) {
Log.e(TAG, "Rust caused ErrorDisplay message was: ${rustStr.s}")
Timber.e(TAG, "Rust caused ErrorDisplay message was: ${rustStr.s}")
submitErrorState("rust error not handled, fix it!")
} else {
defaultHandler?.uncaughtException(t, e) ?: throw e
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/io/parity/signer/domain/Helpers.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.parity.signer.domain

import android.util.Log
import timber.log.Timber
import io.parity.signer.BuildConfig
import io.parity.signer.uniffi.ErrorDisplayed
import java.lang.RuntimeException

fun submitErrorState(message: String) {
Log.e("error state", message)
Timber.e("error state", message)
if (BuildConfig.DEBUG) {
throw RuntimeException(message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.parity.signer.domain

import android.annotation.SuppressLint
import android.content.*
import android.util.Log
import timber.log.Timber
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -34,7 +34,7 @@ class MainFlowViewModel() : ViewModel() {
AuthResult.AuthError,
AuthResult.AuthFailed,
AuthResult.AuthUnavailable -> {
Log.e("Signer", "Auth failed, not unlocked")
Timber.e("Signer", "Auth failed, not unlocked")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/io/parity/signer/domain/Navigation.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.domain

import android.content.Context
import android.util.Log
import timber.log.Timber
import android.widget.Toast
import io.parity.signer.R
import io.parity.signer.dependencygraph.ServiceLocator
Expand Down Expand Up @@ -44,7 +44,7 @@ class FakeNavigator : Navigator {
try {
backendAction(action, details, seedPhrase)
} catch (e: ErrorDisplayed) {
Log.e("fake navigation error", e.message ?: e.toString())
Timber.e("fake navigation error", e.message ?: e.toString())
}
//do nothing with result
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.domain

import android.os.Bundle
import android.util.Log
import timber.log.Timber
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavHostController
Expand All @@ -19,7 +19,7 @@ private class NavLogger(val tag: String) :
destination: NavDestination,
arguments: Bundle?
) {
Log.d(tag, "destination is " + destination.route)
Timber.d(tag, "destination is " + destination.route)
}

}
4 changes: 2 additions & 2 deletions android/src/main/java/io/parity/signer/domain/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.parity.signer.domain

import android.content.Context
import android.graphics.BitmapFactory
import android.util.Log
import timber.log.Timber
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -65,7 +65,7 @@ fun List<UByte>.intoImageBitmap(): ImageBitmap {
return try {
BitmapFactory.decodeByteArray(picture, 0, picture.size).asImageBitmap()
} catch (e: java.lang.Exception) {
Log.d("image decoding error", e.toString())
Timber.d("image decoding error", e.toString())
ImageBitmap(1, 1)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.domain.storage

import android.security.keystore.UserNotAuthenticatedException
import android.util.Log
import timber.log.Timber
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import io.parity.signer.domain.AuthResult
Expand Down Expand Up @@ -67,7 +67,7 @@ class SeedRepository(
}
}
} catch (e: java.lang.Exception) {
Log.d("get seed failure", e.toString())
Timber.d("get seed failure", e.toString())
Toast.makeText(activity, "get seed failure: $e", Toast.LENGTH_LONG).show()
RepoResult.Failure(RuntimeException("Unexpected Exception", e))
}
Expand Down Expand Up @@ -111,7 +111,7 @@ class SeedRepository(
}
}
} catch (e: java.lang.Exception) {
Log.d("get seed failure", e.toString())
Timber.d("get seed failure", e.toString())
Toast.makeText(activity, "get seed failure: $e", Toast.LENGTH_LONG).show()
RepoResult.Failure(RuntimeException("Unexpected Exception", e))
}
Expand Down Expand Up @@ -141,12 +141,12 @@ class SeedRepository(
AuthResult.AuthError,
AuthResult.AuthFailed,
AuthResult.AuthUnavailable -> {
Log.e(TAG, "auth error - $authResult")
Timber.e(TAG, "auth error - $authResult")
false
}
}
} catch (e: java.lang.Exception) {
Log.e(TAG, e.toString())
Timber.e(TAG, e.toString())
return false
}
}
Expand Down Expand Up @@ -181,15 +181,15 @@ class SeedRepository(
is UniffiResult.Success -> OperationResult.Ok(Unit)
}
} catch (e: java.lang.Exception) {
Log.d("remove seed error", e.toString())
Timber.d("remove seed error", e.toString())
OperationResult.Err(e)
}
}

AuthResult.AuthError,
AuthResult.AuthFailed,
AuthResult.AuthUnavailable -> {
Log.d("remove seed auth error ", authResult.toString())
Timber.d("remove seed auth error ", authResult.toString())
OperationResult.Err(Exception("remove seed auth error $authResult"))
}
}
Expand Down Expand Up @@ -223,7 +223,7 @@ class SeedRepository(
AuthResult.AuthError,
AuthResult.AuthFailed,
AuthResult.AuthUnavailable -> {
Log.e(TAG, "auth error - $authResult")
Timber.e(TAG, "auth error - $authResult")
false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Build
import android.security.keystore.UserNotAuthenticatedException
import android.util.Log
import timber.log.Timber
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import io.parity.signer.domain.FeatureFlags
Expand Down Expand Up @@ -51,7 +51,7 @@ class SeedStorage {
false
}

Log.d("strongbox available:", hasStrongbox.toString())
Timber.d("strongbox available:", hasStrongbox.toString())

// Init crypto for seeds:
// https://developer.android.com/training/articles/keystore
Expand All @@ -74,7 +74,7 @@ class SeedStorage {
.build()
}

Log.e("ENCRY", "$appContext $KEYSTORE_NAME $masterKey")
Timber.e("ENCRY", "$appContext $KEYSTORE_NAME $masterKey")
//we need to be authenticated for this
sharedPreferences =
if (FeatureFlags.isEnabled(FeatureOption.SKIP_UNLOCK_FOR_DEVELOPMENT)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.screens.createderivation

import android.content.Context
import android.util.Log
import timber.log.Timber
import android.widget.Toast
import androidx.lifecycle.ViewModel
import io.parity.signer.R
Expand Down Expand Up @@ -157,10 +157,10 @@ class DerivationCreateViewModel : ViewModel() {
}
}
} else {
Log.e(TAG, "Seed phrase received but it's empty")
Timber.e(TAG, "Seed phrase received but it's empty")
}
} catch (e: java.lang.Exception) {
Log.e(TAG, e.toString())
Timber.e(TAG, e.toString())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.screens.initial

import android.content.res.Configuration
import android.util.Log
import timber.log.Timber
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.parity.signer.screens.initial.eachstartchecks.screenlock
import android.content.Intent
import android.content.res.Configuration
import android.provider.Settings
import android.util.Log
import timber.log.Timber
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
Expand Down Expand Up @@ -83,7 +83,7 @@ fun SetScreenLockScreen() {
null
)
} else {
Log.e("screen lock", "Settings activity not found")
Timber.e("screen lock", "Settings activity not found")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.parity.signer.screens.keysetdetails

import android.util.Log
import timber.log.Timber
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.parity.signer.dependencygraph.ServiceLocator
Expand Down Expand Up @@ -104,7 +104,7 @@ class KeySetDetailsViewModel : ViewModel() {

return when (result) {
null, is OperationResult.Err -> {
Log.d(
Timber.d(
"Keyset",
"wrong seed name requested or wrong last known seed getting another one"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.screens.keysets.create

import android.content.res.Configuration
import android.util.Log
import timber.log.Timber
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.screens.keysets.restore.keysetname

import android.content.res.Configuration
import android.util.Log
import timber.log.Timber
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.parity.signer.screens.scan

import android.content.Context
import android.util.Log
import timber.log.Timber
import android.widget.Toast
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -76,7 +76,7 @@ class ScanViewModel : ViewModel() {
suspend fun performTransactionPayload(payload: String, context: Context) {
val fakeNavigator = FakeNavigator()
if (transactionIsInProgress.value) {
Log.e(TAG, "started transaction while it was in progress, ignoring")
Timber.e(TAG, "started transaction while it was in progress, ignoring")
return
}
transactionIsInProgress.value = true
Expand All @@ -92,7 +92,7 @@ class ScanViewModel : ViewModel() {
val screenData = navigateResponse.result.screenData
val transactions: List<MTransaction> =
(screenData as? ScreenData.Transaction)?.f ?: run {
Log.e(
Timber.e(
TAG,
"Error in getting transaction from qr payload, " + "screenData is $screenData, navigation resp is $navigateResponse"
)
Expand Down Expand Up @@ -224,7 +224,7 @@ class ScanViewModel : ViewModel() {
) {
when (val phrases = seedRepository.getAllSeeds()) {
is RepoResult.Failure -> {
Log.e(
Timber.e(
TAG,
"cannot get seeds to show import dynamic derivations ${phrases.error}"
)
Expand Down Expand Up @@ -255,7 +255,7 @@ class ScanViewModel : ViewModel() {
) {
when (val phrases = seedRepository.getAllSeeds()) {
is RepoResult.Failure -> {
Log.e(
Timber.e(
TAG,
"cannot get seeds to show import dynamic derivations ${phrases.error}"
)
Expand Down Expand Up @@ -435,7 +435,7 @@ class ScanViewModel : ViewModel() {
): ActionResult? {
return when (val phrases = seedRepository.getSeedPhrases(seedNames)) {
is RepoResult.Failure -> {
Log.w(TAG, "signature transactions failure ${phrases.error}")
Timber.w(TAG, "signature transactions failure ${phrases.error}")
null
}

Expand All @@ -453,7 +453,7 @@ class ScanViewModel : ViewModel() {
scanFlowInteractor.handlePasswordEntered(password)
val actionResult =
(navigateResponse as? OperationResult.Ok)?.result ?: run {
Log.e(
Timber.e(
TAG,
"Error in entering password for a key, " + "navigation resp is $navigateResponse"
)
Expand All @@ -478,7 +478,7 @@ class ScanViewModel : ViewModel() {
}
//ignore the rest modals
else -> {
Log.e(
Timber.e(
TAG,
"Password is entered for transaction, but neither new password or signature is passed! Should not happen" + "actionResult is $actionResult"
)
Expand Down
Loading
Loading