375 lines
15 KiB
Diff
375 lines
15 KiB
Diff
From f4f7f906ed1c9763c8e79f0882d25caaa00eb264 Mon Sep 17 00:00:00 2001
|
|
From: Lars Schmertmann <Lars.Schmertmann@governikus.de>
|
|
Date: Tue, 29 Nov 2016 16:34:37 +0100
|
|
Subject: Android: QNearfieldTarget: Introduce maxCommandLength()
|
|
|
|
For the communication with a German ID card its required to execute
|
|
commands with a length up to 500 byte. With this change it is
|
|
possible to check if the required length is supported.
|
|
|
|
[ChangeLog][QNearfieldTarget] Introduce maxCommandLength() to
|
|
make it possible to check the maximum supported length for commands.
|
|
|
|
Change-Id: I7e655f419765d8ad728f6d6005a85a01d5aa03e9
|
|
---
|
|
src/nfc/nfc.pro | 7 +++--
|
|
src/nfc/qnearfieldtarget.cpp | 15 +++++++++-
|
|
src/nfc/qnearfieldtarget.h | 1 +
|
|
src/nfc/qnearfieldtarget_android.cpp | 31 ++++++++++++++++++--
|
|
src/nfc/qnearfieldtarget_android_p.cpp | 53 ++++++++++++++++++++++++++++++++++
|
|
src/nfc/qnearfieldtarget_android_p.h | 1 +
|
|
src/nfc/qnearfieldtarget_neard_p.cpp | 52 +++++++++++++++++++++++++++++++++
|
|
src/nfc/qnearfieldtarget_p.cpp | 52 +++++++++++++++++++++++++++++++++
|
|
src/nfc/qnearfieldtarget_p.h | 8 +++++
|
|
9 files changed, 214 insertions(+), 6 deletions(-)
|
|
create mode 100644 src/nfc/qnearfieldtarget_android_p.cpp
|
|
create mode 100644 src/nfc/qnearfieldtarget_neard_p.cpp
|
|
create mode 100644 src/nfc/qnearfieldtarget_p.cpp
|
|
|
|
diff --git x/qtconnectivity/src/nfc/nfc.pro y/qtconnectivity/src/nfc/nfc.pro
|
|
index 0819cc4f..ce193efa 100644
|
|
--- x/qtconnectivity/src/nfc/nfc.pro
|
|
+++ y/qtconnectivity/src/nfc/nfc.pro
|
|
@@ -74,7 +74,8 @@ linux:!android:qtHaveModule(dbus) {
|
|
qllcpserver_p.cpp \
|
|
qnearfieldsharemanagerimpl_p.cpp \
|
|
qnearfieldsharetargetimpl_p.cpp \
|
|
- qnearfieldmanager_neard.cpp
|
|
+ qnearfieldmanager_neard.cpp \
|
|
+ qnearfieldtarget_neard_p.cpp
|
|
|
|
include(neard/neard.pri)
|
|
|
|
@@ -107,6 +108,7 @@ linux:!android:qtHaveModule(dbus) {
|
|
android/androidjninfc.cpp \
|
|
qnearfieldmanager_android.cpp \
|
|
qnearfieldtarget_android.cpp \
|
|
+ qnearfieldtarget_android_p.cpp \
|
|
qnearfieldsharemanagerimpl_p.cpp \
|
|
qnearfieldsharetargetimpl_p.cpp \
|
|
android/androidmainnewintentlistener.cpp
|
|
@@ -127,7 +129,8 @@ isEmpty(NFC_BACKEND_AVAILABLE) {
|
|
qllcpserver_p.cpp \
|
|
qnearfieldmanagerimpl_p.cpp \
|
|
qnearfieldsharemanagerimpl_p.cpp \
|
|
- qnearfieldsharetargetimpl_p.cpp
|
|
+ qnearfieldsharetargetimpl_p.cpp \
|
|
+ qnearfieldtarget_p.cpp
|
|
}
|
|
|
|
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget.cpp y/qtconnectivity/src/nfc/qnearfieldtarget.cpp
|
|
index a65b4be2..274ef175 100644
|
|
--- x/qtconnectivity/src/nfc/qnearfieldtarget.cpp
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget.cpp
|
|
@@ -277,7 +277,7 @@ QNearFieldTarget::RequestId &QNearFieldTarget::RequestId::operator=(const Reques
|
|
Constructs a new near field target with \a parent.
|
|
*/
|
|
QNearFieldTarget::QNearFieldTarget(QObject *parent)
|
|
-: QObject(parent), d_ptr(new QNearFieldTargetPrivate)
|
|
+: QObject(parent), d_ptr(new QNearFieldTargetPrivate(this))
|
|
{
|
|
qRegisterMetaType<QNearFieldTarget::RequestId>();
|
|
qRegisterMetaType<QNearFieldTarget::Error>();
|
|
@@ -365,6 +365,19 @@ QNearFieldTarget::RequestId QNearFieldTarget::writeNdefMessages(const QList<QNde
|
|
}
|
|
|
|
/*!
|
|
+ \since 5.9
|
|
+
|
|
+ Returns the maximum number of bytes that can be sent with sendCommand. 0 will
|
|
+ be returned if the target does not support sending tag type specific commands.
|
|
+
|
|
+ \sa sendCommand(), sendCommands()
|
|
+*/
|
|
+int QNearFieldTarget::maxCommandLength() const
|
|
+{
|
|
+ return d_ptr->maxCommandLength();
|
|
+}
|
|
+
|
|
+/*!
|
|
Sends \a command to the near field target. Returns a request id which can be used to track the
|
|
completion status of the request. An invalid request id will be returned if the target does not
|
|
support sending tag type specific commands.
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget.h y/qtconnectivity/src/nfc/qnearfieldtarget.h
|
|
index dfb474f6..620ea813 100644
|
|
--- x/qtconnectivity/src/nfc/qnearfieldtarget.h
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget.h
|
|
@@ -134,6 +134,7 @@ public:
|
|
virtual RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
|
|
|
|
// TagTypeSpecificAccess
|
|
+ int maxCommandLength() const;
|
|
virtual RequestId sendCommand(const QByteArray &command);
|
|
virtual RequestId sendCommands(const QList<QByteArray> &commands);
|
|
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget_android.cpp y/qtconnectivity/src/nfc/qnearfieldtarget_android.cpp
|
|
index 478f4d8c..f41b0b2e 100644
|
|
--- x/qtconnectivity/src/nfc/qnearfieldtarget_android.cpp
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget_android.cpp
|
|
@@ -170,9 +170,34 @@ QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages()
|
|
return requestId;
|
|
}
|
|
|
|
+int NearFieldTarget::maxCommandLength() const
|
|
+{
|
|
+ QAndroidJniObject tagTech;
|
|
+ if (m_techList.contains(QStringLiteral(ISODEPTECHNOLOGY))) {
|
|
+ tagTech = getTagTechnology(QStringLiteral(ISODEPTECHNOLOGY));
|
|
+ } else if (m_techList.contains(QStringLiteral(NFCATECHNOLOGY))) {
|
|
+ tagTech = getTagTechnology(QStringLiteral(NFCATECHNOLOGY));
|
|
+ } else if (m_techList.contains(QStringLiteral(NFCBTECHNOLOGY))) {
|
|
+ tagTech = getTagTechnology(QStringLiteral(NFCBTECHNOLOGY));
|
|
+ } else if (m_techList.contains(QStringLiteral(NFCFTECHNOLOGY))) {
|
|
+ tagTech = getTagTechnology(QStringLiteral(NFCFTECHNOLOGY));
|
|
+ } else if (m_techList.contains(QStringLiteral(NFCVTECHNOLOGY))) {
|
|
+ tagTech = getTagTechnology(QStringLiteral(NFCVTECHNOLOGY));
|
|
+ } else {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ int returnVal = tagTech.callMethod<jint>("getMaxTransceiveLength");
|
|
+ if (catchJavaExceptions()) {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ return returnVal;
|
|
+}
|
|
+
|
|
QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &command)
|
|
{
|
|
- if (command.size() == 0) {
|
|
+ if (command.size() == 0 || command.size() > maxCommandLength()) {
|
|
Q_EMIT QNearFieldTarget::error(QNearFieldTarget::InvalidParametersError, QNearFieldTarget::RequestId());
|
|
return QNearFieldTarget::RequestId();
|
|
}
|
|
@@ -184,8 +209,8 @@ QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &comma
|
|
QAndroidJniEnvironment env;
|
|
|
|
QAndroidJniObject tagTech;
|
|
- if (m_techList.contains(ISODEPTECHNOLOGY)) {
|
|
- tagTech = getTagTechnology(ISODEPTECHNOLOGY);
|
|
+ if (m_techList.contains(QStringLiteral(ISODEPTECHNOLOGY))) {
|
|
+ tagTech = getTagTechnology(QStringLiteral(ISODEPTECHNOLOGY));
|
|
} else if (m_techList.contains(QStringLiteral(NFCATECHNOLOGY))) {
|
|
tagTech = getTagTechnology(QStringLiteral(NFCATECHNOLOGY));
|
|
} else if (m_techList.contains(QStringLiteral(NFCBTECHNOLOGY))) {
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget_android_p.cpp y/qtconnectivity/src/nfc/qnearfieldtarget_android_p.cpp
|
|
new file mode 100644
|
|
index 00000000..da2d8f2d
|
|
--- /dev/null
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget_android_p.cpp
|
|
@@ -0,0 +1,53 @@
|
|
+/****************************************************************************
|
|
+**
|
|
+** Copyright (C) 2017 Governikus GmbH & Co. KG
|
|
+** Contact: https://www.qt.io/licensing/
|
|
+**
|
|
+** This file is part of the QtNfc module of the Qt Toolkit.
|
|
+**
|
|
+** $QT_BEGIN_LICENSE:LGPL$
|
|
+** Commercial License Usage
|
|
+** Licensees holding valid commercial Qt licenses may use this file in
|
|
+** accordance with the commercial license agreement provided with the
|
|
+** Software or, alternatively, in accordance with the terms contained in
|
|
+** a written agreement between you and The Qt Company. For licensing terms
|
|
+** and conditions see https://www.qt.io/terms-conditions. For further
|
|
+** information use the contact form at https://www.qt.io/contact-us.
|
|
+**
|
|
+** GNU Lesser General Public License Usage
|
|
+** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
+** General Public License version 3 as published by the Free Software
|
|
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
+** packaging of this file. Please review the following information to
|
|
+** ensure the GNU Lesser General Public License version 3 requirements
|
|
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
|
+**
|
|
+** GNU General Public License Usage
|
|
+** Alternatively, this file may be used under the terms of the GNU
|
|
+** General Public License version 2.0 or (at your option) the GNU General
|
|
+** Public license version 3 or any later version approved by the KDE Free
|
|
+** Qt Foundation. The licenses are as published by the Free Software
|
|
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
+** included in the packaging of this file. Please review the following
|
|
+** information to ensure the GNU General Public License requirements will
|
|
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
+** https://www.gnu.org/licenses/gpl-3.0.html.
|
|
+**
|
|
+** $QT_END_LICENSE$
|
|
+**
|
|
+****************************************************************************/
|
|
+
|
|
+#include <QCoreApplication>
|
|
+
|
|
+#include "qnearfieldtarget_p.h"
|
|
+#include "qnearfieldtarget_android_p.h"
|
|
+
|
|
+QT_BEGIN_NAMESPACE
|
|
+
|
|
+int QNearFieldTargetPrivate::maxCommandLength() const
|
|
+{
|
|
+ NearFieldTarget * const q = reinterpret_cast<NearFieldTarget *>(q_ptr);
|
|
+ return q->maxCommandLength();
|
|
+}
|
|
+
|
|
+QT_END_NAMESPACE
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget_android_p.h y/qtconnectivity/src/nfc/qnearfieldtarget_android_p.h
|
|
index 94bb394d..f2e2ee7f 100644
|
|
--- x/qtconnectivity/src/nfc/qnearfieldtarget_android_p.h
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget_android_p.h
|
|
@@ -77,6 +77,7 @@ public:
|
|
virtual AccessMethods accessMethods() const;
|
|
virtual bool hasNdefMessage();
|
|
virtual RequestId readNdefMessages();
|
|
+ int maxCommandLength() const;
|
|
virtual RequestId sendCommand(const QByteArray &command);
|
|
virtual RequestId sendCommands(const QList<QByteArray> &commands);
|
|
virtual RequestId writeNdefMessages(const QList<QNdefMessage> &messages);
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget_neard_p.cpp y/qtconnectivity/src/nfc/qnearfieldtarget_neard_p.cpp
|
|
new file mode 100644
|
|
index 00000000..3d1bfa6c
|
|
--- /dev/null
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget_neard_p.cpp
|
|
@@ -0,0 +1,52 @@
|
|
+/****************************************************************************
|
|
+**
|
|
+** Copyright (C) 2017 Governikus GmbH & Co. K
|
|
+** Contact: https://www.qt.io/licensing/
|
|
+**
|
|
+** This file is part of the QtNfc module of the Qt Toolkit.
|
|
+**
|
|
+** $QT_BEGIN_LICENSE:LGPL$
|
|
+** Commercial License Usage
|
|
+** Licensees holding valid commercial Qt licenses may use this file in
|
|
+** accordance with the commercial license agreement provided with the
|
|
+** Software or, alternatively, in accordance with the terms contained in
|
|
+** a written agreement between you and The Qt Company. For licensing terms
|
|
+** and conditions see https://www.qt.io/terms-conditions. For further
|
|
+** information use the contact form at https://www.qt.io/contact-us.
|
|
+**
|
|
+** GNU Lesser General Public License Usage
|
|
+** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
+** General Public License version 3 as published by the Free Software
|
|
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
+** packaging of this file. Please review the following information to
|
|
+** ensure the GNU Lesser General Public License version 3 requirements
|
|
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
|
+**
|
|
+** GNU General Public License Usage
|
|
+** Alternatively, this file may be used under the terms of the GNU
|
|
+** General Public License version 2.0 or (at your option) the GNU General
|
|
+** Public license version 3 or any later version approved by the KDE Free
|
|
+** Qt Foundation. The licenses are as published by the Free Software
|
|
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
+** included in the packaging of this file. Please review the following
|
|
+** information to ensure the GNU General Public License requirements will
|
|
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
+** https://www.gnu.org/licenses/gpl-3.0.html.
|
|
+**
|
|
+** $QT_END_LICENSE$
|
|
+**
|
|
+****************************************************************************/
|
|
+
|
|
+#include <QCoreApplication>
|
|
+
|
|
+#include "qnearfieldtarget.h"
|
|
+#include "qnearfieldtarget_p.h"
|
|
+
|
|
+QT_BEGIN_NAMESPACE
|
|
+
|
|
+int QNearFieldTargetPrivate::maxCommandLength() const
|
|
+{
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+QT_END_NAMESPACE
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget_p.cpp y/qtconnectivity/src/nfc/qnearfieldtarget_p.cpp
|
|
new file mode 100644
|
|
index 00000000..3d1bfa6c
|
|
--- /dev/null
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget_p.cpp
|
|
@@ -0,0 +1,52 @@
|
|
+/****************************************************************************
|
|
+**
|
|
+** Copyright (C) 2017 Governikus GmbH & Co. K
|
|
+** Contact: https://www.qt.io/licensing/
|
|
+**
|
|
+** This file is part of the QtNfc module of the Qt Toolkit.
|
|
+**
|
|
+** $QT_BEGIN_LICENSE:LGPL$
|
|
+** Commercial License Usage
|
|
+** Licensees holding valid commercial Qt licenses may use this file in
|
|
+** accordance with the commercial license agreement provided with the
|
|
+** Software or, alternatively, in accordance with the terms contained in
|
|
+** a written agreement between you and The Qt Company. For licensing terms
|
|
+** and conditions see https://www.qt.io/terms-conditions. For further
|
|
+** information use the contact form at https://www.qt.io/contact-us.
|
|
+**
|
|
+** GNU Lesser General Public License Usage
|
|
+** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
+** General Public License version 3 as published by the Free Software
|
|
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
+** packaging of this file. Please review the following information to
|
|
+** ensure the GNU Lesser General Public License version 3 requirements
|
|
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
|
+**
|
|
+** GNU General Public License Usage
|
|
+** Alternatively, this file may be used under the terms of the GNU
|
|
+** General Public License version 2.0 or (at your option) the GNU General
|
|
+** Public license version 3 or any later version approved by the KDE Free
|
|
+** Qt Foundation. The licenses are as published by the Free Software
|
|
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
+** included in the packaging of this file. Please review the following
|
|
+** information to ensure the GNU General Public License requirements will
|
|
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
+** https://www.gnu.org/licenses/gpl-3.0.html.
|
|
+**
|
|
+** $QT_END_LICENSE$
|
|
+**
|
|
+****************************************************************************/
|
|
+
|
|
+#include <QCoreApplication>
|
|
+
|
|
+#include "qnearfieldtarget.h"
|
|
+#include "qnearfieldtarget_p.h"
|
|
+
|
|
+QT_BEGIN_NAMESPACE
|
|
+
|
|
+int QNearFieldTargetPrivate::maxCommandLength() const
|
|
+{
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+QT_END_NAMESPACE
|
|
diff --git x/qtconnectivity/src/nfc/qnearfieldtarget_p.h y/qtconnectivity/src/nfc/qnearfieldtarget_p.h
|
|
index 7a787ace..9b2ed480 100644
|
|
--- x/qtconnectivity/src/nfc/qnearfieldtarget_p.h
|
|
+++ y/qtconnectivity/src/nfc/qnearfieldtarget_p.h
|
|
@@ -57,6 +57,7 @@
|
|
|
|
#include <QtCore/QMap>
|
|
#include <QtCore/QSharedData>
|
|
+#include <QtCore/QVariant>
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
@@ -66,8 +67,15 @@ class QNearFieldTarget::RequestIdPrivate : public QSharedData
|
|
|
|
class QNearFieldTargetPrivate
|
|
{
|
|
+ QNearFieldTarget *q_ptr;
|
|
+ Q_DECLARE_PUBLIC(QNearFieldTarget)
|
|
+
|
|
public:
|
|
+ QNearFieldTargetPrivate(QNearFieldTarget *q) : q_ptr(q) {}
|
|
+
|
|
QMap<QNearFieldTarget::RequestId, QVariant> m_decodedResponses;
|
|
+
|
|
+ int maxCommandLength() const;
|
|
};
|
|
|
|
QT_END_NAMESPACE
|
|
--
|
|
2.11.0
|
|
|