Skip to content

Code cleanup, threading fixes, and deprecation removal - #7

Merged
hatsch merged 7 commits into
mainfrom
cleanup-and-improve
Feb 4, 2026
Merged

hatsch merged 7 commits into
mainfrom
cleanup-and-improve

Conversation

@hatsch

@hatsch hatsch commented Feb 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix threading and resource management issues across services
  • Remove deprecated API usage and resolve all compiler warnings
  • Improve async handling and robustness

Changes

Threading & Concurrency

  • Use AtomicBoolean for isRecording flag in FloatingMicService and TextInjectionService
  • Add @Volatile to TextInjectionService.instance for thread visibility
  • Use CopyOnWriteArrayList for fileObservers in AudioMonitorService
  • Fix mutex scope issues in services

Deprecation Fixes

  • Replace deprecated onBackPressed() with OnBackPressedDispatcher in VoiceInputActivity
  • Remove deprecated AccessibilityNodeInfo.recycle() and obtain() calls (auto-managed since API 26)
  • Add explicit ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE for Android 14+
  • Replace Handler.postDelayed with coroutine delay()

Other Improvements

  • Fix async/timeout issues in model initialization
  • Dismiss audio detected notification when closing transcription popup
  • Remove non-functional language setting
  • Properly cancel debounceJob in AudioMonitorService cleanup

hatsch and others added 7 commits February 4, 2026 16:03
Co-Authored-By: Claude <noreply@anthropic.com>
- FloatingMicService: Replace runBlocking with async position loading
- SpeechRecognitionService: Add 10s timeout to model init, fix callback timing
- VoiceInputMethodService: Remove recursive startRecording, add init timeout
- TranscribeActivity: Add configChanges to preserve state on rotation
- AudioMonitorService: Use DEBOUNCE_MS constant, add file validation
- BootReceiver: Add timeout to DataStore reads
- RecognizerManager: Replace manual timeout loop with withTimeoutOrNull
- Theme: Use safe Activity cast to prevent preview crash

Co-Authored-By: Claude <noreply@anthropic.com>
The Parakeet TDT model auto-detects language regardless of user selection.
Remove the unused language preference UI and code:

- Remove LanguageSettingItem from Settings UI
- Remove preferredLanguage flow and related methods from SettingsRepository
- Remove languageCode parameter from transcribe() methods
- Remove setting_language strings from all locale files

Co-Authored-By: Claude <noreply@anthropic.com>
- AudioRecorder: Use AtomicBoolean for thread-safe isRecording flag
- TextInjectionService/FloatingMicService: Fix mutex scope for audioRecorder
- TextInjectionService: Add try-finally to prevent AccessibilityNodeInfo leaks
- ModelManager: Use response.use{} to prevent HTTP connection leaks
- RecognizerManager: Move isLoading check inside mutex to prevent race
- BootReceiver: Use runBlocking to ensure pendingResult.finish() is called
- AudioMonitorService: Stop old observers before starting new ones
- DictionaryManager: Cache compiled regex patterns for performance

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
- Replace deprecated onBackPressed with OnBackPressedDispatcher in VoiceInputActivity
- Add ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE for Android 14+ in FloatingMicService
- Use AtomicBoolean for isRecording flag in FloatingMicService and TextInjectionService
- Add @volatile to TextInjectionService.instance for thread visibility
- Replace Handler.postDelayed with coroutine delay in TextInjectionService
- Use CopyOnWriteArrayList for fileObservers in AudioMonitorService
- Cancel debounceJob in AudioMonitorService.stopMonitoring()

Co-Authored-By: Claude <noreply@anthropic.com>
Android 26+ automatically manages AccessibilityNodeInfo lifecycle,
making manual recycle() and obtain() calls unnecessary.

Co-Authored-By: Claude <noreply@anthropic.com>
@hatsch
hatsch merged commit c94ff71 into main Feb 4, 2026
2 checks passed
@hatsch
hatsch deleted the cleanup-and-improve branch February 4, 2026 19:29
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