• Android 12 打开网络ADB并禁用USB连接ADB


    在这里插入图片描述

    平台

    RK3588 + Android 12

    Android 调试桥 (adb)
        Android 调试桥 (adb) 是一种功能多样的命令行工具,可让您与设备进行通信。adb 命令可用于执行各种设备操作,例如安装和调试应用。adb 提供对 Unix shell(可用来在设备上运行各种命令)的访问权限。它是一种客户端-服务器程序,包括以下三个组件:

    • 客户端:用于发送命令。客户端在开发机器上运行。您可以通过发出 adb 命令从命令行终端调用客户端。
    • 守护程序 (adbd):用于在设备上运行命令。守护程序在每个设备上作为后台进程运行。
    • 服务器:用于管理客户端与守护程序之间的通信。服务器在开发机器上作为后台进程运行。

    AndroidStudio 中显示的设备名称

    在这里插入图片描述
    第一个 rockchip 来自系统属性: ro.product.product.manufacturer
    第二个一般是ro.product.model
    PS 如果 manufacturer 和 model 一样, 那么会只显示一个的值.

    ADB使能和控制USB调试

    • ADB调试的开关:
      系统属性persist.sys.usb.config值里是否包含adb
      系统设置数据库Settings.Global.ADB_ENABLED值是否为非0

    frameworks/base/services/core/java/com/android/server/adb/AdbService.java

        private static final String USB_PERSISTENT_CONFIG_PROPERTY = "persist.sys.usb.config";
    
        private void initAdbState() {
            try {
                /*
                 * Use the normal bootmode persistent prop to maintain state of adb across
                 * all boot modes.
                 */
                mIsAdbUsbEnabled = containsFunction(
                        SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, ""),
                        UsbManager.USB_FUNCTION_ADB);
                mIsAdbWifiEnabled = "1".equals(
                        SystemProperties.get(WIFI_PERSISTENT_CONFIG_PROPERTY, "0"));
    
                // register observer to listen for settings changes
                mObserver = new AdbSettingsObserver();
                mContentResolver.registerContentObserver(
                        Settings.Global.getUriFor(Settings.Global.ADB_ENABLED),
                        false, mObserver);
                mContentResolver.registerContentObserver(
                        Settings.Global.getUriFor(Settings.Global.ADB_WIFI_ENABLED),
                        false, mObserver);
            } catch (Exception e) {
                Slog.e(TAG, "Error in initAdbState", e);
            }
        }
    
        private void setAdbEnabled(boolean enable, byte transportType) {
            if (DEBUG) {
                Slog.d(TAG, "setAdbEnabled(" + enable + "), mIsAdbUsbEnabled=" + mIsAdbUsbEnabled
                        + ", mIsAdbWifiEnabled=" + mIsAdbWifiEnabled + ", transportType="
                            + transportType);
            }
    
            if (transportType == AdbTransportType.USB && enable != mIsAdbUsbEnabled) {
                mIsAdbUsbEnabled = enable;
            } else if (transportType == AdbTransportType.WIFI && enable != mIsAdbWifiEnabled) {
                mIsAdbWifiEnabled = enable;
                if (mIsAdbWifiEnabled) {
                    if (!AdbProperties.secure().orElse(false) && mDebuggingManager == null) {
                        // Start adbd. If this is secure adb, then we defer enabling adb over WiFi.
                        SystemProperties.set(WIFI_PERSISTENT_CONFIG_PROPERTY, "1");
                        mConnectionPortPoller =
                                new AdbDebuggingManager.AdbConnectionPortPoller(mPortListener);
                        mConnectionPortPoller.start();
                    }
                } else {
                    // Stop adb over WiFi.
                    SystemProperties.set(WIFI_PERSISTENT_CONFIG_PROPERTY, "0");
                    if (mConnectionPortPoller != null) {
                        mConnectionPortPoller.cancelAndWait();
                        mConnectionPortPoller = null;
                    }
                }
            } else {
                // No change
                return;
            }
    
            if (enable) {
                startAdbd();
            } else {
                stopAdbd();
            }
    
            for (IAdbTransport transport : mTransports.values()) {
                try {
                    transport.onAdbEnabled(enable, transportType);
                } catch (RemoteException e) {
                    Slog.w(TAG, "Unable to send onAdbEnabled to transport " + transport.toString());
                }
            }
    
            if (mDebuggingManager != null) {
                mDebuggingManager.setAdbEnabled(enable, transportType);
            }
        }
    
        private void startAdbd() {
            SystemProperties.set(CTL_START, ADBD);
        }
    
        private void stopAdbd() {
            if (!mIsAdbUsbEnabled && !mIsAdbWifiEnabled) {
                SystemProperties.set(CTL_STOP, ADBD);
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87

    使用设置系统属性ctl.start启动和ctl.stop停止adbd服务

    • 增加系统控制是否启用USB调试

    packages/modules/adb/daemon/main.cpp

    int adbd_main(int server_port) {
        umask(0);
    
        signal(SIGPIPE, SIG_IGN);
    //.....
    #if defined(__ANDROID__)
    	bool adb_usb_on = android::base::GetBoolProperty("persist.adb.adb_usb", false);
        if (access(USB_FFS_ADB_EP0, F_OK) == 0 && adb_usb_on) {
            // Listen on USB.
            usb_init();
            is_usb = true;
        }
    #endif
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    修改系统属性后, 重启adbd服务生效.

    • 默认网络ADB调试端口
      系统属性service.adb.tcp.port

    修改 packages/modules/adb/daemon/main.cpp 需注意, 可能导致烧录后不能启动, 卡在下面LOG:

    emmc_point is /dev/block/mmcblk0
    sd_point is (null)
    sd_point_2 is (null)
    read cmdline
    I:Boot command: boot-recovery
    I:Got 2 arguments from boot message
    ensure_path_mounted path=/cache/recovery/last_locale 
    I:[libfs_mgr]superblock s_max_mnt_count:65535,/dev/block/by-name/cache
    I:[libfs_mgr]__mount(source=/dev/block/by-name/cache,target=/cache,type=ext4)=0: Success
    Loading make_device from librecovery_ui_ext.so
    W:Failed to read max brightness: No such file or directory
    I:Screensaver disabled
              erasing_text: zh (81 x 38 @ 5031)
           no_command_text: zh (111 x 38 @ 5031)
                error_text: zh (65 x 38 @ 5031)
    W:Failed to load bitmap cancel_wipe_data_text for locale zh-Hans-CN (error -1). Falling back to use default locale.
    E:Failed to load bitmap cancel_wipe_data_text for locale en-US (error -1)
    W:Failed to load bitmap factory_data_reset_text for locale zh-Hans-CN (error -1). Falling back to use default locale.
    E:Failed to load bitmap factory_data_reset_text for locale en-US (error -1)
    W:Failed to load bitmap try_again_text for locale zh-Hans-CN (error -1). Falling back to use default locale.
    E:Failed to load bitmap try_again_text for locale en-US (error -1)
    W:Failed to load bitmap wipe_data_confirmation_text for locale zh-Hans-CN (error -1). Falling back to use default loc.
    E:Failed to load bitmap wipe_data_confirmation_text for locale en-US (error -1)
    W:Failed to load bitmap wipe_data_menu_header_text for locale zh-Hans-CN (error -1). Falling back to use default loca.
    E:Failed to load bitmap wipe_data_menu_header_text for locale en-US (error -1)
    I:Starting recovery (pid 258) on Fri Nov 17 01:15:53 2023
    
    I:locale is [zh-Hans-CN]
    SELinux: Loaded file_contexts
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
  • 相关阅读:
    粒子群优化算法(PSO)python实践
    Axure RP PC电商平台Web端交互原型模板
    理性推广 | C1N短网址帮您节省运营成本!
    RSA与AES加密
    5.springcloudalibaba nacos 2.2.3源码下载并且注册服务到nacos
    Linux vim 文本编辑 操作文本 三种模式
    面试题整理
    如何在Excel中去除、修改和移除编辑密码
    网络安全系列-三十一:基于kali系统安装CALDERA【建立在MITRE ATT&CK™之上的网络安全平台】
    借鉴前端事件机制的Spring AOP
  • 原文地址:https://blog.csdn.net/ansondroider/article/details/134444587