源码位置:frameworks/base/services/core/java/com/android/server/NetworkManagementService.java

启动

见SystemServer.java

1291             traceBeginAndSlog("StartNetworkManagementService");
1292             try {
1293                 networkManagement = NetworkManagementService.create(context);
1294                 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
1295             } catch (Throwable e) {
1296                 reportWtf("starting NetworkManagement Service", e);
1297             }
1298             traceEnd();

创建

 280     static NetworkManagementService create(Context context, SystemServices services)
 281             throws InterruptedException {
 282         final NetworkManagementService service =
 283                 new NetworkManagementService(context, services);
 284         if (DBG) Slog.d(TAG, "Creating NetworkManagementService");
 285         if (DBG) Slog.d(TAG, "Connecting native netd service");
 286         service.connectNativeNetdService();
 287         if (DBG) Slog.d(TAG, "Connected");
 288         return service;
 289     }
 290 
 291     public static NetworkManagementService create(Context context) throws InterruptedException {
 292         return create(context, new SystemServices());
 293     }

SystemServices为NetworkManagementService的内部类:

 123     static class SystemServices {
 124         public IBinder getService(String name) {
 125             return ServiceManager.getService(name);
 126         }
 127         public void registerLocalService(NetworkManagementInternal nmi) {
 128             LocalServices.addService(NetworkManagementInternal.class, nmi);
 129         }
 130         public INetd getNetd() {
 131             return NetdService.get();
 132         }
 133     }

方法

  • connectNativeNetdService
    获取NetdService服务

    513     private void connectNativeNetdService() {
    514         mNetdService = mServices.getNetd();
    515         try {
    516             mNetdService.registerUnsolicitedEventListener(mNetdUnsolicitedEventListener);
    517             if (DBG) Slog.d(TAG, "Register unsolicited event listener");
    518         } catch (RemoteException | ServiceSpecificException e) {
    519             Slog.e(TAG, "Failed to set Netd unsolicited event listener " + e);
    520         }
    521     }
  • listInterfaces(列出网口)

    740     //
    741     // INetworkManagementService members
    742     //
    743     @Override
    744     public String[] listInterfaces() {
    745         mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    746         try {
    747             return mNetdService.interfaceGetList();
    748         } catch (RemoteException | ServiceSpecificException e) {
    749             throw new IllegalStateException(e);
    750         }
    751     }

0 条评论

发表回复

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