Skip to content

Seamless Legacy Network Switching (Android 7-11) & UI Cleanup - #21

Merged
Dhangofa merged 14 commits into
mainfrom
legacy-support
Aug 18, 2026
Merged

Seamless Legacy Network Switching (Android 7-11) & UI Cleanup#21
Dhangofa merged 14 commits into
mainfrom
legacy-support

Conversation

@Dhangofa

Copy link
Copy Markdown
Owner

📝 Summary

This Pull Request introduces full, seamless network mode switching support for older Android devices (Android 7 to 11). Since the cmd phone utility used for Android 12+ is unavailable on older versions, this PR implements a robust "Pro" fallback mechanism using a headless Java payload executed via app_process. It also includes housekeeping to remove unused resources flagged by Android Lint, reducing overall APK size.

🚀 Key Changes

1. Legacy Java Payload Implementation (Seamless Switching)

  • Standalone Java Payload: Created a headless Java class (NetworkModePayload) with a main method designed to run natively via app_process outside the standard app lifecycle.
  • Java Reflection: Implemented reflection to securely hook into the hidden android.os.ServiceManager, retrieve the phone service binder, and invoke ITelephony.setPreferredNetworkType(subId, mode) directly.
  • Dynamic Classpath Execution: Refactored the legacy apply() method to dynamically resolve the app's base APK path (context.getApplicationInfo().sourceDir) to use as the CLASSPATH for app_process execution.
  • ProGuard/R8 Protection: Added @Keep annotations to the payload class and main method to ensure they are not stripped or obfuscated during release builds.
  • Note: This cleanly replaces an initial experimental iteration that relied on unstable settings put global and Airplane Mode toggles.

2. Architecture & Routing Dispatch

  • Version-Aware Dispatch: Routed Android 7 to 11 mode changes through the new legacy backend, while keeping Android 12+ mode changes on the existing allowed-network-types backend.
  • Context Management: Exposed the application context to telephony package controllers and added explicit null handling for the active subscription list.
  • Legacy Mode Mappings: Added precise legacy integer values for the NetworkMode enum:
    • 5G Only: 23
    • Preferred 5G: 33
    • 4G Only: 11
    • Preferred 4G: 9
    • Preferred 3G: 0
    • 2G Only: 1

3. Housekeeping & Dead Code Removal

Cleaned up unused XML files and resources to shrink the APK size and resolve Lint warnings:

  • Theme Colors: Removed unused hex values (segmented_selected, segmented_text_selected, accent_green, cycle_badge_bg) from both Light and Dark theme colors.xml files.
  • Color State Lists: Deleted obsolete segmented text color state list (color_segmented_text.xml).
  • Drawables: Deleted unused icons and shape backgrounds (ic_menu_book.xml, section_outline_bg.xml).
  • Selectors: Deleted obsolete tab selectors (selector_segmented_tab.xml, selector_segmented_tab_rect.xml).

LEGACY MODE VALUES
- 5G Only: 23
- Preferred 5G: 33
- 4G Only: 11
- Preferred 4G: 9
- Preferred 3G: 0
- 2G Only: 1
…lers

- Added explicit null handling for the active subscription list
- Exposes the existing apllication context get context
- Routed Android 7 to 11 mode changes through the legacy backend
- Kept Android 12+ mode changes the existing allowed-network-types backend
- Added a dedicated legacy network mode backend.
- Added transactional mode writes and cellular modem restart.
- Added airplane mode radio-list preservation and restoration.
- Added clean up traps and post operation verification.
- Removed all legacy shell scripts that relied on settings put global and Airplane Mode toggling to force network changes.
- Added dynamic path resolution (context.getApplicationInfo().sourceDir) to locate the app's base APK at runtime.
- Refactored the apply() method to format and execute an app_process shell command using the APK as the CLASSPATH and targeting NetworkModePayload.
- Simplified the legacy execution flow and error handling, relying on the Java payload's internal success/failure outputs.
…hing

- Created a headless Java class with a main method designed to run natively via app_process outside the standard app lifecycle.
- Implemented Java Reflection to securely hook into the hidden android.os.ServiceManager and retrieve the phone service binder.
- Added logic to invoke ITelephony.setPreferredNetworkType(subId, mode) directly, bypassing standard Android permission restrictions.
- Added @keep annotations to the class and main method to ensure R8/ProGuard does not strip or obfuscate the payload during release builds.
- Removed the unused segmented_selected color hex value.
- Removed the unused segmented_text_selected color hex value.
- Removed the unused accent_green color hex value.
- Removed the unused cycle_badge_bg color hex value to resolve Android Lint warnings and clean up the resource file.
- Removed the unused segmented_selected color hex value.
- Removed the unused segmented_text_selected color hex value.
- Removed the unused accent_green color hex value.
- Removed the unused cycle_badge_bg color hex value to maintain parity with the light theme cleanup and resolve Lint warnings.
Deleted the unused XML color state list selector (color_segmented_text.xml) identified during the Android Lint analysis to reduce APK size.
- Removed the ic_menu_book.xml Material Design vector drawable that was no longer referenced by any UI layouts.
- Removed the obsolete section_outline_bg.xml shape drawable to eliminate dead code and shrink the resource bundle.
- Deleted the unused selector_segmented_tab.xml background state selector based on the Lint dead-code analysis.
- Deleted the unused rectangular variant of the segmented tab background selector (selector_segmented_tab_rect.xml) to keep the codebase clean.
@Dhangofa
Dhangofa merged commit 29e763e into main Aug 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant