19 addAction(QJniObject::fromString(
20 valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ActionBondStateChanged>()));
21 addAction(QJniObject::fromString(
22 valueForStaticField<QtJniTypes::BluetoothAdapter, JavaNames::ActionScanModeChanged>()));
23 addAction(QJniObject::fromString(
24 valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ActionAclConnected>()));
25 addAction(QJniObject::fromString(
26 valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ActionAclDisconnected>()));
30 for (uint i = 0; i < (
sizeof(hostModePreset)/
sizeof(hostModePreset[0])); i++) {
31 hostModePreset[i] = QJniObject::getStaticField<jint>(
32 QtJniTypes::Traits<QtJniTypes::BluetoothAdapter>::className(),
36 for (uint i = 0; i < (
sizeof(bondingModePreset)/
sizeof(bondingModePreset[0])); i++) {
37 bondingModePreset[i] = QJniObject::getStaticField<jint>(
38 QtJniTypes::Traits<QtJniTypes::BluetoothDevice>::className(),
48 QJniObject intentObject(intent);
49 const QString action = intentObject.callMethod<jstring>(
"getAction").toString();
50 qCDebug(QT_BT_ANDROID) << QStringLiteral(
"LocalDeviceBroadcastReceiver::onReceive() - event: %1").arg(action);
52 if (action == valueForStaticField<QtJniTypes::BluetoothAdapter,
53 JavaNames::ActionScanModeChanged>()) {
55 const QJniObject extrasBundle =
56 intentObject.callMethod<QtJniTypes::Bundle>(
"getExtras");
57 const QJniObject keyExtra =
58 QJniObject::fromString(valueForStaticField<QtJniTypes::BluetoothAdapter,
59 JavaNames::ExtraScanMode>());
61 int extra = extrasBundle.callMethod<jint>(
"getInt", keyExtra.object<jstring>());
63 if (previousScanMode != extra) {
64 previousScanMode = extra;
66 if (extra == hostModePreset[0])
67 emit hostModeStateChanged(QBluetoothLocalDevice::HostPoweredOff);
68 else if (extra == hostModePreset[1])
69 emit hostModeStateChanged(QBluetoothLocalDevice::HostConnectable);
70 else if (extra == hostModePreset[2])
71 emit hostModeStateChanged(QBluetoothLocalDevice::HostDiscoverable);
73 qCWarning(QT_BT_ANDROID) <<
"Unknown Host State";
75 }
else if (action == valueForStaticField<QtJniTypes::BluetoothDevice,
76 JavaNames::ActionBondStateChanged>()) {
78 QJniObject keyExtra = QJniObject::fromString(
79 valueForStaticField<QtJniTypes::BluetoothDevice,
80 JavaNames::ExtraDevice>());
81 const QJniObject bluetoothDevice =
82 intentObject.callMethod<QtJniTypes::Parcelable>(
"getParcelableExtra",
83 keyExtra.object<jstring>());
86 keyExtra = QJniObject::fromString(valueForStaticField<QtJniTypes::BluetoothDevice,
87 JavaNames::ExtraBondState>());
88 const QJniObject extrasBundle =
89 intentObject.callMethod<QtJniTypes::Bundle>(
"getExtras");
90 int bondState = extrasBundle.callMethod<jint>(
"getInt", keyExtra.object<jstring>());
92 QBluetoothAddress address(bluetoothDevice.callMethod<jstring>(
"getAddress").toString());
96 if (bondState == bondingModePreset[0])
97 emit pairingStateChanged(address, QBluetoothLocalDevice::Unpaired);
98 else if (bondState == bondingModePreset[1])
100 else if (bondState == bondingModePreset[2])
101 emit pairingStateChanged(address, QBluetoothLocalDevice::Paired);
103 qCWarning(QT_BT_ANDROID) <<
"Unknown BOND_STATE_CHANGED value:" << bondState;
105 }
else if (action == valueForStaticField<QtJniTypes::BluetoothDevice,
106 JavaNames::ActionAclConnected>() ||
107 action == valueForStaticField<QtJniTypes::BluetoothDevice,
108 JavaNames::ActionAclDisconnected>()) {
110 const QString connectEvent = valueForStaticField<QtJniTypes::BluetoothDevice,
111 JavaNames::ActionAclConnected>();
112 const bool isConnectEvent =
113 action == connectEvent ?
true :
false;
116 const QJniObject keyExtra =
117 QJniObject::fromString(valueForStaticField<QtJniTypes::BluetoothDevice,
118 JavaNames::ExtraDevice>());
119 QJniObject bluetoothDevice =
120 intentObject.callMethod<QtJniTypes::Parcelable>(
"getParcelableExtra",
121 keyExtra.object<jstring>());
123 QBluetoothAddress address(bluetoothDevice.callMethod<jstring>(
"getAddress").toString());
124 if (address.isNull())
127 emit connectDeviceChanges(address, isConnectEvent);