ReviewOS

also looking at this

craft-native/craft

feat(android): getNetworkStatus — the action iOS cannot serve

#146
Merged glennmichael123 wants to merge feat/android-network-status into main
7 files +407 -3
packages/zig/src/android_dispatch.zigmodified+24-1
Changes to packages/zig/src/android_dispatch.zig
@@ -40,6 +40,7 @@ const device = ;
4040const system = ;
4141const clipboard = ;
4242const intents = ;
43const network = ;
4344
4445const Jni = jni.Jni;
4546
@@ -159,6 +160,11 @@ const natives = [_]jni.JNINativeMethod{
159160 .signature = "(Landroid/app/Activity;Ljava/lang/String;Ljava/lang/String;)Z",
160161 .fnPtr = @ptrCast(&nativeShare),
161162 },
163 .{
164 .name = "nativeGetNetworkStatus",
165 .signature = "(Landroid/app/Activity;)Ljava/lang/String;",
166 .fnPtr = @ptrCast(&nativeGetNetworkStatus),
167 },
162168};
163169
164170/// How binding went. A value rather than a log line, so every path is
@@ -365,6 +371,23 @@ fn nativeShare(
365371 return jni.JNI_TRUE;
366372}
367373
374fn nativeGetNetworkStatus(env: jni.JNIEnv, _: jni.jobject, activity: jni.jobject) callconv(.c) jni.jstring {
375 const j = Jni.init(env);
376 var arena = std.heap.ArenaAllocator.init(backing);
377 defer arena.deinit();
378 const allocator = arena.allocator();
379
380 const status = network.read(j, activity) catch |err| {
381 std.log.warn("craft: getNetworkStatus fell through to the shim ({s})", .{@errorName(err)});
382 return null;
383 };
384
385 const json = network.render(allocator, status) catch return null;
386 const owned = allocator.allocSentinel(u8, json.len, 0) catch return null;
387 @memcpy(owned, json);
388 return j.newStringUtf(owned.ptr) catch null;
389}
390
368391// =============================================================================
369392// Tests
370393// =============================================================================
@@ -476,7 +499,7 @@ test "the registered natives name methods the Kotlin actually declares" {
476499 // A descriptor is checked by the JVM at registration, so a wrong one fails
477500 // at load rather than at call — but only if the *name* matches something.
478501 // These two strings are the contract with CraftBridge.kt.
479 try testing.expectEqual(@as(usize, 7), natives.len);
502 try testing.expectEqual(@as(usize, 8), natives.len);
480503 try testing.expectEqualStrings("nativeGetDeviceInfo", std.mem.span(natives[0].name));
481504
482505 // And the class they bind to is the fixed one, not the templated bridge.