Android Framework层设置Ip-Settings模块代码编译调试

系统环境:Android 13(高通8550)

一、背景

Android13中,为双网卡模式,有eth0和eth1两个网卡,eth0为业务网卡,eth1为管理网卡,设置ip时,一般设置的是业务网,博主这边设置Ip时封装了一个setip.sh,里面根据persist.ruichi.native_agent属性,判断是上层设置网络还是Native层设置网络。

示例命令如下:

setip.sh eth0 192.168.16.155 255.255.255.0 192.168.16.1 114.114.114.114

二、设置ip流程分析

1、setip.sh中接收到ip、netmask、gateway、dns等参数,通过广播形式发送

am broadcast -n $BROADCAST_PACKAGE -a android.net.action.ETHERNET_IP_CHANGED --es netMode "static" --es nic $1 --es ipaddr $2 --es netMask $3 --es gateway $4 --es dns1 $5

2、EthernetBoardcastReceive.java文件中接收到广播,处理相关设置逻辑,主要工作流程总结如下:

(1)、广播接收的值设置到Property属性和eeprom中

  readSystemCMD("setprop persist.net.ipaddr " + Ip);
                readSystemCMD("setprop persist.net.mEthNetmask " + Netmask);
                readSystemCMD("setprop persist.net.mEthGateway " + Gateway);
                readSystemCMD("setprop persist.net.dns1 " + dns1);
                readSystemCMD("setprop persist.net.dns2 " + dns2);
                readSystemCMD("eeprom_tools set 16 " + "'" + Ip + " " + Netmask + " " + " " + Gateway + " " + dns1 + " " + dns2 + "'");

(2)、将封装后的IP等值写入配置文件

    private static final String ETHERNET_DIR = "/data/misc/ethernet/";
    private static final String ETH0 = "ipconfig.txt";
    private static final String ETH1 = "ipconfig1.txt";


   /*
     * save ipconfig in /data/misc/ethernet/
     */
    private void saveNetConfig(String nicName, IpConfiguration ipConfiguration) {
        File dir = new File(ETHERNET_DIR);
        if (!dir.exists()) {
            dir.mkdir();
        }

        File config;
        if (nicName.equals("eth0")) {
            config = new File(ETHERNET_DIR, ETH0);
        } else if (nicName.equals("eth1")) {
            config = new File(ETHERNET_DIR, ETH1);
        } else {
            Log.w(TAG, "Invalid nic name : " + nicName);
            return;
        }

        if (config.exists()) {
            Log.i(TAG, "Recreate config file :" + config.getName());
            config.delete();
        } else {
            Log.i(TAG, "Save " + nicName + " config to " + config.getName());
        }

        IpConfigStore store = new IpConfigStore();
        ArrayMap<String, IpConfiguration> map = new ArrayMap<>();
        if (nicName.equals("eth0")) {
            map.put("eth0", ipConfiguration);
            Log.d(TAG, "writeIpConfigurations for eth0");
            store.writeIpConfigurations(ETHERNET_DIR + ETH0, map);
        } else if (nicName.equals("eth1")) {
            map.put("eth1", ipConfiguration);
            Log.d(TAG, "writeIpConfigurations for eth1");
            store.writeIpConfigurations(ETHERNET_DIR + ETH1, map);
        } else {
            Log.w(TAG, "Invalid nic name : " + nicName);
            return;
        }
}

三、EthernetBoardcastReceive.java中更改日志编译调试

路径:Qualcomm8550_CS/qssi/LA.QSSI.13.0/LINUX/android/packages/apps/Settings/src/com/android/settings/EthernetBoardcastReceive.java

1、在广播接收处更改日志

2、编译

(1)、qssi/LA.QSSI.13.0/LINUX/android  目录下执行 source build/envsetup.sh &  lunch 40

(2)、qssi/LA.QSSI.13.0/LINUX/android  目录下执行  mmm packages/apps/Settings
   如果编译test目录中的文件报错,删除即可
   rm packages/apps/Settings/tests/robotests/src/com/android/settings/biometrics/combination/CombinedBiometricStatusPreferenceControllerTest.java

(3)、编译生成的文件目录: out/target/product/qssi/system_ext/priv-app/Settings/Settings.apk

(4)、替换系统中该目录原先的 system_ext/priv-app/Settings/Settings.apk

(5)、查看settings服务

service list | grep settings 

(6)、重启服务(重启服务,新push 的apk才会生效)

am restart settings 

(7)、执行setip.sh脚本,查看日志

setip.sh eth0 192.168.16.155 255.255.255.0 192.168.16.1 114.114.114.114

logcat -s EthernetBoardcastReceive,日志如下:

从上面可以看到,我们更改的日志已生效

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

粤M温同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值