<string name="bluetooth_settings_summary">Manage connections, set device name & discoverability</string>
<!-- Title for the dialog to enter PIN. -->
- <string name="bluetooth_pin_entry">Bluetooth pairing request</string>
+ <string name="bluetooth_pairing_request">Bluetooth pairing request</string>
<!-- Title for the bluetooth device info screen. -->
<string name="bluetooth_device_info">Bluetooth device info</string>
<!-- Message when bluetooth dialog for pin entry is showing -->
<string name="bluetooth_enter_passkey_msg">\nType passkey to pair with \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022.</string>
<!-- Message when bluetooth dialog for confirmation of passkey is showing -->
<string name="bluetooth_confirm_passkey_msg">To pair with \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022, confirm that it is showing the passkey: <xliff:g id="passkey">%2$s</xliff:g>.</string>
+ <!-- Message when bluetooth incoming pairing request for (2.1 devices) dialog is showing -->
+ <string name="bluetooth_incoming_pairing_msg"><xliff:g id="device_name">%1$s</xliff:g>\nwants to pair.</string>
+ <!-- Message when bluetooth dialog when passkey needs to be displayed. -->
+ <string name="bluetooth_display_passkey_msg">Enter <xliff:g id="passkey">%2$s</xliff:g> on \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022 to pair. </string>
<!-- Button text for accepting an incoming pairing request -->
<string name="bluetooth_pairing_accept">Pair</string>
<!-- Button text for declining an incoming pairing request -->
<string name="bluetooth_pairing_decline">Don\u0027t Pair</string>
+ <!-- Generic string for remote Bluetooth device -->
+ <string name="bluetooth_remote_device">bluetooth device</string>
<!-- Title for BT error dialogs. -->
<string name="bluetooth_error_title">Attention</string>
<string name="bluetooth_pairing_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g>.</string>
<!-- Message for the error dialog when BT pairing fails because the PIN /
Passkey entered is incorrect. -->
- <string name="bluetooth_pairing_pin_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g> because the typed PIN or Passkey is incorrect.</string>
+ <string name="bluetooth_pairing_pin_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g> because the PIN or Passkey is incorrect.</string>
<!-- Message for the error dialog when BT pairing fails because the other device is down. -->
<string name="bluetooth_pairing_device_down_error_message">Cannot establish communication with <xliff:g id="device_name">%1$s</xliff:g>.</string>
<!-- Message for the error dialog when BT pairing fails because the other device rejected the pairing. -->
private LocalBluetoothManager mLocalManager;
private BluetoothDevice mDevice;
private int mType;
- private String mConfirmationPasskey;
+ private String mPasskey;
private EditText mPairingView;
private Button mOkButton;
- private static final String INSTANCE_KEY_PAIRING_CANCELED = "received_pairing_canceled";
- private boolean mReceivedPairingCanceled;
-
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- if (!BluetoothDevice.ACTION_PAIRING_CANCEL.equals(intent.getAction())) {
- return;
- }
-
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- if (device == null || device.equals(mDevice)) {
- onReceivedPairingCanceled();
+ if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(intent.getAction())) {
+ int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
+ BluetoothDevice.ERROR);
+ if (bondState == BluetoothDevice.BOND_BONDED ||
+ bondState == BluetoothDevice.BOND_NONE) {
+ dismissDialog();
+ }
+ } else if(BluetoothDevice.ACTION_PAIRING_CANCEL.equals(intent.getAction())) {
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ if (device == null || device.equals(mDevice)) {
+ dismissDialog();
+ }
}
}
};
createUserEntryDialog();
} else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY) {
createUserEntryDialog();
- } else if (mType == BluetoothDevice.PAIRING_VARIANT_CONFIRMATION){
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION){
int passkey =
intent.getIntExtra(BluetoothDevice.EXTRA_PASSKEY, BluetoothDevice.ERROR);
if (passkey == BluetoothDevice.ERROR) {
Log.e(TAG, "Invalid ConfirmationPasskey received, not showing any dialog");
return;
}
- mConfirmationPasskey = String.format("%06d", passkey);
+ mPasskey = String.format("%06d", passkey);
createConfirmationDialog();
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
+ createConsentDialog();
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
+ int passkey =
+ intent.getIntExtra(BluetoothDevice.EXTRA_PASSKEY, BluetoothDevice.ERROR);
+ if (passkey == BluetoothDevice.ERROR) {
+ Log.e(TAG, "Invalid ConfirmationPasskey received, not showing any dialog");
+ return;
+ }
+ mPasskey = String.format("%06d", passkey);
+ createDisplayPasskeyDialog();
} else {
Log.e(TAG, "Incorrect pairing type received, not showing any dialog");
}
* finish the activity in the background if pairing is canceled.
*/
registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_PAIRING_CANCEL));
+ registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
}
private void createUserEntryDialog() {
final AlertController.AlertParams p = mAlertParams;
p.mIconId = android.R.drawable.ic_dialog_info;
- p.mTitle = getString(R.string.bluetooth_pin_entry);
+ p.mTitle = getString(R.string.bluetooth_pairing_request);
p.mView = createView();
p.mPositiveButtonText = getString(android.R.string.ok);
p.mPositiveButtonListener = this;
} else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY){
messageView.setText(getString(R.string.bluetooth_enter_passkey_msg, name));
// Maximum of 6 digits for passkey
- mPairingView.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
+ mPairingView.setInputType(InputType.TYPE_CLASS_NUMBER |
+ InputType.TYPE_NUMBER_FLAG_SIGNED);
mPairingView.setFilters(new InputFilter[] {
new LengthFilter(BLUETOOTH_PASSKEY_MAX_LENGTH)});
- } else {
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) {
mPairingView.setVisibility(View.GONE);
messageView.setText(getString(R.string.bluetooth_confirm_passkey_msg, name,
- mConfirmationPasskey));
+ mPasskey));
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
+ mPairingView.setVisibility(View.GONE);
+ messageView.setText(getString(R.string.bluetooth_incoming_pairing_msg, name));
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
+ mPairingView.setVisibility(View.GONE);
+ messageView.setText(getString(R.string.bluetooth_display_passkey_msg, name, mPasskey));
+ } else {
+ Log.e(TAG, "Incorrect pairing type received, not creating view");
}
return view;
}
private void createConfirmationDialog() {
final AlertController.AlertParams p = mAlertParams;
p.mIconId = android.R.drawable.ic_dialog_info;
- p.mTitle = getString(R.string.bluetooth_pin_entry);
+ p.mTitle = getString(R.string.bluetooth_pairing_request);
p.mView = createView();
p.mPositiveButtonText = getString(R.string.bluetooth_pairing_accept);
p.mPositiveButtonListener = this;
setupAlert();
}
- @Override
- protected void onRestoreInstanceState(Bundle savedInstanceState) {
- super.onRestoreInstanceState(savedInstanceState);
-
- mReceivedPairingCanceled = savedInstanceState.getBoolean(INSTANCE_KEY_PAIRING_CANCELED);
- if (mReceivedPairingCanceled) {
- onReceivedPairingCanceled();
- }
+ private void createConsentDialog() {
+ final AlertController.AlertParams p = mAlertParams;
+ p.mIconId = android.R.drawable.ic_dialog_info;
+ p.mTitle = getString(R.string.bluetooth_pairing_request);
+ p.mView = createView();
+ p.mPositiveButtonText = getString(R.string.bluetooth_pairing_accept);
+ p.mPositiveButtonListener = this;
+ p.mNegativeButtonText = getString(R.string.bluetooth_pairing_decline);
+ p.mNegativeButtonListener = this;
+ setupAlert();
}
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
+ private void createDisplayPasskeyDialog() {
+ final AlertController.AlertParams p = mAlertParams;
+ p.mIconId = android.R.drawable.ic_dialog_info;
+ p.mTitle = getString(R.string.bluetooth_pairing_request);
+ p.mView = createView();
+ p.mPositiveButtonText = getString(android.R.string.ok);
+ p.mPositiveButtonListener = this;
+ setupAlert();
- outState.putBoolean(INSTANCE_KEY_PAIRING_CANCELED, mReceivedPairingCanceled);
+ // Since its only a notification, send an OK to the framework,
+ // indicating that the dialog has been displayed.
+ mDevice.setPairingConfirmation(true);
}
@Override
protected void onDestroy() {
super.onDestroy();
-
unregisterReceiver(mReceiver);
}
}
}
- private void onReceivedPairingCanceled() {
- mReceivedPairingCanceled = true;
-
- TextView messageView = (TextView) findViewById(R.id.message);
- messageView.setText(getString(R.string.bluetooth_pairing_error_message,
- mDevice.getName()));
-
- mPairingView.setVisibility(View.GONE);
- mPairingView.clearFocus();
- mPairingView.removeTextChangedListener(this);
-
- mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
- mOkButton.setEnabled(true);
- mOkButton.setText(android.R.string.ok);
- mAlert.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE);
+ private void dismissDialog() {
+ this.dismiss();
}
private void onPair(String value) {
} else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY) {
int passkey = Integer.parseInt(value);
mDevice.setPasskey(passkey);
- } else {
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) {
mDevice.setPairingConfirmation(true);
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
+ mDevice.setPairingConfirmation(true);
+ } else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
+ // Do Nothing.
+ } else {
+ Log.e(TAG, "Incorrect pairing type received");
}
}