Пример #1
0
  private WifiConfiguration changeNetworkCommon(NetworkSetting input) {
    statusView.setText(R.string.wifi_creating_network);
    Log.d(
        TAG,
        "Adding new configuration: \nSSID: "
            + input.getSsid()
            + "\nType: "
            + input.getNetworkType());
    WifiConfiguration config = new WifiConfiguration();

    config.allowedAuthAlgorithms.clear();
    config.allowedGroupCiphers.clear();
    config.allowedKeyManagement.clear();
    config.allowedPairwiseCiphers.clear();
    config.allowedProtocols.clear();

    // Android API insists that an ascii SSID must be quoted to be correctly handled.
    config.SSID = NetworkUtil.convertToQuotedString(input.getSsid());
    config.hiddenSSID = true;
    return config;
  }
Пример #2
0
  private int changeNetwork(NetworkSetting setting) {
    // If the SSID is empty, throw an error and return
    if (setting.getSsid() == null || setting.getSsid().length() == 0) {
      return doError(R.string.wifi_ssid_missing);
    }
    // If the network type is invalid
    if (setting.getNetworkType() == NetworkType.NETWORK_INVALID) {
      return doError(R.string.wifi_type_incorrect);
    }

    // If the password is empty, this is an unencrypted network
    if (setting.getPassword() == null
        || setting.getPassword().length() == 0
        || setting.getNetworkType() == null
        || setting.getNetworkType() == NetworkType.NETWORK_NOPASS) {
      return changeNetworkUnEncrypted(setting);
    }
    if (setting.getNetworkType() == NetworkType.NETWORK_WPA) {
      return changeNetworkWPA(setting);
    } else {
      return changeNetworkWEP(setting);
    }
  }