• Lv0
    粉丝1

积分297 / 贡献0

提问41答案被采纳11文章1

查了一下文档arkts好像没有关闭以太网的接口。请问大佬们有别的办法在应用层上实现关闭以太网吗

云端筑梦 显示全部楼层 发表于 2024-2-2 09:12:37
我也尝试了用napi的方法写但是也不行(上传了测试用的demo,请大佬们帮忙看一下)

![]()

![]()

ethtest.zip

5.42 MB, 下载次数: 1

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

精彩评论6

momo

沙发 发表于 2024-2-26 09:27:22
1.新建init services如下,放到/system/etc/init/  
  1. {
  2.     "jobs" : [{
  3.             "name" : "param:sys.ifconfig.eth0=up",
  4.             "condition" : "sys.ifconfig.eth0=up",
  5.             "cmds" : [
  6.                 "start if_eth0_up"
  7.             ]
  8.         }, {
  9.             "name" : "param:sys.ifconfig.eth0=down",
  10.             "condition" : "sys.ifconfig.eth0=down",
  11.             "cmds" : [
  12.                 "start if_eth0_down"
  13.             ]
  14.         }
  15.     ],
  16.         "services" : [{
  17.             "name" : "if_eth0_up",
  18.             "start-mode" : "condition",
  19.             "path" : ["/system/bin/ifconfig", "eth0", "up"],
  20.             "disabled" : 1,
  21.             "sandbox" : 0,
  22.             "uid" : "root",
  23.             "gid" : ["shell"],
  24.             "once" : 1,
  25.             "secon" : "u:object_r:sh_exec:s0"
  26.         },
  27.         {
  28.             "name" : "if_eth0_down",
  29.             "start-mode" : "condition",
  30.             "path" : ["/system/bin/ifconfig", "eth0", "down"],
  31.             "disabled" : 1,
  32.             "sandbox" : 0,
  33.             "uid" : "root",
  34.             "gid" : ["shell"],
  35.             "once" : 1,
  36.             "secon" : "u:object_r:sh_exec:s0"
  37.         }
  38.     ]
  39. }
复制代码


2.应用端使用
import systemparameter from '@ohos.systemparameter';
//关掉以太网
  try {
    systemparameter.setSync("sys.ifconfig.eth0", "down");
  }catch(e){
    console.log("set unexpected error: " + e);
  }
  //打开以太网
try {
  systemparameter.setSync("sys.ifconfig.eth0", "up");
}catch(e){
  console.log("set unexpected error: " + e);
}

xq_qyh

发表于 2024-2-26 17:30  IP属地: - 中国广东省广州市 中国电信IDC

回复 momo: 大佬好厉害啊

xq_qyh

发表于 2024-2-27 11:34  IP属地: - 中国广东省广州市 中国电信IDC

回复 xq_qyh: 如果说我要把它内置到源码里去应该放在哪个目录下面呢,我尝试了一下放在base\startup\init\services\etc\目录下,但是好像并没有生效

momo

发表于 2024-2-27 13:53  IP属地: - 中国广东省广州市 中国电信IDC

回复 xq_qyh: 新建ifconfig_eth.cfg保存上面回复内容,然后把文件编译到/system/etc/init/ 这个目录就行
主要修改BUILD.gn添加
ohos_prebuilt_etc("ifconfig_eth.cfg") {
     source = "ifconfig_eth.cfg"
     relative_install_dir = "init"
     part_name = "product_rk3568"
  }

xq_qyh

发表于 2024-2-28 09:07  IP属地: - 中国广东省广州市 中国电信IDC

回复 momo: 好的,谢谢大佬

【4 条回复】

18025342273

板凳 发表于 2024-4-1 15:15:53
mark一下

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部