Add new pairing dialog for keyboard pairings.
Change-Id: I672a3d874a7876fca6bd38091444dc9c5fb3a2f1
This commit is contained in:
@@ -763,8 +763,8 @@
|
|||||||
<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>
|
<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 -->
|
<!-- 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>
|
<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. -->
|
<!-- Message when bluetooth dialog when passkey or pin 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>
|
<string name="bluetooth_display_passkey_pin_msg">Enter \u0022<xliff:g id="passkey">%2$s</xliff:g>\u0022 on \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022 to pair followed by return or enter. </string>
|
||||||
<!-- Button text for accepting an incoming pairing request -->
|
<!-- Button text for accepting an incoming pairing request -->
|
||||||
<string name="bluetooth_pairing_accept">Pair</string>
|
<string name="bluetooth_pairing_accept">Pair</string>
|
||||||
<!-- Button text for declining an incoming pairing request -->
|
<!-- Button text for declining an incoming pairing request -->
|
||||||
|
@@ -51,7 +51,7 @@ public class BluetoothPairingDialog extends AlertActivity implements DialogInter
|
|||||||
private LocalBluetoothManager mLocalManager;
|
private LocalBluetoothManager mLocalManager;
|
||||||
private BluetoothDevice mDevice;
|
private BluetoothDevice mDevice;
|
||||||
private int mType;
|
private int mType;
|
||||||
private String mPasskey;
|
private String mPairingKey;
|
||||||
private EditText mPairingView;
|
private EditText mPairingView;
|
||||||
private Button mOkButton;
|
private Button mOkButton;
|
||||||
|
|
||||||
@@ -96,24 +96,29 @@ public class BluetoothPairingDialog extends AlertActivity implements DialogInter
|
|||||||
createUserEntryDialog();
|
createUserEntryDialog();
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION){
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION){
|
||||||
int passkey =
|
int passkey =
|
||||||
intent.getIntExtra(BluetoothDevice.EXTRA_PASSKEY, BluetoothDevice.ERROR);
|
intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, BluetoothDevice.ERROR);
|
||||||
if (passkey == BluetoothDevice.ERROR) {
|
if (passkey == BluetoothDevice.ERROR) {
|
||||||
Log.e(TAG, "Invalid ConfirmationPasskey received, not showing any dialog");
|
Log.e(TAG, "Invalid ConfirmationPasskey received, not showing any dialog");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mPasskey = String.format("%06d", passkey);
|
mPairingKey = String.format("%06d", passkey);
|
||||||
createConfirmationDialog();
|
createConfirmationDialog();
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
|
||||||
createConsentDialog();
|
createConsentDialog();
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY ||
|
||||||
int passkey =
|
mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
|
||||||
intent.getIntExtra(BluetoothDevice.EXTRA_PASSKEY, BluetoothDevice.ERROR);
|
int pairingKey =
|
||||||
if (passkey == BluetoothDevice.ERROR) {
|
intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, BluetoothDevice.ERROR);
|
||||||
Log.e(TAG, "Invalid ConfirmationPasskey received, not showing any dialog");
|
if (pairingKey == BluetoothDevice.ERROR) {
|
||||||
|
Log.e(TAG, "Invalid Confirmation Passkey or PIN received, not showing any dialog");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mPasskey = String.format("%06d", passkey);
|
if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
|
||||||
createDisplayPasskeyDialog();
|
mPairingKey = String.format("%06d", pairingKey);
|
||||||
|
} else {
|
||||||
|
mPairingKey = String.format("%04d", pairingKey);
|
||||||
|
}
|
||||||
|
createDisplayPasskeyOrPinDialog();
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT) {
|
||||||
createConsentDialog();
|
createConsentDialog();
|
||||||
} else {
|
} else {
|
||||||
@@ -166,13 +171,15 @@ public class BluetoothPairingDialog extends AlertActivity implements DialogInter
|
|||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) {
|
||||||
mPairingView.setVisibility(View.GONE);
|
mPairingView.setVisibility(View.GONE);
|
||||||
messageView.setText(getString(R.string.bluetooth_confirm_passkey_msg, name,
|
messageView.setText(getString(R.string.bluetooth_confirm_passkey_msg, name,
|
||||||
mPasskey));
|
mPairingKey));
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
|
||||||
mPairingView.setVisibility(View.GONE);
|
mPairingView.setVisibility(View.GONE);
|
||||||
messageView.setText(getString(R.string.bluetooth_incoming_pairing_msg, name));
|
messageView.setText(getString(R.string.bluetooth_incoming_pairing_msg, name));
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY ||
|
||||||
|
mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
|
||||||
mPairingView.setVisibility(View.GONE);
|
mPairingView.setVisibility(View.GONE);
|
||||||
messageView.setText(getString(R.string.bluetooth_display_passkey_msg, name, mPasskey));
|
messageView.setText(getString(R.string.bluetooth_display_passkey_pin_msg, name,
|
||||||
|
mPairingKey));
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT) {
|
||||||
mPairingView.setVisibility(View.GONE);
|
mPairingView.setVisibility(View.GONE);
|
||||||
messageView.setText(getString(R.string.bluetooth_incoming_pairing_msg, name));
|
messageView.setText(getString(R.string.bluetooth_incoming_pairing_msg, name));
|
||||||
@@ -206,18 +213,23 @@ public class BluetoothPairingDialog extends AlertActivity implements DialogInter
|
|||||||
setupAlert();
|
setupAlert();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDisplayPasskeyDialog() {
|
private void createDisplayPasskeyOrPinDialog() {
|
||||||
final AlertController.AlertParams p = mAlertParams;
|
final AlertController.AlertParams p = mAlertParams;
|
||||||
p.mIconId = android.R.drawable.ic_dialog_info;
|
p.mIconId = android.R.drawable.ic_dialog_info;
|
||||||
p.mTitle = getString(R.string.bluetooth_pairing_request);
|
p.mTitle = getString(R.string.bluetooth_pairing_request);
|
||||||
p.mView = createView();
|
p.mView = createView();
|
||||||
p.mPositiveButtonText = getString(android.R.string.ok);
|
p.mNegativeButtonText = getString(android.R.string.cancel);
|
||||||
p.mPositiveButtonListener = this;
|
p.mNegativeButtonListener = this;
|
||||||
setupAlert();
|
setupAlert();
|
||||||
|
|
||||||
// Since its only a notification, send an OK to the framework,
|
// Since its only a notification, send an OK to the framework,
|
||||||
// indicating that the dialog has been displayed.
|
// indicating that the dialog has been displayed.
|
||||||
mDevice.setPairingConfirmation(true);
|
if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
|
||||||
|
mDevice.setPairingConfirmation(true);
|
||||||
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
|
||||||
|
byte[] pinBytes = BluetoothDevice.convertPinToBytes(mPairingKey);
|
||||||
|
mDevice.setPin(pinBytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -252,6 +264,8 @@ public class BluetoothPairingDialog extends AlertActivity implements DialogInter
|
|||||||
mDevice.setPairingConfirmation(true);
|
mDevice.setPairingConfirmation(true);
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
|
||||||
// Do Nothing.
|
// Do Nothing.
|
||||||
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
|
||||||
|
// Do Nothing
|
||||||
} else if (mType == BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT) {
|
} else if (mType == BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT) {
|
||||||
mDevice.setRemoteOutOfBandData();
|
mDevice.setRemoteOutOfBandData();
|
||||||
} else {
|
} else {
|
||||||
|
@@ -55,9 +55,11 @@ public class BluetoothPairingRequest extends BroadcastReceiver {
|
|||||||
pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
|
pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
|
||||||
pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
|
pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
|
||||||
if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION ||
|
if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION ||
|
||||||
type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) {
|
type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY ||
|
||||||
int passkey = intent.getIntExtra(BluetoothDevice.EXTRA_PASSKEY, BluetoothDevice.ERROR);
|
type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
|
||||||
pairingIntent.putExtra(BluetoothDevice.EXTRA_PASSKEY, passkey);
|
int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
|
||||||
|
BluetoothDevice.ERROR);
|
||||||
|
pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
|
||||||
}
|
}
|
||||||
pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
|
pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
|
||||||
pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
Reference in New Issue
Block a user