Conversation
- Added MODE_NONE as default execution mode to avoid auto-selecting Root or Shizuku on fresh install. - Updated first-launch behavior to show setup prompt instead of assuming Root mode. - Added Root permission check using `su -c id` when Root mode is selected or restored. - Re-check Root permission on app open if Root mode was previously saved. - Changed Shizuku flow so permission is requested only when user manually selects Shizuku mode. - For saved Shizuku mode, only check current Shizuku status without triggering permission popup. - Added Shizuku binder received/dead/result listeners with current-mode validation. - Prevented Shizuku callbacks from overwriting Root mode status. - Prevented stale Root permission check result from overwriting UI if user switches mode during check. - Wrapped Shizuku permission checks in try/catch for safer binder failure handling. - Removed listener references in onDestroy to avoid memory leaks.
- Added explicit execution mode constants for none, root, and Shizuku. - Added explicit network state constants including STATE_UNKNOWN. - Updated tile startup to avoid assuming 4G Only when no cached state exists. - Added unknown/unavailable tile state for unconfigured mode. - Added cached QS tile icons to avoid regenerating bitmap icons on every tile update. - Refactored state cycling into getNextState(). - Refactored state-to-bitmask selection into getBinaryForState(). - Prevented tile click from running when no execution mode is selected. - Updated applyNetworkMode() to use execution mode constants instead of defaulting to Root.
- Changed applyNetworkMode() to return success or failure. - Updated QS tile click flow to save and display the next state only after successful command execution. - Added separate Root and Shizuku command runners. - Simplified Root execution using `su -c`. - Added exit code checks for both Root and Shizuku command execution. - Prevented tile state from changing visually when command execution fails. - Preserved previous tile state on failed toggle attempt. - Removed old DataOutputStream-based Root command flow.
- Added default data subscription lookup using SubscriptionManager. - Replaced hardcoded `-s 0` with the current default data subscription ID. - Added invalid subscription handling using SubscriptionManager.INVALID_SUBSCRIPTION_ID. - Prevented network mode command execution when no valid data subscription is available. - Improved dual-SIM compatibility by targeting the active/default data SIM instead of assuming subscription 0. - Kept existing binary allowed-network-type values because the command path supports them on tested devices.
- Added a single-thread executor for QS tile command execution. - Moved root/Shizuku network mode command execution off the tile click callback path. - Added immediate "Switching..." tile feedback while the command runs. - Updated tile state on the main executor after command completion. - Preserved previous tile state when command execution fails. - Prevented the QS tile from blocking while waiting for root/Shizuku process completion.
- Replaced API 28+ getMainExecutor() usage with Handler and Looper.getMainLooper() for Android 7+ compatibility. - Added AtomicBoolean switching guard to prevent rapid QS tile taps from queueing duplicate network mode commands. - Kept network mode command execution on a background single-thread executor. - Posted tile UI updates back to the main thread after command completion. - Preserved previous tile state when command execution fails. - Improved QS tile stability across Android 7 through newer Android versions.
- Avoided running real network mode checks on every QS panel open. - Updated onStartListening() to show cached tile state immediately. - Queried real current network mode only when cached state is unknown. - Used `settings get global multi_sim_data_call` as the active data SIM source. - Read current legacy network mode from `preferred_network_mode1/2` based on active data SIM. - Mapped active data SIM index to phone command index for network mode updates. - multi_sim_data_call 1 -> cmd phone -s 0 - multi_sim_data_call 2 -> cmd phone -s 1 - Removed SubscriptionManager-based data subscription lookup from tile command flow. - Added legacy network mode ID mapping for tile state detection. - 11 -> 4G Only - 23 -> 5G Only - 33 -> Preferred 5G - 9 -> Preferred 4G - Simplified current mode detection using preferred_network_mode legacy values. - Cached Shizuku `newProcess` reflection Method to avoid repeated method lookup. - Cached number regex Pattern used for legacy mode parsing. - Simplified CommandResult by removing unused stderr storage. - Added process cleanup in Root and Shizuku command execution paths. - Kept command execution asynchronous and protected by duplicate-toggle guard. - Reduced shell/Shizuku process usage during normal QS tile refresh.
- Added Activity destroyed flag to prevent stale UI updates after MainActivity closes. - Tracked Root permission check thread and process. - Destroyed active Root check process during onDestroy(). - Interrupted active Root check thread during Activity cleanup. - Preserved Shizuku listener cleanup in onDestroy(). - Guarded Shizuku callbacks so they update UI only when Activity is alive and Shizuku mode is selected. - Prevented stale Root permission check result from updating UI after Activity destruction.
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.
Summary
This PR merges the dev branch improvements into main to make NetToggle safer, lighter, and more reliable for Root/Shizuku based network mode switching.
The update improves execution mode handling, Root/Shizuku permission flow, QS tile state accuracy, command execution safety, icon caching, SIM handling, and lifecycle cleanup.
MainActivity changes
MODE_NONEMODE_ROOTMODE_SHIZUKUonDestroy().onDestroy().NetworkTileService changes
STATE_UNKNOWNto avoid assuming 4G Only on first install.getNextState().getBinaryForState().multi_sim_data_call.multi_sim_data_call=1->cmd phone -s 0multi_sim_data_call=2->cmd phone -s 1preferred_network_mode1/2using legacy mode IDs.11-> 4G Only23-> 5G Only33-> Preferred 5G9-> Preferred 4GnewProcessreflection Method to avoid repeated reflection lookup.Performance impact
Reliability impact
Testing
Tested expected flows:
preferred_network_mode1/2values.