Show QR Code picture for WiFi sharing

Bug: 118794858
Test: make RunSettingsRoboTests
Change-Id: Ic5a489840ba59262eb444f02d77bf066889a4220
This commit is contained in:
Johnson Lu
2018-12-20 15:02:50 +08:00
committed by Arc Wang
parent feb271378c
commit 7414543635
7 changed files with 204 additions and 13 deletions

View File

@@ -119,6 +119,51 @@ public class WifiNetworkConfig {
return true;
}
/**
* Escaped special characters "\", ";", ":", "," with a backslash
* See https://github.com/zxing/zxing/wiki/Barcode-Contents
*/
private String escapeSpecialCharacters(String str) {
if (TextUtils.isEmpty(str)) {
return str;
}
StringBuilder buf = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch =='\\' || ch == ',' || ch == ';' || ch == ':') {
buf.append('\\');
}
buf.append(ch);
}
return buf.toString();
}
/**
* Construct a barcode string for WiFi network login.
* See https://en.wikipedia.org/wiki/QR_code#WiFi_network_login
*/
public String getQrCode() {
final String empty = "";
String barcode = new StringBuilder("WIFI:")
.append("S:")
.append(escapeSpecialCharacters(mSsid))
.append(";")
.append("T:")
.append(TextUtils.isEmpty(mSecurity) ? empty : mSecurity)
.append(";")
.append("P:")
.append(TextUtils.isEmpty(mPreSharedKey) ? empty
: escapeSpecialCharacters(mPreSharedKey))
.append(";")
.append("H:")
.append(mHiddenSsid)
.append(";;")
.toString();
return barcode;
}
@Keep
public String getSecurity() {
return mSecurity;