Most screen time tools suffer from a fundamental mathematical flaw: they compute total screen exposure by summing independent device scalars rather than calculating the union of overlapping time intervals.
If you spend two hours working on a laptop while occasionally responding to messages on your phone for 30 minutes, standard digital wellbeing trackers report 2 hours and 30 minutes of screen time. Your biological eyes were exposed to displays for exactly 2 hours, with 30 minutes spent in a state of multi-device fragmentation ("second-screening").
To solve this, I built OmniScreen: an open-source, local-first engine for Windows and Android that synchronizes active screen sessions over your local Wi-Fi network and computes the mathematical interval union with zero cloud servers and zero telemetry.
1. The Mathematical Problem: Scalar Sum vs. Interval Union
Every operating system measures screen activity as discrete active sessions:
Session S = [t_start, t_end]
When aggregating screen time across multiple devices, existing digital wellbeing dashboards compute the naive sum:
Raw Exposure = Duration(Device 1) + Duration(Device 2) + ... + Duration(Device N)
When multiple devices are active simultaneously, this naive scalar addition double-counts the overlapping period.
The Correct Formulation: Interval Union
True screen exposure is the measure of the mathematical union of all session intervals across all devices along a single real timeline:
True Exposure = Measure( Union of all [t_start, t_end] across Device 1 .. N )
Where overlapping intervals are merged into continuous spans so that 1 minute of real wall-clock time never counts as more than 1 minute of physical screen exposure.
From this, we derive the exact duration of concurrent multi-screening:
Second-Screening Duration = Raw Exposure - True Exposure
We also compute an Attention Fragmentation Index (or Second-Screening Index, SSI):
Attention Fragmentation Index (SSI) = ( Second-Screening Duration / True Exposure ) * 100%
A high SSI indicates fragmented cognitive attention, where your focus was repeatedly split across multiple glowing displays simultaneously.
2. Implementing the Interval Union in O(N log N)
To compute the interval union efficiently on a low-power local background daemon, we use a sorted sweep-line interval merge algorithm:
def calculate_interval_union(sessions: list[tuple[float, float]]) -> float:
"""
Computes the total non-overlapping duration from a list of [start_ts, end_ts] intervals.
Time Complexity: O(N log N) due to sorting.
Space Complexity: O(N) to store merged intervals.
"""
if not sessions:
return 0.0
# 1. Sort intervals by start timestamp
sorted_intervals = sorted(sessions, key=lambda x: x[0])
merged = []
current_start, current_end = sorted_intervals[0]
for start, end in sorted_intervals[1:]:
if start <= current_end:
# Overlapping or contiguous interval: extend the current boundary
current_end = max(current_end, end)
else:
# Disjoint interval: commit previous interval and advance
merged.append((current_start, current_end))
current_start, current_end = start, end
merged.append((current_start, current_end))
# 2. Sum the durations of disjoint merged intervals
return sum(end - start for start, end in merged)
Running this on thousands of raw session intervals takes less than 2 milliseconds on standard hardware, eliminating CPU overhead on the host machine.
3. System Architecture: Local-First with SQLite WAL
Screen time data is among the most sensitive personal telemetry possible: it records the exact minute you wake up, every application you switch to, and when you go to bed. Storing this on third-party cloud servers poses unacceptable privacy risks.
OmniScreen is architected strictly as a local-first system:
+-------------------------------------------------------------+
| Local Wi-Fi Network |
| |
| +-------------------+ +------------------+ |
| | Android Agent | UDP Probe | Windows PC Hub | |
| | (Kotlin Sensor) | -----------> | (FastAPI+SQLite) | |
| | | <----------- | | |
| | | HTTP Sync | | |
| +-------------------+ +------------------+ |
| | |
| v |
| +--------------+ |
| | SQLite (WAL) | |
| | Local Storage| |
| +--------------+ |
+-------------------------------------------------------------+
The local PC hub uses SQLite with Write-Ahead Logging (WAL) enabled:
conn.execute("PRAGMA journal_mode=WAL")
conn.execute("PRAGMA synchronous=NORMAL")
conn.execute("PRAGMA busy_timeout=15000")
- WAL mode allows concurrent readers (such as the web dashboard querying metrics) while background agent syncs write incoming sessions without locking the database file.
- All administrative and mutating endpoints (
/api/device/delete,/api/device/rename,/api/tv/add) enforce loopback checks (require_localhost), ensuring external network requests cannot modify device records even on an open Wi-Fi network.
4. Native Device Sensors
Windows Win32 Agent
The desktop background agent runs quietly in the Windows System Tray with zero terminal windows:
- Uses
ctypesto call Win32 APIs:GetForegroundWindow(),GetWindowTextW(), andGetWindowThreadProcessId(). - Implements tick-gap detection: rather than assuming continuous usage, the polling loop calculates elapsed wall-clock time between iterations. If the system sleeps, hibernates, or locks, the gap is automatically detected and excluded from active session recording.
Android Companion Sensor
On Android, query polling drains battery. Instead, OmniScreen uses native Kotlin with UsageStatsManager.queryEvents():
- Queries raw OS events (
UsageEvents.Event.ACTIVITY_RESUMEDandUsageEvents.Event.ACTIVITY_PAUSED). - Clamps event boundaries strictly to local midnight (
00:00:00) to prevent multi-day leakage. - Filters out system launchers and navigation overlays, tracking only genuine foreground applications.
5. Local Wi-Fi Auto-Discovery: Eliminating Cloud Relays
To allow the Android app to communicate with the PC hub without requiring static IP configurations or central accounts, OmniScreen implements a dual-discovery protocol:
- UDP Broadcast Auto-Discovery: The Android client broadcasts a lightweight discovery payload over UDP port
8766. The PC hub listens on0.0.0.0:8766and responds with its local LAN IP address and HTTP port (8765). - 1-Tap QR Fallback: The desktop dashboard generates a local QR code encoding
omniscreen://pair?host=<LAN_IP>:8765. Scanning the QR code deep-links directly into the Android app and establishes pairing in less than 2 seconds.
6. Key Takeaways & Open Source
Building OmniScreen reinforced several systems engineering principles:
- Always question basic domain math: The double-counting error in digital wellbeing metrics had existed unchallenged simply because naive summation is easier to compute than interval unions.
- Local-first is performant and viable: Complex multi-device synchronization does not require cloud infrastructure or subscriptions. Local networks and SQLite WAL handle modern workloads effortlessly with zero latency.
- Security through minimal surface area: By refusing external cloud relays, all data remains on your physical hardware under your control.
OmniScreen is 100% free and open source under the GNU General Public License v3.0 (GPL-3.0).
→ GitHub Repository: https://github.com/aditya8242/omniscreen-agent
→ Windows & Android Release: v0.9-beta Releases