From 1ea4edddec8d47e4f944da31aa92663308fff5b6 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 7 Nov 2024 11:54:09 -0800
Subject: [PATCH] Fixed Java exception if mConnection is null
---
.../app/src/main/java/org/libsdl/app/HIDDeviceUSB.java | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java
index 5b5d201f78778..27414386df76f 100644
--- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java
+++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java
@@ -154,6 +154,11 @@ public boolean open() {
@Override
public int writeReport(byte[] report, boolean feature) {
+ if (mConnection == null) {
+ Log.w(TAG, "writeReport() called with no device connection");
+ return -1;
+ }
+
if (feature) {
int res = -1;
int offset = 0;
@@ -201,6 +206,11 @@ public boolean readReport(byte[] report, boolean feature) {
boolean skipped_report_id = false;
byte report_number = report[0];
+ if (mConnection == null) {
+ Log.w(TAG, "readReport() called with no device connection");
+ return false;
+ }
+
if (report_number == 0x0) {
/* Offset the return buffer by 1, so that the report ID
will remain in byte 0. */