阅读:3085回复:3
以太网开机或者插网线就自动连接?
有人知道在哪控制不?
|
|
最新喜欢:zhaoyf... |
沙发#
发布于:2022-04-27 08:55
我知道,在这个目录:
frameworks\opt\net\ethernet\java\com\android\server\ethernet 开机之后系统会调用EthernetServiceImpl 的start() , mTracker.start(mContext, mHandler);然后以太网就会尝试连接,这个是Android8.1的, 我看了9.0 和11.0的代码都是差不多的。 |
|
|
板凳#
发布于:2022-04-27 14:44
|
|
地板#
发布于:2022-04-29 11:44
@@ -174,6 +176,12 @@ final class EthernetTracker { private void addInterface(String iface) { InterfaceConfiguration config = null; // Bring up the interface so we get link status indications. + + if (TextUtils.equals(iface, "eth0") && !TextUtils.equals(SystemProperties.get("persist.sys.eth_up", "true"), "true") ) { + Log.e(TAG, "addInterface exit, reason: eth_up false"); + return; + } + + /** + state + true 开启以太网 + false 关闭以太网 + **/ + public boolean setInterfaceStatus(String iface, boolean state){ + try { + if(!TextUtils.isEmpty(iface)) { + + if(!state) { + mNMService.setInterfaceDown(iface); + //removeInterface(iface); + } else { + maybeTrackInterface(iface); + mNMService.setInterfaceUp(iface); + } + return true; + } else { + Log.e(TAG,"iface is null"); + } + } catch (Exception e) { + Log.e(TAG, "Error setInterfaceStatus : " + iface + " state : " + state + " exception : " + e); + } + return false; + + } 2个关键点: addInterface和maybeTrackInterface |
|