Skip to content

feat: fix critical bugs, optimize AppBlockerService battery usage, and add AI validation selector#30

Open
Afrasyaab-GH wants to merge 5 commits into
QuestPhone:mainfrom
Afrasyaab-GH:clean-pr
Open

feat: fix critical bugs, optimize AppBlockerService battery usage, and add AI validation selector#30
Afrasyaab-GH wants to merge 5 commits into
QuestPhone:mainfrom
Afrasyaab-GH:clean-pr

Conversation

@Afrasyaab-GH

@Afrasyaab-GH Afrasyaab-GH commented Jul 10, 2026

Copy link
Copy Markdown

Hi there! This Pull Request resolves several critical bugs in the navigation and sync layers, optimizes background service performance to prevent battery drain, resolves Android 14+ foreground service crashes, and introduces a unified AI Validation Engine settings configuration screen.


🛠️ Changes Made

1. Android 14+ Foreground Service Crash Fixes (New)

  • AppBlockerService Type Update: Changed the service type from dataSync to specialUse (with subtype app_blocking_and_screentime_restrictions in the manifest). This prevents the strict 24-hour runtime exhaustion limit on Android 14+ (which was throwing ForegroundServiceStartNotAllowedException).
  • Background Start Safety: Wrapped all startForegroundService invocations in try-catch blocks across MainActivity, DeepFocusQuestView, OnboardingScreen, and AppListViewModel to safely handle background start restrictions without crashing.

2. Navigation & Sync Bug Fixes

  • Route Typo in RootRoute.kt: Corrected ShowTutorials route string from "showTutorial{/" to "showTutorial/" to prevent navigation crashes.
  • MainActivity Sync Parallelization: Wrapped unSyncedQuestItems and unSyncedStatsItems collections in separate launch coroutine builders so they execute in parallel. Stats are now successfully synced without getting blocked by the quest flow.
  • Database Loop in StatsSyncWorker.kt: Changed the worker to mark stats as synced on the statsRepository instead of the questRepository, resolving the infinite synchronization loop.
  • FCM Gift Coins Key in FcmHandler.kt: Corrected the lookup key from "coins" to "gift_coins".
  • Boost Activation in UserRepository.kt: Updated activateBoost to store the actual passed item instead of hardcoding InventoryItem.XP_BOOSTER.
  • Screentime CoerceAtLeast Fix: Refactored ScreenUsageStatsHelper.kt and UsageStatsHelper.kt to prevent start time constraints from being silently discarded.

3. AppBlockerService battery & UI optimizations

  • Refactored AppBlockerService.kt to run the 100ms polling loop on a dedicated background thread (HandlerThread "AppBlockerMonitor") instead of the main/UI thread.
  • Removed high-frequency synchronous disk I/O (loadUnlockedAppsFromServer()) from the tight 100ms loop and set up cache updates reactively.

4. AI Validation Selector Settings & Failure Recovery UI

  • Settings Selection UI: Added a settings selector card in the profile page so users can toggle validation between QuestPhone Cloud Server, Local On-Device AI, and Private Gemini API Key.
  • Enhanced Failure Recovery Screen: If a validation fails, the UI displays a radio-group selector enabling you to switch engines immediately. It includes inline API key input and lets you download/select ONNX models directly without returning to settings.
  • Automatic Engine Selection: Downloading/selecting a model in ModelDownloadDialog now automatically switches your active engine to "local".

⚠️ Notes on Testing & Validation Engines

  • Private Gemini API Key Mode: Thoroughly tested and works perfectly. Captures are successfully sent to Gemini and correctly validated.
  • QuestPhone Cloud Server Mode: Untested (I have not tested the default server/cloud-based validation engine).
  • Local On-Device AI Mode (ONNX/SIGLIP): There are known issues with the local HuggingFace SIGLIP model files parsing (throwing ORT_INVALID_PROTOBUF errors during load time on ONNX Runtime), which remain unresolved. Selecting local models will show a description dialog but may fail during evaluation.

@nethical6

Copy link
Copy Markdown
Collaborator

tchhh, you could've just made a custom quest for adding that nano gemini support

@nethical6

Copy link
Copy Markdown
Collaborator

i'd like to merge this but its been so long i last worked on this project that i don't remember a thing. so it will take a bit more time.

@Afrasyaab-GH

Afrasyaab-GH commented Jul 11, 2026

Copy link
Copy Markdown
Author

i'd like to merge this but its been so long i last worked on this project that i don't remember a thing. so it will take a bit more time.

No worries at all, please take all the time you need to review it! There is absolutely no rush.

tchhh, you could've just made a custom quest for adding that nano gemini support
Haha!

Regarding the Nano support, a custom quest is definitely a cool alternative! We ended up building it directly into the AI Snap Quest pipeline so that users can seamlessly toggle between Cloud, Private API Key, and Local Offline (Nano/ONNX) validation engines depending on their device capabilities and privacy preferences.

I also just pushed a few updates to address some critical crashes and UI bugs:

  1. Android 14+ Foreground Service Crash Fixes: Switched AppBlockerService from dataSync to specialUse type to bypass the strict 24-hour dataSync accumulated runtime limit on Android 14+. I also wrapped the service start calls in try-catch blocks to handle background launch restrictions without crashing the app.
  2. Inline Recovery UI: If validation fails, the evaluation dialog now displays a direct selection menu where you can configure/save your Gemini API key or change engines inline without having to exit back to Settings.
  3. Photo Preview Fix: Corrected the evaluation screen's photo path to pull from filesDir (matching where CameraScreen saves it) so the captured snapshot preview renders correctly on screen during validation.

@Afrasyaab-GH

Copy link
Copy Markdown
Author

⚠️ Notes on Testing & Validation Engines

  • Private Gemini API Key Mode: Thoroughly tested and works perfectly. Captures are successfully sent to Gemini and correctly validated.
  • QuestPhone Cloud Server Mode: Untested (I have not tested the default server/cloud-based validation engine).
  • Local On-Device AI Mode (ONNX/SIGLIP): There are known issues with the local HuggingFace SIGLIP model files parsing (throwing ORT_INVALID_PROTOBUF errors during load time on ONNX Runtime), which remain unresolved. Selecting local models will show a description dialog but may fail during evaluation.

@Afrasyaab-GH

Copy link
Copy Markdown
Author

PLease someone test the

QuestPhone Cloud Server Mode: Untested (I have not tested the default server/cloud-based validation engine).
Local On-Device AI Mode (ONNX/SIGLIP): There are known issues with the local HuggingFace SIGLIP model files parsing (throwing ORT_INVALID_PROTOBUF errors during load time on ONNX Runtime), which remain unresolved. Selecting local models will show a description dialog but may fail during evaluation.

I will try to fix it but I can not promise

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.

2 participants