2.3 KiB
EPG stale-cleanup implementation
Exact target and lifecycle
The stock target is channels.apk!/classes4.dex,
Lorg/droidtv/channels/epg/bcepg/EpgProvider$deleteStaleDataRunnable;->run()V
at code_off=0xe298c. The Runnable executes under the provider monitor, reads
the Philips TV clock, calculates and logs a cutoff, but never calls a delete,
batch, applyBatch, or SQLite mutation. The production integration must move
the potentially long legacy cleanup outside that provider-wide monitor and
serialize it with EPG acquisition writes.
Unit contract and retention
The clock API returns epoch milliseconds. Physical scheduletable.starttime
and endtime values are epoch seconds, proven from both the historic and
reacquired databases. Therefore the only supported conversion is:
long nowMillis = clock.currentTimeMillis();
long cutoffSeconds = TimeUnit.MILLISECONDS.toSeconds(nowMillis)
- TimeUnit.DAYS.toSeconds(7);
Seven past days preserve backward-guide behavior while all future rows remain.
The first fix intentionally touches only scheduletable; Now/Next are tiny and
FVP expiry semantics require separate product tests.
Database operation
Use scheduletable(endtime) for the ordered candidate scan. Each non-exclusive
transaction removes at most 2,000 IDs selected by endtime, _id, commits, then
yields briefly. Abort cleanly on interruption or sustained busy/IO failure.
Log the unit, cutoff, batch count, rows, elapsed time, DB size, and error class.
Schedule one daily maintenance invocation with unique/KEEP semantics.
SQLite journaling makes each batch atomic; an interrupted run merely resumes
at the next oldest row. The predicate is idempotent. The stock database has
auto_vacuum=FULL, so continuous small retention also returns tail pages
without a separate VACUUM.
Deliverables and evidence
PATCH.diff: source-level production specification.SMALI-PATCH.md: exact DEX boundary and integration constraints.tools/epg_retention.py: guarded offline reference implementation.tools/test_epg_retention.py: synthetic regression harness.TEST-RESULTS.md: complete old-snapshot result.
This is not a signed APK. Philips source or a controlled smali/DEX rebuild, platform signing, ART/preopt handling, and a recoverable image path are still required for firmware deployment.