fix: make extension hooks fail safe and tidy Midas Settings, AssetLogger and Markdown helpers #114

Closed
midas wants to merge 0 commits from review/extension-safety into dev
Owner

Part of #105, fixes #91, #98, #99 and #101.

  • #99: removes the never-applied overviewComponentFilterPatch, its fingerprint and the empty filter array.
  • #91: every extension hook entry point has an outer catch (Throwable) that logs and returns the app's original value (incl. filterFeedTeasers, SettingsMenuPatch.handleClick, Crashlytics/FIAM/onboarding hooks, Force HD, the settings launcher); pattern documented in AGENTS.md; redundant dependsOn(sharedExtensionPatch) removed where midasSettingsPatch already brings it.
  • #98: isApplied caches only a successful read; a missing asset is cached as empty, other failures retry at most every 2 s; the reflective Application lookup is cached; DayNight theme only on API 29+; restart kills the process 300 ms after finish().
  • #101: AssetLogger logs only the DRM type, strips query/fragment/user info and token-like path segments, 64-entry LRU dedupe; GregorianCalendar in ArticleDates (th_TH test); ~~ and entity-starting & escaped; no links in image alt text; cached resource ids; icon resource names cross-checked by a test.

Verified: unit tests (all green), buildAndroid, Applied on de Volkskrant 7.53.1 (13), Tubantia 9.22.0 (15), Videoland 1.115.2 (Hide ads, Force HD, Log video assets). Not verified: settings screen on API 26 and the Kubus icon tint in dark mode (device needed).

🤖 Generated with Claude Code

Part of #105, fixes #91, #98, #99 and #101. - #99: removes the never-applied `overviewComponentFilterPatch`, its fingerprint and the empty filter array. - #91: every extension hook entry point has an outer `catch (Throwable)` that logs and returns the app's original value (incl. `filterFeedTeasers`, `SettingsMenuPatch.handleClick`, Crashlytics/FIAM/onboarding hooks, Force HD, the settings launcher); pattern documented in AGENTS.md; redundant `dependsOn(sharedExtensionPatch)` removed where `midasSettingsPatch` already brings it. - #98: `isApplied` caches only a successful read; a missing asset is cached as empty, other failures retry at most every 2 s; the reflective Application lookup is cached; DayNight theme only on API 29+; restart kills the process 300 ms after `finish()`. - #101: AssetLogger logs only the DRM type, strips query/fragment/user info and token-like path segments, 64-entry LRU dedupe; `GregorianCalendar` in `ArticleDates` (th_TH test); `~~` and entity-starting `&` escaped; no links in image alt text; cached resource ids; icon resource names cross-checked by a test. Verified: unit tests (all green), `buildAndroid`, Applied on de Volkskrant 7.53.1 (13), Tubantia 9.22.0 (15), Videoland 1.115.2 (Hide ads, Force HD, Log video assets). Not verified: settings screen on API 26 and the Kubus icon tint in dark mode (device needed). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
overviewComponentFilterPatch was never a dependency of any patch and
OVERVIEW_COMPONENT_FILTERS was empty, so the hook and its fingerprint
never ran and could go stale unnoticed. Remove the patch, the
OverviewComponentToViewData fingerprint, filterOverviewComponent and
the empty array; docs/apps/volkskrant.md notes the removal.

Refs #99

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Wrap the whole body of every hook entry point that smali calls in
try/catch (Throwable), log it under the Midas tag and return the
original input or the "do nothing" result. Previously unguarded:
GelderlanderContentFilters.filterFeedTeasers and
shouldDropArticleComponent (a model constructor and the article
mapper), the Volkskrant ContentFilters hooks, Videoland
SettingsMenuPatch.handleClick and ForceHdPatch, DisableCrashlyticsPatch,
HideInAppMessagesPatch, HideOnboardingPopupsPatch,
MidasSettingsLauncher.handleUrl and AssetLogger.onPlayerParameters.

Unit tests prove filterFeedTeasers and filterArticleBlocks return the
input unchanged when reading the list throws. AGENTS.md documents the
pattern. Also drop the redundant dependsOn(sharedExtensionPatch) from
patches that already depend on midasSettingsPatch, which depends on it.

Refs #91

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MidasSettings.isApplied cached an empty key set after a failed asset
read, silently switching off every filter that relies on isActive()
for the rest of the process. It now caches only after a successful
read and retries on the next call; the failure is logged once. The
reflective ActivityThread.currentApplication lookup is resolved once,
the Application is kept, and the "no context" warning is logged at
most once. A unit test covers the retry (org.json is added for tests,
as the android.jar one only returns defaults).

MidasSettingsActivity used Theme_DeviceDefault_DayNight (API 29)
without a guard, on apps with minSdk 24; before API 29 it now uses
Theme_DeviceDefault_Light, which defines the text and accent
attributes the screen reads. The restart button starts the launch
intent, finishes the activity and kills the process after 300 ms, so
the launch request is not lost. Not verified on an API 26 device.

Refs #98

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
AssetLogger: of an asset's Drm only the type (HARDWARE/SOFTWARE/UNKNOWN)
is logged, never the DrmConfig (customer, service and content ids);
URLs lose query, fragment, user info and token-like path segments; the
dedupe set is a 64-entry LRU; onPick logs the number of candidates and
the pick instead of dumping every candidate (onAsset already logs each
one, onPicked the picked one).

Markdown: escape runs of ~~ and an & that starts an entity reference, so
HTML "&amp;copy;" stays the text "&copy;" and is not decoded a second
time by the renderer; image alt text keeps link text but not the
[text](url) syntax; the icon's resource ids are looked up once. The two
resource names that patch and extension both spell out are now checked
against each other by MarkdownIconNamesTest.

ArticleDates uses new GregorianCalendar(tz) instead of
Calendar.getInstance(tz), which gave a Buddhist or imperial year under
th_TH or ja_JP_JP defaults (ArticleDatesLocaleTest).

The icon's dark-mode tint on Kubus is not verified (needs a device);
noted in docs/apps/gelderlander.md.

Refs #101

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix: cache a missing Midas Settings asset and throttle read retries
All checks were successful
CI / Build (pull_request) Successful in 1m14s
f437358c44
isApplied runs for every filtered feed item and article block. A
missing midas_settings.json (extension merged, midasSettingsPatch not
applied) is permanent, so FileNotFoundException now caches an empty key
set after one warning instead of failing an AssetManager.open per item.
Other failed reads (IOException, bad JSON) still retry, but at most
once every 2 seconds; a missing application context stays unthrottled
as it costs nothing. The clock is a package-private seam so the tests
control time.

Refs #98

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
midas closed this pull request 2026-10-17 16:42:00 +02:00
All checks were successful
CI / Build (pull_request) Successful in 1m14s
Required
Details

Pull request closed

Sign in to join this conversation.
No description provided.