当前位置:   article > 正文

Android 使用adb操作WiFi连接扫描等相关指令_adb wifi

adb wifi

Android 使用adb操作WiFi连接扫描等相关指令

一、前言

Android系统调试是,如果没有系统原生设置应用又需要调试验证WiFi功能时,

可以使用一些指令来验证调试WiFi相关功能,

最常用的就是 svc wifi enable/disable,或者使用iv dev来验证,

但对于AP功能就没办法验证了,并且可调试功能比较少,

其实Android系统自带有组很强大的shell指令集,

这里记录下平时使用的cmd wifi 相关指令。

系统初期开发或者定位一下wifi、热点问题会比较有用。

本文不仅详细介绍cmd wifi相关用法,并且后续有介绍系统Java代码中具体控制位置,

如果有特殊需求可以对命令进行扩展定制。

目前网上还没有这么全面介绍的文章,有wifi调试需求的可以先收藏后续慢慢查看。

二、adb shell cmd wifi 主要命令

### 1、adb shell cmd wifi -h

查看WiFi所有指令以及参数

命令具体信息太多,最后展示。

串口查看命令具体参数技巧,grep 某个关键字:

console:/ # cmd wifi -h | grep   connect-network                               
  connect-network <ssid> open|owe|wpa2|wpa3|wep [<passphrase>] [-x] [-m] [-d] [-b <bssid>] [-r auto|none|persistent|non_persistent]
console:/ # 
  • 1
  • 2
  • 3

下面很多命令返回的结果是使用串口工具展示的,串口命令是不需要adb 连接的。

2、打开关闭WLAN

adb shell cmd wifi set-wifi-enabled enabled

adb shell cmd wifi set-wifi-enabled disabled

3、扫描WiFi 和查看扫描列表

adb shell cmd wifi start-scan             //扫描

adb shell cmd wifi list-scan-results    //查看扫描结果
  • 1
  • 2
  • 3

cmd wifi list-scan-results 命令扫描到的信息:

console:/ # 
console:/ # cmd wifi list-scan-results  
    BSSID              Frequency      RSSI           Age(sec)     SSID   Flags
  48:5f:08:ed:f7:f1       5200        -68             10.148    synwcs_5G                         [WPA2-PSK-CCMP][RSN-PSK-CCMP][WPA-PSK-CCMP][ESS]
  34:f7:16:92:87:6c       2442        -38             10.148    syrj                              [WPA-PSK-CCMP][WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS]
  de:00:1a:bc:b3:4a       2422        -57             10.148    IFLYHub_86_7849                   [WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS]
  80:ea:07:28:ef:1c       5240        -96             10.148    HorionRj_5G                       [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][RSN-PSK-CCMP+TKIP][ESS]
  48:5f:08:45:a6:c1       5805        -53             10.148    SYEBSW-5G                         [WPA-PSK-CCMP][WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS]
  f4:84:8d:24:19:35       5785        -77             10.148    synwcs-m_5G                       [WPA-PSK-CCMP][WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS]

console:/ # 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

扫描列表中信息含义:

BSSID     :MAC地址
Frequency :信号频段,5G:5160到5865,2.4G:2401~2483MHz
RSSI      :wifi信号强度,RSSI >=-55为满格信号,level为4,每个level之间的Rssi的跳变为15
Age(sec)  :响应时间?
SSID      :wifi名称
Flags     :加密格式,包含加密相关字符
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4、连接WiFi

adb shell cmd wifi connect-network wifiName wpa2 12345678
  • 1

//wifiName 连接WiFi名称

//wpa2 加密方式,如果没有密码写 open ,最后的密码不用写

//12345678 密码

如果没有密码,连接xm名称的wifi:

cmd wifi connect-network xm open
  • 1

5、查看WiFi状态

adb shell cmd wifi status

(1) wifi 正常连接下的信息:
C:\Users\As11040>adb shell cmd wifi status
Wifi is enabled //(1)查看到Wifi的开关状态
Wifi scanning is only available when wifi is enabled //(2)扫描状态
==== Primary ClientModeManager instance ====
Wifi is connected to "xm5G" //(3)wifi连接的名称,下面是详细信息
WifiInfo: SSID: "xm5G", BSSID: 8c:53:c3:53:c6:59, MAC: c0:f5:35:4f:a3:e0, IP: /192.168.31.17, Security type: 0, Supplicant state: COMPLETED, Wi-Fi standard: 5, RSSI: -46, Link speed: 702Mbps, Tx Link speed: 702Mbps, Max Supported Tx Link speed: 866Mbps, Rx Link speed: 780Mbps, Max Supported Rx Link speed: 866Mbps, Frequency: 5785MHz, Net ID: 2, Metered hint: false, score: 60, isUsable: true, CarrierMerged: false, SubscriptionId: -1, IsPrimary: 1, Trusted: true, Restricted: false, Ephemeral: false, OEM paid: false, OEM private: false, OSU AP: false, FQDN: <none>, Provider friendly name: <none>, Requesting package name: <none>"xm5G"openMLO Information: , Is TID-To-Link negotiation supported by the AP: false, AP MLD Address: <none>, AP MLO Link Id: <none>, AP MLO Affiliated links: <none>
successfulTxPackets: 317
successfulTxPacketsPerSecond: 2.4672825327175896
retriedTxPackets: 3898
retriedTxPacketsPerSecond: 0.4502428708131321
lostTxPackets: 42
lostTxPacketsPerSecond: 0.0
successfulRxPackets: 173
successfulRxPacketsPerSecond: 2.4364789031543634

C:\Users\As11040>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
(2)串口查看wifi关闭情况的信息:
console:/ # cmd wifi status                                                    
Wifi is disabled
Wifi scanning is only available when wifi is enabled
console:/ # 
  • 1
  • 2
  • 3
  • 4
(3)串口查看wifi开启,但是未连接wifi情况的信息:
console:/ # cmd wifi status                                                    
Wifi is enabled
Wifi scanning is only available when wifi is enabled
==== ClientModeManager instance: ConcreteClientModeManager{id=2374293 iface=wlan0 role=ROLE_CLIENT_PRIMARY} ====
Wifi is not connected
console:/ # 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

6、查看已保存或者连接的WiFi列表

Unknown command: list-network //未连接wifi前的情况
255|console:/ # cmd wifi list-networks                                         
No networks
console:/ # 

console:/ # cmd wifi list-networks //连接wifi后的打印   
Network Id      SSID                         Security type
0            xm5G                             open
0            xm5G                             owe^
1            syrj                             wpa2-psk
1            syrj                             wpa3-sae^
console:/ # 
console:/ # 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

上面可以看到每连接一个wifi都会有重复多一个,另外一个信息是不准确的,这个不影响。

7、打开关闭热点

(1)打开热点
adb shell cmd wifi start-softap ap_ssidxx wpa2 12345678 -b 5
  • 1

// ap_ssidxx 热点名称

// wpa2 加密方式

//12345678 密码

//-b 5 5G频段

实际运行运行中,运行上面代码,会有点小问题:
热点是开启了,也可以被搜到和连接上;

但是打开Setings应用发现,热点名称,密码,加密类型等信息并没有修改,重启后也是无效的;

所以说这个方法开启热点只能单次有效。

(2)关闭热点
adb shell cmd wifi stop-softap
  • 1

关闭是没啥问题的。

三、其他

1、adb shell cmd wifi -h 完整信息

C:\Users\As11140>adb shell cmd wifi -h
Wi-Fi (wifi) commands:
  help or -h
    Print this help text.
  get-country-code //(1)获取国家码
    Gets country code as a two-letter string
  set-wifi-enabled enabled|disabled //(2)wifi打开和关闭
    Enables/disables Wifi on this device.
  set-scan-always-available enabled|disabled //(3)设置是否扫描状态
    Sets whether scanning should be available even when wifi is off.
  list-scan-results //(4)查看扫描到的列表
    Lists the latest scan results
  start-scan //(5)开始扫描
    Start a new scan
  list-networks //(6)保存的wifi,名称和networkid
    Lists the saved networks
  forget-network <networkId> //(7)忘记某个网络的networkid
    Remove the network mentioned by <networkId>
        - Use list-networks to retrieve <networkId> for the network
  status  //(8)wifi当前状态,打开状态和连接状态
    Current wifi status
  set-verbose-logging enabled|disabled  //(9)wifi打印等级是否调高
    Set the verbose logging enabled or disabled
  is-verbose-logging  //(10)wifi打印等级查看
    Check whether verbose logging enabled or disabled
  start-restricting-auto-join-to-subscription-id subId
    temporarily disable all wifi networks except merged carrier networks with the given subId
  stop-restricting-auto-join-to-subscription-id
    Undo the effects of start-restricting-auto-join-to-subscription-id
  add-suggestion <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-u] [-o] [-p] [-m]  [-s] [-d] [-b <bssid>] [-e] [-i] [-a <carrierId>] [-c <subscriptionId>]
    Add a network suggestion with provided params
    Use 'network-suggestions-set-user-approved com.android.shell yes' to approve suggestions added via shell (Needs root access)
    <ssid> - SSID of the network
    open|owe|wpa2|wpa3 - Security type of the network.
        - Use 'open' or 'owe' for networks with no passphrase
           - 'open' - Open networks (Most prevalent)
           - 'owe' - Enhanced open networks
        - Use 'wpa2' or 'wpa3' for networks with passphrase
           - 'wpa2' - WPA-2 PSK networks (Most prevalent)
           - 'wpa3' - WPA-3 PSK networks
    -u - Mark the suggestion untrusted.
    -o - Mark the suggestion oem paid.
    -p - Mark the suggestion oem private.
    -m - Mark the suggestion metered.
    -h - Mark the network hidden.
    -s - Share the suggestion with user.
    -d - Mark the suggestion autojoin disabled.
    -b <bssid> - Set specific BSSID.
    -r - Enable non_persistent randomization (disabled by default)
    -a - Mark the suggestion carrier merged
    -c <carrierId> - set carrier Id
    -i <subscriptionId> - set subscription Id, if -a is used, this must be set
  remove-suggestion <ssid> [-l]
    Remove a network suggestion with provided SSID of the network
    -l - Remove suggestion with lingering, if not set will disconnect immediately
  remove-all-suggestions
    Removes all suggestions added via shell
  list-suggestions  //(12)对应List<WifiNetworkSuggestion> ,不清楚作用
    Lists the suggested networks added via shell
  set-coex-cell-channels [lte|nr <bandNumber 1-261> <downlinkFreqKhz or UNKNOWN: -1> <downlinkBandwidthKhz or UNKNOWN: 0> <uplinkFreqKhz or UNKNOWN: -1> <uplinkBandwidthKhz or UNKNOWN: 0>] ...
    Sets a list of zero or more cell channels to use for coex calculations. Actual device reported cell channels will be ignored until reset-coex-cell-channels is called.
  reset-coex-cell-channels
    Removes all cell channels set in set-coex-cell-channels and returns to listening on actual device reported cell channels
  get-coex-cell-channels
    Prints the cell channels being used for coex.
  set-connected-score <score>
    Set connected wifi network score (to choose between LTE & Wifi for default route).
    This turns off the active connected scorer (default or external).
    Only works while connected to a wifi network. This score will stay in effect until you call reset-connected-score or the device disconnects from the current network.
    <score> - Integer score should be in the range of 0 - 60
  reset-connected-score
    Turns on the default connected scorer.
    Note: Will clear any external scorer set.
  //(13)打开热点
  start-softap <ssid> (open|wpa2|wpa3|wpa3_transition|owe|owe_transition) <passphrase> [-b 2|5|6|any|bridged|bridged_2_5|bridged_2_6|bridged_5_6] [-x] [-f <int> [<int>]]
    Start softap with provided params
    Note that the shell command doesn't activate internet tethering. In some devices, internet sharing is possible when Wi-Fi STA is also enabled and isassociated to another AP with internet access.
    <ssid> - SSID of the network
    open|wpa2|wpa3|wpa3_transition|owe|owe_transition - Security type of the network.
        - Use 'open', 'owe', 'owe_transition' for networks with no passphrase
        - Use 'wpa2', 'wpa3', 'wpa3_transition' for networks with passphrase
    -b 2|5|6|any|bridged|bridged_2_5|bridged_2_6|bridged_5_6 - select the preferred bands.
        - Use '2' to select 2.4GHz band as the preferred band
        - Use '5' to select 5GHz band as the preferred band
        - Use '6' to select 6GHz band as the preferred band
        - Use 'any' to indicate no band preference
        - Use 'bridged' to indicate bridged AP which enables APs on both 2.4G + 5G
        - Use 'bridged_2_5' to indicate bridged AP which enables APs on both 2.4G + 5G
        - Use 'bridged_2_6' to indicate bridged AP which enables APs on both 2.4G + 6G
        - Use 'bridged_5_6' to indicate bridged AP which enables APs on both 5G + 6G
    Note: If the band option is not provided, 2.4GHz is the preferred band.
          The exact channel is auto-selected by FW unless overridden by force-softap-channel command or '-f <int> <int>' option
    -f <int> <int> - force exact channel frequency for operation channel
    Note: -f <int> <int> - must be the last option
          For example:
          Use '-f 2412' to enable single Soft Ap on 2412
          Use '-f 2412 5745' to enable bridged dual Soft Ap on 2412 and 5745
    -x - Specifies the SSID as hex digits instead of plain text (T and above)
  stop-softap
    Stop softap (hotspot) //(14)关闭热点
  pmksa-flush <networkId>
        - Flush the local PMKSA cache associated with the network id. Use list-networks to retrieve <networkId> for the network
  reload-resources
    Reset the WiFi resources cache which will cause them to be reloaded next time they are accessed. Necessary if overlays are manually modified.
  launch-dialog-simple [-t <title>] [-m <message>] [-l <url> <url_start> <url_end>] [-y <positive_button_text>] [-n <negative_button_text>] [-x <neutral_button_text>] [-c <timeout_millis>]
    Launches a simple dialog and waits up to 15 seconds to print the response.
    -t - Title
    -m - Message
    -l - URL of the message, with the start and end index inside the message
    -y - Positive Button Text
    -n - Negative Button Text
    -x - Neutral Button Text
    -c - Optional timeout in milliseconds
    -s - Use the legacy dialog implementation on the system process
  launch-dialog-p2p-invitation-sent <device_name> <pin> [-i <display_id>]
    Launches a P2P Invitation Sent dialog.
    <device_name> - Name of the device the invitation was sent to
    <pin> - PIN for the invited device to input
  launch-dialog-p2p-invitation-received <device_name> [-p] [-d <pin>] [-i <display_id>] [-c <timeout_millis>]
    Launches a P2P Invitation Received dialog and waits up to 15 seconds to print the response.
    <device_name> - Name of the device sending the invitation
    -p - Show PIN input
    -d - Display PIN <pin>
    -i - Display ID
    -c - Optional timeout in milliseconds
  query-interface <uid> <package_name> STA|AP|AWARE|DIRECT [-new]
    Query whether the specified could be created for the specified UID and package name, and if so - what other interfaces would be destroyed
    -new - query for a new interfaces (otherwise an existing interface is ok
  interface-priority-interactive-mode enable|disable|default
    Enable or disable asking the user when there's an interface priority conflict, |default| implies using the device default behavior.
  set-one-shot-screen-on-delay-ms <delayMs>
    set the delay for the next screen-on connectivity scan in milliseconds.
  set-network-selection-config <enabled|disabled> <enabled|disabled> -a <associated_network_selection_override>
    set whether sufficiency check is enabled for screen off case (first arg), and screen on case (second arg)
    -a - set as one of the int WifiNetworkSelectionConfig.ASSOCIATED_NETWORK_SELECTION_OVERRIDE_ values:
      0 - no override
      1 - override to enabled
      2 - override to disabled
  set-ipreach-disconnect enabled|disabled
    Sets whether CMD_IP_REACHABILITY_LOST events should trigger disconnects.
  get-ipreach-disconnect
    Gets setting of CMD_IP_REACHABILITY_LOST events triggering disconnects.
  take-bugreport
    take bugreport through betterBug. If it failed, take bugreport through bugreport manager.
  get-allowed-channel  //(15)当前设备支持的信道值,热点相关
    get allowed channels in each operation mode from wifiManager if available. Otherwise, it returns from wifiScanner.


C:\Users\As11140>

  • 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
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150

上面标记了15个 可能会用到的场景,其他的场景看不懂,也没怎么用过,有兴趣的可以自己看看。

整个信息太多了,有时候不好找。

可以在adb shell 或者设备串口中使用 grep 过滤关键字查看相关信息:

cmd wifi -h | grep xxx关键字    
  • 1

2、 adb shell cmd wifi 命令在系统中的具体代码

Android cmd wifi 控制和查询wifi命令的控制代码都在 WifiShellCommand.java 里面。

WifiShellCommand.java 代码位置:

Android13 或者更新版本的 WifiShellCommand.java 的具体位置:
package\modules\Wifi\service\java\com\android\server\wifi\WifiShellCommand.java
Android11 或者更旧版本的 WifiShellCommand.java 的具体位置:
frameworks\opt\net\wifi\service\java\com\android\server\wifi\WifiShellCommand.java
  • 1
  • 2
  • 3
  • 4

关键代码如下:

public class WifiShellCommand extends BasicShellCommandHandler {
    @VisibleForTesting
    public static String SHELL_PACKAGE_NAME = "com.android.shell";

    // These don't require root access.
    // However, these do perform permission checks in the corresponding WifiService methods.
    private static final String[] NON_PRIVILEGED_COMMANDS = {//命令汇总
            "add-suggestion",
            "forget-network",
            "get-country-code",
            "help",
            "-h",
            "is-verbose-logging",
            "list-scan-results",
            "list-networks",
            "list-suggestions",
            "remove-suggestion",
            "remove-all-suggestions",
            "reset-connected-score",
            "set-connected-score",
            "set-scan-always-available",
            "set-verbose-logging",
            "set-wifi-enabled",
            "set-passpoint-enabled",
            "set-multi-internet-state",
            "start-scan",
            "start-softap",
            "status",
            "stop-softap",
            "query-interface",
            "interface-priority-interactive-mode",
            "set-one-shot-screen-on-delay-ms",
            "set-network-selection-config",
            "set-ipreach-disconnect",
            "get-ipreach-disconnect",
            "take-bugreport",
            "get-allowed-channel",
    };

    @Override
    public int onCommand(String cmd) {
        // Treat no command as help command.
        if (TextUtils.isEmpty(cmd)) {
            cmd = "help";
        }
        // Explicit exclusion from root permission
        if (ArrayUtils.indexOf(NON_PRIVILEGED_COMMANDS, cmd) == -1) {
            final int uid = Binder.getCallingUid();
            if (uid != Process.ROOT_UID) {
                throw new SecurityException(
                        "Uid " + uid + " does not have access to " + cmd + " wifi command "
                                + "(or such command doesn't exist)");
            }
        }
        final PrintWriter pw = getOutPrintWriter();
        try {
            switch (cmd) {
                case "set-ipreach-disconnect": {
                    boolean enabled = getNextArgRequiredTrueOrFalse("enabled", "disabled");
                    mWifiGlobals.setIpReachabilityDisconnectEnabled(enabled);
                    return 0;
                }
                case "set-wifi-enabled": { //开关wifi
                    boolean enabled = getNextArgRequiredTrueOrFalse("enabled", "disabled");
                    //调用 WifiService.setWifiEnabled 接口开关wifi
                    mWifiService.setWifiEnabled(SHELL_PACKAGE_NAME, enabled);
                    return 0;
                }
                case "list-networks":  //查看已连接或者已保存的wifi列表
                	//获取wifi列表
                    ParceledListSlice<WifiConfiguration> networks =
                            mWifiService.getConfiguredNetworks(SHELL_PACKAGE_NAME, null, false);
                    if (networks == null || networks.getList().isEmpty()) {
                        pw.println("No networks");
                    } else {
                        pw.println("Network Id      SSID                         Security type");
                        for (WifiConfiguration network : networks.getList()) {
                            String securityType = network.getSecurityParamsList().stream()
                                    .map(p -> WifiConfiguration.getSecurityTypeName(
                                                    p.getSecurityType())
                                            + (p.isAddedByAutoUpgrade() ? "^" : ""))
                                    .collect(Collectors.joining("/"));
                            pw.println(String.format("%-12d %-32s %-4s",
                                    network.networkId, WifiInfo.sanitizeSsid(network.SSID),
                                    securityType));
                        }
                    }
                    return 0;
                case ...
            }
        }
    }
    
}
  • 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
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94

上面只展示了set-wifi-enabled 和 list-networks 命令相关代码,

其他的也是类似的调用WifiService 相关api实现具体功能,部分接口是有用print打印返回的数据。

代码大概有两千多行,有兴趣的可以看看源码:

http://aospxref.com/android-13.0.0_r3/xref/packages/modules/Wifi/service/java/com/android/server/wifi/WifiShellCommand.java

3、svc控制 wifi、热点、蓝牙命令

svc 主要命令:

adb shell svc power|wifi|bluetooth|usb|nfc 
  • 1

从上面介绍可以知道,其实只要记住 svc,那么就是提示其他相关命令,然后再输入功能命令,就会显示具体参数介绍。

svc 功能只能对某个模块开关等基础功能。

svc详解: https://blog.csdn.net/wenzhi20102321/article/details/132779708

4、iw dev命令

(1)iw dev 示例

iw dev 命令比较特殊,这个命令是直接对节点数据进行查询和设置的,不需要经过WifiService那些Java逻辑。

console:/ # iw dev //查看无线设备信息,和相关节点                                                           
phy#0
        Unnamed/non-netdev interface
                wdev 0x4
                addr c2:f5:35:4f:a3:e0
                type P2P-device
                txpower 31.00 dBm
        Interface wlan1 //热点 节点
                ifindex 17
                wdev 0x2
                addr d2:4e:71:f2:ce:56
                ssid AndroidAP_1026 //热点名称
                type AP
                channel 157 (5785 MHz), width: 80 MHz, center1: 5775 MHz
                txpower 31.00 dBm
        Interface wlan0 //wifi节点
                ifindex 16
                wdev 0x1
                addr c0:f5:35:4f:a3:e0
                ssid xm5G //wifi已连接的名称
                type managed
                channel 157 (5785 MHz), width: 80 MHz, center1: 5775 MHz
                txpower 31.00 dBm
console:/ # sched_stop 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

这个命令我也不熟悉,是最近几天通过驱动底层开发人员一起调试设备了解到的命令。

(2)通过wifi节点搜索wifi列表

比如搜索wifi列表, iw wlan0 scan | grep SSID:

console:/ # iw wlan0 scan | grep SSID
        SSID: 
        SSID: syrj_5G
                 * SSID List
        SSID: B-LINK-5G_EE7180
        SSID: xm5G
        SSID: ktceb-vpn-5G
        SSID: VPN_5G
        SSID: SYEBSW-5G
        SSID: syrj
                 * SSID List
        SSID: ktceb-vpn-2.4G
        SSID: 
        SSID: SYEBSW-2.4G
console:/ # 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

如果没有grep SSID会看到很多打印,比如每个wifi的加密情况和其他配置信息。

实际开发调试中系统有出现过上层接口无法打开wifi的情况(原因:上层调用IWifi接口卡死),

但是强制up打开 wlan0 后,是直接可以使用iw wlan0 命令搜索到wifi 列表,

说明内核是正常加载的,后面发现是binder IWifi异常了,是hardware 层的服务无法连接,

并不是WifiManager到WifiService的 binder异常,

底层适配修改了 usb_inotify 、ko驱动和相关加载逻辑进行解决。

(3)iw dev 主要命令
iw 命令后面加上不同的参数,例如:

iw dev interface add 用于添加一个新的接口

iw dev del 用于删除一个接口

iw dev scan 用于扫描可用的无线网络

iw dev support 用于查看设备支持的参数

dev 表示不同的节点名称,比我wifi的 wlan0

请注意,某些命令可能需要root权限才能运行。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

常用的就是:iw dev del,iw dev scan ,其他命令简单执行了一下,发现返回的提示数据非常多,有点看不懂。

5、adb简介及常用命令总结

1、启动adb:adb start-server;adb shell start 包名/类名 启动应用
2、查看已经连接的设备:adb devices
3、adb logcat: 打印log信息
4、发送文件到设备:adb push
5、下载文件到电脑:adb pull 手机文件路径 电脑目标路径
6、截屏命令:adb shell screencap /sdcard/screen.png
传出到本地:adb pull /sdcard/screen.png
7、杀死adb:adb kill-server
8、adb连接:adb connect …(ip地址)
9、adb 命令控制:adb shell
10、adb connect/disconnect:通过wifi远程连接手机调试.
11、adb shell am:am即activity manager.
备注:该命令用来执行一些系统动作, 例如启动指定activity, 结束进程, 发送广播, 更改屏幕属性等

12、 adb root:以root身份重新进入adb

13、adb remount刷新文件系统

14、adb pull sdcard/bk100 c:/ 取出bk100文件夹下面的所有文件到c盘根目录

15、adb push c:/log.txt sdcard/ 将c盘下的log文件复制到sdcard根目录

16、adb shell am force-stop 包名 停止应用

17、adb shell am kill 包名 停止应用并杀死进程

18、adb install c:/a.apk安装a.apk到设备

19、adb uninstall 包名 卸载应用

20、adb shell input tap 100,200 点击屏幕x,y坐标

21、adb shell input swipe 250 250 300 300 滑动操作

22、adb shell input keyevent 3 模拟按键,比如home键的keycode=3,back键的keycode=4

23、studio 连接不上夜神模拟器解决方法:进入夜神bin目录——M:\Program Files (x86)\Nox\bin——执行如下命令:
nox_adb.exe connect 127.0.0.1:62001

  • 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

adb简介及常用命令总结详解:

https://blog.csdn.net/wenzhi20102321/article/details/113487927

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/985264
推荐阅读
相关标签
  

闽ICP备14008679号