also looking at this
feat(android): setKeepAwake through the trampoline — ratchet 70 → 69
#174
7 files
+140
-13
| @@ -52,7 +52,7 @@ const shareditem = ; | ||
| 52 | 52 | const contacts = ; |
| 53 | 53 | const widgets = ; |
| 54 | 54 | const shortcuts = ; |
| 55 | const orientation = ; | |
| 55 | const screen = ; | |
| 56 | 56 | const main_thread = ; |
| 57 | 57 | |
| 58 | 58 | const Jni = jni.Jni; |
| @@ -342,6 +342,11 @@ const natives = [_]jni.JNINativeMethod{ | ||
| 342 | 342 | .signature = "(Landroid/app/Activity;)Z", |
| 343 | 343 | .fnPtr = @ptrCast(&nativeUnlockOrientation), |
| 344 | 344 | }, |
| 345 | .{ | |
| 346 | .name = "nativeSetKeepAwake", | |
| 347 | .signature = "(Landroid/app/Activity;Z)Z", | |
| 348 | .fnPtr = @ptrCast(&nativeSetKeepAwake), | |
| 349 | }, | |
| 345 | 350 | }; |
| 346 | 351 | |
| 347 | 352 | /// How binding went. A value rather than a log line, so every path is |
| @@ -1354,7 +1359,7 @@ fn nativeLockOrientation( | ||
| 1354 | 1359 | |
| 1355 | 1360 | const text = j.stringToUtf8(arena.allocator(), name) catch return jni.JNI_FALSE; |
| 1356 | 1361 | |
| 1357 | orientation.apply(j, activity, orientation.modeFor(text)) catch |err| { | |
| 1362 | screen.apply(j, activity, screen.modeFor(text)) catch |err| { | |
| 1358 | 1363 | std.log.warn("craft: lockOrientation fell through to the shim ({s})", .{@errorName(err)}); |
| 1359 | 1364 | return jni.JNI_FALSE; |
| 1360 | 1365 | }; |
| @@ -1369,13 +1374,33 @@ fn nativeUnlockOrientation( | ||
| 1369 | 1374 | ) callconv(.c) jni.jboolean { |
| 1370 | 1375 | const j = Jni.init(env); |
| 1371 | 1376 | |
| 1372 | orientation.apply(j, activity, .unspecified) catch |err| { | |
| 1377 | screen.apply(j, activity, .unspecified) catch |err| { | |
| 1373 | 1378 | std.log.warn("craft: unlockOrientation fell through to the shim ({s})", .{@errorName(err)}); |
| 1374 | 1379 | return jni.JNI_FALSE; |
| 1375 | 1380 | }; |
| 1376 | 1381 | return jni.JNI_TRUE; |
| 1377 | 1382 | } |
| 1378 | 1383 | |
| 1384 | /// `nativeSetKeepAwake(activity, enabled)`. | |
| 1385 | /// | |
| 1386 | /// Safe to serve where the flashlight pair is not: the shim's block ends | |
| 1387 | /// `isKeepingAwake = enabled`, and nothing in `CraftBridge.kt` ever reads that | |
| 1388 | /// field — so the Kotlin body not running leaves nothing stale behind. | |
| 1389 | fn nativeSetKeepAwake( | |
| 1390 | env: jni.JNIEnv, | |
| 1391 | _: jni.jobject, | |
| 1392 | activity: jni.jobject, | |
| 1393 | enabled: jni.jboolean, | |
| 1394 | ) callconv(.c) jni.jboolean { | |
| 1395 | const j = Jni.init(env); | |
| 1396 | ||
| 1397 | screen.keepAwake(j, activity, enabled != jni.JNI_FALSE) catch |err| { | |
| 1398 | std.log.warn("craft: setKeepAwake fell through to the shim ({s})", .{@errorName(err)}); | |
| 1399 | return jni.JNI_FALSE; | |
| 1400 | }; | |
| 1401 | return jni.JNI_TRUE; | |
| 1402 | } | |
| 1403 | ||
| 1379 | 1404 | // ============================================================================= |
| 1380 | 1405 | // Tests |
| 1381 | 1406 | // ============================================================================= |
| @@ -1487,7 +1512,7 @@ test "the registered natives name methods the Kotlin actually declares" { | ||
| 1487 | 1512 | // A descriptor is checked by the JVM at registration, so a wrong one fails |
| 1488 | 1513 | // at load rather than at call — but only if the *name* matches something. |
| 1489 | 1514 | // These two strings are the contract with CraftBridge.kt. |
| 1490 | try testing.expectEqual(@as(usize, 34), natives.len); | |
| 1515 | try testing.expectEqual(@as(usize, 35), natives.len); | |
| 1491 | 1516 | try testing.expectEqualStrings("nativeGetDeviceInfo", std.mem.span(natives[0].name)); |
| 1492 | 1517 | |
| 1493 | 1518 | // And the class they bind to is the fixed one, not the templated bridge. |