Android 13(SDK 33)中启用以太网设置界面的源码修改方案咨询
Android 13(SDK 33)中启用以太网设置界面的源码修改方案咨询
Hey there! I’ve gone through the hassle of enabling Ethernet settings on Android 13 (SDK 33) before, and since the Android 9 method is totally incompatible with the newer codebase, let’s break down the exact source code changes you need to make to get this working without build errors:
1. Make Ethernet Visible in the Settings App
First, we need to unhide the Ethernet entry in the Network & Internet section of the Settings app:
- Navigate to the Settings app source:
packages/apps/Settings - Open
res/xml/network_and_internet_settings.xml
Look for the Ethernet preference entry—it might be commented out or set toandroid:visibility="gone". Update it toandroid:visibility="visible"and remove any conditional attributes likesettings:userRestriction="no_ethernet"that might be hiding it. - Next, open
src/com/android/settings/network/NetworkAndInternetDashboardFragment.java
In thegetAvailableTiles()method, ensure that the Ethernet settings tile is included. If it’s commented out, uncomment the line that addsEthernetSettings.classto the list of available network tiles. For example:// Uncomment or add this line addTile(new Tile.Builder() .setCategory(CATEGORY_NETWORK) .setFragment(EthernetSettings.class.getName()) .setPriority(10) .build());
2. Enable System-Level Ethernet Support
Even if the Settings entry is visible, the system might still block Ethernet functionality by default:
- Go to
frameworks/base/core/res/res/values/config.xml
Find the boolean resourceconfig_disable_ethernetand change its value fromtruetofalse:<bool name="config_disable_ethernet">false</bool> - Check the Ethernet service module in
frameworks/opt/net/ethernet
Ensure the module is set to compile for your target. Open theAndroid.bpfile here and confirm there’s novisibility: ["//visibility:private"]orenabled: falsethat would prevent it from being included in the build. If needed, adjust it to:android_library { name: "ethernet-service", srcs: ["java/**/*.java"], resource_dirs: ["res"], manifest: "AndroidManifest.xml", sdk_version: "33", visibility: ["//visibility:public"], }
3. Fix SELinux Permissions (If Needed)
If you still run into issues after the above steps, SELinux might be blocking Ethernet operations:
- Navigate to your device’s SEpolicy directory, usually
device/[your_oem]/[your_device]/sepolicy - Add rules to allow the Ethernet service to access necessary system resources. For example, create or update
ethernet.tewith:
These rules mirror common permissions granted to other network services like Wi-Fi.allow ethernet_service netd_service:service_manager find; allow ethernet_service sysfs_net:file rw_file_perms; allow ethernet_service system_netctl:service_manager find;
Quick Build & Test Tips
- After making changes, you can build just the affected modules to save time:
make Settings framework-base ethernet-service -j$(nproc) - Flash the updated modules to your device, or do a full system build with
make -j$(nproc)if you’re rebuilding the entire image. - Once booted, head to Settings > Network & Internet—you should see the Ethernet option now, and it should detect connected adapters properly.
内容来源于stack exchange




