2 * Copyright (C) 2010 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.android.wifi;
19 import android.text.TextUtils;
23 * http://chart.apis.google.com/chart?cht=qr&chs=240x240&chl=WIFI:S:linksys;P:mypass;T:WPA;;
25 * TODO(vikrama): Test with binary ssid or password.
27 * @author Vikram Aggarwal
29 final class NetworkUtil {
31 private NetworkUtil() {
35 * Encloses the incoming string inside double quotes, if it isn't already quoted.
36 * @param string: the input string
37 * @return a quoted string, of the form "input". If the input string is null, it returns null as well.
39 static String convertToQuotedString(String string) {
43 if (TextUtils.isEmpty(string)) {
46 int lastPos = string.length() - 1;
47 if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) {
50 return '\"' + string + '\"';
53 private static boolean isHex(CharSequence key) {
57 for (int i = key.length() - 1; i >= 0; i--) {
58 char c = key.charAt(i);
59 if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
67 * Check if wepKey is a valid hexadecimal string.
68 * @param wepKey the input to be checked
69 * @return true if the input string is indeed hex or empty. False if the input string is non-hex or null.
71 static boolean isHexWepKey(CharSequence wepKey) {
75 int len = wepKey.length();
76 // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
77 return (len == 10 || len == 26 || len == 58) && isHex(wepKey);