Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Android 14 and fix IOException for Prolific PL2303GT (prodId … #63

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions UsbSerialForAndroid/Extensions/UsbManagerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ public static Task<bool> RequestPermissionAsync(this UsbManager manager, UsbDevi
var completionSource = new TaskCompletionSource<bool>();

var usbPermissionReceiver = new UsbPermissionReceiver(completionSource);
context.RegisterReceiver(usbPermissionReceiver, new IntentFilter(ACTION_USB_PERMISSION));
if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)
{
#pragma warning disable CA1416
context.RegisterReceiver(usbPermissionReceiver, new IntentFilter(ACTION_USB_PERMISSION), ReceiverFlags.NotExported);
#pragma warning restore CA1416
}
else
{
context.RegisterReceiver(usbPermissionReceiver, new IntentFilter(ACTION_USB_PERMISSION));
}

// Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
#if NET6_0_OR_GREATER
Expand All @@ -36,9 +45,14 @@ public static Task<bool> RequestPermissionAsync(this UsbManager manager, UsbDevi
PendingIntentFlags pendingIntentFlags = Build.VERSION.SdkInt >= (BuildVersionCodes)31 ? (PendingIntentFlags).33554432 : 0;
#endif

var intent = PendingIntent.GetBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), pendingIntentFlags);
var intent = new Intent(ACTION_USB_PERMISSION);
if (Build.VERSION.SdkInt >= BuildVersionCodes.UpsideDownCake)
{
intent.SetPackage(context.PackageName);
}
var pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, pendingIntentFlags);

manager.RequestPermission(device, intent);
manager.RequestPermission(device, pendingIntent);

return completionSource.Task;
}
Expand Down
22 changes: 11 additions & 11 deletions UsbSerialForAndroid/driver/ProlificSerialDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,23 +374,23 @@ public override void Open(UsbDeviceConnection connection)
{
mDeviceType = DeviceType.DEVICE_TYPE_01;
}
else if (deviceVersion == 0x300 && usbVersion == 0x200)
else if (usbVersion == 0x200)
{
mDeviceType = DeviceType.DEVICE_TYPE_T; // TA
}
else if (deviceVersion == 0x500)
{
mDeviceType = DeviceType.DEVICE_TYPE_T; // TB
}
else if (usbVersion == 0x200 && !TestHxStatus())
{
mDeviceType = DeviceType.DEVICE_TYPE_HXN;
if ((deviceVersion == 0x300 || deviceVersion == 0x500) && TestHxStatus())
{
mDeviceType = DeviceType.DEVICE_TYPE_T; // TA & TB
}

else
{
mDeviceType = DeviceType.DEVICE_TYPE_HXN;
}
}
else
{
mDeviceType = DeviceType.DEVICE_TYPE_HX;
}

SetControlLines(mControlLinesValue);
ResetDevice();

Expand Down