Android7.1开机默认静态ip调试

匿名 (未验证) 提交于 2019-12-03 00:22:01


先来看看系统的进程的入口SystemServer ,main方法里通过SystemServiceManage启动EthernetService

//frameworks/base/services/Java/com/Android/server/SystemServer.java      public final class SystemServer {         private static final String ETHERNET_SERVICE_CLASS =               "com.android.server.ethernet.EthernetService";         public static void main(String[] args) {           new SystemServer().run();         }         private void run() {           startOtherServices();         }         private void startOtherServices() {           if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET)) {                       mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);           }         } 




3.当系统进入到 PHASE_SYSTEM_SERVICES_READY时状态时,EthernetService的onBootPhase()方法被触发,调用EthernetServiceImpl .Start();

//frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetService.java      public final class EthernetService extends SystemService {      private static final String TAG = "EthernetService";     final EthernetServiceImpl mImpl;      public EthernetService(Context context) {         super(context);         mImpl = new EthernetServiceImpl(context);     }      @Override     public void onStart() {     // 将ServiceImpl注册到ServiceManager           Log.i(TAG, "Registering service " + Context.ETHERNET_SERVICE);         publishBinderService(Context.ETHERNET_SERVICE, mImpl);     }      @Override     public void onBootPhase(int phase) {      //当系统运行到PHASE_SYSTEM_SERVICES_READY状态是时,Service启动EthernetServiceImpl            if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {             mImpl.start();         }     } }

//frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetConfigStore.java public class EthernetConfigStore extends IpConfigStore {      private static final String ipConfigFile =  Environment.getDataDirectory() +             "/misc/ethernet/ipconfig.txt";      public EthernetConfigStore() {     }      public IpConfiguration readIpAndProxyConfigurations() {         SparseArray<IpConfiguration> networks = readIpAndProxyConfigurations(ipConfigFile);          if (networks.size() == 0) {             Log.w(TAG, "No Ethernet configuration found. Using default.");             return new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null);         }          if (networks.size() > 1) {             // Currently we only support a single Ethernet interface.             Log.w(TAG, "Multiple Ethernet configurations detected. Only reading first one.");         }          return networks.valueAt(0);     }

  • 可知,ipconfig存储在 “data/misc/ethernet/ipconfig.txt”中。那么解决方案也就来了

step 2配置以太网设置默认为静态ip

  • 1.手动配置好一份静态ip





  • 因为是在桌面输入的命令行,所以复制出的ipconfig.txt 的位置在桌面





  • 3)将上面提到的EthernetConfigStore 类中的ipConfigFile 修改为

    private static final String ipConfigFile = Environment.getRootDirectory() +         "/etc/ipconfig.txt";
    • 1
    • 2

    参考 https://blog.csdn.net/qq_34705828/article/details/76283929安卓5.1的调试

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!