fix: replace printStackTrace with Log.e for better error logging #156

Closed
septs wants to merge 1 commit from septs:exc-to-log into master
8 changed files with 13 additions and 11 deletions

View file

@ -258,7 +258,7 @@ open class DefaultEuiccChannelManager(
}
} catch (e: Exception) {
// Ignored -- skip forward
e.printStackTrace()
Log.e(TAG, "Failed to open eUICC channel on USB device ${device.deviceId}:${device.vendorId}", e)
}
Log.i(TAG, "No valid eUICC channel found on USB device ${device.deviceId}:${device.vendorId}")
}

View file

@ -82,8 +82,7 @@ class OmapiApduInterface(
throw RuntimeException("Retransmit attempts exhausted; this was likely caused by checksum errors")
} catch (e: Exception) {
Log.e(TAG, "OMAPI APDU exception")
e.printStackTrace()
Log.e(TAG, "OMAPI APDU exception", e)
throw e
}
}

View file

@ -42,7 +42,7 @@ class UsbApduInterface(
// https://www.usb.org/sites/default/files/DWG_Smart-Card_USB-ICC_ICCD_rev10.pdf
atr = transceiver.iccPowerOn().data
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "Failed to power on ICC", e)
throw e
}
}
@ -60,7 +60,7 @@ class UsbApduInterface(
val resp = try {
transmitApduByChannel(req, 0)
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "OPEN LOGICAL CHANNEL failed", e)
return -1
}

View file

@ -99,7 +99,7 @@ suspend inline fun EuiccChannelManager.beginTrackedOperation(
}
} catch (e: Exception) {
// Ignore any error during notification handling
e.printStackTrace()
Log.e(TAG, "Error during notification handling", e)
}
}
Log.d(TAG, "Operation complete")

View file

@ -1,6 +1,7 @@
package im.angry.openeuicc
import android.content.Intent
import android.util.Log
import im.angry.openeuicc.di.UnprivilegedAppContainer
import im.angry.openeuicc.ui.LogsActivity
import im.angry.openeuicc.util.*
@ -16,7 +17,7 @@ class UnprivilegedOpenEuiccApplication : OpenEuiccApplication() {
super.onCreate()
Thread.setDefaultUncaughtExceptionHandler { _, e ->
e.printStackTrace()
Log.e(TAG, "Uncaught exception", e)
Intent(this, LogsActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

View file

@ -5,6 +5,7 @@ import android.content.pm.PackageManager
import android.os.Build
import android.se.omapi.Reader
import android.telephony.TelephonyManager
import android.util.Log
import im.angry.easyeuicc.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@ -155,7 +156,7 @@ internal class IsdrChannelAccessCheck(private val context: Context): Compatibili
// SecurityException is only thrown when Channel is constructed, which means everything else needs to succeed
Pair(it.slotIndex, State.SUCCESS)
} catch (e: IOException) {
e.printStackTrace()
Log.e(TAG, "Failed to open logical channel", e)
if (e.message?.contains("Secure Element is not present") == true) {
failureDescription = context.getString(R.string.compatibility_check_isdr_channel_desc_unknown)
Pair(it.slotIndex, State.FAILURE_UNKNOWN)
@ -163,7 +164,7 @@ internal class IsdrChannelAccessCheck(private val context: Context): Compatibili
Pair(it.slotIndex, State.FAILURE)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "Failed to open logical channel", e)
Pair(it.slotIndex, State.FAILURE)
}
}.fold(Pair(mutableListOf<Int>(), State.SUCCESS)) { (ids, result), (id, ok) ->

View file

@ -3,6 +3,7 @@ package im.angry.openeuicc.util
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
import android.telephony.UiccSlotMapping
import android.util.Log
import im.angry.openeuicc.core.EuiccChannel
import im.angry.openeuicc.core.EuiccChannelManager
import kotlinx.coroutines.flow.onEach
@ -68,7 +69,7 @@ suspend fun TelephonyManager.updateSimSlotMapping(
try {
simSlotMapping = newMapping
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "Failed to update sim slot mapping", e)
undo.forEach { it() } // Undo what we just did
throw e // Rethrow for caller to handle
}

View file

@ -75,7 +75,7 @@ class HttpInterfaceImpl(
return HttpInterface.HttpResponse(conn.responseCode, bytes)
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "Failed to transmit", e)
throw e
}
}