Bluetooth: Dismiss pairing dialog on user click
* Existing pairing dialog should be dismissed when user clicks on Yes/No * In a pairing session with multiple pairing dialogs, this is necessary as otherwise the second pairing dialog will not be shown * Modified unit test to test this behavior * Launch pairing dialog as UserHandle.CURRENT to avoid Context warnings Bug: 35833536 Test: make, unit test, pair with Bluetooth devices Change-Id: I1823b78d287134505f59eab7caca2329ecc3a36f
This commit is contained in:
@@ -47,6 +47,7 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
|
||||
private AlertDialog.Builder mBuilder;
|
||||
private AlertDialog mDialog;
|
||||
private BluetoothPairingController mPairingController;
|
||||
private BluetoothPairingDialog mPairingDialogActivity;
|
||||
private EditText mPairingView;
|
||||
/**
|
||||
* The interface we expect a listener to implement. Typically this should be done by
|
||||
@@ -61,9 +62,13 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
if (mPairingController == null) {
|
||||
if (!isPairingControllerSet()) {
|
||||
throw new IllegalStateException(
|
||||
"Must call setPairingController() before showing dialog");
|
||||
"Must call setPairingController() before showing dialog");
|
||||
}
|
||||
if (!isPairingDialogActivitySet()) {
|
||||
throw new IllegalStateException(
|
||||
"Must call setPairingDialogActivity() before showing dialog");
|
||||
}
|
||||
mBuilder = new AlertDialog.Builder(getActivity());
|
||||
mDialog = setupDialog();
|
||||
@@ -97,6 +102,7 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
|
||||
} else if (which == DialogInterface.BUTTON_NEGATIVE) {
|
||||
mPairingController.onDialogNegativeClick(this);
|
||||
}
|
||||
mPairingDialogActivity.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,14 +125,41 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
|
||||
* controller may not be substituted once it is assigned. Forcibly switching a
|
||||
* controller for a new one will lead to undefined behavior.
|
||||
*/
|
||||
public void setPairingController(BluetoothPairingController pairingController) {
|
||||
if (mPairingController != null) {
|
||||
void setPairingController(BluetoothPairingController pairingController) {
|
||||
if (isPairingControllerSet()) {
|
||||
throw new IllegalStateException("The controller can only be set once. "
|
||||
+ "Forcibly replacing it will lead to undefined behavior");
|
||||
}
|
||||
mPairingController = pairingController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether mPairingController is set
|
||||
* @return True when mPairingController is set, False otherwise
|
||||
*/
|
||||
boolean isPairingControllerSet() {
|
||||
return mPairingController != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the BluetoothPairingDialog activity that started this fragment
|
||||
* @param pairingDialogActivity The pairing dialog activty that started this fragment
|
||||
*/
|
||||
void setPairingDialogActivity(BluetoothPairingDialog pairingDialogActivity) {
|
||||
if (isPairingDialogActivitySet()) {
|
||||
throw new IllegalStateException("The pairing dialog activity can only be set once");
|
||||
}
|
||||
mPairingDialogActivity = pairingDialogActivity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether mPairingDialogActivity is set
|
||||
* @return True when mPairingDialogActivity is set, False otherwise
|
||||
*/
|
||||
boolean isPairingDialogActivitySet() {
|
||||
return mPairingDialogActivity != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the appropriate type of dialog and returns it.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user