Commit 61790790 authored by Roger Yang's avatar Roger Yang
Browse files

Close #6409: Use application version if specified

parent 5131ec9f
......@@ -42,6 +42,7 @@ internal const val UNCAUGHT_EXCEPTION_TYPE = "uncaught exception"
internal const val FATAL_NATIVE_CRASH_TYPE = "fatal native crash"
internal const val NON_FATAL_NATIVE_CRASH_TYPE = "non-fatal native crash"
internal const val DEFAULT_VERSION_NAME = "N/A"
/**
* A [CrashReporterService] implementation uploading crash reports to crash-stats.mozilla.com.
*
......@@ -66,20 +67,22 @@ class MozillaSocorroService(
private val buildId: String = BuildConfig.MOZ_APP_BUILDID,
private val vendor: String = BuildConfig.MOZ_APP_VENDOR,
private var serverUrl: String? = null,
private var versionName: String = "N/A",
private var versionName: String = DEFAULT_VERSION_NAME,
private val releaseChannel: String = BuildConfig.MOZ_UPDATE_CHANNEL
) : CrashReporterService {
private val logger = Logger("mozac/MozillaSocorroCrashHelperService")
private val startTime = System.currentTimeMillis()
init {
try {
versionName = applicationContext.packageManager
.getPackageInfo(applicationContext.packageName, 0).versionName
} catch (e: PackageManager.NameNotFoundException) {
Logger.error("package name not found, failed to get application version")
} catch (e: IllegalStateException) {
Logger.error("failed to get application version")
if (versionName == DEFAULT_VERSION_NAME) {
try {
versionName = applicationContext.packageManager
.getPackageInfo(applicationContext.packageName, 0).versionName
} catch (e: PackageManager.NameNotFoundException) {
Logger.error("package name not found, failed to get application version")
} catch (e: IllegalStateException) {
Logger.error("failed to get application version")
}
}
if (serverUrl == null) {
......
......@@ -271,6 +271,41 @@ class MozillaSocorroServiceTest {
verify(service).sendReport(throwable, null, null, false, false)
}
@Test
fun `MozillaSocorroService caught exception request with no app version`() {
val mockWebServer = MockWebServer()
mockWebServer.enqueue(MockResponse().setResponseCode(200)
.setBody("CrashID=bp-924121d3-4de3-4b32-ab12-026fc0190928"))
mockWebServer.start()
val serverUrl = mockWebServer.url("/")
val service = spy(MozillaSocorroService(
testContext,
"Test App",
"{1234-1234-1234}",
"0.1",
"1.0",
"Mozilla Test",
serverUrl = serverUrl.toString()
))
val throwable = RuntimeException("Test")
service.report(throwable)
val fileInputStream = ByteArrayInputStream(mockWebServer.takeRequest().body.inputStream().readBytes())
val inputStream = GZIPInputStream(fileInputStream)
val reader = InputStreamReader(inputStream)
val bufferedReader = BufferedReader(reader)
val request = bufferedReader.readText()
assert(request.contains("name=JavaStackTrace\r\n\r\n$INFO_PREFIX java.lang.RuntimeException: Test"))
assert(request.contains("name=Android_ProcessName\r\n\r\nmozilla.components.lib.crash.test"))
assert(request.contains("name=ProductID\r\n\r\n{1234-1234-1234}"))
assert(request.contains("name=Version\r\n\r\nN/A"))
verify(service).report(throwable)
verify(service).sendReport(throwable, null, null, false, false)
}
@Test
fun `MozillaSocorroService handles caught exception with no stacktrace correctly`() {
val mockWebServer = MockWebServer()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment