0

By default, Android bring up an ethernet interface through addInterface() in EthernetTracker.java. That is, When a ethernet cable is connected, it will bring up that interface and set Ip automatically.

How to not bring up the interface by default? That is only when enableInterface() is called from my service, the interface should be up. And even if ethernet cable is connected, that interface should not come up until and unless my service calls interface up.

Things I have tried: Made a service to startup very early and listen to "Interface added/Interface state changed" notification and set the interface down to ensure the interface is down by default. But this approach brings unnecessary bring up and down of interfaces during bootup.

What I wanted: Suggest a proper way of setting ethernet interface as down by default. A solution without changing AOSP code is preferred.

Enable/disable APIs: https://source.android.com/docs/automotive/connectivity/ethernet-manage

EthernetTracker.java: https://cs.android.com/android/platform/superproject/+/android15-qpr2-release:packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetTracker.java?q=EthernetTracker.java

3
  • And what problem does that solve? When messing with ifupdown, just make it reply "interface eth0 not configured". Commented Apr 1 at 13:18
  • I want a specific interface should be always down at bootup and my service should turn it on as required. Commented Apr 3 at 16:00
  • The specified interface should stay deactivated at startup, with activation managed only by our service. A script to disable it is feasible but inefficient, causing unnecessary link state changes before our service deactivates it. Additionally, conflicts may arise if other services try to use it before our script runs, requiring a more robust solution. Wi-Fi already follows this approach and stays off by default. Commented Apr 3 at 16:09

1 Answer 1

0

You could update the resource overlay for config_ethernet_iface_regex, and make sure whatever you name your ethernet interface doesn't match the regex.

<!-- Regex of wired ethernet ifaces. Network interfaces that match this regex will be tracked by ethernet service. If set to "*", ethernet service uses "(eth|usb)\\d+" on Android V+ and eth\\d+ on Android T and U. -->
    <string translatable="false" name="config_ethernet_iface_regex">*</string>

In the above definition, you could name the interface iface01 and it would not be initialized by Android. When you were ready to have it tracked by Android (and initialized), you could just rename it to eth01 or the like.

Examples of usage as well as definition can be found at: https://cs.android.com/search?q=config_ethernet_iface_regex&sq=&ss=android%2Fplatform%2Fsuperproject%2Fmain

Sign up to request clarification or add additional context in comments.

4 Comments

Can we make changes to config_ethernet_iface_regex value during runtime? config.xml files (like the one in frameworks/base/core/res/res/values/config.xml) contain compile-time system resource values.
You're correct that resource overlays are compile time values. If you need runtime values, you could use EthernetManager.disableInterface(): source.android.com/docs/automotive/connectivity/… Let me know if that's what you're looking for and I'll update the answer. One note; the interface will still come up initially if it is picked up due to the ethernet regex I pointed out, you can then however bring it back down.
Yes, we can use disableInterface() API to bring down the interface once it is set up by Ethernet tracker. But it will cause unnecessary interface state transitions on every bootup. I'm looking for a way to set ethernet interface state down until I use enableInterface() to bring up the interface.
Yeah, in that case your only options would be to use the compile time overlay config_ethernet_iface_regex, of you have to have some custom linux networking scripts to disable the ethernet interface at boot (you'd need to be able to update the device's make file in this case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.