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
Merge branch 'buttons'
vcvkkefd464a4dd07
diff --cc userland/src/inject_sb.cindex 9ccd101,a6fdf31..0d76729--- a/userland/src/inject_sb.c+++ b/userland/src/inject_sb.c@@@ -18,14 -18,12 +18,16 @@@* - 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().+ * - Where CoreAnimation draws with its software renderer (QEMU; the phone without gpu=1) the+ * "vibrant" views draw their content as it is: see plain_vibrancy().+ * - 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"+ * com.redwood.layers write down the layers SpringBoard has on the screen: see layers()*/#include <CoreFoundation/CoreFoundation.h>+#include <IOKit/IOKitLib.h>#include <dispatch/dispatch.h>#include <notify.h>#include <objc/message.h>@@@ -142,58 -141,61 +145,115 @@@ snapshot_output_format(__unused id selfreturn SNAPSHOT_FORMAT_PNG;}+/* ---- the lock screen's clock without a GPU ------------------------------------------------------- */++#define REDWOOD_GL "/redwood/lib/libredwood-gl.dylib"++/* Does the window server draw with OpenGL ES? The same question, asked the same way, as opengl_es() in inject.c. */+static bool+gpu_draws(void)+{+ char arguments[1024] = "";+ size_t size = sizeof(arguments) - 1;+ const char *argument;+ io_service_t gpu;++ if (access(REDWOOD_GL, R_OK) != 0) {+ return false;+ }+ if (sysctlbyname("kern.bootargs", arguments, &size, NULL, 0) == 0) {+ for (argument = arguments; (argument = strstr(argument, "gl=")) != NULL; argument += 3) {+ if (argument == arguments || argument[-1] == ' ') {+ return argument[3] != '0';+ }+ }+ }+ gpu = IOServiceGetMatchingService(0, IOServiceMatching("RedwoodGPU"));+ if (gpu != 0) {+ IOObjectRelease(gpu);+ }+ return gpu != 0;+}++/*+ * The clock of the lock screen is a "vibrant" view (BSUIVibrancyEffectView in BaseBoardUI): its+ * digits are not drawn, they are a mask -- a copy of them through a colour matrix that keeps red+ * as alpha -- through which the filter vibrantColorMatrix lets the wallpaper behind come out+ * lighter; and a gradient over the whole screen, red at the top, tones the wallpaper down the+ * same way. On the GPU that is what is seen (eagl.c draws the two filters). CoreAnimation's+ * software renderer shows neither: the digits come out red, and the top of the wallpaper as it+ * was. Why was not found out; that renderer is in QuartzCore, not here.+ * Such views have a switch, the user default BSUIVibrancyEffectViewDisabled: with it they show+ * their content as it is drawn, the clock in plain white. It is set for this run of SpringBoard+ * alone (nothing is written), and only where the software renderer draws.+ */+static void+plain_vibrancy(void)+{+ if (gpu_draws()) {+ return;+ }+ CFPreferencesSetAppValue(CFSTR("BSUIVibrancyEffectViewDisabled"), kCFBooleanTrue, kCFPreferencesCurrentApplication);+ say("redwood: SpringBoard: no GPU draws, vibrant views are plain (the lock screen's clock is white)\n");+}+++/* ---- the side button's long press ---------------------------------------------------------------- */+++ /*+ * -[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 */@@@ -388,10 -243,11 +448,12 @@@ redwood_springboard_init(void"_setSetupRequiredReason:", 0x1c4cdd3a4UL, (IMP)set_setup_required_reason);snapshot_format = replace_method_of_kind('+', "XBApplicationSnapshotManifestImpl", "_outputFormatForSnapshot:",0x1f1c91480UL, (IMP)snapshot_output_format);+ plain_vibrancy();- 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;