private void updateConnectionState(DetailedState state) {
    /* sticky broadcasts can call this when wifi is disabled */
    if (!mWifiManager.isWifiEnabled()) {
      mScanner.pause();
      return;
    }

    if (state == DetailedState.OBTAINING_IPADDR) {
      mScanner.pause();
    } else {
      mScanner.resume();
    }

    mLastInfo = mWifiManager.getConnectionInfo();
    if (state != null) {
      mLastState = state;
    }

    for (int i = getPreferenceScreen().getPreferenceCount() - 1; i >= 0; --i) {
      // Maybe there's a WifiConfigPreference
      Preference preference = getPreferenceScreen().getPreference(i);
      if (preference instanceof AccessPoint) {
        final AccessPoint accessPoint = (AccessPoint) preference;
        accessPoint.update(mLastInfo, mLastState);
      }
    }
  }
  /** 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;
  }
예제 #3
0
  AccessPoint(Context context, Bundle savedState) {
    super(context);
    setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);

    mConfig = savedState.getParcelable(KEY_CONFIG);
    if (mConfig != null) {
      loadConfig(mConfig);
    }
    mScanResult = (ScanResult) savedState.getParcelable(KEY_SCANRESULT);
    if (mScanResult != null) {
      loadResult(mScanResult);
    }
    mInfo = (WifiInfo) savedState.getParcelable(KEY_WIFIINFO);
    if (savedState.containsKey(KEY_DETAILEDSTATE)) {
      mState = DetailedState.valueOf(savedState.getString(KEY_DETAILEDSTATE));
    }
    update(mInfo, mState);
  }