From e278a208bc8298963080dfb5352acedc65aad083 Mon Sep 17 00:00:00 2001 From: Casper Bonde Date: Fri, 8 May 2015 15:19:03 +0200 Subject: [PATCH] SAP: Make it possible to enforce a 16-digit pin code (5/5) This change enable the posibility to enforce using a 16-digit pin or MITM for a RFCOMM or L2CAP connection. This is needed for the SIM access profile. Change-Id: I6bb2b0dff1ebf4b4f1d8faad97aa7c480000d3ea Signed-off-by: Casper Bonde --- res/values/strings.xml | 3 +++ .../settings/bluetooth/BluetoothPairingDialog.java | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index e6e73806a4c..31311ee14f9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1170,6 +1170,9 @@ Usually 0000 or 1234 + + Must be 16 digits + You may also need to type this PIN on the other device. diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java index 578528530cb..ffe49450f52 100755 --- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java @@ -116,6 +116,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements switch (mType) { case BluetoothDevice.PAIRING_VARIANT_PIN: + case BluetoothDevice.PAIRING_VARIANT_PIN_16_DIGITS: case BluetoothDevice.PAIRING_VARIANT_PASSKEY: createUserEntryDialog(); break; @@ -181,6 +182,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements private View createPinEntryView() { View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_entry, null); TextView messageViewCaption = (TextView) view.findViewById(R.id.message_caption); + TextView messageViewCaptionHint = (TextView) view.findViewById(R.id.pin_values_hint); TextView messageViewContent = (TextView) view.findViewById(R.id.message_subhead); TextView messageView2 = (TextView) view.findViewById(R.id.message_below_pin); CheckBox alphanumericPin = (CheckBox) view.findViewById(R.id.alphanumeric_pin); @@ -190,8 +192,12 @@ public final class BluetoothPairingDialog extends AlertActivity implements int messageId1; int messageId2; + int messageIdHint = R.string.bluetooth_pin_values_hint; int maxLength; switch (mType) { + case BluetoothDevice.PAIRING_VARIANT_PIN_16_DIGITS: + messageIdHint = R.string.bluetooth_pin_values_hint_16_digits; + // FALLTHROUGH case BluetoothDevice.PAIRING_VARIANT_PIN: messageId1 = R.string.bluetooth_enter_pin_msg; messageId2 = R.string.bluetooth_enter_pin_other_device; @@ -213,6 +219,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements } messageViewCaption.setText(messageId1); + messageViewCaptionHint.setText(messageIdHint); messageViewContent.setText(mCachedDeviceManager.getName(mDevice)); messageView2.setText(messageId2); mPairingView.setInputType(InputType.TYPE_CLASS_NUMBER); @@ -316,13 +323,18 @@ public final class BluetoothPairingDialog extends AlertActivity implements public void afterTextChanged(Editable s) { if (mOkButton != null) { - mOkButton.setEnabled(s.length() > 0); + if (mType == BluetoothDevice.PAIRING_VARIANT_PIN_16_DIGITS) { + mOkButton.setEnabled(s.length() >= 16); + } else { + mOkButton.setEnabled(s.length() > 0); + } } } private void onPair(String value) { switch (mType) { case BluetoothDevice.PAIRING_VARIANT_PIN: + case BluetoothDevice.PAIRING_VARIANT_PIN_16_DIGITS: byte[] pinBytes = BluetoothDevice.convertPinToBytes(value); if (pinBytes == null) { return;