コード例 #1
0
  private void updateAccessPoints(List<ScanResult> scanResultList) {
    List<WifiAccessPoint> accessPoints = new ArrayList<WifiAccessPoint>();

    WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    String ssid = wifiInfo.getSSID();

    List<ScanResult> results = scanResultList;
    if (results != null) {
      for (ScanResult result : results) {
        if (result.SSID == null
            || result.SSID.length() == 0
            || result.capabilities.contains("[IBSS]")) {
          continue;
        }
        boolean found = false;
        for (WifiAccessPoint accessPoint : accessPoints) {
          if (accessPoint.update(result)) {
            found = true;
          }
        }
        if (!found) {
          WifiAccessPoint accessPoint = new WifiAccessPoint(result);
          ssid = WifiUtil.removeDoubleQuotes(ssid);

          if (ssid != null && result.SSID.compareTo(ssid) == 0 && ip > 0) {
            accessPoint.setConnectStatus(WifiConst.CONNCETED);
          }
          accessPoints.add(accessPoint);
        }
      }
    }
    mAccessPoints = accessPoints;
  }
コード例 #2
0
  /** Returns sorted list of access points */
  private List<AccessPoint> constructAccessPoints() {
    ArrayList<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
    /**
     * Lookup table to more quickly update AccessPoints by only considering objects with the correct
     * SSID. Maps SSID -> List of AccessPoints with the given SSID.
     */
    Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>();

    final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
    if (configs != null) {
      for (WifiConfiguration config : configs) {
        AccessPoint accessPoint = new AccessPoint(getActivity(), config);
        accessPoint.update(mLastInfo, mLastState);
        accessPoints.add(accessPoint);
        apMap.put(accessPoint.ssid, accessPoint);
      }
    }

    final List<ScanResult> results = mWifiManager.getScanResults();
    if (results != null) {
      for (ScanResult result : results) {
        // Ignore hidden networks.
        if (result.SSID == null || result.SSID.length() == 0) {
          continue;
        }

        // Ignore IBSS if chipset does not support them
        if (!mIbssSupported && result.capabilities.contains("[IBSS]")) {
          continue;
        }

        boolean found = false;
        for (AccessPoint accessPoint : apMap.getAll(result.SSID)) {
          if (accessPoint.update(result)) found = true;
        }
        if (!found) {
          AccessPoint accessPoint = new AccessPoint(getActivity(), result);
          accessPoints.add(accessPoint);
          apMap.put(accessPoint.ssid, accessPoint);
        }
      }
    }

    // Pre-sort accessPoints to speed preference insertion
    Collections.sort(accessPoints);
    return accessPoints;
  }