WifiResultParser.java (zxing-zxing-3.4.0) | : | WifiResultParser.java (zxing-zxing-3.4.1) | ||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
import com.google.zxing.Result; | import com.google.zxing.Result; | |||
/** | /** | |||
* <p>Parses a WIFI configuration string. Strings will be of the form:</p> | * <p>Parses a WIFI configuration string. Strings will be of the form:</p> | |||
* | * | |||
* <p>{@code WIFI:T:[network type];S:[network SSID];P:[network password];H:[hidd en?];;}</p> | * <p>{@code WIFI:T:[network type];S:[network SSID];P:[network password];H:[hidd en?];;}</p> | |||
* | * | |||
* <p>For WPA2 enterprise (EAP), strings will be of the form:</p> | * <p>For WPA2 enterprise (EAP), strings will be of the form:</p> | |||
* | * | |||
* <p>{@code WIFI:T:WPA2-EAP;S:[network SSID];H:[hidden?];E:[EAP method];H:[Phas e 2 method];A:[anonymous identity];I:[username];P:[password];;}</p> | * <p>{@code WIFI:T:WPA2-EAP;S:[network SSID];H:[hidden?];E:[EAP method];PH2:[Ph ase 2 method];A:[anonymous identity];I:[username];P:[password];;}</p> | |||
* | * | |||
* <p>"EAP method" can e.g. be "TTLS" or "PWD" or one of the other fields in <a href="https://developer.android.com/reference/android/net/wifi/WifiEnterpriseCon fig.Eap.html">WifiEnterpriseConfig.Eap</a> and "Phase 2 method" can e.g. be "MSC HAPV2" or any of the other fields in <a href="https://developer.android.com/refe rence/android/net/wifi/WifiEnterpriseConfig.Phase2.html">WifiEnterpriseConfig.Ph ase2</a></p> | * <p>"EAP method" can e.g. be "TTLS" or "PWD" or one of the other fields in <a href="https://developer.android.com/reference/android/net/wifi/WifiEnterpriseCon fig.Eap.html">WifiEnterpriseConfig.Eap</a> and "Phase 2 method" can e.g. be "MSC HAPV2" or any of the other fields in <a href="https://developer.android.com/refe rence/android/net/wifi/WifiEnterpriseConfig.Phase2.html">WifiEnterpriseConfig.Ph ase2</a></p> | |||
* | * | |||
* <p>The fields can appear in any order. Only "S:" is required.</p> | * <p>The fields can appear in any order. Only "S:" is required.</p> | |||
* | * | |||
* @author Vikram Aggarwal | * @author Vikram Aggarwal | |||
* @author Sean Owen | * @author Sean Owen | |||
* @author Steffen Kieß | * @author Steffen Kieß | |||
*/ | */ | |||
public final class WifiResultParser extends ResultParser { | public final class WifiResultParser extends ResultParser { | |||
skipping to change at line 56 | skipping to change at line 56 | |||
rawText = rawText.substring("WIFI:".length()); | rawText = rawText.substring("WIFI:".length()); | |||
String ssid = matchSinglePrefixedField("S:", rawText, ';', false); | String ssid = matchSinglePrefixedField("S:", rawText, ';', false); | |||
if (ssid == null || ssid.isEmpty()) { | if (ssid == null || ssid.isEmpty()) { | |||
return null; | return null; | |||
} | } | |||
String pass = matchSinglePrefixedField("P:", rawText, ';', false); | String pass = matchSinglePrefixedField("P:", rawText, ';', false); | |||
String type = matchSinglePrefixedField("T:", rawText, ';', false); | String type = matchSinglePrefixedField("T:", rawText, ';', false); | |||
if (type == null) { | if (type == null) { | |||
type = "nopass"; | type = "nopass"; | |||
} | } | |||
boolean hidden = Boolean.parseBoolean(matchSinglePrefixedField("H:", rawText | ||||
, ';', false)); | // Unfortunately, in the past, H: was not just used for boolean 'hidden', bu | |||
t 'phase 2 method'. | ||||
// To try to retain backwards compatibility, we set one or the other based o | ||||
n whether the string | ||||
// is 'true' or 'false': | ||||
boolean hidden = false; | ||||
String phase2Method = matchSinglePrefixedField("PH2:", rawText, ';', false); | ||||
String hValue = matchSinglePrefixedField("H:", rawText, ';', false); | ||||
if (hValue != null) { | ||||
// If PH2 was specified separately, or if the value is clearly boolean, in | ||||
terpret it as 'hidden' | ||||
if (phase2Method != null || "true".equalsIgnoreCase(hValue) || "false".equ | ||||
alsIgnoreCase(hValue)) { | ||||
hidden = Boolean.parseBoolean(hValue); | ||||
} else { | ||||
phase2Method = hValue; | ||||
} | ||||
} | ||||
String identity = matchSinglePrefixedField("I:", rawText, ';', false); | String identity = matchSinglePrefixedField("I:", rawText, ';', false); | |||
String anonymousIdentity = matchSinglePrefixedField("A:", rawText, ';', fals e); | String anonymousIdentity = matchSinglePrefixedField("A:", rawText, ';', fals e); | |||
String eapMethod = matchSinglePrefixedField("E:", rawText, ';', false); | String eapMethod = matchSinglePrefixedField("E:", rawText, ';', false); | |||
String phase2Method = matchSinglePrefixedField("H:", rawText, ';', false); | ||||
return new WifiParsedResult(type, ssid, pass, hidden, identity, anonymousIde ntity, eapMethod, phase2Method); | return new WifiParsedResult(type, ssid, pass, hidden, identity, anonymousIde ntity, eapMethod, phase2Method); | |||
} | } | |||
} | } | |||
End of changes. 3 change blocks. | ||||
4 lines changed or deleted | 22 lines changed or added |