Skip to content

Ashish-CodeJourney/MindGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

44 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ MindGuard

Reclaim your attention. Block Instagram Reels, YouTube Shorts, TikTok, and Snapchat Spotlight โ€” entirely on your phone.

MindGuard is a privacy-first Android app that detects and blocks short-form video feeds before you get sucked in. No accounts. No tracking. No servers. Just you, your focus, and 500ms of protection.


The Problem

You pick up your phone for one thing. Instagram for 5 minutes. YouTube to find a tutorial. TikTok just to check. Snapchat for your streak.

Three hours later, you're still scrolling. You lost the afternoon. Again.

MindGuard stops this. Instantly.


How It Works

When you open Instagram and navigate to Reels, MindGuard detects the exact moment the short-video player loads and hits back before you can get hooked. Same with YouTube Shorts, TikTok, and Snapchat Spotlight.

All of this happens:

  • On your phone โ€” no internet needed
  • In 500ms โ€” faster than you can react
  • With zero data collection โ€” your choices stay yours

What You Get

Home Screen โ€” Status at a Glance

See if blocking is active and track your progress in real-time.

MindGuard Home Screen
  • Active Shield โ€” blocks are running, Reels & Shorts can't get you
  • Reels Blocked โ€” how many times the app saved you today
  • Time Saved โ€” estimated hours you didn't lose
  • Attempts โ€” how many times you wanted a short-form feed
  • Deflected โ€” your success rate (blocks / attempts)
  • Streak โ€” current clean days + your personal best

Settings โ€” Fine-Grained Control

Decide which apps to block and when.

MindGuard Settings Screen

Per-App Toggles

  • Instagram Reels
  • YouTube Shorts
  • TikTok
  • Snapchat Spotlight

Focus Schedule

  • Auto-block during work hours (or custom times)
  • Pause manually anytime
  • 30-second pause button in notification shade

Streak Tracking

  • See your current streak and personal best
  • Built-in motivation to keep the streak alive

Setup โ€” Two Steps (Android 13+)

MindGuard Permission Setup
  1. Allow Restricted Settings (one-time, Android 13+ only)
  2. Enable MindGuard Accessibility Service

That's it. Blocking starts immediately.


Under the Hood

MindGuard uses Android's Accessibility API to read screen layout in real-time. It watches for specific resource IDs that indicate the short-video player is on screen, then instantly navigates away.

User opens Instagram Reels
           โ†“
AccessibilityService detects 'reel_pager' resource ID
           โ†“
RuleEngine evaluates: "Is this a Reels player?"
           โ†“
Decision: YES โ†’ Block
           โ†“
BlockActionExecutor clicks Home tab (stay in Instagram)
           โ†“
User sees Home feed instead of Reels
           โ†“
MindGuard logs: +1 block, +1 attempt

Why Resource IDs?

MindGuard doesn't read text or analyze navigation buttons. It uses resource IDs only โ€” internal view IDs that identify the exact component.

This means:

  • Opening Instagram doesn't trigger a block (just the app icon shows, no Reels player)
  • Opening YouTube doesn't trigger a block (Shorts nav tab visible, but player not loaded)
  • Only the confirmed player-specific layout triggers a block

Detection Accuracy

Each app's short-form player has its own set of signature resource IDs:

App Blocked Player IDs
Instagram clips_viewer_view_pager, reel_pager, reel_play_button, reels_viewer
YouTube reel_watch_fragment_root, reel_progress_bar, shorts_container
TikTok TikTok video-feed container IDs
Snapchat spotlight_container

Instagram's home feed, Explore, and Messaging are never blocked โ€” the service has an explicit guard that short-circuits detection for feed screens.


Architecture

mindguard/
โ”œโ”€โ”€ shared/                  โ† Pure Kotlin (no Android deps)
โ”‚   โ””โ”€โ”€ commonTest/
โ”‚       โ”œโ”€โ”€ rules/           RuleEngine, InstagramReelRule, YouTubeShortsRule, ...
โ”‚       โ”œโ”€โ”€ models/          ScreenSnapshot, DetectionResult, BlockAction
โ”‚       โ””โ”€โ”€ usecases/        FocusPauseLogic, BlockCooldown, DetectBlockedContentUseCase
โ”‚
โ””โ”€โ”€ androidApp/              โ† Android layer
    โ”œโ”€โ”€ accessibility/       MindGuardAccessibilityService, BlockActionExecutor
    โ”œโ”€โ”€ storage/             SettingsDataStore (DataStore Preferences)
    โ”œโ”€โ”€ ui/                  Compose screens: Home, Settings, Stats, Onboarding
    โ””โ”€โ”€ di/                  Koin dependency injection

The shared module is 100% testable on the JVM โ€” zero Android dependencies. All detection logic, rules, and decision-making run as unit tests before any Android code touches them.


Installation

From GitHub Releases

Download the APK from the latest release and install it.

From Source

git clone https://github.com/Ashish-CodeJourney/MindGuard.git
cd MindGuard
./gradlew :androidApp:assembleDebug
# APK at: androidApp/build/outputs/apk/debug/app-debug.apk

Android 13+ Setup

After installing a sideloaded APK:

  1. Go to Settings โ†’ Apps โ†’ MindGuard
  2. Tap โ‹ฎ โ†’ Allow restricted settings
  3. Go to Settings โ†’ Accessibility โ†’ MindGuard โ†’ enable

Quick Settings Tile (Optional)

Long-press your notification shade โ†’ Edit tiles โ†’ drag Focus Mode into active tiles. Now you can pause blocking with one tap.


Privacy

  • โœ… On-device only โ€” all detection runs locally
  • โœ… No accounts โ€” nothing to sign up for
  • โœ… No tracking โ€” no analytics, no user profiling
  • โœ… No internet โ€” zero network requests
  • โœ… Accessibility scope limited โ€” service can only read from 4 apps (Instagram, YouTube, TikTok, Snapchat)
  • โœ… Explicit consent โ€” you enable it manually in system settings

Read the full accessibility declaration.


Development

Running Tests

./gradlew :shared:testDebugUnitTest

All business logic is test-first (TDD). Tests live in shared/src/commonTest/ and run on the JVM.

Tech Stack

  • Language โ€” Kotlin Multiplatform (shared logic + Android UI)
  • UI โ€” Jetpack Compose + Material 3
  • Async โ€” Coroutines + Flow
  • Storage โ€” DataStore Preferences
  • DI โ€” Koin
  • Testing โ€” Kotlin Test

Adding a New Blocking Rule

  1. Create a new BlockingRule in the shared module:
class BeRealRule : BlockingRule {
    override fun evaluate(snapshot: ScreenSnapshot): DetectionResult {
        if (snapshot.packageName != "com.bereal.app") return noBlock()
        
        return if (snapshot.resourceIds.any { it.contains("camera_view") })
            DetectionResult(shouldBlock = true, action = BlockAction.GO_BACK, reason = "BeReal camera detected")
        else noBlock()
    }
}
  1. Register in MindGuardAccessibilityService:
RuleEngine(listOf(
    InstagramReelRule(), YouTubeShortsRule(), TikTokRule(), 
    SnapchatSpotlightRule(), BeRealRule()  // add here
))
  1. Add the package name to:
    • androidApp/src/main/res/xml/accessibility_config.xml (service scope)
    • SettingsDataStore (user toggles)

Requirements

  • Android 7.0+ (API 24+)
  • Accessibility Service permission (granted in system settings)

License

MIT โ€” see LICENSE


Questions?

  • ๐Ÿ’ฌ GitHub Discussions
  • ๐Ÿ› Found a bug? Issues
  • ๐Ÿค Want to contribute? PRs welcome!

About

Reduce doom scrolling As much As possible

Resources

License

Stars

Watchers

Forks

Contributors