Updates for Qt6.7 and Android API 34
This commit is contained in:
parent
a37ee985d6
commit
2b205fda91
4 changed files with 21 additions and 6 deletions
|
@ -62,6 +62,7 @@ public class USBSerialWrapper implements SerialInputOutputManagerTest.Listener {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("USB Permission Denied");
|
System.out.println("USB Permission Denied");
|
||||||
|
device_denied();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) || (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) ) {
|
if ( (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) || (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) ) {
|
||||||
|
@ -171,10 +172,11 @@ public class USBSerialWrapper implements SerialInputOutputManagerTest.Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_driver = availableDrivers.get(devicenum);
|
m_driver = availableDrivers.get(devicenum);
|
||||||
PendingIntent mPendingIntent = PendingIntent.getBroadcast(c, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE);
|
PendingIntent mPendingIntent = PendingIntent.getBroadcast(c, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT);
|
||||||
m_manager.requestPermission(m_driver.getDevice(), mPendingIntent);
|
m_manager.requestPermission(m_driver.getDevice(), mPendingIntent);
|
||||||
|
System.out.println("setup_serial() finished");
|
||||||
return "Yipee!";
|
return "Yipee!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,5 +255,6 @@ public class USBSerialWrapper implements SerialInputOutputManagerTest.Listener {
|
||||||
|
|
||||||
private static native void data_received(byte[] data);
|
private static native void data_received(byte[] data);
|
||||||
private static native void device_open();
|
private static native void device_open();
|
||||||
|
private static native void device_denied();
|
||||||
private static native void devices_changed();
|
private static native void devices_changed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ AndroidSerialPort::AndroidSerialPort(QObject *)
|
||||||
qDebug() << "com.hoho.android.usbserial.driver/UsbSerialDriver available";
|
qDebug() << "com.hoho.android.usbserial.driver/UsbSerialDriver available";
|
||||||
serialJavaObject = QAndroidJniObject("DroidStar/USBSerialWrapper");
|
serialJavaObject = QAndroidJniObject("DroidStar/USBSerialWrapper");
|
||||||
QAndroidJniEnvironment env;
|
QAndroidJniEnvironment env;
|
||||||
JNINativeMethod methods[] = { {"data_received", "([B)V", reinterpret_cast<void*>(java_data_received)}, {"device_open", "()V", reinterpret_cast<void*>(java_device_open)}, {"devices_changed", "()V", reinterpret_cast<void*>(java_devices_changed)}};
|
JNINativeMethod methods[] = { {"data_received", "([B)V", reinterpret_cast<void*>(java_data_received)}, {"device_open", "()V", reinterpret_cast<void*>(java_device_open)}, {"device_denied", "()V", reinterpret_cast<void*>(java_device_denied)}, {"devices_changed", "()V", reinterpret_cast<void*>(java_devices_changed)}};
|
||||||
jclass objectClass = env->GetObjectClass(serialJavaObject.object<jobject>());
|
jclass objectClass = env->GetObjectClass(serialJavaObject.object<jobject>());
|
||||||
env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0]));
|
env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0]));
|
||||||
env->DeleteLocalRef(objectClass);
|
env->DeleteLocalRef(objectClass);
|
||||||
|
@ -41,8 +41,8 @@ QStringList AndroidSerialPort::discover_devices()
|
||||||
QStringList l;
|
QStringList l;
|
||||||
l.clear();
|
l.clear();
|
||||||
qDebug() << "AndroidSerialPort::discover_devices()";
|
qDebug() << "AndroidSerialPort::discover_devices()";
|
||||||
|
auto activity = QJniObject(QNativeInterface::QAndroidApplication::context());
|
||||||
QAndroidJniObject d = serialJavaObject.callObjectMethod("discover_devices", "(Landroid/content/Context;)[Ljava/lang/String;", QNativeInterface::QAndroidApplication::context());
|
QAndroidJniObject d = serialJavaObject.callObjectMethod("discover_devices", "(Landroid/content/Context;)[Ljava/lang/String;", activity.object());
|
||||||
jobjectArray devices = d.object<jobjectArray>();
|
jobjectArray devices = d.object<jobjectArray>();
|
||||||
int size = env->GetArrayLength(devices);
|
int size = env->GetArrayLength(devices);
|
||||||
|
|
||||||
|
@ -55,7 +55,9 @@ QStringList AndroidSerialPort::discover_devices()
|
||||||
|
|
||||||
int AndroidSerialPort::open(int p)
|
int AndroidSerialPort::open(int p)
|
||||||
{
|
{
|
||||||
serialJavaObject.callObjectMethod("setup_serial", "(Landroid/content/Context;)Ljava/lang/String;", QNativeInterface::QAndroidApplication::context());
|
auto activity = QJniObject(QNativeInterface::QAndroidApplication::context());
|
||||||
|
serialJavaObject.callObjectMethod("setup_serial", "(Landroid/content/Context;)Ljava/lang/String;", activity.object());
|
||||||
|
qDebug() << "AndroidSerialPort::open() finished";
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +146,13 @@ void AndroidSerialPort::java_device_open(JNIEnv *, jobject)
|
||||||
emit AndroidSerialPort::GetInstance().device_ready();
|
emit AndroidSerialPort::GetInstance().device_ready();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AndroidSerialPort::java_device_denied(JNIEnv *, jobject)
|
||||||
|
{
|
||||||
|
emit AndroidSerialPort::GetInstance().device_denied();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void AndroidSerialPort::java_devices_changed(JNIEnv *, jobject)
|
void AndroidSerialPort::java_devices_changed(JNIEnv *, jobject)
|
||||||
{
|
{
|
||||||
emit AndroidSerialPort::GetInstance().devices_changed();
|
emit AndroidSerialPort::GetInstance().devices_changed();
|
||||||
|
|
|
@ -51,11 +51,13 @@ signals:
|
||||||
void readyRead();
|
void readyRead();
|
||||||
void data_received(QByteArray);
|
void data_received(QByteArray);
|
||||||
void device_ready();
|
void device_ready();
|
||||||
|
void device_denied();
|
||||||
void devices_changed();
|
void devices_changed();
|
||||||
private:
|
private:
|
||||||
explicit AndroidSerialPort(QObject * parent = nullptr);
|
explicit AndroidSerialPort(QObject * parent = nullptr);
|
||||||
static void java_data_received(JNIEnv *env, jobject t, jbyteArray data);
|
static void java_data_received(JNIEnv *env, jobject t, jbyteArray data);
|
||||||
static void java_device_open(JNIEnv *env, jobject t);
|
static void java_device_open(JNIEnv *env, jobject t);
|
||||||
|
static void java_device_denied(JNIEnv *env, jobject t);
|
||||||
static void java_devices_changed(JNIEnv *env, jobject t);
|
static void java_devices_changed(JNIEnv *env, jobject t);
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 3, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 3, 0)
|
||||||
QAndroidJniObject serialJavaObject;
|
QAndroidJniObject serialJavaObject;
|
||||||
|
|
|
@ -120,6 +120,7 @@ void SerialAMBE::connect_to_serial(QString p)
|
||||||
#else
|
#else
|
||||||
m_serial = &AndroidSerialPort::GetInstance();
|
m_serial = &AndroidSerialPort::GetInstance();
|
||||||
connect(m_serial, SIGNAL(device_ready()), this, SLOT(config_ambe()));
|
connect(m_serial, SIGNAL(device_ready()), this, SLOT(config_ambe()));
|
||||||
|
//connect(m_serial, SIGNAL(device_denied()), this, SLOT(config_ambe()));
|
||||||
#endif
|
#endif
|
||||||
m_serial->setPortName(p);
|
m_serial->setPortName(p);
|
||||||
m_serial->setBaudRate(br);
|
m_serial->setBaudRate(br);
|
||||||
|
|
Loading…
Add table
Reference in a new issue