Merge "Bluetooth: Add pairing initiator extra"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2cb875aefc
@@ -60,6 +60,7 @@ public class BluetoothPairingController implements OnCheckedChangeListener,
|
|||||||
private String mUserInput;
|
private String mUserInput;
|
||||||
private String mPasskeyFormatted;
|
private String mPasskeyFormatted;
|
||||||
private int mPasskey;
|
private int mPasskey;
|
||||||
|
private int mInitiator;
|
||||||
private String mDeviceName;
|
private String mDeviceName;
|
||||||
private LocalBluetoothProfile mPbapClientProfile;
|
private LocalBluetoothProfile mPbapClientProfile;
|
||||||
private boolean mPbapAllowed;
|
private boolean mPbapAllowed;
|
||||||
@@ -84,6 +85,8 @@ public class BluetoothPairingController implements OnCheckedChangeListener,
|
|||||||
|
|
||||||
mType = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
|
mType = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
|
||||||
mPasskey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, BluetoothDevice.ERROR);
|
mPasskey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, BluetoothDevice.ERROR);
|
||||||
|
mInitiator =
|
||||||
|
intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_INITIATOR, BluetoothDevice.ERROR);
|
||||||
mDeviceName = mBluetoothManager.getCachedDeviceManager().getName(mDevice);
|
mDeviceName = mBluetoothManager.getCachedDeviceManager().getName(mDevice);
|
||||||
mPbapClientProfile = mBluetoothManager.getProfileManager().getPbapClientProfile();
|
mPbapClientProfile = mBluetoothManager.getProfileManager().getPbapClientProfile();
|
||||||
mPasskeyFormatted = formatKey(mPasskey);
|
mPasskeyFormatted = formatKey(mPasskey);
|
||||||
@@ -177,7 +180,7 @@ public class BluetoothPairingController implements OnCheckedChangeListener,
|
|||||||
default:
|
default:
|
||||||
if (mDevice.getBluetoothClass().getDeviceClass()
|
if (mDevice.getBluetoothClass().getDeviceClass()
|
||||||
== BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) {
|
== BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) {
|
||||||
return true;
|
return BluetoothDevice.EXTRA_PAIRING_INITIATOR_FOREGROUND == mInitiator;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -37,9 +37,6 @@ public final class BluetoothPairingRequest extends BroadcastReceiver {
|
|||||||
if (!action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
|
if (!action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// convert broadcast intent into activity intent (same action string)
|
|
||||||
Intent pairingIntent = BluetoothPairingService.getPairingDialogIntent(context, intent);
|
|
||||||
|
|
||||||
PowerManager powerManager =
|
PowerManager powerManager =
|
||||||
(PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
(PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
||||||
BluetoothDevice device =
|
BluetoothDevice device =
|
||||||
@@ -51,6 +48,10 @@ public final class BluetoothPairingRequest extends BroadcastReceiver {
|
|||||||
if (powerManager.isInteractive() && shouldShowDialog) {
|
if (powerManager.isInteractive() && shouldShowDialog) {
|
||||||
// Since the screen is on and the BT-related activity is in the foreground,
|
// Since the screen is on and the BT-related activity is in the foreground,
|
||||||
// just open the dialog
|
// just open the dialog
|
||||||
|
// convert broadcast intent into activity intent (same action string)
|
||||||
|
Intent pairingIntent = BluetoothPairingService.getPairingDialogIntent(context, intent,
|
||||||
|
BluetoothDevice.EXTRA_PAIRING_INITIATOR_FOREGROUND);
|
||||||
|
|
||||||
context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
|
context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
|
||||||
} else {
|
} else {
|
||||||
// Put up a notification that leads to the dialog
|
// Put up a notification that leads to the dialog
|
||||||
|
@@ -51,7 +51,7 @@ public final class BluetoothPairingService extends Service {
|
|||||||
|
|
||||||
private BluetoothDevice mDevice;
|
private BluetoothDevice mDevice;
|
||||||
|
|
||||||
public static Intent getPairingDialogIntent(Context context, Intent intent) {
|
public static Intent getPairingDialogIntent(Context context, Intent intent, int initiator) {
|
||||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
|
int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
|
||||||
BluetoothDevice.ERROR);
|
BluetoothDevice.ERROR);
|
||||||
@@ -65,6 +65,7 @@ public final class BluetoothPairingService extends Service {
|
|||||||
int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
|
int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
|
||||||
BluetoothDevice.ERROR);
|
BluetoothDevice.ERROR);
|
||||||
pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
|
pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
|
||||||
|
pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_INITIATOR, initiator);
|
||||||
}
|
}
|
||||||
pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
|
pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
|
||||||
pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
@@ -124,7 +125,8 @@ public final class BluetoothPairingService extends Service {
|
|||||||
.setLocalOnly(true);
|
.setLocalOnly(true);
|
||||||
|
|
||||||
PendingIntent pairIntent = PendingIntent.getActivity(this, 0,
|
PendingIntent pairIntent = PendingIntent.getActivity(this, 0,
|
||||||
getPairingDialogIntent(this, intent),
|
getPairingDialogIntent(this, intent,
|
||||||
|
BluetoothDevice.EXTRA_PAIRING_INITIATOR_BACKGROUND),
|
||||||
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
PendingIntent dismissIntent = PendingIntent.getBroadcast(this, 0,
|
PendingIntent dismissIntent = PendingIntent.getBroadcast(this, 0,
|
||||||
|
Reference in New Issue
Block a user