Loading res/layout/write_wifi_config_to_nfc.xml +15 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2014 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/wifi_section"> Loading res/values/strings.xml +7 −5 Original line number Diff line number Diff line Loading @@ -1417,6 +1417,8 @@ <string name="wifi_menu_forget">Forget network</string> <!-- Menu option to modify a Wi-Fi network configuration --> <string name="wifi_menu_modify">Modify network</string> <!-- Menu option to write a Wi-Fi configuration token to an NFC tag [CHAR_LIMIT=30]--> <string name="wifi_menu_write_to_nfc">Write to NFC tag</string> <!-- Wi-Fi settings. text displayed when Wi-Fi is off and network list is empty [CHAR LIMIT=50]--> <string name="wifi_empty_list_wifi_off">To see available networks, turn Wi\u2011Fi on.</string> <!-- Wi-Fi settings. text displayed when Wi-Fi is on and network list is empty [CHAR LIMIT=50]--> Loading Loading @@ -1522,8 +1524,8 @@ <!-- Substring of wifi status for wifi with authentication. This version is for when the string is not first in the list (lowercase in english) --> <string name="wifi_secured_second_item">, secured with <xliff:g id="wifi_security_short">%1$s</xliff:g></string> <!-- Message in WriteWifiConfigToNfcDialog when prompted to enter network password [CHAR LIMIT=150] --> <string name="wifi_wps_nfc_enter_password">Enter your network password.</string> <!-- Message in WriteWifiConfigToNfcDialog when prompted to enter network password [CHAR_LIMIT=40] --> <string name="wifi_wps_nfc_enter_password">Enter your network password</string> <!-- Do not translate. Concise terminology for wifi with WEP security --> <string name="wifi_security_short_wep">WEP</string> Loading Loading @@ -5138,10 +5140,10 @@ settings button --> <string name="notification_app_settings_button">Notification settings</string> <!-- NFC WiFi pairing/setup strings--> <!-- NFC Wi-Fi pairing/setup strings--> <!-- Write NFC tag for WiFi pairing/setup title --> <string name="setup_wifi_nfc_tag">Set up WiFi NFC Tag</string> <!-- Write NFC tag for Wi-Fi pairing/setup title [CHAR_LIMIT=30]--> <string name="setup_wifi_nfc_tag">Set up Wi-Fi NFC Tag</string> <!-- Text for button to confirm writing tag --> <string name="write_tag">Write</string> <!-- Text to inform the user to tap a tag to complete the setup process --> Loading src/com/android/settings/wifi/WifiSettings.java +6 −4 Original line number Diff line number Diff line Loading @@ -570,7 +570,7 @@ public class WifiSettings extends RestrictedSettingsFragment if (mSelectedAccessPoint.security != AccessPoint.SECURITY_NONE) { // Only allow writing of NFC tags for password-protected networks. menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, "Write to NFC Tag"); menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, R.string.wifi_menu_write_to_nfc); } } } Loading Loading @@ -705,9 +705,11 @@ public class WifiSettings extends RestrictedSettingsFragment }) .create(); case WRITE_NFC_DIALOG_ID: if (mSelectedAccessPoint != null) { mWifiToNfcDialog = new WriteWifiConfigToNfcDialog( getActivity(), mSelectedAccessPoint, mWifiManager); return mWifiToNfcDialog; } } return super.onCreateDialog(dialogId); Loading src/com/android/settings/wifi/WriteWifiConfigToNfcDialog.java +32 −13 Original line number Diff line number Diff line /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.wifi; import android.app.Activity; Loading Loading @@ -39,6 +55,8 @@ class WriteWifiConfigToNfcDialog extends AlertDialog private static final String TAG = WriteWifiConfigToNfcDialog.class.getName().toString(); private static final String PASSWORD_FORMAT = "102700%s%s"; private static final int HEX_RADIX = 16; private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); private final PowerManager.WakeLock mWakeLock; Loading @@ -58,12 +76,13 @@ class WriteWifiConfigToNfcDialog extends AlertDialog WriteWifiConfigToNfcDialog(Context context, AccessPoint accessPoint, WifiManager wifiManager) { super(context); this.mContext = context; this.mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)) mContext = context; mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock"); this.mAccessPoint = accessPoint; this.mOnTextChangedHandler = new Handler(); this.mWifiManager = wifiManager; mAccessPoint = accessPoint; mOnTextChangedHandler = new Handler(); mWifiManager = wifiManager; } @Override Loading Loading @@ -105,9 +124,9 @@ class WriteWifiConfigToNfcDialog extends AlertDialog = mWifiManager.getWpsNfcConfigurationToken(mAccessPoint.networkId); String passwordHex = byteArrayToHexString(password.getBytes()); String passwordLength = password.length() >= 16 ? "" + Character.forDigit(password.length(), 16) : "0" + Character.forDigit(password.length(), 16); String passwordLength = password.length() >= HEX_RADIX ? "" + Character.forDigit(password.length(), HEX_RADIX) : "0" + Character.forDigit(password.length(), HEX_RADIX); passwordHex = String.format(PASSWORD_FORMAT, passwordLength, passwordHex).toUpperCase(); Loading Loading @@ -166,11 +185,11 @@ class WriteWifiConfigToNfcDialog extends AlertDialog setViewText(mCancelButton, com.android.internal.R.string.done_label); } catch (IOException e) { setViewText(mLabelView, R.string.status_failed_to_write); Log.e(TAG, "Unable to write WiFi config to NFC tag.", e); Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e); return; } catch (FormatException e) { setViewText(mLabelView, R.string.status_failed_to_write); Log.e(TAG, "Unable to write WiFi config to NFC tag.", e); Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e); return; } } else { Loading Loading @@ -239,14 +258,13 @@ class WriteWifiConfigToNfcDialog extends AlertDialog byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); data[i / 2] = (byte) ((Character.digit(s.charAt(i), HEX_RADIX) << 4) + Character.digit(s.charAt(i + 1), HEX_RADIX)); } return data; } final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); private static String byteArrayToHexString(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for ( int j = 0; j < bytes.length; j++ ) { Loading @@ -259,6 +277,7 @@ class WriteWifiConfigToNfcDialog extends AlertDialog @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) {} } Loading
res/layout/write_wifi_config_to_nfc.xml +15 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2014 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/wifi_section"> Loading
res/values/strings.xml +7 −5 Original line number Diff line number Diff line Loading @@ -1417,6 +1417,8 @@ <string name="wifi_menu_forget">Forget network</string> <!-- Menu option to modify a Wi-Fi network configuration --> <string name="wifi_menu_modify">Modify network</string> <!-- Menu option to write a Wi-Fi configuration token to an NFC tag [CHAR_LIMIT=30]--> <string name="wifi_menu_write_to_nfc">Write to NFC tag</string> <!-- Wi-Fi settings. text displayed when Wi-Fi is off and network list is empty [CHAR LIMIT=50]--> <string name="wifi_empty_list_wifi_off">To see available networks, turn Wi\u2011Fi on.</string> <!-- Wi-Fi settings. text displayed when Wi-Fi is on and network list is empty [CHAR LIMIT=50]--> Loading Loading @@ -1522,8 +1524,8 @@ <!-- Substring of wifi status for wifi with authentication. This version is for when the string is not first in the list (lowercase in english) --> <string name="wifi_secured_second_item">, secured with <xliff:g id="wifi_security_short">%1$s</xliff:g></string> <!-- Message in WriteWifiConfigToNfcDialog when prompted to enter network password [CHAR LIMIT=150] --> <string name="wifi_wps_nfc_enter_password">Enter your network password.</string> <!-- Message in WriteWifiConfigToNfcDialog when prompted to enter network password [CHAR_LIMIT=40] --> <string name="wifi_wps_nfc_enter_password">Enter your network password</string> <!-- Do not translate. Concise terminology for wifi with WEP security --> <string name="wifi_security_short_wep">WEP</string> Loading Loading @@ -5138,10 +5140,10 @@ settings button --> <string name="notification_app_settings_button">Notification settings</string> <!-- NFC WiFi pairing/setup strings--> <!-- NFC Wi-Fi pairing/setup strings--> <!-- Write NFC tag for WiFi pairing/setup title --> <string name="setup_wifi_nfc_tag">Set up WiFi NFC Tag</string> <!-- Write NFC tag for Wi-Fi pairing/setup title [CHAR_LIMIT=30]--> <string name="setup_wifi_nfc_tag">Set up Wi-Fi NFC Tag</string> <!-- Text for button to confirm writing tag --> <string name="write_tag">Write</string> <!-- Text to inform the user to tap a tag to complete the setup process --> Loading
src/com/android/settings/wifi/WifiSettings.java +6 −4 Original line number Diff line number Diff line Loading @@ -570,7 +570,7 @@ public class WifiSettings extends RestrictedSettingsFragment if (mSelectedAccessPoint.security != AccessPoint.SECURITY_NONE) { // Only allow writing of NFC tags for password-protected networks. menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, "Write to NFC Tag"); menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, R.string.wifi_menu_write_to_nfc); } } } Loading Loading @@ -705,9 +705,11 @@ public class WifiSettings extends RestrictedSettingsFragment }) .create(); case WRITE_NFC_DIALOG_ID: if (mSelectedAccessPoint != null) { mWifiToNfcDialog = new WriteWifiConfigToNfcDialog( getActivity(), mSelectedAccessPoint, mWifiManager); return mWifiToNfcDialog; } } return super.onCreateDialog(dialogId); Loading
src/com/android/settings/wifi/WriteWifiConfigToNfcDialog.java +32 −13 Original line number Diff line number Diff line /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.wifi; import android.app.Activity; Loading Loading @@ -39,6 +55,8 @@ class WriteWifiConfigToNfcDialog extends AlertDialog private static final String TAG = WriteWifiConfigToNfcDialog.class.getName().toString(); private static final String PASSWORD_FORMAT = "102700%s%s"; private static final int HEX_RADIX = 16; private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); private final PowerManager.WakeLock mWakeLock; Loading @@ -58,12 +76,13 @@ class WriteWifiConfigToNfcDialog extends AlertDialog WriteWifiConfigToNfcDialog(Context context, AccessPoint accessPoint, WifiManager wifiManager) { super(context); this.mContext = context; this.mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)) mContext = context; mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock"); this.mAccessPoint = accessPoint; this.mOnTextChangedHandler = new Handler(); this.mWifiManager = wifiManager; mAccessPoint = accessPoint; mOnTextChangedHandler = new Handler(); mWifiManager = wifiManager; } @Override Loading Loading @@ -105,9 +124,9 @@ class WriteWifiConfigToNfcDialog extends AlertDialog = mWifiManager.getWpsNfcConfigurationToken(mAccessPoint.networkId); String passwordHex = byteArrayToHexString(password.getBytes()); String passwordLength = password.length() >= 16 ? "" + Character.forDigit(password.length(), 16) : "0" + Character.forDigit(password.length(), 16); String passwordLength = password.length() >= HEX_RADIX ? "" + Character.forDigit(password.length(), HEX_RADIX) : "0" + Character.forDigit(password.length(), HEX_RADIX); passwordHex = String.format(PASSWORD_FORMAT, passwordLength, passwordHex).toUpperCase(); Loading Loading @@ -166,11 +185,11 @@ class WriteWifiConfigToNfcDialog extends AlertDialog setViewText(mCancelButton, com.android.internal.R.string.done_label); } catch (IOException e) { setViewText(mLabelView, R.string.status_failed_to_write); Log.e(TAG, "Unable to write WiFi config to NFC tag.", e); Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e); return; } catch (FormatException e) { setViewText(mLabelView, R.string.status_failed_to_write); Log.e(TAG, "Unable to write WiFi config to NFC tag.", e); Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e); return; } } else { Loading Loading @@ -239,14 +258,13 @@ class WriteWifiConfigToNfcDialog extends AlertDialog byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); data[i / 2] = (byte) ((Character.digit(s.charAt(i), HEX_RADIX) << 4) + Character.digit(s.charAt(i + 1), HEX_RADIX)); } return data; } final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); private static String byteArrayToHexString(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for ( int j = 0; j < bytes.length; j++ ) { Loading @@ -259,6 +277,7 @@ class WriteWifiConfigToNfcDialog extends AlertDialog @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) {} }