How snowcat6/kernelgesture works
Project Type and Purpose
• This is an Android application (“KernelGesture”) that uses native C/C++ code (via the NDK) plus Kotlin/Java layers to listen for low-level gesture events from the Linux kernel and trigger user-defined actions (e.g., flashlight toggle, launching apps, speech notifications).
• The README confirms it integrates with custom kernels/drivers to detect wake-up gestures and maps them to actions on the device.
File Structure
• Top-level “app” module holds all Android code:
• src/main/java – Kotlin/Java classes for UI, background service, drivers abstraction, gesture detectors, and action implementations.
• src/main/cpp & jni – native C event-reader code, Android.mk/Application.mk build scripts, plus Python helper script for labeling input devices.
• JNI libs under jniLibs for prebuilt architectures (arm64, armeabi, x86, x86_64).
• res/ & AndroidManifest.xml – layouts, menus, XML prefs, etc.
• build.gradle, proguard-rules.pro, gradle wrapper files for build config.
• There’s also a top-level “AndroidKernelCompile” folder for kernel compilation scripts.
Key Insights from README
• The app runs a background GestureService, reads raw events (via native library), and depending on kernel support, recognizes gestures to wake/unlock or perform custom actions.
• It supports customizing kernels by injecting its gesture-recognition code.
Main Components & Relationships
a. Android UI Layer
• SettingsActivity & PreferenceFragment for user to configure gestures → stored in SharedPreferences.
• Detect Activities for calibration/detection tests.
b. Background Service & Gesture Engine
• GestureService (Kotlin) runs on boot, binds to native layer.
• RxInputReader / UnpackEventReader manage reactive stream of input events.
c. JNI / Native Bridge
• EventReader.c reads /dev/input events via ioctl or read.
• JNI exports methods to start/stop event capture, passing data to Java via JNI callbacks.
d. Gesture Detection
• Detector classes (InputDetector, EventDetector, DetectModelView) implement pattern recognition on event streams.
e. Action Dispatcher
• ActionItem hierarchy (flashlight, camera, apps, speech, screen on/off, unlock, music) implements Command pattern.
• ShellSU utility invokes commands with root privileges if needed.
f. Kernel & Hardware
• Underlying Linux kernel drivers (touchscreen, proximity, custom gesture modules) generate input events.
g. Auxiliary Tools
• Python “generate-input.h-labels.py” maps device codes to human-readable names for debugging.
• KernelCompile scripts to build custom kernel with gesture support.
Architectural Patterns & Technologies
• Event-driven, reactive pipeline using RxJava-like constructs in RxInputReader and RxScreenOn.
• Command pattern for action handlers.
• JNI bridging between C-level event reader and Kotlin layer.
• MV(P) for UI preference screens.