summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothlocaldevice_android.cpp
diff options
context:
space:
mode:
authorOleg Shparber <trollixx@gmail.com>2014-04-23 00:50:08 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-23 17:30:05 +0200
commit34b32040ec0e80108890c0f97bcdc85989200409 (patch)
tree889090e214d59ef7b20f938b2005a6c7379d6781 /src/bluetooth/qbluetoothlocaldevice_android.cpp
parent347afa3ec58f82da2e4059c1241f3fdd8c5ad2e7 (diff)
Fix coding style in QBluetooth
Affected: QBluetooth, QBluetoothAddress, QBluetoothDeviceDiscoveryAgent, QBluetoothDeviceInfo, QBluetoothHostInfo, QBluetoothLocalDevice Change-Id: Ia5af61f87eafecfba56b75fa61b81014cdd38960 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothlocaldevice_android.cpp')
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_android.cpp201
1 files changed, 107 insertions, 94 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_android.cpp b/src/bluetooth/qbluetoothlocaldevice_android.cpp
index a6d2b5d6..475ecd95 100644
--- a/src/bluetooth/qbluetoothlocaldevice_android.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_android.cpp
@@ -55,23 +55,26 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(
- QBluetoothLocalDevice *q, const QBluetoothAddress &address)
- : q_ptr(q), obj(0), pendingHostModeTransition(false)
+ QBluetoothLocalDevice *q, const QBluetoothAddress &address) :
+ q_ptr(q),
+ obj(0),
+ pendingHostModeTransition(false)
{
initialize(address);
receiver = new LocalDeviceBroadcastReceiver(q_ptr);
- QObject::connect(receiver, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
- this, SLOT(processHostModeChange(QBluetoothLocalDevice::HostMode)));
- QObject::connect(receiver, SIGNAL(pairingStateChanged(QBluetoothAddress,QBluetoothLocalDevice::Pairing)),
- this, SLOT(processPairingStateChanged(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));
- QObject::connect(receiver, SIGNAL(connectDeviceChanges(QBluetoothAddress,bool)),
- this, SLOT(processConnectDeviceChanges(QBluetoothAddress,bool)));
- QObject::connect(receiver, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress,QString)),
- this, SLOT(processDisplayConfirmation(QBluetoothAddress,QString)));
+ connect(receiver, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
+ this, SLOT(processHostModeChange(QBluetoothLocalDevice::HostMode)));
+ connect(receiver, SIGNAL(pairingStateChanged(QBluetoothAddress,
+ QBluetoothLocalDevice::Pairing)),
+ this, SLOT(processPairingStateChanged(QBluetoothAddress,
+ QBluetoothLocalDevice::Pairing)));
+ connect(receiver, SIGNAL(connectDeviceChanges(QBluetoothAddress, bool)),
+ this, SLOT(processConnectDeviceChanges(QBluetoothAddress, bool)));
+ connect(receiver, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress, QString)),
+ this, SLOT(processDisplayConfirmation(QBluetoothAddress, QString)));
}
-
QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate()
{
receiver->unregisterReceiver();
@@ -90,17 +93,21 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address)
jclass btAdapterClass = env->FindClass("android/bluetooth/BluetoothAdapter");
if (btAdapterClass == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
return;
}
- jmethodID getDefaultAdapterID = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;");
+ jmethodID getDefaultAdapterID
+ = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter",
+ "()Landroid/bluetooth/BluetoothAdapter;");
if (getDefaultAdapterID == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to get method ID: getDefaultAdapter of android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to get method ID: " \
+ "getDefaultAdapter of android/bluetooth/BluetoothAdapter";
return;
}
-
jobject btAdapterObject = env->CallStaticObjectMethod(btAdapterClass, getDefaultAdapterID);
if (btAdapterObject == NULL) {
qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
@@ -112,14 +119,13 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address)
if (!obj->isValid()) {
delete obj;
obj = 0;
- } else {
- if (!address.isNull()) {
- const QString localAddress = obj->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
- if (localAddress != address.toString()) {
- //passed address not local one -> invalid
- delete obj;
- obj = 0;
- }
+ } else if (!address.isNull()) {
+ const QString localAddress
+ = obj->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
+ if (localAddress != address.toString()) {
+ // passed address not local one -> invalid
+ delete obj;
+ obj = 0;
}
}
@@ -132,17 +138,16 @@ bool QBluetoothLocalDevicePrivate::isValid() const
return obj ? true : false;
}
-
void QBluetoothLocalDevicePrivate::processHostModeChange(QBluetoothLocalDevice::HostMode newMode)
{
if (!pendingHostModeTransition) {
- //if not in transition -> pass data on
+ // if not in transition -> pass data on
emit q_ptr->hostModeStateChanged(newMode);
return;
}
if (isValid() && newMode == QBluetoothLocalDevice::HostPoweredOff) {
- bool success = (bool) obj->callMethod<jboolean>("enable", "()Z");
+ bool success = (bool)obj->callMethod<jboolean>("enable", "()Z");
if (!success)
emit q_ptr->error(QBluetoothLocalDevice::UnknownError);
}
@@ -162,26 +167,25 @@ int QBluetoothLocalDevicePrivate::pendingPairing(const QBluetoothAddress &addres
return -1;
}
-
void QBluetoothLocalDevicePrivate::processPairingStateChanged(
- const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
+ const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
{
int index = pendingPairing(address);
if (index < 0)
- return; //ignore unrelated pairing signals
+ return; // ignore unrelated pairing signals
QPair<QBluetoothAddress, bool> entry = pendingPairings.takeAt(index);
- if ((entry.second && pairing == QBluetoothLocalDevice::Paired) ||
- (!entry.second && pairing == QBluetoothLocalDevice::Unpaired)) {
+ if ((entry.second && pairing == QBluetoothLocalDevice::Paired)
+ || (!entry.second && pairing == QBluetoothLocalDevice::Unpaired)) {
emit q_ptr->pairingFinished(address, pairing);
} else {
emit q_ptr->error(QBluetoothLocalDevice::PairingError);
}
-
}
-void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothAddress& address, bool isConnectEvent)
+void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothAddress &address,
+ bool isConnectEvent)
{
int index = -1;
for (int i = 0; i < connectedDevices.count(); i++) {
@@ -191,21 +195,22 @@ void QBluetoothLocalDevicePrivate::processConnectDeviceChanges(const QBluetoothA
}
}
- if (isConnectEvent) { //connect event
+ if (isConnectEvent) { // connect event
if (index >= 0)
return;
connectedDevices.append(address);
emit q_ptr->deviceConnected(address);
- } else { //disconnect event
+ } else { // disconnect event
connectedDevices.removeAll(address);
emit q_ptr->deviceDisconnected(address);
}
}
-void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAddress &address, const QString &pin)
+void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAddress &address,
+ const QString &pin)
{
- //only send pairing notification for pairing requests issued by
- //this QBluetoothLocalDevice instance
+ // only send pairing notification for pairing requests issued by
+ // this QBluetoothLocalDevice instance
if (pendingPairing(address) == -1)
return;
@@ -213,14 +218,14 @@ void QBluetoothLocalDevicePrivate::processDisplayConfirmation(const QBluetoothAd
emit q_ptr->pairingDisplayPinCode(address, pin);
}
-QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent)
-: QObject(parent),
+QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) :
+ QObject(parent),
d_ptr(new QBluetoothLocalDevicePrivate(this, QBluetoothAddress()))
{
}
-QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent)
-: QObject(parent),
+QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) :
+ QObject(parent),
d_ptr(new QBluetoothLocalDevicePrivate(this, address))
{
}
@@ -236,8 +241,10 @@ QString QBluetoothLocalDevice::name() const
QBluetoothAddress QBluetoothLocalDevice::address() const
{
QString result;
- if (d_ptr->adapter())
- result = d_ptr->adapter()->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
+ if (d_ptr->adapter()) {
+ result
+ = d_ptr->adapter()->callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
+ }
QBluetoothAddress address(result);
return address;
@@ -249,7 +256,7 @@ void QBluetoothLocalDevice::powerOn()
return;
if (d_ptr->adapter()) {
- bool ret = (bool) d_ptr->adapter()->callMethod<jboolean>("enable", "()Z");
+ bool ret = (bool)d_ptr->adapter()->callMethod<jboolean>("enable", "()Z");
if (!ret)
emit error(QBluetoothLocalDevice::UnknownError);
}
@@ -267,23 +274,26 @@ void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode requeste
if (mode == QBluetoothLocalDevice::HostPoweredOff) {
bool success = false;
if (d_ptr->adapter())
- success = (bool) d_ptr->adapter()->callMethod<jboolean>("disable", "()Z");
+ success = (bool)d_ptr->adapter()->callMethod<jboolean>("disable", "()Z");
if (!success)
emit error(QBluetoothLocalDevice::UnknownError);
} else if (mode == QBluetoothLocalDevice::HostConnectable) {
if (hostMode() == QBluetoothLocalDevice::HostDiscoverable) {
- //cannot directly go from Discoverable to Connectable
- //we need to go to disabled mode and enable once disabling came through
+ // cannot directly go from Discoverable to Connectable
+ // we need to go to disabled mode and enable once disabling came through
setHostMode(QBluetoothLocalDevice::HostPoweredOff);
d_ptr->pendingHostModeTransition = true;
} else {
- QAndroidJniObject::callStaticMethod<void>("org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setConnectable");
+ QAndroidJniObject::callStaticMethod<void>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setConnectable");
}
- } else if (mode == QBluetoothLocalDevice::HostDiscoverable ||
- mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) {
- QAndroidJniObject::callStaticMethod<void>("org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setDiscoverable");
+ } else if (mode == QBluetoothLocalDevice::HostDiscoverable
+ || mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) {
+ QAndroidJniObject::callStaticMethod<void>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setDiscoverable");
}
}
@@ -293,14 +303,14 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
jint scanMode = d_ptr->adapter()->callMethod<jint>("getScanMode");
switch (scanMode) {
- case 20: //BluetoothAdapter.SCAN_MODE_NONE
- return HostPoweredOff;
- case 21: //BluetoothAdapter.SCAN_MODE_CONNECTABLE
- return HostConnectable;
- case 23: //BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE
- return HostDiscoverable;
- default:
- break;
+ case 20: // BluetoothAdapter.SCAN_MODE_NONE
+ return HostPoweredOff;
+ case 21: // BluetoothAdapter.SCAN_MODE_CONNECTABLE
+ return HostConnectable;
+ case 23: // BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE
+ return HostDiscoverable;
+ default:
+ break;
}
}
@@ -309,24 +319,28 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
{
- //Android only supports max of one device (so far)
+ // Android only supports max of one device (so far)
QList<QBluetoothHostInfo> localDevices;
QAndroidJniEnvironment env;
jclass btAdapterClass = env->FindClass("android/bluetooth/BluetoothAdapter");
if (btAdapterClass == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to find class android/bluetooth/BluetoothAdapter";
return localDevices;
}
- jmethodID getDefaultAdapterID = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;");
+ jmethodID getDefaultAdapterID
+ = env->GetStaticMethodID(btAdapterClass, "getDefaultAdapter",
+ "()Landroid/bluetooth/BluetoothAdapter;");
if (getDefaultAdapterID == NULL) {
- qCWarning(QT_BT_ANDROID) << "Native registration unable to get method ID: getDefaultAdapter of android/bluetooth/BluetoothAdapter";
+ qCWarning(QT_BT_ANDROID)
+ << "Native registration unable to get method ID: " \
+ "getDefaultAdapter of android/bluetooth/BluetoothAdapter";
env->DeleteLocalRef(btAdapterClass);
return localDevices;
}
-
jobject btAdapterObject = env->CallStaticObjectMethod(btAdapterClass, getDefaultAdapterID);
if (btAdapterObject == NULL) {
qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
@@ -338,7 +352,8 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
if (o.isValid()) {
QBluetoothHostInfo info;
info.setName(o.callObjectMethod("getName", "()Ljava/lang/String;").toString());
- info.setAddress(QBluetoothAddress(o.callObjectMethod("getAddress", "()Ljava/lang/String;").toString()));
+ info.setAddress(QBluetoothAddress(o.callObjectMethod("getAddress",
+ "()Ljava/lang/String;").toString()));
localDevices.append(info);
}
@@ -352,61 +367,60 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai
{
if (address.isNull()) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
const Pairing previousPairing = pairingStatus(address);
Pairing newPairing = pairing;
- if (pairing == AuthorizedPaired) //AuthorizedPaired same as Paired on Android
+ if (pairing == AuthorizedPaired) // AuthorizedPaired same as Paired on Android
newPairing = Paired;
if (previousPairing == newPairing) {
QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
- Q_ARG(QBluetoothAddress, address),
- Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
+ Q_ARG(QBluetoothAddress, address),
+ Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
return;
}
- //BluetoothDevice::createBond() requires Android API 19
+ // BluetoothDevice::createBond() requires Android API 19
if (QtAndroidPrivate::androidSdkVersion() < 19 || !d_ptr->adapter()) {
qCWarning(QT_BT_ANDROID) << "Unable to pair: requires Android API 19+";
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
return;
}
QAndroidJniObject inputString = QAndroidJniObject::fromString(address.toString());
jboolean success = QAndroidJniObject::callStaticMethod<jboolean>(
- "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
- "setPairingMode",
- "(Ljava/lang/String;Z)Z",
- inputString.object<jstring>(),
- newPairing == Paired ? JNI_TRUE : JNI_FALSE);
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setPairingMode",
+ "(Ljava/lang/String;Z)Z",
+ inputString.object<jstring>(),
+ newPairing == Paired ? JNI_TRUE : JNI_FALSE);
if (!success) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::PairingError));
+ Q_ARG(QBluetoothLocalDevice::Error,
+ QBluetoothLocalDevice::PairingError));
} else {
- d_ptr->pendingPairings.append(qMakePair(address,
- newPairing == Paired ? true : false));
+ d_ptr->pendingPairings.append(qMakePair(address, newPairing == Paired ? true : false));
}
-
}
-QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const
+QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(
+ const QBluetoothAddress &address) const
{
if (address.isNull() || !d_ptr->adapter())
return Unpaired;
QAndroidJniObject inputString = QAndroidJniObject::fromString(address.toString());
- QAndroidJniObject remoteDevice =
- d_ptr->adapter()->callObjectMethod("getRemoteDevice",
- "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;",
- inputString.object<jstring>());
+ QAndroidJniObject remoteDevice
+ = d_ptr->adapter()->callObjectMethod("getRemoteDevice",
+ "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;",
+ inputString.object<jstring>());
QAndroidJniEnvironment env;
if (env->ExceptionCheck()) {
env->ExceptionClear();
@@ -415,7 +429,7 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet
jint bondState = remoteDevice.callMethod<jint>("getBondState");
switch (bondState) {
- case 12: //BluetoothDevice.BOND_BONDED
+ case 12: // BluetoothDevice.BOND_BONDED
return Paired;
default:
break;
@@ -432,7 +446,6 @@ void QBluetoothLocalDevice::pairingConfirmation(bool confirmation)
bool success = d_ptr->receiver->pairingConfirmation(confirmation);
if (!success)
emit error(PairingError);
-
}
QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
@@ -449,9 +462,9 @@ QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
* but at least it can complement our already detected connections.
*/
QAndroidJniObject connectedDevices = QAndroidJniObject::callStaticObjectMethod(
- "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
- "getConnectedDevices",
- "()[Ljava/lang/String;");
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "getConnectedDevices",
+ "()[Ljava/lang/String;");
if (!connectedDevices.isValid())
return d_ptr->connectedDevices;