diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5fcb29d2e1b..3785b21224f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2099,6 +2099,8 @@
Device settings
Close
+
+ %1$s failed to connect
Device details
diff --git a/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogFragment.java
index 671e282c338..6b25bed88f4 100644
--- a/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogFragment.java
@@ -66,7 +66,7 @@ public class BluetoothKeyMissingDialogFragment extends InstrumentedDialogFragmen
View view = getActivity().getLayoutInflater().inflate(R.layout.bluetooth_key_missing, null);
TextView keyMissingTitle = view.findViewById(R.id.bluetooth_key_missing_title);
keyMissingTitle.setText(
- getString(R.string.bluetooth_key_missing_title, mBluetoothDevice.getName()));
+ getString(R.string.bluetooth_key_missing_title, mBluetoothDevice.getAlias()));
builder.setView(view);
builder.setPositiveButton(getString(R.string.bluetooth_key_missing_device_settings), this);
builder.setNegativeButton(getString(R.string.bluetooth_key_missing_close), this);
diff --git a/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java b/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java
index cfe9c056d39..2ae9fd9f846 100644
--- a/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java
+++ b/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java
@@ -28,6 +28,7 @@ import android.os.PowerManager;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
+import android.widget.Toast;
import androidx.core.app.NotificationCompat;
@@ -68,15 +69,23 @@ public final class BluetoothKeyMissingReceiver extends BroadcastReceiver {
return;
}
Integer keyMissingCount = BluetoothUtils.getKeyMissingCount(device);
- if (keyMissingCount != null && keyMissingCount != 1) {
- Log.d(TAG, "Key missing count is " + keyMissingCount + ", skip.");
- return;
- }
+ boolean keyMissingFirstTime = keyMissingCount == null || keyMissingCount == 1;
if (shouldShowDialog(context, device, powerManager)) {
- Intent pairingIntent = getKeyMissingDialogIntent(context, device);
- Log.d(TAG, "Show key missing dialog:" + device);
- context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
- } else {
+ if (keyMissingFirstTime) {
+ Intent pairingIntent = getKeyMissingDialogIntent(context, device);
+ Log.d(TAG, "Show key missing dialog:" + device);
+ context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
+ } else {
+ Log.d(TAG, "Show key missing toast:" + device);
+ Toast.makeText(
+ context,
+ context.getString(
+ R.string.bluetooth_key_missing_toast,
+ device.getAlias()),
+ Toast.LENGTH_SHORT)
+ .show();
+ }
+ } else if (keyMissingFirstTime) {
Log.d(TAG, "Show key missing notification: " + device);
showNotification(context, device);
}
@@ -123,7 +132,7 @@ public final class BluetoothKeyMissingReceiver extends BroadcastReceiver {
.setLocalOnly(true);
builder.setContentTitle(
context.getString(
- R.string.bluetooth_key_missing_title, bluetoothDevice.getName()))
+ R.string.bluetooth_key_missing_title, bluetoothDevice.getAlias()))
.setContentText(context.getString(R.string.bluetooth_key_missing_message))
.setContentIntent(pairIntent)
.setAutoCancel(true)