Code example for Pattern

Methods: matcher

0
  // Adding a WPA or WPA2 network 
  private int changeNetworkWPA(NetworkSetting input) {
    WifiConfiguration config = changeNetworkCommon(input);
    String pass = input.getPassword();
    // Hex passwords that are 64 bits long are not to be quoted. 
    if (HEX_DIGITS_64.matcher(pass).matches()){
      Log.d(TAG, "A 64 bit hex password entered.");
      config.preSharedKey = pass;
    } else { 
      Log.d(TAG, "A normal password entered: I am quoting it.");
      config.preSharedKey = NetworkUtil.convertToQuotedString(pass);
    } 
    config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    // For WPA 
    config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    // For WPA2 
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
    config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
    return requestNetworkChange(config);