You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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:
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).
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).
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.
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:
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.
I should publish the new rules.. forgot about that. Will do soon
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
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.
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