Skip to content

Commit cac98bc

Browse files
authored
Merge pull request #63 from v2bsd/dev
Support Android 14 and fix IOException for Prolific PL2303GT (prodId …
2 parents ebfe4c8 + 1960d6f commit cac98bc

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

UsbSerialForAndroid/Extensions/UsbManagerExtensions.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ public static Task<bool> RequestPermissionAsync(this UsbManager manager, UsbDevi
2727
var completionSource = new TaskCompletionSource<bool>();
2828

2929
var usbPermissionReceiver = new UsbPermissionReceiver(completionSource);
30-
context.RegisterReceiver(usbPermissionReceiver, new IntentFilter(ACTION_USB_PERMISSION));
30+
if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)
31+
{
32+
#pragma warning disable CA1416
33+
context.RegisterReceiver(usbPermissionReceiver, new IntentFilter(ACTION_USB_PERMISSION), ReceiverFlags.NotExported);
34+
#pragma warning restore CA1416
35+
}
36+
else
37+
{
38+
context.RegisterReceiver(usbPermissionReceiver, new IntentFilter(ACTION_USB_PERMISSION));
39+
}
3140

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

39-
var intent = PendingIntent.GetBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), pendingIntentFlags);
48+
var intent = new Intent(ACTION_USB_PERMISSION);
49+
if (Build.VERSION.SdkInt >= BuildVersionCodes.UpsideDownCake)
50+
{
51+
intent.SetPackage(context.PackageName);
52+
}
53+
var pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, pendingIntentFlags);
4054

41-
manager.RequestPermission(device, intent);
55+
manager.RequestPermission(device, pendingIntent);
4256

4357
return completionSource.Task;
4458
}

UsbSerialForAndroid/driver/ProlificSerialDriver.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,23 +374,23 @@ public override void Open(UsbDeviceConnection connection)
374374
{
375375
mDeviceType = DeviceType.DEVICE_TYPE_01;
376376
}
377-
else if (deviceVersion == 0x300 && usbVersion == 0x200)
377+
else if (usbVersion == 0x200)
378378
{
379-
mDeviceType = DeviceType.DEVICE_TYPE_T; // TA
380-
}
381-
else if (deviceVersion == 0x500)
382-
{
383-
mDeviceType = DeviceType.DEVICE_TYPE_T; // TB
384-
}
385-
else if (usbVersion == 0x200 && !TestHxStatus())
386-
{
387-
mDeviceType = DeviceType.DEVICE_TYPE_HXN;
379+
if ((deviceVersion == 0x300 || deviceVersion == 0x500) && TestHxStatus())
380+
{
381+
mDeviceType = DeviceType.DEVICE_TYPE_T; // TA & TB
382+
}
383+
384+
else
385+
{
386+
mDeviceType = DeviceType.DEVICE_TYPE_HXN;
387+
}
388388
}
389389
else
390390
{
391391
mDeviceType = DeviceType.DEVICE_TYPE_HX;
392392
}
393-
393+
394394
SetControlLines(mControlLinesValue);
395395
ResetDevice();
396396

0 commit comments

Comments
 (0)