现象:
代码路径:
packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
在代码中BluetoothPairingRequest.java文件中,手机端连接蓝牙后会发送该广播ACTION_PAIRING_REQUEST出去,shouldShowDialog该变量来控制是否显示配对请求对话框
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// SPRD:bug#785347 action may be null
if (!BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) {
return;
}
// convert broadcast intent into activity intent (same action string)
Intent pairingIntent = BluetoothPairingService.getPairingDialogIntent(context, intent);
PowerManager powerManager =
(PowerManager)context.getSystemService(Context.POWER_SERVICE);
BluetoothDevice device =
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceAddress = device != null ? device.getAddress() : null;
String deviceName = device != null ? device.getName() : null;
boolean shouldShowDialog = LocalBluetoothPreferences.shouldShowDialogInForeground(
context, deviceAddress, deviceName);
if (powerManager.isInteractive() && shouldShowDialog) {
// Since the screen is on and the BT-related activity is in the foreground,
// just open the dialog
context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
} else {
// Put up a notification that leads to the dialog
intent.setClass(context, BluetoothPairingService.class);
context.startServiceAsUser(intent, UserHandle.CURRENT);
}
}