$ show NoWakeLock/NoWakeLock
NoWakeLock is a production-grade Android Xposed module and companion app that provides granular control over system power management. It intercepts and selectively blocks or limits WakeLocks, Alarms, and Services at the Android framework level via Xposed hooks, enabling users to reduce battery drain. The system consists of two processes: an Xposed module running in the system_server process that performs the actual interception using both legacy (XposedBridge) and modern (libxposed API 102) APIs, and a standard Android application with a Jetpack Compose UI that allows users to configure per-app and per-item blocking rules, view real-time statistics, and manage settings. Data flows from the Xposed hooks through a ContentProvider-based IPC (XProvider) into a dual Room database architecture (AppDatabase for configuration, InfoDatabase for runtime events). The app features Material Design 3, multi-language support, backup/restore via JSON, multi-user profiles, module health diagnostics, and hot reload support for modern Xposed frameworks. The codebase demonstrates a clean MVVM architecture with Koin dependency injection, Kotlin Coroutines/Flow for reactive data flow, and comprehensive unit/instrumentation tests. While primarily a standalone application, several core concurrency utilities (BoundedEventQueue, ReloadableEventConsumer, WakelockRegistry) could be extracted and reused in other Android or system-level projects.
The LLM identified 4 files worth highlighting for reuse:
A thread-safe, multi-producer single-consumer bounded queue that atomically tracks rejections. The queue has a fixed capacity and a 'retire' mechanism to prevent new offers after shutdown. It uses a ConcurrentLinkedQueue for the internal buffer and AtomicInteger for rejection counting, with a non-blocking offer and a blocking drain. This is a reusable concurrency primitive for event processing pipelines.
A coroutine-based consumer that processes events from a BoundedEventQueue with a configurable timeout. It supports retirement (stop after timeout without processing new events) and resumption. The consumer is designed to be reloadable: it can be stopped and restarted, with the ability to transfer its state (registered wakelocks) across hot reloads. This pattern is useful for any system requiring graceful shutdown and state transfer between generations.
An in-memory registry for tracking active WakeLock instances and computing non-overlapping duration using a union-of-intervals approach. It is thread-safe via ConcurrentHashMap and supports state transfer (snapshot/restore) for hot reload scenarios. The registry handles acquire/release events, calculates total time across overlapping periods, and emits duration updates. This component demonstrates a practical approach to interval arithmetic and multi-threaded state management.
A data class hierarchy and serialization logic for exporting/importing app configuration as JSON using kotlinx.serialization. It defines backup structures for app info, blocking rules, and user preferences. The design is self-contained and could be adapted to any Android app needing JSON-based backup/restore of Room entities with proper schema versioning and migration.