DEV Community

Weavri
Weavri

Posted on

An Android app blocker that only triggers on one WiFi network (no root)

I kept losing the first hour of every workday to my phone. Not because I lack discipline in general — but because the office WiFi is exactly where my worst habits live. Home is fine. The train is fine. The moment I sit at my desk and connect to Office-5G, my thumb goes to the same three apps.

Most app blockers treat "blocking" as a global switch. I wanted something contextual: an app blocker that only asserts itself on one specific network.

The idea: a WiFi-triggered attention guard

Instead of blocking everything forever, define a rule:

  • Target WiFi SSID → Office-5G
  • Target app → the app you keep opening

When both match — you're on that network and that app comes to the foreground — you get a loud, hard-to-ignore nudge: a sound, a notification, and a full-screen overlay. Leave the network and everything is normal again.

It's not a hard block (I don't want to fight my own phone). It's a tripwire. The point is to interrupt the autopilot moment, which is where the habit actually happens.

How it works (no root)

You do not need root. Two Android pieces do the whole job:

  1. Reading the current SSID. On Android 8+ this is straightforward; on Android 12/12L WifiManager.getConnectionInfo() returns <unknown ssid> unless you hold ACCESS_FINE_LOCATION, and on Android 13+ you need NEARBY_WIFI_DEVICES. (I wrote up that permission trap separately — it's the single most common reason SSID reading silently fails.)

  2. Detecting the foreground app. A small AccessibilityService receives window-state-change events and calls getRootInActiveWindow() / reads the event's packageName. No polling, no root, no special OEM permission.

Put those two signals together and you have a state machine: on-target-network AND target-app-foreground → fire the warning, then cool down for 30 seconds so it never spams you.

// sketch: the two conditions that gate a warning
val onTargetWifi = currentSsid() == config.targetSsid
val targetInFront = foregroundPackage() == config.targetPackage

if (onTargetWifi && targetInFront && !inCooldown()) {
    warn() // sound + notification + full-screen overlay
    startCooldown(30_000)
}
Enter fullscreen mode Exit fullscreen mode

The whole thing runs 100% on-device: no cloud, no analytics, no account.

Try it / read the code

I packaged this as a small FOSS app called WiFi Beacon (a.k.a. WiFi Sentry):

The source is genuinely complete and MIT-licensed — use it, fork it, ship it. The paid tiers (a ready-to-install APK, a re-branded build) exist only for people who'd rather not fight Gradle.

If you build something on top of the AccessibilityService + SSID approach, I'd love to see it — that pattern is useful well beyond this one app.

Top comments (0)