Skip to content

Commit 462ff63

Browse files
committed
Fix handling of hidden access points
We now get raw hex data from the supplicant and we convert it into printable format. For hidden access point, we always used to return a single empty string. We need to make sure we maintain that behavior for apps to not start displaying empty strings. Bug: 7310749 Change-Id: I2599b9b5e15be91fc34e9af629ad893b1a0357fc
1 parent b3f55fd commit 462ff63

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)