Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
jni_android_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef JNI_ANDROID_P_H
5#define JNI_ANDROID_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qbluetooth.h"
19#include <QtCore/QJniObject>
20#include <QtCore/private/qglobal_p.h>
21#include <QtCore/qcoreapplication_platform.h>
22
24
25// CLASS declaration implies also TYPE declaration
26Q_DECLARE_JNI_CLASS(QtBtBroadcastReceiver,
27 "org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver");
28Q_DECLARE_JNI_CLASS(QtBtGattCharacteristic,
29 "org/qtproject/qt/android/bluetooth/QtBluetoothGattCharacteristic");
30Q_DECLARE_JNI_CLASS(QtBtGattDescriptor,
31 "org/qtproject/qt/android/bluetooth/QtBluetoothGattDescriptor");
32Q_DECLARE_JNI_CLASS(QtBtInputStreamThread,
33 "org/qtproject/qt/android/bluetooth/QtBluetoothInputStreamThread")
34Q_DECLARE_JNI_CLASS(QtBtSocketServer, "org/qtproject/qt/android/bluetooth/QtBluetoothSocketServer")
35Q_DECLARE_JNI_CLASS(QtBtLEServer, "org/qtproject/qt/android/bluetooth/QtBluetoothLEServer")
36Q_DECLARE_JNI_CLASS(QtBtLECentral, "org/qtproject/qt/android/bluetooth/QtBluetoothLE")
38Q_DECLARE_JNI_CLASS(ParcelUuid, "android/os/ParcelUuid")
39Q_DECLARE_JNI_CLASS(AdvertiseDataBuilder, "android/bluetooth/le/AdvertiseData$Builder")
40Q_DECLARE_JNI_CLASS(AdvertiseSettingsBuilder, "android/bluetooth/le/AdvertiseSettings$Builder")
41Q_DECLARE_JNI_CLASS(BluetoothGattService, "android/bluetooth/BluetoothGattService")
42Q_DECLARE_JNI_CLASS(BluetoothGattDescriptor, "android/bluetooth/BluetoothGattDescriptor")
43Q_DECLARE_JNI_CLASS(BluetoothGattCharacteristic, "android/bluetooth/BluetoothGattCharacteristic")
45Q_DECLARE_JNI_CLASS(IntentFilter, "android/content/IntentFilter")
46Q_DECLARE_JNI_CLASS(AndroidContext, "android/content/Context")
47Q_DECLARE_JNI_CLASS(UUID, "java/util/UUID")
48
49Q_DECLARE_JNI_TYPE(ParcelableArray, "[Landroid/os/Parcelable;")
50Q_DECLARE_JNI_TYPE(ParcelUuidArray, "[Landroid/os/ParcelUuid;")
51Q_DECLARE_JNI_TYPE(StringArray, "[Ljava/lang/String;")
52
53Q_DECLARE_JNI_TYPE(BluetoothManager, "Landroid/bluetooth/BluetoothManager;")
54Q_DECLARE_JNI_TYPE(AdvertiseData, "Landroid/bluetooth/le/AdvertiseData;")
55Q_DECLARE_JNI_TYPE(AdvertiseSettings, "Landroid/bluetooth/le/AdvertiseSettings;")
56Q_DECLARE_JNI_TYPE(InputStream, "Ljava/io/InputStream;")
57Q_DECLARE_JNI_TYPE(OutputStream, "Ljava/io/OutputStream;")
58Q_DECLARE_JNI_TYPE(BluetoothSocket, "Landroid/bluetooth/BluetoothSocket;")
59Q_DECLARE_JNI_TYPE(BroadcastReceiver, "Landroid/content/BroadcastReceiver;")
60Q_DECLARE_JNI_TYPE(BluetoothClass, "Landroid/bluetooth/BluetoothClass;")
61Q_DECLARE_JNI_TYPE(Parcelable, "Landroid/os/Parcelable;")
62Q_DECLARE_JNI_TYPE(Intent, "Landroid/content/Intent;")
63Q_DECLARE_JNI_TYPE(Bundle, "Landroid/os/Bundle;")
64Q_DECLARE_JNI_TYPE(List, "Ljava/util/List;")
65
66// QLowEnergyHandle is a quint16, ensure it is interpreted as jint
67template<>
68constexpr auto QtJniTypes::typeSignature<QLowEnergyHandle>()
69{
70 return QtJniTypes::String("I");
71}
72
91};
92
93QJniObject valueFromStaticFieldCache(const char *key, const char *className, const char *fieldName);
94
95
96template<typename Klass, JavaNames Field>
98{
99 constexpr auto className = QtJniTypes::className<Klass>();
100 constexpr auto fieldName = []() -> auto {
101 if constexpr (Field == JavaNames::ActionAclConnected)
102 return QtJniTypes::String("ACTION_ACL_CONNECTED");
103 else if constexpr (Field == ActionAclDisconnected)
104 return QtJniTypes::String("ACTION_ACL_DISCONNECTED");
105 else if constexpr (Field == ActionBondStateChanged)
106 return QtJniTypes::String("ACTION_BOND_STATE_CHANGED");
107 else if constexpr (Field == ActionDiscoveryStarted)
108 return QtJniTypes::String("ACTION_DISCOVERY_STARTED");
109 else if constexpr (Field == ActionDiscoveryFinished)
110 return QtJniTypes::String("ACTION_DISCOVERY_FINISHED");
111 else if constexpr (Field == ActionFound)
112 return QtJniTypes::String("ACTION_FOUND");
113 else if constexpr (Field == ActionScanModeChanged)
114 return QtJniTypes::String("ACTION_SCAN_MODE_CHANGED");
115 else if constexpr (Field == ActionUuid)
116 return QtJniTypes::String("ACTION_UUID");
117 else if constexpr (Field == ExtraBondState)
118 return QtJniTypes::String("EXTRA_BOND_STATE");
119 else if constexpr (Field == ExtraDevice)
120 return QtJniTypes::String("EXTRA_DEVICE");
121 else if constexpr (Field == ExtraPairingKey)
122 return QtJniTypes::String("EXTRA_PAIRING_KEY");
123 else if constexpr (Field == ExtraPairingVariant)
124 return QtJniTypes::String("EXTRA_PAIRING_VARIANT");
125 else if constexpr (Field == ExtraRssi)
126 return QtJniTypes::String("EXTRA_RSSI");
127 else if constexpr (Field == ExtraScanMode)
128 return QtJniTypes::String("EXTRA_SCAN_MODE");
129 else if constexpr (Field == ExtraUuid)
130 return QtJniTypes::String("EXTRA_UUID");
131 else
132 QtJniTypes::staticAssertTypeMismatch();
133 }();
134
135 return valueFromStaticFieldCache(className + fieldName, className.data(), fieldName.data());
136}
137
139
140#endif // JNI_ANDROID_P_H
\inmodule QtCore
QJniObject valueFromStaticFieldCache(const char *key, const char *className, const char *fieldName)
JavaNames
@ ExtraDevice
@ ExtraUuid
@ ExtraBondState
@ ExtraRssi
@ ActionScanModeChanged
@ ExtraPairingKey
@ ActionFound
@ ActionDiscoveryStarted
@ ActionAclDisconnected
@ ActionBondStateChanged
@ ActionUuid
@ BluetoothAdapter
@ ExtraPairingVariant
@ ExtraScanMode
@ BluetoothDevice
@ ActionAclConnected
@ ActionDiscoveryFinished
QT_BEGIN_NAMESPACE Q_DECLARE_JNI_CLASS(QtBtBroadcastReceiver, "org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver")
QJniObject valueForStaticField()
Combined button and popup list for selecting options.
quint16 QLowEnergyHandle
Definition qbluetooth.h:42
GLuint64 key
Q_DECLARE_JNI_TYPE(File, "Ljava/io/File;")
const char className[16]
[1]
Definition qwizard.cpp:100
QPointer< QLineEdit > le