From d6f7270748564effbd892b6d958da9cbe1137dfb Mon Sep 17 00:00:00 2001 From: Haijie Hong Date: Wed, 19 Mar 2025 14:01:50 +0800 Subject: [PATCH] Add toast for bond loss Test: local tested, haven't find good way to add unit test for reflection. Flag: EXEMPT minor fix Bug: 380801155 Change-Id: Ia0d05ef933b0ae24077f31e4ff46c9948b99628a --- res/values/strings.xml | 2 ++ .../BluetoothKeyMissingDialogFragment.java | 2 +- .../BluetoothKeyMissingReceiver.java | 27 ++++++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 6d865c21096..266decdaab6 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)