зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1036228 - Patch2: Handle pairing requests reported by bluedroid in bluetooth services. r=btian
This commit is contained in:
Родитель
68c5209cb0
Коммит
109a2d162b
|
@ -344,20 +344,13 @@ BluetoothService::DistributeSignal(const BluetoothSignal& aSignal)
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (aSignal.path().EqualsLiteral(KEY_LOCAL_AGENT)) {
|
||||
Notify(aSignal);
|
||||
return;
|
||||
} else if (aSignal.path().EqualsLiteral(KEY_REMOTE_AGENT)) {
|
||||
Notify(aSignal);
|
||||
return;
|
||||
}
|
||||
|
||||
BluetoothSignalObserverList* ol;
|
||||
if (!mBluetoothSignalObserverTable.Get(aSignal.path(), &ol)) {
|
||||
BT_WARNING("No observer registered for path %s",
|
||||
NS_ConvertUTF16toUTF8(aSignal.path()).get());
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(ol->Length());
|
||||
ol->Broadcast(aSignal);
|
||||
}
|
||||
|
@ -735,52 +728,3 @@ BluetoothService::FireAdapterStateChanged(bool aEnable)
|
|||
NS_LITERAL_STRING(KEY_ADAPTER), value);
|
||||
DistributeSignal(signal);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothService::Notify(const BluetoothSignal& aData)
|
||||
{
|
||||
nsString type = NS_LITERAL_STRING("bluetooth-pairing-request");
|
||||
|
||||
AutoSafeJSContext cx;
|
||||
JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(),
|
||||
JS::NullPtr()));
|
||||
NS_ENSURE_TRUE_VOID(obj);
|
||||
|
||||
if (!SetJsObject(cx, aData.value(), obj)) {
|
||||
BT_WARNING("Failed to set properties of system message!");
|
||||
return;
|
||||
}
|
||||
|
||||
BT_LOGD("[S] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get());
|
||||
|
||||
if (aData.name().EqualsLiteral("RequestConfirmation")) {
|
||||
MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 4,
|
||||
"RequestConfirmation: Wrong length of parameters");
|
||||
} else if (aData.name().EqualsLiteral("RequestPinCode")) {
|
||||
MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 3,
|
||||
"RequestPinCode: Wrong length of parameters");
|
||||
} else if (aData.name().EqualsLiteral("RequestPasskey")) {
|
||||
MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 3,
|
||||
"RequestPinCode: Wrong length of parameters");
|
||||
} else if (aData.name().EqualsLiteral("Cancel")) {
|
||||
MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 0,
|
||||
"Cancel: Wrong length of parameters");
|
||||
type.AssignLiteral("bluetooth-cancel");
|
||||
} else if (aData.name().EqualsLiteral(PAIRED_STATUS_CHANGED_ID)) {
|
||||
MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 1,
|
||||
"pairedstatuschanged: Wrong length of parameters");
|
||||
type.AssignLiteral("bluetooth-pairedstatuschanged");
|
||||
} else {
|
||||
BT_WARNING("Not handling service signal: %s",
|
||||
NS_ConvertUTF16toUTF8(aData.name()).get());
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
|
||||
do_GetService("@mozilla.org/system-message-internal;1");
|
||||
NS_ENSURE_TRUE_VOID(systemMessenger);
|
||||
|
||||
JS::Rooted<JS::Value> value(cx, JS::ObjectValue(*obj));
|
||||
systemMessenger->BroadcastMessage(type, value,
|
||||
JS::UndefinedHandleValue);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ class BluetoothSignal;
|
|||
typedef mozilla::ObserverList<BluetoothSignal> BluetoothSignalObserverList;
|
||||
|
||||
class BluetoothService : public nsIObserver
|
||||
, public BluetoothSignalObserver
|
||||
{
|
||||
class ToggleBtTask;
|
||||
friend class ToggleBtTask;
|
||||
|
@ -97,13 +96,6 @@ public:
|
|||
void
|
||||
DistributeSignal(const BluetoothSignal& aEvent);
|
||||
|
||||
/**
|
||||
* Called when get a Bluetooth Signal from BluetoothDBusService
|
||||
*
|
||||
*/
|
||||
void
|
||||
Notify(const BluetoothSignal& aParam);
|
||||
|
||||
/**
|
||||
* Returns the BluetoothService singleton. Only to be called from main thread.
|
||||
*
|
||||
|
|
|
@ -632,23 +632,22 @@ PinRequestCallback(bt_bdaddr_t* aRemoteBdAddress,
|
|||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
InfallibleTArray<BluetoothNamedValue> propertiesArray;
|
||||
nsAutoString remoteAddress;
|
||||
BdAddressTypeToString(aRemoteBdAddress, remoteAddress);
|
||||
InfallibleTArray<BluetoothNamedValue> props;
|
||||
nsAutoString deviceAddress;
|
||||
BdAddressTypeToString(aRemoteBdAddress, deviceAddress);
|
||||
|
||||
BT_APPEND_NAMED_VALUE(propertiesArray, "address", remoteAddress);
|
||||
BT_APPEND_NAMED_VALUE(propertiesArray, "method",
|
||||
NS_LITERAL_STRING("pincode"));
|
||||
BT_APPEND_NAMED_VALUE(propertiesArray, "name",
|
||||
NS_ConvertUTF8toUTF16(
|
||||
(const char*)aRemoteBdName->name));
|
||||
BT_APPEND_NAMED_VALUE(props, "address", deviceAddress);
|
||||
BT_APPEND_NAMED_VALUE(props, "passkey", EmptyString());
|
||||
BT_APPEND_NAMED_VALUE(props, "type",
|
||||
NS_LITERAL_STRING(PAIRING_REQ_TYPE_ENTERPINCODE));
|
||||
|
||||
BluetoothValue value = propertiesArray;
|
||||
BluetoothSignal signal(NS_LITERAL_STRING("RequestPinCode"),
|
||||
NS_LITERAL_STRING(KEY_LOCAL_AGENT), value);
|
||||
nsRefPtr<DistributeBluetoothSignalTask>
|
||||
t = new DistributeBluetoothSignalTask(signal);
|
||||
if (NS_FAILED(NS_DispatchToMainThread(t))) {
|
||||
BluetoothSignal signal(NS_LITERAL_STRING("PairingRequest"),
|
||||
NS_LITERAL_STRING(KEY_ADAPTER),
|
||||
BluetoothValue(props));
|
||||
|
||||
nsRefPtr<DistributeBluetoothSignalTask> task =
|
||||
new DistributeBluetoothSignalTask(signal);
|
||||
if (NS_FAILED(NS_DispatchToMainThread(task))) {
|
||||
BT_WARNING("Failed to dispatch to main thread!");
|
||||
}
|
||||
}
|
||||
|
@ -660,24 +659,49 @@ SspRequestCallback(bt_bdaddr_t* aRemoteBdAddress, bt_bdname_t* aRemoteBdName,
|
|||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
InfallibleTArray<BluetoothNamedValue> propertiesArray;
|
||||
nsAutoString remoteAddress;
|
||||
BdAddressTypeToString(aRemoteBdAddress, remoteAddress);
|
||||
InfallibleTArray<BluetoothNamedValue> props;
|
||||
nsAutoString deviceAddress;
|
||||
BdAddressTypeToString(aRemoteBdAddress, deviceAddress);
|
||||
|
||||
BT_APPEND_NAMED_VALUE(propertiesArray, "address", remoteAddress);
|
||||
BT_APPEND_NAMED_VALUE(propertiesArray, "method",
|
||||
NS_LITERAL_STRING("confirmation"));
|
||||
BT_APPEND_NAMED_VALUE(propertiesArray, "name",
|
||||
NS_ConvertUTF8toUTF16(
|
||||
(const char*)aRemoteBdName->name));
|
||||
BT_APPEND_NAMED_VALUE(propertiesArray, "passkey", aPasskey);
|
||||
nsAutoString passkey;
|
||||
nsAutoString pairingType;
|
||||
|
||||
BluetoothValue value = propertiesArray;
|
||||
BluetoothSignal signal(NS_LITERAL_STRING("RequestConfirmation"),
|
||||
NS_LITERAL_STRING(KEY_LOCAL_AGENT), value);
|
||||
nsRefPtr<DistributeBluetoothSignalTask>
|
||||
t = new DistributeBluetoothSignalTask(signal);
|
||||
if (NS_FAILED(NS_DispatchToMainThread(t))) {
|
||||
/**
|
||||
* Assign pairing request type and passkey based on the pairing variant.
|
||||
*
|
||||
* passkey value based on pairing request type:
|
||||
* 1) aPasskey: PAIRING_REQ_TYPE_CONFIRMATION and
|
||||
* PAIRING_REQ_TYPE_DISPLAYPASSKEY
|
||||
* 2) empty string: PAIRING_REQ_TYPE_CONSENT
|
||||
*/
|
||||
switch (aPairingVariant) {
|
||||
case BT_SSP_VARIANT_PASSKEY_CONFIRMATION:
|
||||
pairingType.AssignLiteral(PAIRING_REQ_TYPE_CONFIRMATION);
|
||||
passkey.AppendInt(aPasskey);
|
||||
break;
|
||||
case BT_SSP_VARIANT_PASSKEY_NOTIFICATION:
|
||||
pairingType.AssignLiteral(PAIRING_REQ_TYPE_DISPLAYPASSKEY);
|
||||
passkey.AppendInt(aPasskey);
|
||||
break;
|
||||
case BT_SSP_VARIANT_CONSENT:
|
||||
pairingType.AssignLiteral(PAIRING_REQ_TYPE_CONSENT);
|
||||
break;
|
||||
default:
|
||||
BT_WARNING("Unhandled SSP Bonding Variant: %d", aPairingVariant);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_APPEND_NAMED_VALUE(props, "address", deviceAddress);
|
||||
BT_APPEND_NAMED_VALUE(props, "passkey", passkey);
|
||||
BT_APPEND_NAMED_VALUE(props, "type", pairingType);
|
||||
|
||||
BluetoothSignal signal(NS_LITERAL_STRING("PairingRequest"),
|
||||
NS_LITERAL_STRING(KEY_ADAPTER),
|
||||
BluetoothValue(props));
|
||||
|
||||
nsRefPtr<DistributeBluetoothSignalTask> task =
|
||||
new DistributeBluetoothSignalTask(signal);
|
||||
if (NS_FAILED(NS_DispatchToMainThread(task))) {
|
||||
BT_WARNING("Failed to dispatch to main thread!");
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче