源码位置:frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetService.java

启动

frameworks/base/services/java/com/android/server/SystemServer.java

 224     private static final String ETHERNET_SERVICE_CLASS =
 225             "com.android.server.ethernet.EthernetService";
...

1385             if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) ||
1386                     mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
1387                 traceBeginAndSlog("StartEthernet");
1388                 mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
1389                 traceEnd();
1390             }

com.android.server.ethernet.EthernetService类的实例被创建,并调用其onStart方法。

EthernetService源码

 23 public final class EthernetService extends SystemService {
 24 
 25     private static final String TAG = "EthernetService";
 26     final EthernetServiceImpl mImpl;
 27 
 28     public EthernetService(Context context) {
 29         super(context);
 30         mImpl = new EthernetServiceImpl(context);
 31     }
 32 
 33     @Override
 34     public void onStart() {
 35         Log.d(TAG, "CZLog Registering service " + Context.ETHERNET_SERVICE);
 36         publishBinderService(Context.ETHERNET_SERVICE, mImpl);
 37     }
 38 
 39     @Override
 40     public void onBootPhase(int phase) {
 41         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
 42             mImpl.start();
 43         }
 44     }
 45 }

通过http://xinyiworld.top/wordpress_it/?p=13900我们可知frameworks/base/services/java/com/android/server/SystemServer.java会触发EthernetService的onBootPhase方法被执行。

1986         traceBeginAndSlog("StartBootPhaseSystemServicesReady");
1987         mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
1988         traceEnd();

EthernetServiceImpl源码

源码位置:frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetServiceImpl.java

 78     public void start() {
 79         Log.d(TAG, "CZLog Starting Ethernet service");
 80 
 81         HandlerThread handlerThread = new HandlerThread("EthernetServiceThread");
 82         handlerThread.start();
 83         mHandler = new Handler(handlerThread.getLooper());
 84 
 85         mTracker = new EthernetTracker(mContext, mHandler);
 86         mTracker.start();
 87 
 88         mStarted.set(true);
 89     }

EthernetTracker源码

源码位置:frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java

115     void start() {
116         mConfigStore.read();
117 
118         // Default interface is just the first one we want to track.
119         mIpConfigForDefaultInterface = mConfigStore.getIpConfigurationForDefaultInterface();
120         final ArrayMap<String, IpConfiguration> configs = mConfigStore.getIpConfigurations();
121         for (int i = 0; i < configs.size(); i++) {
122             mIpConfigurations.put(configs.keyAt(i), configs.valueAt(i));
123         }
124 
125         try {
126             mNMService.registerObserver(new InterfaceObserver());
127         } catch (RemoteException e) {
128             Log.e(TAG, "Could not register InterfaceObserver " + e);
129         }
130 
131         mHandler.post(this::trackAvailableInterfaces);
132     }
259     private void trackAvailableInterfaces() {
260         try {
261             final String[] ifaces = mNMService.listInterfaces();
262             for (String iface : ifaces) {
263                 maybeTrackInterface(iface);
264             }
265         } catch (RemoteException | IllegalStateException e) {
266             Log.e(TAG, "Could not get list of interfaces " + e);
267         }
268     }
  • mNMService.listInterfaces()
    90         // The services we use.
    91         IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
    92         mNMService = INetworkManagementService.Stub.asInterface(b);

0 条评论

发表回复

您的电子邮箱地址不会被公开。