Search code examples
androidacra

ACRA can't send customHttpSender to Acrarium


I need to modify the report sends to Acrarium, so I use HttpSender. I have tried using ReportSender instead of HttpSender but the result is the same: report is not send to Acrarium. It works fine using the default settings(without SenderFactory::class).

This is MyApplication class:

@AcraCore(
    buildConfigClass = BuildConfig::class,
    reportContent = [ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE],
    reportSenderFactoryClasses = [SenderFactory::class]
)
@AcraHttpSender(
    uri = "http://localhost:port/report",
    basicAuthLogin = "..........",
    basicAuthPassword = "..........,
    httpMethod = HttpSender.Method.POST
)
class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        ACRA.init(this)
    }
}

My CustomHttpSender:

class CustomSender(config: CoreConfiguration, method: Method = Method.POST, type: StringFormat? = null)
    : HttpSender(config, method, type) {

    override fun send(context: Context, report: CrashReportData) {
        try {
            report.put(
                ReportField.PHONE_MODEL,
                report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
            )

            println("Report: \n" + report.getString(ReportField.PHONE_MODEL))
//            sendHttpRequests(config, context, mMethod, mType.matchingHttpContentType, login, password, httpConfig.connectionTimeout,
//                httpConfig.socketTimeout, httpConfig.httpHeaders, reportAsString, reportUrl, uris)

            Log.e("YourOwnSender", report.toJSON())
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

    override fun sendHttpRequests(configuration: CoreConfiguration, context: Context, method: Method,
        contentType: String, login: String?, password: String?, connectionTimeOut: Int, socketTimeOut: Int,
        headers: MutableMap<String, String>?, content: String, url: URL, attachments: MutableList<Uri>
    ) {
    }

    fun getAdditionalInfo(): String {
        return " ABC-001"
    }
}

My SenderFactory:

@AutoService(ReportSenderFactory::class)
class SenderFactory: ReportSenderFactory {
    override fun create(context: Context, config: CoreConfiguration): ReportSender {
        return CustomSender(config, HttpSender.Method.POST, StringFormat.JSON)
    }

    override fun enabled(config: CoreConfiguration): Boolean {
        return true
    }
}

The logcat is the same between using the default setting and CustomSender:

2021-02-26 10:55:05.163 1448-1448/? I/xample.acrates: Late-enabling -Xcheck:jni
2021-02-26 10:55:05.330 1448-1448/? E/xample.acrates: Unknown bits set in runtime_flags: 0x8000
2021-02-26 10:55:05.628 1448-1448/com.example.acratest I/ACRA: ACRA is enabled for com.example.acratest, initializing...
2021-02-26 10:55:05.774 1448-1448/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.853 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-02-26 10:55:05.854 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-02-26 10:55:05.952 1448-1525/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: QUALCOMM build                   : 4a00b69, I4e7e888065
    Build Date                       : 04/09/19
    OpenGL ES Shader Compiler Version: EV031.26.06.00
    Local Branch                     : mybranche95ae4c8-d77f-f18d-a9ef-1458d0b52ae8
    Remote Branch                    : quic/gfx-adreno.lnx.1.0
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: Build Config                     : S L 8.0.5 AArch64
2021-02-26 10:55:06.003 1448-1495/com.example.acratest I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
2021-02-26 10:55:06.020 1448-1495/com.example.acratest W/Gralloc3: mapper 3.x is not supported

There's a difference in tab Run.

The default settings without SenderFactory::class: The default settings without SenderFactory::class

With SenderFactory: With SenderFactory

How do I send the modified report to Acrarium?

--------------- EDIT ---------------

I only need to add one line:

super.send(context, report)

override fun send(context: Context, report: CrashReportData) {
    try {
        report.put(
            ReportField.PHONE_MODEL,
            report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
        )
        Log.e("YourOwnSender", report.toJSON())
        super.send(context, report)
    } catch (e: Exception) {
        throw ReportSenderException(
            "Error while sending JSON report via Http POST",
            e
        )
    }

}

And I don't need to override fun sendHttpRequests.


Solution

  • Always call super when you're overriding methods.

    Your Sender overrides two methods without calling super methods, essentially removing the functionality.

    You'll also want to disable the default sender when registering your own.