also looking at this
feat(android): getMemoryUsage and log — ratchet 102 -> 100
#143
7 files
+377
-3
| @@ -57,6 +57,8 @@ object CraftNative { | ||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | private external fun nativeGetDeviceInfo(activity: Activity): String? |
| 60 | private external fun nativeGetMemoryUsage(): String? | |
| 61 | private external fun nativeLog(message: String): Boolean | |
| 60 | 62 | |
| 61 | 63 | /** |
| 62 | 64 | * `getDeviceInfo`, or null to use the Kotlin implementation. |
| @@ -76,4 +78,31 @@ object CraftNative { | ||
| 76 | 78 | null |
| 77 | 79 | } |
| 78 | 80 | } |
| 81 | ||
| 82 | /** The JVM heap as JSON, or null to use the Kotlin implementation. */ | |
| 83 | fun getMemoryUsage(): String? { | |
| 84 | if (!isAvailable) return null | |
| 85 | return try { | |
| 86 | nativeGetMemoryUsage() | |
| 87 | } catch (e: UnsatisfiedLinkError) { | |
| 88 | null | |
| 89 | } | |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Write a log line, reporting whether it was written. | |
| 94 | * | |
| 95 | * The only native here that answers with a boolean rather than a nullable | |
| 96 | * result, because there is no value to return and "not mine" still has to | |
| 97 | * be sayable — a void native would leave the caller unable to tell a | |
| 98 | * written line from a declined one, and it would log twice or not at all. | |
| 99 | */ | |
| 100 | fun log(message: String): Boolean { | |
| 101 | if (!isAvailable) return false | |
| 102 | return try { | |
| 103 | nativeLog(message) | |
| 104 | } catch (e: UnsatisfiedLinkError) { | |
| 105 | false | |
| 106 | } | |
| 107 | } | |
| 79 | 108 | } |