void BluetoothPairingListener::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; BluetoothValue value = aData.value(); if (aData.name().EqualsLiteral("PairingRequest")) { MOZ_ASSERT(value.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = value.get_ArrayOfBluetoothNamedValue(); MOZ_ASSERT(arr.Length() == 4 && arr[0].value().type() == BluetoothValue::TnsString && // address arr[1].value().type() == BluetoothValue::TnsString && // name arr[2].value().type() == BluetoothValue::TnsString && // passkey arr[3].value().type() == BluetoothValue::TnsString); // type nsString address = arr[0].value().get_nsString(); nsString name = arr[1].value().get_nsString(); nsString passkey = arr[2].value().get_nsString(); nsString type = arr[3].value().get_nsString(); // Notify pairing listener of pairing requests DispatchPairingEvent(name, address, passkey, type); } else { BT_WARNING("Not handling pairing listener signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothDevice::Notify(const BluetoothSignal& aData) { if (aData.name().EqualsLiteral("PropertyChanged")) { NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue, "PropertyChanged: Invalid value type"); InfallibleTArray<BluetoothNamedValue> arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!"); BluetoothNamedValue v = arr[0]; nsString name = v.name(); SetPropertyByValue(v); if (name.EqualsLiteral("Connected")) { DispatchTrustedEvent(mConnected ? NS_LITERAL_STRING("connected") : NS_LITERAL_STRING("disconnected")); } else { nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(name); e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged")); } } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling device signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }
void BluetoothGattServer::Notify(const BluetoothSignal& aData) { BT_LOGD("[GattServer] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); NS_ENSURE_TRUE_VOID(mSignalRegistered); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("ServerRegistered")) { HandleServerRegistered(v); } else if (aData.name().EqualsLiteral("ServerUnregistered")) { HandleServerUnregistered(v); } else if (aData.name().EqualsLiteral(GATT_CONNECTION_STATE_CHANGED_ID)) { HandleConnectionStateChanged(v); } else if (aData.name().EqualsLiteral("ServiceHandleUpdated")) { HandleServiceHandleUpdated(v); } else if (aData.name().EqualsLiteral("CharacteristicHandleUpdated")) { HandleCharacteristicHandleUpdated(v); } else if (aData.name().EqualsLiteral("DescriptorHandleUpdated")) { HandleDescriptorHandleUpdated(v); } else if (aData.name().EqualsLiteral("ReadRequested")) { HandleReadWriteRequest(v, NS_LITERAL_STRING(ATTRIBUTE_READ_REQUEST)); } else if (aData.name().EqualsLiteral("WriteRequested")) { HandleReadWriteRequest(v, NS_LITERAL_STRING(ATTRIBUTE_WRITE_REQUEST)); } else { BT_WARNING("Not handling GATT signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothAdapter::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; BT_LOG("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("DeviceFound")) { nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value()); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), this, nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicefound"), false, false, device); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral("PropertyChanged")) { NS_ASSERTION(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue, "PropertyChanged: Invalid value type"); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!"); SetPropertyByValue(arr[0]); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling adapter signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }
void BluetoothAdapter::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; if (aData.name().EqualsLiteral("DeviceFound")) { nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value()); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicefound"), false, false, device); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral("DeviceDisappeared")) { const nsAString& deviceAddress = aData.value().get_nsString(); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("devicedisappeared"), false, false, deviceAddress); DispatchTrustedEvent(e); } else if (aData.name().EqualsLiteral("DeviceCreated")) { NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue, "DeviceCreated: Invalid value type"); nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), GetPath(), aData.value()); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicecreated"), false, false, device); DispatchTrustedEvent(e); } else if (aData.name().EqualsLiteral("PropertyChanged")) { NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue, "PropertyChanged: Invalid value type"); arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!"); BluetoothNamedValue v = arr[0]; SetPropertyByValue(v); nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(v.name()); e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged")); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling adapter signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }
void BluetoothDiscoveryHandle::Notify(const BluetoothSignal& aData) { BT_LOGD("[DH] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); if (aData.name().EqualsLiteral("DeviceFound")) { DispatchDeviceEvent(aData.value()); } else { BT_WARNING("Not handling discovery handle signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothManager::Notify(const BluetoothSignal& aData) { if (aData.name().EqualsLiteral("AdapterAdded")) { DispatchTrustedEvent(NS_LITERAL_STRING("adapteradded")); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling manager signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }
void BluetoothManager::Notify(const BluetoothSignal& aData) { BT_LOGD("[M] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); if (aData.name().EqualsLiteral("AdapterAdded")) { HandleAdapterAdded(aData.value()); } else if (aData.name().EqualsLiteral("AdapterRemoved")) { HandleAdapterRemoved(aData.value()); } else { BT_WARNING("Not handling manager signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothGattCharacteristic::Notify(const BluetoothSignal& aData) { BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); NS_ENSURE_TRUE_VOID(mSignalRegistered); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("CharacteristicValueUpdated")) { HandleCharacteristicValueUpdated(v); } else { BT_WARNING("Not handling GATT Characteristic signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothGattService::Notify(const BluetoothSignal& aData) { BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("IncludedServicesDiscovered")) { HandleIncludedServicesDiscovered(v); } else if (aData.name().EqualsLiteral("CharacteristicsDiscovered")) { HandleCharacteristicsDiscovered(v); } else { BT_WARNING("Not handling GATT Service signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothAdapter::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; BT_LOG("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("DeviceFound")) { nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value()); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), this, nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicefound"), false, false, device); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral("PropertyChanged")) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); MOZ_ASSERT(arr.Length() == 1); SetPropertyByValue(arr[0]); } else if (aData.name().EqualsLiteral(PAIRED_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(HFP_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(SCO_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(A2DP_STATUS_CHANGED_ID)) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); MOZ_ASSERT(arr.Length() == 2 && arr[0].value().type() == BluetoothValue::TnsString && arr[1].value().type() == BluetoothValue::Tbool); nsString address = arr[0].value().get_nsString(); bool status = arr[1].value().get_bool(); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothStatusChangedEvent( getter_AddRefs(event), this, nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothStatusChangedEvent> e = do_QueryInterface(event); e->InitBluetoothStatusChangedEvent(aData.name(), false, false, address, status); DispatchTrustedEvent(event); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling adapter signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }
void BluetoothService::Notify(const BluetoothSignal& aData) { nsString type = NS_LITERAL_STRING("bluetooth-pairing-request"); 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 { nsCString warningMsg; warningMsg.AssignLiteral("Not handling service signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); BT_WARNING(warningMsg.get()); return; } BroadcastSystemMessage(type, aData.value()); }
void BluetoothGatt::Notify(const BluetoothSignal& aData) { BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("ClientRegistered")) { MOZ_ASSERT(v.type() == BluetoothValue::Tuint32_t); mClientIf = v.get_uint32_t(); } else if (aData.name().EqualsLiteral("ClientUnregistered")) { mClientIf = 0; } else if (aData.name().EqualsLiteral(GATT_CONNECTION_STATE_CHANGED_ID)) { MOZ_ASSERT(v.type() == BluetoothValue::Tbool); BluetoothConnectionState state = v.get_bool() ? BluetoothConnectionState::Connected : BluetoothConnectionState::Disconnected; UpdateConnectionState(state); } else if (aData.name().EqualsLiteral("ServicesDiscovered")) { HandleServicesDiscovered(v); } else if (aData.name().EqualsLiteral("DiscoverCompleted")) { MOZ_ASSERT(v.type() == BluetoothValue::Tbool); bool isDiscoverSuccess = v.get_bool(); if (!isDiscoverSuccess) { // Clean all discovered attributes if failed mServices.Clear(); BluetoothGattBinding::ClearCachedServicesValue(this); } mDiscoveringServices = false; } else { BT_WARNING("Not handling GATT signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothService::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr = aData.value().get_ArrayOfBluetoothNamedValue(); nsString type; JSContext* cx = nsContentUtils::GetSafeJSContext(); NS_ASSERTION(!::JS_IsExceptionPending(cx), "Shouldn't get here when an exception is pending!"); JSAutoRequest jsar(cx); JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL); if (!obj) { NS_WARNING("Failed to new JSObject for system message!"); return; } bool ok = SetJsObject(cx, obj, arr); if (!ok) { NS_WARNING("Failed to set properties of system message!"); return; } if (aData.name().EqualsLiteral("RequestConfirmation")) { NS_ASSERTION(arr.Length() == 3, "RequestConfirmation: Wrong length of parameters"); type.AssignLiteral("bluetooth-requestconfirmation"); } else if (aData.name().EqualsLiteral("RequestPinCode")) { NS_ASSERTION(arr.Length() == 2, "RequestPinCode: Wrong length of parameters"); type.AssignLiteral("bluetooth-requestpincode"); } else if (aData.name().EqualsLiteral("RequestPasskey")) { NS_ASSERTION(arr.Length() == 2, "RequestPinCode: Wrong length of parameters"); type.AssignLiteral("bluetooth-requestpasskey"); } else if (aData.name().EqualsLiteral("Authorize")) { NS_ASSERTION(arr.Length() == 2, "Authorize: Wrong length of parameters"); type.AssignLiteral("bluetooth-authorize"); } else if (aData.name().EqualsLiteral("Cancel")) { NS_ASSERTION(arr.Length() == 0, "Cancel: Wrong length of parameters"); type.AssignLiteral("bluetooth-cancel"); } else if (aData.name().EqualsLiteral("PairedStatusChanged")) { NS_ASSERTION(arr.Length() == 1, "PairedStatusChagned: Wrong length of parameters"); type.AssignLiteral("bluetooth-pairingstatuschanged"); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling service signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } nsCOMPtr<nsISystemMessagesInternal> systemMessenger = do_GetService("@mozilla.org/system-message-internal;1"); if (!systemMessenger) { NS_WARNING("Failed to get SystemMessenger service!"); return; } systemMessenger->BroadcastMessage(type, OBJECT_TO_JSVAL(obj)); }
void BluetoothManager::Notify(const BluetoothSignal& aData) { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling manager signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif }
void BluetoothManager::Notify(const BluetoothSignal& aData) { BT_LOGD("[M] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get()); if (aData.name().EqualsLiteral("AdapterAdded")) { DispatchTrustedEvent(NS_LITERAL_STRING("adapteradded")); } else if (aData.name().EqualsLiteral("Enabled")) { DispatchTrustedEvent(NS_LITERAL_STRING("enabled")); } else if (aData.name().EqualsLiteral("Disabled")) { DispatchTrustedEvent(NS_LITERAL_STRING("disabled")); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling manager signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); BT_WARNING(warningMsg.get()); #endif } }
void BluetoothPairingListener::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; BluetoothValue value = aData.value(); if (aData.name().EqualsLiteral("PairingRequest")) { MOZ_ASSERT(value.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = value.get_ArrayOfBluetoothNamedValue(); MOZ_ASSERT(arr.Length() == 4 && arr[0].value().type() == BluetoothValue::TnsString && // address arr[1].value().type() == BluetoothValue::TnsString && // name arr[2].value().type() == BluetoothValue::TnsString && // passkey arr[3].value().type() == BluetoothValue::TnsString); // type nsString deviceAddress = arr[0].value().get_nsString(); nsString deviceName = arr[1].value().get_nsString(); nsString passkey = arr[2].value().get_nsString(); nsString type = arr[3].value().get_nsString(); // Create a temporary device with deviceAddress and deviceName InfallibleTArray<BluetoothNamedValue> props; BT_APPEND_NAMED_VALUE(props, "Address", deviceAddress); BT_APPEND_NAMED_VALUE(props, "Name", deviceName); nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), props); // Notify pairing listener of pairing requests DispatchPairingEvent(device, passkey, type); } else { BT_WARNING("Not handling pairing listener signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothDevice::Notify(const BluetoothSignal& aData) { BT_LOGD("[D] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("PropertyChanged")) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) { SetPropertyByValue(arr[i]); } } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling device signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); BT_WARNING(warningMsg.get()); #endif } }
void BluetoothManager::Notify(const BluetoothSignal& aData) { if (aData.name().EqualsLiteral("AdapterAdded")) { nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nullptr, nullptr); nsresult rv = event->InitEvent(NS_LITERAL_STRING("adapteradded"), false, false); if (NS_FAILED(rv)) { NS_WARNING("Failed to init the adapteradded event!!!"); return; } event->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling manager signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }
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 { nsCString warningMsg; warningMsg.AssignLiteral("Not handling service signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); BT_WARNING(warningMsg.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); }
void BluetoothAdapter::Notify(const BluetoothSignal& aData) { BT_LOGD("[A] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); NS_ENSURE_TRUE_VOID(mSignalRegistered); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("PropertyChanged")) { HandlePropertyChanged(v); } else if (aData.name().EqualsLiteral("DeviceFound")) { /* * DeviceFound signal will be distributed to all existing adapters while * doing discovery operations. * The signal needs to be handled only if this adapter is holding a valid * discovery handle, which means that the discovery operation is triggered * by this adapter. */ if (mDiscoveryHandleInUse) { HandleDeviceFound(v); } } else if (aData.name().EqualsLiteral(DEVICE_PAIRED_ID)) { HandleDevicePaired(aData.value()); } else if (aData.name().EqualsLiteral(DEVICE_UNPAIRED_ID)) { HandleDeviceUnpaired(aData.value()); } else if (aData.name().EqualsLiteral(HFP_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(SCO_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(A2DP_STATUS_CHANGED_ID)) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); MOZ_ASSERT(arr.Length() == 2 && arr[0].value().type() == BluetoothValue::TnsString && arr[1].value().type() == BluetoothValue::Tbool); nsString address = arr[0].value().get_nsString(); bool status = arr[1].value().get_bool(); BluetoothStatusChangedEventInit init; init.mBubbles = false; init.mCancelable = false; init.mAddress = address; init.mStatus = status; nsRefPtr<BluetoothStatusChangedEvent> event = BluetoothStatusChangedEvent::Constructor(this, aData.name(), init); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral(PAIRING_ABORTED_ID) || aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) { DispatchEmptyEvent(aData.name()); } else { BT_WARNING("Not handling adapter signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
void BluetoothAdapter::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; BT_LOGD("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("DeviceFound")) { nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value()); BluetoothDeviceEventInit init; init.mBubbles = false; init.mCancelable = false; init.mDevice = device; nsRefPtr<BluetoothDeviceEvent> event = BluetoothDeviceEvent::Constructor(this, NS_LITERAL_STRING("devicefound"), init); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral("PropertyChanged")) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) { SetPropertyByValue(arr[i]); } } else if (aData.name().EqualsLiteral(PAIRED_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(HFP_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(SCO_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(A2DP_STATUS_CHANGED_ID)) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); MOZ_ASSERT(arr.Length() == 2 && arr[0].value().type() == BluetoothValue::TnsString && arr[1].value().type() == BluetoothValue::Tbool); nsString address = arr[0].value().get_nsString(); bool status = arr[1].value().get_bool(); BluetoothStatusChangedEventInit init; init.mBubbles = false; init.mCancelable = false; init.mAddress = address; init.mStatus = status; nsRefPtr<BluetoothStatusChangedEvent> event = BluetoothStatusChangedEvent::Constructor(this, aData.name(), init); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) { nsCOMPtr<nsIDOMEvent> event; nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); NS_ENSURE_SUCCESS_VOID(rv); rv = event->InitEvent(aData.name(), false, false); NS_ENSURE_SUCCESS_VOID(rv); DispatchTrustedEvent(event); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling adapter signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); BT_WARNING(warningMsg.get()); #endif } }
void BluetoothAdapter::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; if (aData.name().EqualsLiteral("DeviceFound")) { nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value()); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicefound"), false, false, device); e->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else if (aData.name().EqualsLiteral("DeviceDisappeared")) { const nsAString& deviceAddress = aData.value().get_nsString(); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("devicedisappeared"), false, false, deviceAddress); e->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else if (aData.name().EqualsLiteral("PropertyChanged")) { // Get BluetoothNamedValue, make sure array length is 1 arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!"); NS_ASSERTION(arr[0].value().type() == BluetoothValue::TArrayOfBluetoothNamedValue, "PropertyChanged: Invalid value type"); BluetoothNamedValue v = arr[0]; SetPropertyByValue(v); nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(v.name()); e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged")); } else if (aData.name().EqualsLiteral("RequestConfirmation")) { arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 2, "RequestConfirmation: Wrong length of parameters"); NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString, "RequestConfirmation: Invalid value type"); NS_ASSERTION(arr[1].value().type() == BluetoothValue::Tuint32_t, "RequestConfirmation: Invalid value type"); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothPairingEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothPairingEvent> e = do_QueryInterface(event); e->InitBluetoothPairingEvent(NS_LITERAL_STRING("requestconfirmation"), false, false, arr[0].value().get_nsString(), arr[1].value().get_uint32_t()); e->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else if (aData.name().EqualsLiteral("RequestPinCode")) { arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 1, "RequestPinCode: Wrong length of parameters"); NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString, "RequestPinCode: Invalid value type"); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("requestpincode"), false, false, arr[0].value().get_nsString()); e->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else if (aData.name().EqualsLiteral("RequestPasskey")) { arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 1, "RequestPasskey: Wrong length of parameters"); NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString, "RequestPasskey: Invalid value type"); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event); e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("requestpasskey"), false, false, arr[0].value().get_nsString()); e->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else if (aData.name().EqualsLiteral("Authorize")) { arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 2, "Authorize: Wrong length of parameters"); NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString, "Authorize: Invalid value type"); NS_ASSERTION(arr[1].value().type() == BluetoothValue::TnsString, "Authorize: Invalid value type"); nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothAuthorizeEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothAuthorizeEvent> e = do_QueryInterface(event); e->InitBluetoothAuthorizeEvent(NS_LITERAL_STRING("authorize"), false, false, arr[0].value().get_nsString(), arr[1].value().get_nsString()); e->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else if (aData.name().EqualsLiteral("Cancel")) { nsCOMPtr<nsIDOMEvent> event; NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr); nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event); // Just send a null nsString, won't be used e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("cancel"), false, false, EmptyString()); e->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling adapter signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }