Fix: Ensure BlockingActivity always launches to foreground when rapidly switching to the blocked app#18
Open
jamesdean268 wants to merge 6 commits into
Open
Fix: Ensure BlockingActivity always launches to foreground when rapidly switching to the blocked app#18jamesdean268 wants to merge 6 commits into
jamesdean268 wants to merge 6 commits into
Conversation
Added Intent.FLAG_ACTIVITY_CLEAR_TASK when launching BlockingActivity from AppMonitoringService to ensure it properly comes to the foreground, especially when launched successively from the Recents menu. Co-authored-by: jamesdean268 <27984001+jamesdean268@users.noreply.github.com>
Switched from `UsageStatsManager.queryUsageStats` to `queryEvents` to accurately determine the foreground app in real-time. Tracking the `ACTIVITY_RESUMED` event allows TapBlok to instantly catch when a user switches to a blocked app via gestures like Quick Switch or the Recents menu, closing the bypass window created by aggregated stats delays. Co-authored-by: jamesdean268 <27984001+jamesdean268@users.noreply.github.com>
…flags-9955110494792391912 Fix: Ensure BlockingActivity always launches to foreground
…ssion Android 13+ (API 33+) requires the POST_NOTIFICATIONS runtime permission to display the foreground service persistent notification. Without this notification being visible, the OS considers the foreground service a background process and terminates it randomly to reclaim resources. This commit adds the POST_NOTIFICATIONS permission to AndroidManifest.xml, prompts the user to grant it in MainActivity on API 33+, and validates its presence before attempting to start the AppMonitoringService from any entry point (UI, shortcuts, NFC intent). Co-authored-by: jamesdean268 <27984001+jamesdean268@users.noreply.github.com>
When an active break ends, TapBlok is supposed to immediately kick the user out of any currently active blocked app. However, TapBlok polls for `ACTIVITY_RESUMED` events in the last 1 minute to determine the foreground app. Since the break is 5 minutes, if the user stays in the app without switching, no new resume events are logged. Thus, `getForegroundApp()` would return null and fail to block the app. This commit updates `getForegroundApp()` to cache the `lastKnownForegroundApp` when it detects a valid app, and returns that fallback when the UsageStats query is empty. Co-authored-by: jamesdean268 <27984001+jamesdean268@users.noreply.github.com>
…-2751649071894736556 Fix monitoring session randomly stopping by requesting Notification permissions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses two bugs where the BlockingActivity would fail to appear if a user navigated to a blocked app via the Recents menu multiple times in quick succession, or navigated to the blocked app by swiping across the bottom bar quickly to get from the TapBlok screen to the blocked app (called "Quick Switch").
It resolves these bugs by:
UsageStatsManager.queryUsageStatstoqueryEventsto accurately determine the foreground app in real-time. Tracking theACTIVITY_RESUMEDevent allows TapBlok to instantly catch when a user switches to a blocked app via gestures like Quick Switch or the Recents menu, closing the bypass window created by aggregated stats delays.