{"id":14392,"date":"2024-08-21T10:12:17","date_gmt":"2024-08-21T02:12:17","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14392"},"modified":"2024-08-26T13:48:47","modified_gmt":"2024-08-26T05:48:47","slug":"ethernetservice%e4%bb%a5%e5%a4%aa%e7%bd%91%e6%9c%8d%e5%8a%a1","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14392","title":{"rendered":"EthernetService(\u4ee5\u592a\u7f51\u670d\u52a1)"},"content":{"rendered":"<p>\u6e90\u7801\u4f4d\u7f6e\uff1a<code>frameworks\/opt\/net\/ethernet\/java\/com\/android\/server\/ethernet\/EthernetService.java<\/code><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14392\/#%E5%90%AF%E5%8A%A8\" title=\"\u542f\u52a8\">\u542f\u52a8<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14392\/#EthernetService%E6%BA%90%E7%A0%81\" title=\"EthernetService\u6e90\u7801\">EthernetService\u6e90\u7801<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14392\/#EthernetServiceImpl%E6%BA%90%E7%A0%81\" title=\"EthernetServiceImpl\u6e90\u7801\">EthernetServiceImpl\u6e90\u7801<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14392\/#EthernetTracker%E6%BA%90%E7%A0%81\" title=\"EthernetTracker\u6e90\u7801\">EthernetTracker\u6e90\u7801<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E5%90%AF%E5%8A%A8\"><\/span>\u542f\u52a8<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u89c1<code>frameworks\/base\/services\/java\/com\/android\/server\/SystemServer.java<\/code><\/p>\n<pre><code class=\"language-java\"> 224     private static final String ETHERNET_SERVICE_CLASS =\n 225             &quot;com.android.server.ethernet.EthernetService&quot;;\n...\n\n1385             if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) ||\n1386                     mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {\n1387                 traceBeginAndSlog(&quot;StartEthernet&quot;);\n1388                 mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);\n1389                 traceEnd();\n1390             }<\/code><\/pre>\n<p>com.android.server.ethernet.EthernetService\u7c7b\u7684\u5b9e\u4f8b\u88ab\u521b\u5efa\uff0c\u5e76\u8c03\u7528\u5176onStart\u65b9\u6cd5\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"EthernetService%E6%BA%90%E7%A0%81\"><\/span>EthernetService\u6e90\u7801<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-java\"> 23 public final class EthernetService extends SystemService {\n 24 \n 25     private static final String TAG = &quot;EthernetService&quot;;\n 26     final EthernetServiceImpl mImpl;\n 27 \n 28     public EthernetService(Context context) {\n 29         super(context);\n 30         mImpl = new EthernetServiceImpl(context);\n 31     }\n 32 \n 33     @Override\n 34     public void onStart() {\n 35         Log.d(TAG, &quot;CZLog Registering service &quot; + Context.ETHERNET_SERVICE);\n 36         publishBinderService(Context.ETHERNET_SERVICE, mImpl);\n 37     }\n 38 \n 39     @Override\n 40     public void onBootPhase(int phase) {\n 41         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {\n 42             mImpl.start();\n 43         }\n 44     }\n 45 }<\/code><\/pre>\n<p>\u901a\u8fc7<a href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=13900\">http:\/\/xinyiworld.top\/wordpress_it\/?p=13900<\/a>\u6211\u4eec\u53ef\u77e5<code>frameworks\/base\/services\/java\/com\/android\/server\/SystemServer.java<\/code>\u4f1a\u89e6\u53d1EthernetService\u7684onBootPhase\u65b9\u6cd5\u88ab\u6267\u884c\u3002<\/p>\n<pre><code class=\"language-java\">1986         traceBeginAndSlog(&quot;StartBootPhaseSystemServicesReady&quot;);\n1987         mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);\n1988         traceEnd();<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"EthernetServiceImpl%E6%BA%90%E7%A0%81\"><\/span>EthernetServiceImpl\u6e90\u7801<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6e90\u7801\u4f4d\u7f6e\uff1a<code>frameworks\/opt\/net\/ethernet\/java\/com\/android\/server\/ethernet\/EthernetServiceImpl.java<\/code><\/p>\n<pre><code class=\"language-java\"> 78     public void start() {\n 79         Log.d(TAG, &quot;CZLog Starting Ethernet service&quot;);\n 80 \n 81         HandlerThread handlerThread = new HandlerThread(&quot;EthernetServiceThread&quot;);\n 82         handlerThread.start();\n 83         mHandler = new Handler(handlerThread.getLooper());\n 84 \n 85         mTracker = new EthernetTracker(mContext, mHandler);\n 86         mTracker.start();\n 87 \n 88         mStarted.set(true);\n 89     }<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"EthernetTracker%E6%BA%90%E7%A0%81\"><\/span>EthernetTracker\u6e90\u7801<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6e90\u7801\u4f4d\u7f6e\uff1a<code>frameworks\/opt\/net\/ethernet\/java\/com\/android\/server\/ethernet\/EthernetTracker.java<\/code><\/p>\n<pre><code class=\"language-java\">115     void start() {\n116         mConfigStore.read();\n117 \n118         \/\/ Default interface is just the first one we want to track.\n119         mIpConfigForDefaultInterface = mConfigStore.getIpConfigurationForDefaultInterface();\n120         final ArrayMap&lt;String, IpConfiguration&gt; configs = mConfigStore.getIpConfigurations();\n121         for (int i = 0; i &lt; configs.size(); i++) {\n122             mIpConfigurations.put(configs.keyAt(i), configs.valueAt(i));\n123         }\n124 \n125         try {\n126             mNMService.registerObserver(new InterfaceObserver());\n127         } catch (RemoteException e) {\n128             Log.e(TAG, &quot;Could not register InterfaceObserver &quot; + e);\n129         }\n130 \n131         mHandler.post(this::trackAvailableInterfaces);\n132     }<\/code><\/pre>\n<pre><code class=\"language-java\">259     private void trackAvailableInterfaces() {\n260         try {\n261             final String[] ifaces = mNMService.listInterfaces();\n262             for (String iface : ifaces) {\n263                 maybeTrackInterface(iface);\n264             }\n265         } catch (RemoteException | IllegalStateException e) {\n266             Log.e(TAG, &quot;Could not get list of interfaces &quot; + e);\n267         }\n268     }<\/code><\/pre>\n<ul>\n<li>mNMService.listInterfaces()\n<pre><code class=\"language-java\">90         \/\/ The services we use.\n91         IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);\n92         mNMService = INetworkManagementService.Stub.asInterface(b);<\/code><\/pre>\n<\/li>\n<\/ul>\n<button class=\"simplefavorite-button\" data-postid=\"14392\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u6e90\u7801\u4f4d\u7f6e\uff1aframeworks\/opt\/net\/ethernet\/java\/com\/android\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1098],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14392"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14392"}],"version-history":[{"count":5,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14392\/revisions"}],"predecessor-version":[{"id":14468,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14392\/revisions\/14468"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14392"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}