public List<WiFiApConfig> getSortedWifiApConfigsList() {
    App.getTraceUtils().startTrace(TAG, "getSortedWifiApConfigsList", Log.DEBUG);

    if (getWifiNetworkStatus().isEmpty()) {
      updateWifiApConfigs();
      App.getTraceUtils()
          .partialTrace(TAG, "getSortedWifiApConfigsList", "updateWifiApConfigs", Log.DEBUG);
    }

    List<WiFiApConfig> list = null;

    synchronized (wifiNetworkStatusLock) {
      list = new ArrayList<WiFiApConfig>(getWifiNetworkStatus().values());
      App.getTraceUtils()
          .partialTrace(TAG, "getSortedWifiApConfigsList", "new ArrayList", Log.DEBUG);

      try {
        Collections.sort(list);
      } catch (IllegalArgumentException e) {
        Timber.e("config_list", configListToDBG().toString());
        Timber.e(e, "Exception during sort of WiFiAPConfigs");
      }
    }

    App.getTraceUtils()
        .partialTrace(TAG, "getSortedWifiApConfigsList", "Collections.sort", Log.DEBUG);
    App.getTraceUtils().stopTrace(TAG, "getSortedWifiApConfigsList", Log.DEBUG);

    return list;
  }
  public void updateCurrentWifiInfo(WifiInfo currentWifiInfo) {
    App.getTraceUtils().startTrace(TAG, "updateCurrentWifiInfo", Log.DEBUG);

    synchronized (wifiNetworkStatusLock) {
      if (!getWifiNetworkStatus().isEmpty()) {
        for (WiFiApConfig conf : getWifiNetworkStatus().values()) {
          conf.updateWifiInfo(currentWifiInfo, null);
        }
      }
    }

    App.getTraceUtils().stopTrace(TAG, "updateCurrentWifiInfo", Log.DEBUG);
  }
  public void updateWifiConfigWithScanResults(List<ScanResult> scanResults) {
    List<String> scanResultsStrings = new ArrayList<String>();

    synchronized (wifiNetworkStatusLock) {
      // clear all the savedConfigurations AP status
      if (!getWifiNetworkStatus().isEmpty()) {
        App.getTraceUtils().startTrace(TAG, "Clear scan status from AP configs", Log.DEBUG);
        for (WiFiApConfig conf : getWifiNetworkStatus().values()) {
          conf.clearScanStatus();
        }
        App.getTraceUtils().stopTrace(TAG, "Clear scan status from AP configs", Log.DEBUG);
      }

      if (scanResults != null) {
        for (ScanResult res : scanResults) {
          scanResultsStrings.add(res.SSID + " level: " + res.level);
          String currSSID = ProxyUtils.cleanUpSSID(res.SSID);
          SecurityType security = ProxyUtils.getSecurity(res);
          APLNetworkId aplNetworkId = new APLNetworkId(currSSID, security);

          if (getWifiNetworkStatus().containsKey(aplNetworkId)) {
            WiFiApConfig conf = getWifiNetworkStatus().get(aplNetworkId);
            if (conf != null) {
              conf.updateScanResults(res);
            }
          } else {
            if (getWifiNetworkStatus().getNotConfiguredWifi().containsKey(aplNetworkId)) {
              getWifiNetworkStatus().getNotConfiguredWifi().remove(aplNetworkId);
            }

            getWifiNetworkStatus().getNotConfiguredWifi().put(aplNetworkId, res);
          }
        }
      } else {
        Timber.w("No ScanResults available for updateWifiConfigWithScanResults");
      }
    }

    Timber.d("Updating from scanresult: " + TextUtils.join(", ", scanResultsStrings.toArray()));
  }
  public WiFiApConfig updateCurrentConfiguration() {
    WiFiApConfig updatedConf = null;

    App.getTraceUtils().startTrace(TAG, "updateCurrentConfiguration", Log.DEBUG);

    try {

      if (APL.getWifiManager() != null && APL.getWifiManager().isWifiEnabled()) {
        WifiInfo info = APL.getWifiManager().getConnectionInfo();

        if (info != null) {
          int networkId = info.getNetworkId();

          if (networkId != -1) {
            WifiConfiguration wifiConfiguration = APL.getConfiguredNetwork(networkId);

            if (wifiConfiguration != null) {
              WiFiApConfig networkConfig = APL.getWiFiAPConfiguration(wifiConfiguration);

              synchronized (wifiNetworkStatusLock) {
                if (getWifiNetworkStatus().containsKey(networkConfig.getAPLNetworkId())) {
                  updatedConf = getWifiNetworkStatus().get(networkConfig.getAPLNetworkId());
                }

                mergeWithCurrentConfiguration(updatedConf);
              }
            }
          }
        }
      }
    } catch (Exception e) {
      Timber.e(e, "Exception updating current configuration");
    }

    App.getTraceUtils().stopTrace(TAG, "updateCurrentConfiguration", Log.DEBUG);

    return updatedConf;
  }
  public void updateWifiApConfigs() {
    synchronized (wifiNetworkStatusLock) {
      App.getTraceUtils().startTrace(TAG, "updateWifiApConfigs", Log.DEBUG, true);

      Map<APLNetworkId, WiFiApConfig> configurations = APL.getWifiAPConfigurations();
      for (APLNetworkId aplNetworkId : configurations.keySet()) {
        getWifiNetworkStatus().put(aplNetworkId, configurations.get(aplNetworkId));
      }

      App.getTraceUtils()
          .partialTrace(TAG, "updateWifiApConfigs", "Got WifiAPConfigurations from APL", Log.DEBUG);

      updateWifiConfigWithScanResults(APL.getWifiManager().getScanResults());

      App.getTraceUtils()
          .partialTrace(
              TAG,
              "updateWifiApConfigs",
              "Updated wifi network status with ScanResults",
              Log.DEBUG);
      App.getTraceUtils().stopTrace(TAG, "updateWifiApConfigs", Log.DEBUG);
    }
  }