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
This commit is contained in:
Haijie Hong
2025-03-19 14:01:50 +08:00
parent fc10fdf30b
commit d6f7270748
3 changed files with 21 additions and 10 deletions

View File

@@ -2099,6 +2099,8 @@
<string name="bluetooth_key_missing_device_settings">Device settings</string>
<!-- Button text to close the bluetooth key missing dialog-->
<string name="bluetooth_key_missing_close">Close</string>
<!-- Toast text to when bluetooth key is missing -->
<string name="bluetooth_key_missing_toast"><xliff:g id="device_name">%1$s</xliff:g> failed to connect</string>
<!-- Title of device details screen [CHAR LIMIT=28]-->
<string name="device_details_title">Device details</string>

View File

@@ -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);

View File

@@ -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)) {
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)