Android11.0系统中启用以太网网络ADB调试

Android11.0系统中启用以太网网络ADB调试

    • 启用以太网网络ADB调试
    • 封装的jar中添加对应方法供第三方应用开发者调用
    • 在系统设置中添加控制开关参见其它文章自行实现

启用以太网网络ADB调试

  1. 添加自定义属性,路径为 /device/rockchip/rk356x/rk356x.prop;
persist.sys.adb_network_debug_open=0
  1. 启用以太网网络ADB调试属性,路径为 /device/rockchip/rk356x/device.mk;
PRODUCT_PROPERTY_OVERRIDES += persist.internet_adb_enable=0
  1. ITestManager及TestManager中添加方法定义,路径为 /frameworks/base/core/com/yjz/test/api/ITestManager.aidl;
    void allowAdbNetworkDebug(boolean isAllow);

/frameworks/base/core/com/yjz/test/TestManager.java

    public void allowAdbNetworkDebug(boolean isAllow) {
        try {
            mService.allowAdbNetworkDebug(isAllow);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
  1. TestManagerService中添加方法,路径为 /frameworks/base/services/core/java/com/android/server/yjz/TestManagerService.java;
//********省略代码******

    private static final int MSG_WHAT_ALLOW_ADB_NETWORK_DEBUG = 10;

    @Override
    public void allowAdbNetworkDebug(boolean b) throws RemoteException {
        Message msg = Message.obtain();
        msg.what = MSG_WHAT_ALLOW_ADB_NETWORK_DEBUG;
        msg.arg1 = b ? 1 : 0;
        mHandler.sendMessage(msg);
    }

    private static final String PERSIST_ADB_NETWORK_DEBUG_OPEN = "persist.sys.adb_network_debug_open";
    private static final String PERSIST_RK_INTERNET_ADB = "persist.internet_adb_enable";

    private Handler mHandler = new Handler() {
        @Override
        public void dispatchMessage(@NonNull Message msg) {
            switch (msg.what) {
                case MSG_WHAT_ALLOW_ADB_NETWORK_DEBUG:
                    SystemProperties.set(PERSIST_RK_INTERNET_ADB, String.valueOf(msg.arg1));
                    break;
            }
        }
    };

    public void onStart() {
        if (SystemProperties.getInt(PERSIST_ADB_NETWORK_DEBUG_OPEN, 0) == 0
                && SystemProperties.getInt(PERSIST_RK_INTERNET_ADB, 0) != 0) {
            SystemProperties.set(PERSIST_RK_INTERNET_ADB, "0");
        }
    }

//********省略代码******
  1. 默认修改了系统属性persist.internet_adb_enable=1后,当设备重启以后会自动恢复为默认值persist.internet_adb_enable=0;当需要设备启动后persist.internet_adb_enable=1不变时,可以设置自定义persist.sys.adb_network_debug_open通过adb命令:
//设置属性开启
adb shell setprop persist.sys.adb_network_debug_open 1

//设置属性关闭
adb shell setprop persist.sys.adb_network_debug_open 0

//查询
adb shell getprop persist.sys.adb_network_debug_open

封装的jar中添加对应方法供第三方应用开发者调用

  1. 在添加 修改路径/vendor/yjz/com/yjz/sdk/SDKManager.java

//********省略代码******
    public void setAllowAdbNetworkDebug(boolean isAllow) {
        mTestManager.allowAdbNetworkDebug(isAllow);
    }
//********省略代码******

  1. 编译 mmm vendor/yjz/ 生成yjz-sdk-api.jar
  2. 应用开发时导入yjz-sdk-api.jar,并调用方法
   SDKManager manger = new SDKManager(this);
   manger.allowAdbNetworkDebug(true);
  1. 进行测试,设置为fase时(persist.internet_adb_enable=0),adb connect 192.xxx.xxx.xx,报如下错误:
unable to connect to 192.168.100.6:5555: cannot connect to 192.168.100.6:5555: 由于目标计算机积极拒绝,无法连接。 (10061)

当设置为true时(persist.internet_adb_enable=1),显示如下

connected to 192.168.100.6:5555

执行adb devices

192.168.100.6:5555      device

在系统设置中添加控制开关参见其它文章自行实现

你可能感兴趣的:(Android11.0,android)