From e3f89d6559f9a73d6c36c218cf47676b0054c5f3 Mon Sep 17 00:00:00 2001 From: Maximilian Richt Date: Mon, 19 Aug 2024 17:44:48 +0200 Subject: [PATCH 1/2] Fix USB device intents for SDK34+ --- libuvccamera/build.gradle | 3 ++- .../main/java/com/serenegiant/usb/USBMonitor.java | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libuvccamera/build.gradle b/libuvccamera/build.gradle index 4ce69800f..b2ed05455 100644 --- a/libuvccamera/build.gradle +++ b/libuvccamera/build.gradle @@ -65,7 +65,8 @@ dependencies { implementation fileTree(dir: new File(buildDir, 'libs'), include: '*.jar') implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.annotation:annotation:1.6.0' + implementation 'androidx.core:core:1.13.1' + implementation 'androidx.annotation:annotation:1.8.2' implementation("com.serenegiant:common:${commonLibVersion}") { exclude module: 'support-v4' diff --git a/libuvccamera/src/main/java/com/serenegiant/usb/USBMonitor.java b/libuvccamera/src/main/java/com/serenegiant/usb/USBMonitor.java index 920f1ada9..d714d6441 100644 --- a/libuvccamera/src/main/java/com/serenegiant/usb/USBMonitor.java +++ b/libuvccamera/src/main/java/com/serenegiant/usb/USBMonitor.java @@ -49,6 +49,9 @@ import android.util.Log; import android.util.SparseArray; +import androidx.core.app.PendingIntentCompat; +import androidx.core.content.ContextCompat; + import com.serenegiant.utils.HandlerThreadHandler; public final class USBMonitor { @@ -167,15 +170,13 @@ public synchronized void register() throws IllegalStateException { if (DEBUG) Log.i(TAG, "register:"); final Context context = mWeakContext.get(); if (context != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE); - } else { - mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0); - } + Intent intent = new Intent(ACTION_USB_PERMISSION); + intent.setPackage(context.getPackageName()); + mPermissionIntent = PendingIntentCompat.getBroadcast(context, 0, intent, 0, true); final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); // ACTION_USB_DEVICE_ATTACHED never comes on some devices so it should not be added here filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); - context.registerReceiver(mUsbReceiver, filter); + ContextCompat.registerReceiver(context, mUsbReceiver, filter, ContextCompat.RECEIVER_EXPORTED); } // start connection check mDeviceCounts = 0; From b417bccb67cbaad8167b0567617cce6a73ffa424 Mon Sep 17 00:00:00 2001 From: Maximilian Richt Date: Mon, 19 Aug 2024 18:00:18 +0200 Subject: [PATCH 2/2] Bump minSDK to 19 --- libuvccamera/build.gradle | 2 +- usbCameraCommon/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libuvccamera/build.gradle b/libuvccamera/build.gradle index b2ed05455..7fe55758d 100644 --- a/libuvccamera/build.gradle +++ b/libuvccamera/build.gradle @@ -34,7 +34,7 @@ android { } defaultConfig { - minSdkVersion 14 + minSdkVersion 19 targetSdkVersion versionTarget } diff --git a/usbCameraCommon/build.gradle b/usbCameraCommon/build.gradle index fecf6de3a..51f5452e3 100644 --- a/usbCameraCommon/build.gradle +++ b/usbCameraCommon/build.gradle @@ -34,7 +34,7 @@ android { } defaultConfig { - minSdkVersion 18 + minSdkVersion 19 targetSdkVersion versionTarget }