Skip to content

Commit b312163

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Fix handling of hidden access points" into jb-mr1-dev
2 parents 3b9e7f3 + 462ff63 commit b312163

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

wifi/java/android/net/wifi/WifiSsid.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,33 @@ private void convertToBytes(String asciiEncoded) {
156156

157157
@Override
158158
public String toString() {
159-
if (octets.size() <= 0) return "";
159+
byte[] ssidBytes = octets.toByteArray();
160+
// Supplicant returns \x00\x00\x00\x00\x00\x00\x00\x00 hex string
161+
// for a hidden access point. Make sure we maintain the previous
162+
// behavior of returning empty string for this case.
163+
if (octets.size() <= 0 || isArrayAllZeroes(ssidBytes)) return "";
160164
// TODO: Handle conversion to other charsets upon failure
161165
Charset charset = Charset.forName("UTF-8");
162166
CharsetDecoder decoder = charset.newDecoder()
163167
.onMalformedInput(CodingErrorAction.REPLACE)
164168
.onUnmappableCharacter(CodingErrorAction.REPLACE);
165169
CharBuffer out = CharBuffer.allocate(32);
166170

167-
CoderResult result = decoder.decode(ByteBuffer.wrap(octets.toByteArray()), out, true);
171+
CoderResult result = decoder.decode(ByteBuffer.wrap(ssidBytes), out, true);
168172
out.flip();
169173
if (result.isError()) {
170174
return NONE;
171175
}
172176
return out.toString();
173177
}
174178

179+
private boolean isArrayAllZeroes(byte[] ssidBytes) {
180+
for (int i = 0; i< ssidBytes.length; i++) {
181+
if (ssidBytes[i] != 0) return false;
182+
}
183+
return true;
184+
}
185+
175186
/** @hide */
176187
public byte[] getOctets() {
177188
return octets.toByteArray();

0 commit comments

Comments
 (0)