Esempio n. 1
0
 @Override
 public void onReceive(Context context, Intent intent) {
   final String action = intent.getAction();
   if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
     synchronized (mMySync) {
       mMySync.expectedState = STATE_WIFI_CHANGED;
       mMySync.notify();
     }
   } else if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
     synchronized (mMySync) {
       mMySync.expectedState = STATE_SCAN_RESULTS_AVAILABLE;
       mMySync.notify();
     }
   }
 }
Esempio n. 2
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    if (!WifiFeature.isWifiSupported(getContext())) {
      // skip the test if WiFi is not supported
      return;
    }
    mMySync = new MySync();
    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.ACTION_PICK_WIFI_NETWORK);

    mContext.registerReceiver(mReceiver, mIntentFilter);
    mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
    assertNotNull(mWifiManager);
    mWifiLock = mWifiManager.createWifiLock(TAG);
    mWifiLock.acquire();
    if (!mWifiManager.isWifiEnabled()) setWifiEnabled(true);
    Thread.sleep(ENABLE_WAIT_MSEC);
    assertTrue(mWifiManager.isWifiEnabled());
    mMySync.expectedState = STATE_NULL;
  }
Esempio n. 3
0
 private void scanAndWait() throws Exception {
   synchronized (mMySync) {
     mMySync.expectedState = STATE_START_SCAN;
     mWifiManager.startScan();
     waitForBroadcast(SCAN_WAIT_MSEC, STATE_SCAN_RESULTS_AVAILABLE);
   }
 }
Esempio n. 4
0
 private void setWifiEnabled(boolean enable) throws Exception {
   synchronized (mMySync) {
     mMySync.expectedState = STATE_WIFI_CHANGING;
     assertTrue(mWifiManager.setWifiEnabled(enable));
     waitForBroadcast(TIMEOUT_MSEC, STATE_WIFI_CHANGED);
   }
 }
Esempio n. 5
0
 private void waitForBroadcast(long timeout, int expectedState) throws Exception {
   long waitTime = System.currentTimeMillis() + timeout;
   while (System.currentTimeMillis() < waitTime && mMySync.expectedState != expectedState)
     mMySync.wait(WAIT_MSEC);
 }