-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ndk): add support for reading native C primitives (long, int, si…
…ze_t, time_t, bool) in Kotlin
- Loading branch information
Showing
7 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
bugsnag-plugin-android-ndk/src/main/java/com/bugsnag/android/ndk/NativeArch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.bugsnag.android.ndk | ||
|
||
import android.os.Build | ||
import androidx.annotation.VisibleForTesting | ||
|
||
internal object NativeArch { | ||
@JvmField | ||
@VisibleForTesting | ||
var _is32Bit: Boolean? = null | ||
|
||
@JvmField | ||
@VisibleForTesting | ||
@Suppress("DEPRECATION") | ||
val supportedAbis: Array<String> = when { | ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> Build.SUPPORTED_ABIS | ||
else -> arrayOf(Build.CPU_ABI, Build.CPU_ABI2) | ||
} | ||
|
||
val is32bit: Boolean | ||
get() { | ||
var result = _is32Bit | ||
if (result == null) { | ||
result = !supportedAbis.any { it.contains("64") } | ||
_is32Bit = result | ||
} | ||
|
||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
bugsnag-plugin-android-ndk/src/test/java/com/bugsnag/android/ndk/CPrimitivesTest32Bit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.bugsnag.android.ndk | ||
|
||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.nio.ByteBuffer | ||
import java.nio.ByteOrder | ||
|
||
class CPrimitivesTest32Bit { | ||
private val sample32BitData = byteArrayOf( | ||
0x0d, 0, 0, 0, 0, 0, 0, 0, // taken from an event_header (int, int) | ||
0xf4.toByte(), 0x10, 0, 0, 0, 0, 0, 0, // bsg_app_info.duration int64_t | ||
0xa0.toByte(), 0x0f, 0, 0, 0, 0, 0, 0, // bsg_app_info.duration_in_foreground int64_t | ||
0x54, 0x01, 0, 0, 0, 0, 0, 0, // bsg_app_info.duration_ms_offset int64_t | ||
0x54, 0x01, 0, 0, // bsg_app_info.duration_in_foreground_ms_offset time_t | ||
0x01, // bsg_app_info.in_foreground | ||
0x00, // bsg_app_info.is_launching | ||
) | ||
|
||
@Before | ||
fun setupArchitecture() { | ||
NativeArch._is32Bit = true | ||
} | ||
|
||
@After | ||
fun unsetupArchitecture() { | ||
NativeArch._is32Bit = null | ||
} | ||
|
||
@Test | ||
fun test32BitPrimitives() { | ||
val data = ByteBuffer.wrap(sample32BitData) | ||
data.order(ByteOrder.LITTLE_ENDIAN) | ||
assertEquals(13, data.getNativeInt()) | ||
assertEquals(0, data.getNativeInt()) | ||
|
||
assertEquals(4340, data.getLong()) | ||
assertEquals(4000, data.getLong()) | ||
assertEquals(340, data.getLong()) | ||
assertEquals(340, data.getNativeTime()) | ||
assertEquals(true, data.getNativeBool()) | ||
assertEquals(false, data.getNativeBool()) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
bugsnag-plugin-android-ndk/src/test/java/com/bugsnag/android/ndk/CPrimitivesTest64Bit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.bugsnag.android.ndk | ||
|
||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.nio.ByteBuffer | ||
import java.nio.ByteOrder | ||
|
||
class CPrimitivesTest64Bit { | ||
private val sample64BitData = byteArrayOf( | ||
0x0d, 0, 0, 0, 0, 0, 0, 0, // taken from an event_header (int, int) | ||
0xf4.toByte(), 0x10, 0, 0, 0, 0, 0, 0, // bsg_app_info.duration int64_t | ||
0xa0.toByte(), 0x0f, 0, 0, 0, 0, 0, 0, // bsg_app_info.duration_in_foreground int64_t | ||
0x54, 0x01, 0, 0, 0, 0, 0, 0, // bsg_app_info.duration_ms_offset int64_t | ||
0x54, 0x01, 0, 0, 0, 0, 0, 0, // bsg_app_info.duration_in_foreground_ms_offset time_t | ||
0x01, // bsg_app_info.in_foreground | ||
0x00, // bsg_app_info.is_launching | ||
) | ||
|
||
@Before | ||
fun setupArchitecture() { | ||
NativeArch._is32Bit = false | ||
} | ||
|
||
@After | ||
fun unsetupArchitecture() { | ||
NativeArch._is32Bit = null | ||
} | ||
|
||
@Test | ||
fun test64BitPrimitives() { | ||
val data = ByteBuffer.wrap(sample64BitData) | ||
data.order(ByteOrder.LITTLE_ENDIAN) | ||
assertEquals(13, data.getNativeInt()) | ||
assertEquals(0, data.getNativeInt()) | ||
|
||
assertEquals(4340, data.getLong()) | ||
assertEquals(4000, data.getLong()) | ||
assertEquals(340, data.getLong()) | ||
assertEquals(340, data.getNativeTime()) | ||
assertEquals(true, data.getNativeBool()) | ||
assertEquals(false, data.getNativeBool()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.47 MB
bugsnag-plugin-android-ndk/src/test/resources/arm32-droid-razr.crash_dump
Binary file not shown.