forked from upstream-mirrors/quik
Improve logging for failed messages
This commit is contained in:
@@ -26,6 +26,7 @@ import android.telephony.SmsManager
|
|||||||
import dagger.android.AndroidInjection
|
import dagger.android.AndroidInjection
|
||||||
import interactor.MarkFailed
|
import interactor.MarkFailed
|
||||||
import interactor.MarkSent
|
import interactor.MarkSent
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SmsSentReceiver : BroadcastReceiver() {
|
class SmsSentReceiver : BroadcastReceiver() {
|
||||||
@@ -48,9 +49,14 @@ class SmsSentReceiver : BroadcastReceiver() {
|
|||||||
SmsManager.RESULT_ERROR_NO_SERVICE,
|
SmsManager.RESULT_ERROR_NO_SERVICE,
|
||||||
SmsManager.RESULT_ERROR_NULL_PDU,
|
SmsManager.RESULT_ERROR_NULL_PDU,
|
||||||
SmsManager.RESULT_ERROR_RADIO_OFF -> {
|
SmsManager.RESULT_ERROR_RADIO_OFF -> {
|
||||||
|
Timber.w(SmsFailedException(resultCode, intent.getIntExtra("errorCode", -1)))
|
||||||
|
|
||||||
val pendingResult = goAsync()
|
val pendingResult = goAsync()
|
||||||
markFailed.execute(MarkFailed.Params(id, resultCode)) { pendingResult.finish() }
|
markFailed.execute(MarkFailed.Params(id, resultCode)) { pendingResult.finish() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SmsFailedException(resultCode: Int, errorCode: Int)
|
||||||
|
: Exception("Message failed to send with resultCode: $resultCode and errorCode: $errorCode")
|
||||||
@@ -29,6 +29,7 @@ import com.bugsnag.android.Bugsnag
|
|||||||
import com.bugsnag.android.Configuration
|
import com.bugsnag.android.Configuration
|
||||||
import com.moez.QKSMS.BuildConfig
|
import com.moez.QKSMS.BuildConfig
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
|
import common.util.BugsnagTree
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.DispatchingAndroidInjector
|
import dagger.android.DispatchingAndroidInjector
|
||||||
import dagger.android.HasActivityInjector
|
import dagger.android.HasActivityInjector
|
||||||
@@ -90,7 +91,7 @@ class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverIn
|
|||||||
|
|
||||||
EmojiCompat.init(FontRequestEmojiCompatConfig(this, fontRequest))
|
EmojiCompat.init(FontRequestEmojiCompatConfig(this, fontRequest))
|
||||||
|
|
||||||
Timber.plant(Timber.DebugTree())
|
Timber.plant(Timber.DebugTree(), BugsnagTree())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun activityInjector(): AndroidInjector<Activity> {
|
override fun activityInjector(): AndroidInjector<Activity> {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package common.util
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import com.bugsnag.android.Bugsnag
|
||||||
|
import com.bugsnag.android.Severity
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If an exception is logged with the [Log.WARN] or [Log.ERROR] priority, the exception will be
|
||||||
|
* sent to Bugsnag
|
||||||
|
*/
|
||||||
|
class BugsnagTree : Timber.Tree() {
|
||||||
|
|
||||||
|
override fun isLoggable(tag: String?, priority: Int): Boolean {
|
||||||
|
return priority == Log.WARN || priority == Log.ERROR
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun log(priority: Int, tag: String?, message: String?, throwable: Throwable?) {
|
||||||
|
val severity = if (priority == Log.ERROR) Severity.ERROR else Severity.WARNING
|
||||||
|
throwable?.run { Bugsnag.notify(this, severity) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user