先来看看系统的进程的入口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);
- }
- }
EthernetService 被启动之后就干了三件事儿:
1.构造函数中创建EthernetServiceImpl 对象
2.在onStart()方法 中将EthernetServiceImpl对象注册进了ServiceManager。
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();
- }
- }
- }
- IpConfiguration 这个类就是以太网配置信息类啊!!!!!!! 模式是DHCP啊还是静态啊,静态的ip ,网关啥的都存在这里头
- //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
2.取出以太网配置文件: ipconfig.txt
进入命令行,输入
adb root
adb pull /data/misc/ethernet/ipconfig.txt
因为是在桌面输入的命令行,所以复制出的ipconfig.txt 的位置在桌面3.device.mk文件中 将 ipconfig 预设置到固定位置
1)找到一份源码编译时一定会编译的device.mk 文件,在device.mk中添加
PRODUCT_COPY_FILES += $(LOCAL_PATH)/ipconfig.txt:system/etc/ipconfig.txt
2)将刚刚拷贝的ipconfig.txt 文件复制到与device.mk同目录下.
3)将上面提到的EthernetConfigStore 类中的ipConfigFile 修改为- private static final String ipConfigFile = Environment.getRootDirectory() +
- "/etc/ipconfig.txt";
3029




被折叠的 条评论
为什么被折叠?



