Skip to content

feat: Add Auto Turn Off Wi-Fi feature in Networks - #773

Draft
Mudit200408 wants to merge 3 commits into
sameerasw:developfrom
Mudit200408:feat-turn-off-wifi-auto
Draft

feat: Add Auto Turn Off Wi-Fi feature in Networks#773
Mudit200408 wants to merge 3 commits into
sameerasw:developfrom
Mudit200408:feat-turn-off-wifi-auto

Conversation

@Mudit200408

Copy link
Copy Markdown
Contributor

If the Wifi is disconnected for a specific amount of time wifi will turn off automatically
This can save battery as we generally forget to turn off wifi when we are away from home/office

@sameerasw sameerasw added the enhancement New feature or request label Aug 14, 2026
@sameerasw sameerasw moved this from Backlog to In review in Essentials Progress Aug 14, 2026
@sameerasw

Copy link
Copy Markdown
Owner

PR Overview: feat-turn-off-wifi-auto

This PR introduces an "Auto Turn Off Wi-Fi" feature to the Essentials Android app under Network Settings.


🔍 What It Does (Compared to develop)

The PR modifies 4 files to automatically disable Wi-Fi via a shell command when the device disconnects from a Wi-Fi network after a user-defined timeout:

  1. ScreenOffAccessibilityService.kt:

    • Registers a ConnectivityManager.NetworkCallback when the accessibility service starts to monitor Wi-Fi connectivity.
    • When Wi-Fi disconnects (onLost), it schedules a timer (Handler.postDelayed) based on wifi_auto_off_timeout (default 60s).
    • When the timer expires, it runs ShellUtils.runCommand(this, "svc wifi disable") to turn off Wi-Fi.
    • Listens to SharedPreferences changes (wifi_auto_off_enabled / wifi_auto_off_timeout).
  2. NetworksSettingsUI.kt:

    • Adds an IconToggleItem to enable/disable auto Wi-Fi turn off.
    • Adds a ConfigSliderItem to configure the timeout (10 to 300 seconds in steps of 10s).
  3. FeatureRegistry.kt:

    • Registers the "Auto turn off Wi-Fi" feature under the Networks category so it shows up in global settings search and feature management.
  4. strings.xml:

    • Adds string resources for the title, description, and search index entries (wifi_auto_off_title, wifi_auto_off_desc, etc.).

⚠️ "Bad Things Done" / Code Smells & Rule Violations

Here is a breakdown of critical issues, compilation errors, and rule breaks in this PR:

❌ 1. CRITICAL: Code Will Not Compile (Missing ViewModel State)

  • In NetworksSettingsUI.kt and FeatureRegistry.kt, the PR calls:
    • viewModel.isWifiAutoOffEnabled
    • viewModel.setWifiAutoOffEnabled(...)
    • viewModel.wifiAutoOffTimeout
    • viewModel.setWifiAutoOffTimeout(...)
  • None of these properties or methods were created in MainViewModel or SettingsRepository. Building the project will fail with unresolved reference errors.

❌ 2. Violation of User Rule #11 (Polluting Accessibility Service)

Rule 11: "If we are using an existing service for another feature, do not make changes that can affect other features unless asked to. As an example, the accessibility service should not be directly modified..."

  • Wi-Fi monitoring callbacks and shell execution logic were pasted directly into ScreenOffAccessibilityService.kt, bloating the service instead of separating the logic into a dedicated helper/manager class or module.

❌ 3. Violation of Import Rules (Inline Fully Qualified Class Names)

Rule 1: "NEVER use inline package imports... ALWAYS add all class and component imports at the top of the file."

  • In ScreenOffAccessibilityService.kt, multiple types are referenced inline rather than imported at the top of the file:
    • android.net.ConnectivityManager
    • android.net.NetworkRequest
    • android.net.NetworkCapabilities
    • android.net.Network
    • android.util.Log
    • android.os.Build
    • com.sameerasw.essentials.utils.ShellUtils

❌ 4. Hardcoded Preference Keys (Bypassing SettingsRepository)

  • Reads directly from SharedPreferences using raw strings "wifi_auto_off_enabled" and "wifi_auto_off_timeout" inside ScreenOffAccessibilityService.kt rather than defining key constants in SettingsRepository.

❌ 5. Silent Failures & Lack of Error Handling

  • Runs "svc wifi disable" via ShellUtils.runCommand(...). If the user does not have root/Shizuku permissions granted, the command silently fails without checking command status or notifying the user.

@sameerasw
sameerasw marked this pull request as draft August 14, 2026 08:38
@sameerasw

Copy link
Copy Markdown
Owner

I should publish the new rules.. forgot about that. Will do soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants