ReviewOS

also looking at this

craft-native/craft

feat(android): getMemoryUsage and log — ratchet 102 -> 100

#143
Merged chris wants to merge feat/android-tier0-memory-log into main
7 files +377 -3
packages/android/templates/CraftNative.kt.templatemodified+29-0
Changes to packages/android/templates/CraftNative.kt.template
@@ -57,6 +57,8 @@ object CraftNative {
5757 }
5858
5959 private external fun nativeGetDeviceInfo(activity: Activity): String?
60 private external fun nativeGetMemoryUsage(): String?
61 private external fun nativeLog(message: String): Boolean
6062
6163 /**
6264 * `getDeviceInfo`, or null to use the Kotlin implementation.
@@ -76,4 +78,31 @@ object CraftNative {
7678 null
7779 }
7880 }
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 }
79108}