Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
The side button wakes the display without Siri's sheet coming up
vcvkk63200d74e666
diff --git a/userland/src/inject.c b/userland/src/inject.cindex f579a19..b2fb082 100644--- a/userland/src/inject.c+++ b/userland/src/inject.c@@ -32,6 +32,7 @@#include <errno.h>#include <fcntl.h>#include <mach/mach.h>+#include <notify.h>#include <objc/runtime.h>#include <pthread.h>#include <stdarg.h>@@ -563,6 +564,23 @@ send_touch(IOHIDServiceClientRef screen, const struct redwood_touch *t)CFRelease(hand);}+/*+ * Whether the side button is held right now, for our code in SpringBoard (inject_sb.c,+ * lock_long_press()): kept as the state of a Darwin notification, 2 = held, 1 = released+ * (0, what a name nobody has set says, = not known), and set before the event is sent.+ */+static void+publish_lock_button(bool down)+{+ static int token = NOTIFY_TOKEN_INVALID;++ if (token == NOTIFY_TOKEN_INVALID && notify_register_check("com.redwood.button.lock", &token) != NOTIFY_STATUS_OK) {+ token = NOTIFY_TOKEN_INVALID;+ return;+ }+ notify_set_state(token, down ? 2 : 1);+}+static voidsend_button(IOHIDServiceClientRef buttons, const struct redwood_touch *t){@@ -574,6 +592,9 @@ send_button(IOHIDServiceClientRef buttons, const struct redwood_touch *t)if (usage == 0) {return;}+ if (t->finger == REDWOOD_BUTTON_LOCK) {+ publish_lock_button(t->type == REDWOOD_BUTTON_DOWN);+ }event = IOHIDEventCreateKeyboardEvent(NULL, t->time, HID_PAGE_CONSUMER, usage, t->type == REDWOOD_BUTTON_DOWN, 0);IOHIDEventSetIntegerValue(event, FIELD_IS_BUILT_IN, 1);IOHIDVirtualServiceClientDispatchEvent(buttons, event);diff --git a/userland/src/inject_sb.c b/userland/src/inject_sb.cindex b0c5f6f..a6fdf31 100644--- a/userland/src/inject_sb.c+++ b/userland/src/inject_sb.c@@ -18,6 +18,8 @@* - The picture SpringBoard keeps of an application that leaves the screen (for the application* switcher and the next launch) is saved as JPEG or PNG, not as an ASTC texture: see* snapshot_output_format().+ * - A press of the side button that is long over is not taken for a long press (Siri) because+ * SpringBoard was busy waking the display: see lock_long_press().* - Darwin notifications as a remote control, for scripts (rwtouch notify NAME):* com.redwood.unlock what the lock screen does after "swipe up to open"*/@@ -27,6 +29,7 @@#include <objc/message.h>#include <objc/runtime.h>#include <stdarg.h>+#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>@@ -138,6 +141,61 @@ snapshot_output_format(__unused id self, __unused SEL selector, id snapshot)return SNAPSHOT_FORMAT_PNG;}+/*+ * -[SBLockHardwareButton longPress:] is what the side button's long press recognizer calls: Siri+ * (here, its "turn on Siri" sheet, nobody having turned it on). The recognizer is a timer of+ * SpringBoard's own: started when the main thread sees the press, stopped when it sees the release+ * -- and a release it has not got round to is no release. A press of the side button with the+ * display off wakes the display from inside the handling of that very press, which on an iPhone+ * takes no time. Here it takes as long as the software renderer needs for the first picture of the+ * lock screen: a tenth of a second on the phone, a second under QEMU. That is longer than a long+ * press, so there every wake by the button (and by a tap, which is a press of that button made in+ * inject.c) ended with Siri's sheet over the lock screen, however short the press had been.+ * Where the button's events come from -- inject.c, in backboardd -- it is known whether the button+ * is still held; a long press of a button that is not is dropped here.+ */+#define GESTURE_BEGAN 1 /* UIGestureRecognizerState */+#define GESTURE_ENDED 3 /* and cancelled, failed after it */++static void (*original_lock_long_press)(id self, SEL selector, id recognizer);++static bool+lock_button_held(void)+{+ static int token = NOTIFY_TOKEN_INVALID;+ uint64_t state = 0;++ if (token == NOTIFY_TOKEN_INVALID && notify_register_check("com.redwood.button.lock", &token) != NOTIFY_STATUS_OK) {+ token = NOTIFY_TOKEN_INVALID;+ return true;+ }+ /* 1 = released; held, or not known: as SpringBoard has it */+ return notify_get_state(token, &state) != NOTIFY_STATUS_OK || state != 1;+}++static void+lock_long_press(id self, SEL selector, id recognizer)+{+ static bool dropping;+ SEL state_selector = sel_registerName("state");+ long state = recognizer != NULL && class_getInstanceMethod(object_getClass(recognizer), state_selector) != NULL ?+ ((long (*)(id, SEL))objc_msgSend)(recognizer, state_selector) : 0;++ if (state == GESTURE_BEGAN) {+ dropping = !lock_button_held();+ if (dropping) {+ say("redwood: SpringBoard: a long press of the side button, which was released long ago: dropped\n");+ }+ }+ if (dropping) {+ if (state >= GESTURE_ENDED) {+ dropping = false;+ }+ return;+ }+ original_lock_long_press(self, selector, recognizer);+}+/* ---- remote control ------------------------------------------------------------------------------ */#define UNLOCK_SOURCE_COVER_SHEET 24 /* what the lock screen itself passes */@@ -185,9 +243,11 @@ redwood_springboard_init(void)"_setSetupRequiredReason:", 0x1c4cdd3a4UL, (IMP)set_setup_required_reason);snapshot_format = replace_method_of_kind('+', "XBApplicationSnapshotManifestImpl", "_outputFormatForSnapshot:",0x1f1c91480UL, (IMP)snapshot_output_format);- say("redwood: SpringBoard: activation %s, setup assistant %s, application snapshots %s\n",+ original_lock_long_press = (void (*)(id, SEL, id))replace_method("SBLockHardwareButton", "longPress:", 0x1c4f6ab44UL,+ (IMP)lock_long_press);+ say("redwood: SpringBoard: activation %s, setup assistant %s, application snapshots %s, the side button's long press %s\n",activation ? "answered here" : "NOT replaced", original_set_setup_required_reason ? "refused" : "NOT replaced",- snapshot_format ? "as JPEG" : "NOT changed");+ snapshot_format ? "as JPEG" : "NOT changed", original_lock_long_press ? "checked" : "NOT checked");{char args[1024] = "";size_t size = sizeof(args) - 1;