Starting March 27, 2025, we recommend using android-latest-release instead of aosp-main to build and contribute to AOSP. For more information, see Changes to AOSP.
         
       
     
  
  
  
  
  
    
    
      
    
    
      
      Stay organized with collections
    
    
      
      Save and categorize content based on your preferences.
    
  
  
    
  
  
  
  
    
  
  
    
    
  
  
WifiHelper
  public
  
  
  
  class
  WifiHelper
  
    extends Object
  
  
  
  
  
  
  
    
    | java.lang.Object | 
  
  
    
      | ↳ | com.android.tradefed.device.WifiHelper | 
  
  
    
  Helper class for manipulating wifi services on device.
Summary
| Public methods | 
|---|
  
  
  
    | 
        
        
        
        
        
        boolean | 
      addOpenNetwork(String ssid)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      addOpenNetwork(String ssid, boolean scanSsid)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      addWpaPskNetwork(String ssid, String psk)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      addWpaPskNetwork(String ssid, String psk, boolean scanSsid)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      checkConnectivity(String urlToCheck)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        void | 
      cleanUp()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      connectToNetwork(String ssid, String psk, String urlToCheck)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        IWifiHelper.WifiConnectionResult | 
      connectToNetwork(String ssid, String psk, String urlToCheck, boolean scanSsid, String defaultType)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        IWifiHelper.WifiConnectionResult | 
      connectToNetwork(String ssid, String psk, String urlToCheck, boolean scanSsid)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      disableWifi()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      disconnectFromNetwork()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      enableWifi()
      
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        File | 
      extractWifiUtilApk()
      Helper method to extract the wifi util apk from the classpath
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        String | 
      getBSSID()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        String | 
      getIpAddress()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        String | 
      getSSID()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
         | 
      getWifiInfo()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      hasValidIp()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      isWifiEnabled()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      removeAllNetworks()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      startMonitor(long interval, String urlToCheck)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
         | 
      stopMonitor()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      waitForIp(long timeout)
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      waitForWifiDisabled(long timeout)
       | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      waitForWifiDisabled()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      waitForWifiEnabled(long timeout)
       | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      waitForWifiEnabled()
      
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        boolean | 
      waitForWifiState(WifiState... expectedStates)
      
        
    
 | 
  
Fields
    INSTRUMENTATION_PKG
    
      
  
      
  
    
public static final String INSTRUMENTATION_PKG
    
    
    
  
    
 
Public constructors
    WifiHelper
    
public WifiHelper (ITestDevice device)
    
    
    
  
    
    | Parameters | 
|---|
      
        | device | ITestDevice | 
    
      
  
 
    WifiHelper
    
public WifiHelper (ITestDevice device, 
                String wifiUtilApkPath)
    
    
    
  
    
    | Parameters | 
|---|
      
        | device | ITestDevice | 
      
        | wifiUtilApkPath | String | 
    
      
  
 
    WifiHelper
    
public WifiHelper (ITestDevice device, 
                String wifiUtilApkPath, 
                boolean doSetup)
    
    
    
  Alternative constructor that can skip the setup of the wifi apk.
    
    | Parameters | 
|---|
      
        | device | ITestDevice | 
      
        | wifiUtilApkPath | String | 
      
        | doSetup | boolean | 
    
      
  
 
    WifiHelper
    
public WifiHelper (ITestDevice device, 
                String wifiUtilApkPath, 
                boolean doSetup, 
                boolean useV2)
    
    
    
  Constructor to specify whether to use new wifi helper v2. v2 operations do not need to
 install the wifi util apk.
    
    | Parameters | 
|---|
      
        | device | ITestDevice | 
      
        | wifiUtilApkPath | String | 
      
        | doSetup | boolean | 
      
        | useV2 | boolean | 
    
      
  
 
Public methods
    addOpenNetwork
    
public boolean addOpenNetwork (String ssid)
    
    
    
  
    
    
      
  
 
    addOpenNetwork
    
public boolean addOpenNetwork (String ssid, 
                boolean scanSsid)
    
    
    
  
    
    | Parameters | 
|---|
      
        | ssid | String | 
      
        | scanSsid | boolean | 
    
    
      
  
 
    addWpaPskNetwork
    
public boolean addWpaPskNetwork (String ssid, 
                String psk)
    
    
    
  
    
    | Parameters | 
|---|
      
        | ssid | String | 
      
        | psk | String | 
    
    
      
  
 
    addWpaPskNetwork
    
public boolean addWpaPskNetwork (String ssid, 
                String psk, 
                boolean scanSsid)
    
    
    
  
    
    | Parameters | 
|---|
      
        | ssid | String | 
      
        | psk | String | 
      
        | scanSsid | boolean | 
    
    
      
  
 
    checkConnectivity
    
public boolean checkConnectivity (String urlToCheck)
    
    
    
  
    
    | Parameters | 
|---|
      
        | urlToCheck | String | 
    
    
      
  
 
    cleanUp
    
public void cleanUp ()
    
    
    
  
      
  
 
    connectToNetwork
    
public boolean connectToNetwork (String ssid, 
                String psk, 
                String urlToCheck)
    
    
    
  
    
    | Parameters | 
|---|
      
        | ssid | String | 
      
        | psk | String | 
      
        | urlToCheck | String | 
    
    
      
  
 
    connectToNetwork
    
public IWifiHelper.WifiConnectionResult connectToNetwork (String ssid, 
                String psk, 
                String urlToCheck, 
                boolean scanSsid, 
                String defaultType)
    
    
    
  
    
    | Parameters | 
|---|
      
        | ssid | String | 
      
        | psk | String | 
      
        | urlToCheck | String | 
      
        | scanSsid | boolean | 
      
        | defaultType | String | 
    
    
      | Returns | 
|---|
      
        | IWifiHelper.WifiConnectionResult |  | 
    
      
  
 
    connectToNetwork
    
public IWifiHelper.WifiConnectionResult connectToNetwork (String ssid, 
                String psk, 
                String urlToCheck, 
                boolean scanSsid)
    
    
    
  
    
    | Parameters | 
|---|
      
        | ssid | String | 
      
        | psk | String | 
      
        | urlToCheck | String | 
      
        | scanSsid | boolean | 
    
    
      | Returns | 
|---|
      
        | IWifiHelper.WifiConnectionResult |  | 
    
      
  
 
    disableWifi
    
public boolean disableWifi ()
    
    
    
  
    
      
  
 
    disconnectFromNetwork
    
public boolean disconnectFromNetwork ()
    
    
    
  
    
      
  
 
    enableWifi
    
public boolean enableWifi ()
    
    
    
  
    
      
  
 
    
    
public static File extractWifiUtilApk ()
    
    
    
  Helper method to extract the wifi util apk from the classpath
    
 
    getBSSID
    
public String getBSSID ()
    
    
    
  
    
      
  
 
    getIpAddress
    
public String getIpAddress ()
    
    
    
  
    
      
  
 
    getSSID
    
public String getSSID ()
    
    
    
  
    
      
  
 
    getWifiInfo
    
public  getWifiInfo ()
    
    
    
  
    
      
  
 
    hasValidIp
    
public boolean hasValidIp ()
    
    
    
  
    
      
  
 
    isWifiEnabled
    
public boolean isWifiEnabled ()
    
    
    
  
    
      
  
 
    removeAllNetworks
    
public boolean removeAllNetworks ()
    
    
    
  
    
      
  
 
    startMonitor
    
public boolean startMonitor (long interval, 
                String urlToCheck)
    
    
    
  
    
    | Parameters | 
|---|
      
        | interval | long | 
      
        | urlToCheck | String | 
    
    
      
  
 
    stopMonitor
    
public  stopMonitor ()
    
    
    
  
    
      
  
 
    waitForIp
    
public boolean waitForIp (long timeout)
    
    
    
  
    
    
      
  
 
    waitForWifiDisabled
    
public boolean waitForWifiDisabled (long timeout)
    
    
    
  
    
    
      
  
 
    waitForWifiDisabled
    
public boolean waitForWifiDisabled ()
    
    
    
  
    
      
  
 
    waitForWifiEnabled
    
public boolean waitForWifiEnabled (long timeout)
    
    
    
  
    
    
      
  
 
    waitForWifiEnabled
    
public boolean waitForWifiEnabled ()
    
    
    
  
    
      
  
 
    waitForWifiState
    
public boolean waitForWifiState (WifiState... expectedStates)
    
    
    
  
    
    | Parameters | 
|---|
      
        | expectedStates | WifiState | 
    
    
      
  
 
 
 
  
  
 
  
    
    
      
    
    
  
       
    
    
  
  
  Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
  Last updated 2024-04-02 UTC.
  
  
  
    
      [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-02 UTC."],[],[]]