Skip to content

Comprehensive codebase improvements based on multi-agent code review - #115

Merged
zfdang merged 10 commits into
masterfrom
improve/systematic-code-review-fixes
Oct 19, 2026
Merged

zfdang merged 10 commits into
masterfrom
improve/systematic-code-review-fixes

Conversation

@zfdang

@zfdang zfdang commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Summary of Improvements

This PR delivers a comprehensive, systematic overhaul of the codebase across accessibility core, concurrency and thread safety, UI lifecycle & memory management, security & OS compatibility, and unit test coverage based on the multi-agent code review findings.

Each issue is resolved in an individual, atomic commit:

1. Build Configuration, Resources & Signing Security (4cb8775)

  • Preserve Pinyin4j Resource: Removed resources { excludes += ['pinyindb/*'] } from app/build.gradle so the dictionary database is bundled in release APKs, fixing silent failure in pinyin sorting.
  • Secure Keystore & Credentials: Keystore and passwords are now loaded strictly from environment variables or local.properties, removing plaintext secrets from gradle.properties.
  • R8 / ProGuard Keep Rules: Added retain rules in proguard-rules.pro for line number attributes, serializable data models, and pinyin4j.

2. Privacy Disclosure & Accessibility Configuration (00eb172)

  • Affirmative User Consent: Added mSetting.isDisclosureAccepted() gate in resumeSkipAdAfterWakeup() and startSkipAdProcess() so the background service remains idle after device reboot/wake until the user agrees to the in-app disclosure.
  • Accessibility Service Config: Updated accessibility_service_config.xml feedback type to feedbackGeneric and removed unused flagRetrieveInteractiveWindows.

3. Accessibility Node Recycling & Overlay IPC Optimization (f13219f)

  • Binder Token Recycling: Wrapped all node traversal in findAllNode() and dumpChildNodes() in try-finally blocks that guarantee every AccessibilityNodeInfo is recycled immediately after extraction.
  • Precomputed Node Outlines: Introduced NodeOutlineData to cache node bounds, area, and metadata in Java heap memory. Sorting outlines no longer invokes native Binder roundtrips on every comparison.
  • Gated Verbose Logging: Debug-level window dump logs are protected by if (BuildConfig.DEBUG).

4. BroadcastReceivers & Package Scheme Registration (95ac160)

  • Data Scheme Filter: Added actions.addDataScheme("package") to PackageChangeReceiver's filter so Android OS forwards package addition and removal events properly.
  • Export Flag for API 33+: Explicitly registered dynamic receivers with ContextCompat.RECEIVER_EXPORTED.
  • Include Custom-Ruled Apps: Augmented target package checking to inspect configured widgets and positions, ensuring non-launcher apps with custom rules are triggered.

5. Settings Concurrency & Defensive Copying (7655dd4)

  • Thread-Safe Settings Singleton: Added double-checked locking lazy initialization for Settings.getInstance().
  • Defensive Copying & Synchronization: Synchronized getters and setters for rule collections and returned unmodifiable/defensive deep copies.
  • Corrupted JSON Resilience: Added robust exception handling during JSON deserialization to fall back safely to empty collections instead of crashing or leaking partial state.
  • Volatile Field Flags: Marked notification and duration preferences volatile.

6. Robust Rule Matching & Model Hardening (286b582)

  • Model Equality & Copying: Implemented robust equals(), hashCode(), toString(), and null-safe copy constructors in PackagePositionDescription and PackageWidgetDescription.
  • Position Future Management: Tracked scheduled position click retry tasks via positionClickFuture and cancelled them upon process reset.
  • Case-Insensitive & Unicode Matching: Enhanced SkipAdRules.parseKeywords() with Unicode whitespace regex ((?U)\\s+), added case-insensitive matching, and stripped zero-width characters (e.g. \u200B, \uFEFF).
  • Non-Empty Bounds Validation: Guaranteed that rules with empty bounds (0,0,0,0) do not match offscreen nodes at (0,0,0,0).

7. Clipboard, Overlay & Dialog Lifecycle Safety (e3eb293)

  • Safe Clipboard Pasting: Used clipData.getItemAt(0).coerceToText(context) with null and item count checks.
  • Android 13+ Clipboard Toast: Suppressed custom copy toast on Android 13+ (TIRAMISU) to prevent system duplicate toast notifications.
  • Isolated Overlay Removal: Handled view removal in isolated try-catch blocks with isAttachedToWindow() checks.
  • Saved State Preservation: Avoided overwriting edited rules across configuration/rotation changes.
  • Service Notification: Dispatched ACTION_REFRESH_CUSTOMIZED_ACTIVITY after saving rules.

8. UI Memory Leak Prevention & MVVM Architecture (141cd08)

  • Dialog Leak Prevention: Retained whitelistDialog instance and safely dismissed it in SettingsFragment.onDestroyView().
  • Cleaned Layouts: Removed dead fragment_settings.xml and bottom padding reflection hack.
  • Clean Preference Pruning: Replaced manual iterative pruning with retainAll().
  • MVVM Encapsulation: Encapsulated MutableLiveData within HomeViewModel and exposed read-only LiveData, moving service status refreshing logic into the ViewModel.
  • Accessibility Attributes: Added missing android:contentDescription to action buttons and status icons.

9. Comprehensive Unit Test Coverage (d1dc434)

  • Added PackagePositionDescriptionTest verifying constructors, equality, hash code, and string representation.
  • Added SettingsTest under Robolectric testing singleton isolation, defensive copying, JSON corruption handling, and preferences persistence.
  • Expanded SkipAdRulesTest with Unicode ideographic space parsing, case insensitivity, zero-width evasion characters, and empty bounds filtering.

Verification

  • Ran ./gradlew assembleDebug (Passed).
  • Ran ./gradlew testDebugUnitTest (All passed).
  • Ran ./gradlew test (Debug and Release test suites passed: 53 tasks executed/up-to-date, 0 failures).

@zfdang
zfdang merged commit 9974e45 into master Oct 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant