-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
290 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,88 @@ | ||
using Android.App; | ||
using System.Net; | ||
|
||
using Android.App; | ||
using Android.Content; | ||
using Android.Hardware.Usb; | ||
using LibUsbDotNet.Main; | ||
using Rtl8812auNet.AndroidDemo.Platforms.Android; | ||
using Rtl8812auNet.AndroidDemo.RtlUsb; | ||
using Rtl8812auNet.Rtl8812au; | ||
using Application = Android.App.Application; | ||
|
||
namespace Rtl8812auNet.AndroidDemo | ||
namespace Rtl8812auNet.AndroidDemo; | ||
|
||
public partial class MainPage : ContentPage | ||
{ | ||
public partial class MainPage : ContentPage | ||
private static string ACTION_USB_PERMISSION = "zone.bld.receiverapp.USB_PERMISSION"; | ||
private readonly MyBroadcastReceiver _broadcastReceiver; | ||
|
||
public MainPage() | ||
{ | ||
InitializeComponent(); | ||
_broadcastReceiver = new MyBroadcastReceiver(this); | ||
} | ||
|
||
private void OnCounterClicked(object sender, EventArgs e) | ||
{ | ||
var context = Android.App.Application.Context; | ||
var usbManager = (UsbManager)context.GetSystemService(Android.Content.Context.UsbService); | ||
|
||
var (_, device) = usbManager.DeviceList.FirstOrDefault(pair => pair.Value.ManufacturerName == "Realtek"); | ||
if (device != null) | ||
{ | ||
if (usbManager.HasPermission(device)) | ||
{ | ||
StatusLabel.Text = $"Device found:{device.DeviceName}" + System.Environment.NewLine + "Starting..."; | ||
StartService(device); | ||
} | ||
else | ||
{ | ||
var pi = PendingIntent.GetBroadcast( | ||
Android.App.Application.Context, | ||
0, | ||
new Intent(ACTION_USB_PERMISSION), | ||
PendingIntentFlags.Immutable); | ||
_broadcastReceiver.Dev = device; | ||
var filter = new IntentFilter(ACTION_USB_PERMISSION); | ||
context.RegisterReceiver(_broadcastReceiver, filter); | ||
|
||
StatusLabel.Text = $"Device found:{device.DeviceName}" + System.Environment.NewLine + "Requesting permissions..."; | ||
usbManager.RequestPermission(device, pi); | ||
} | ||
} | ||
else | ||
{ | ||
StatusLabel.Text = "No RTL8812AU device found"; | ||
} | ||
|
||
Console.WriteLine("READY"); | ||
} | ||
|
||
private void StartService(UsbDevice device) | ||
{ | ||
int count = 0; | ||
StatusLabel.Text = $"Device found:{device.DeviceName}" + System.Environment.NewLine + "Starting..."; | ||
AndroidServiceManager.Device = device; | ||
var context = Android.App.Application.Context; | ||
var usbManager = (UsbManager)context.GetSystemService(Android.Content.Context.UsbService); | ||
AndroidServiceManager.Connection = usbManager.OpenDevice(device); | ||
AndroidServiceManager.StartWfbService(); | ||
} | ||
|
||
public MainPage() | ||
public class MyBroadcastReceiver : BroadcastReceiver | ||
{ | ||
private readonly MainPage _parent; | ||
|
||
public MyBroadcastReceiver(MainPage parent) | ||
{ | ||
InitializeComponent(); | ||
_parent = parent; | ||
} | ||
|
||
private void OnCounterClicked(object sender, EventArgs e) | ||
public override void OnReceive(Context context, Intent intent) | ||
{ | ||
var context = Android.App.Application.Context; | ||
var usbManager = (UsbManager)context.GetSystemService(Android.Content.Context.UsbService); | ||
var dev = usbManager.DeviceList.Single(pair => pair.Value.ManufacturerName == "Realtek").Value; | ||
var pi = PendingIntent.GetBroadcast( | ||
Application.Context, | ||
0, | ||
new Intent(Context.UsbService), | ||
PendingIntentFlags.Immutable); | ||
usbManager.RequestPermission(dev, pi); | ||
|
||
var conn = usbManager.OpenDevice(dev); | ||
var rtlUsbDevice = new RtlUsbDevice(dev, conn); | ||
var rtl = new Rtl8812aDevice(rtlUsbDevice); | ||
rtl.Init(); | ||
|
||
Console.WriteLine("READY"); | ||
_parent.StatusLabel.Text = $"Device found:{Dev.DeviceName}" + System.Environment.NewLine + "Starting..."; | ||
_parent.StartService(Dev); | ||
} | ||
|
||
public UsbDevice Dev { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Rtl8812auNet.AndroidDemo/Platforms/Android/AndroidServiceManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Android.Hardware.Usb; | ||
|
||
namespace Rtl8812auNet.AndroidDemo.Platforms.Android; | ||
|
||
public static class AndroidServiceManager | ||
{ | ||
public static MainActivity MainActivity { get; set; } | ||
|
||
public static bool IsRunning { get; set; } | ||
public static UsbDevice Device { get; set; } | ||
public static UsbDeviceConnection Connection { get; set; } | ||
|
||
public static void StartWfbService() | ||
{ | ||
if (MainActivity == null) | ||
{ | ||
return; | ||
} | ||
|
||
MainActivity.StartService(); | ||
} | ||
|
||
public static void StopWfbService() | ||
{ | ||
if (MainActivity == null) | ||
{ | ||
return; | ||
} | ||
MainActivity.StopService(); | ||
IsRunning = false; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Rtl8812auNet.AndroidDemo/Platforms/Android/DriverBackgroundService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.OS; | ||
using Bld.WlanUtils; | ||
using Java.Util.Logging; | ||
|
||
using LibUsbDotNet.LibUsb; | ||
using Microsoft.Extensions.Logging; | ||
using Rtl8812auNet.AndroidDemo.RtlUsb; | ||
using Rtl8812auNet.Rtl8812au; | ||
using Rtl8812auNet.Rtl8812au.Models; | ||
using ChannelWidth = Rtl8812auNet.Rtl8812au.Enumerations.ChannelWidth; | ||
|
||
namespace Rtl8812auNet.AndroidDemo.Platforms.Android; | ||
|
||
[Service] | ||
public class DriverBackgroundService : Service | ||
{ | ||
private WiFiDriver _driver; | ||
private Rtl8812aDevice _device; | ||
private ILogger<DriverBackgroundService> _logger; | ||
private WlanChannel _channel = Channels.Ch036; | ||
|
||
|
||
public override IBinder OnBind(Intent intent) | ||
{ | ||
return null; | ||
} | ||
|
||
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) | ||
{ | ||
var loggerFactory = IPlatformApplication.Current.Services.GetRequiredService<ILoggerFactory>(); | ||
_logger = loggerFactory.CreateLogger<DriverBackgroundService>(); | ||
_driver = new WiFiDriver(loggerFactory, false); | ||
_device = _driver.CreateRtlDevice(new RtlUsbDevice(AndroidServiceManager.Device, AndroidServiceManager.Connection, loggerFactory.CreateLogger<RtlUsbDevice>())); | ||
_device.Init(PacketProcessor, CreateCurrentChannel()); | ||
_device.SetMonitorChannel(CreateCurrentChannel()); | ||
|
||
return StartCommandResult.Sticky; | ||
} | ||
|
||
private Task PacketProcessor(ParsedRadioPacket arg) | ||
{ | ||
_logger.LogDebug("Received"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
private SelectedChannel CreateCurrentChannel() | ||
{ | ||
return new SelectedChannel | ||
{ | ||
Channel = (byte)_channel.ChannelNumber, | ||
ChannelOffset = 0, | ||
ChannelWidth = ChannelWidth.CHANNEL_WIDTH_20 | ||
}; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Rtl8812auNet.AndroidDemo/Platforms/Android/MainActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Content.PM; | ||
using Android.OS; | ||
using Rtl8812auNet.AndroidDemo.Platforms.Android; | ||
|
||
namespace Rtl8812auNet.AndroidDemo | ||
{ | ||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] | ||
public class MainActivity : MauiAppCompatActivity | ||
{ | ||
public MainActivity() | ||
{ | ||
AndroidServiceManager.MainActivity = this; | ||
} | ||
|
||
public void StartService() | ||
{ | ||
var serviceIntent = new Intent(this, typeof(DriverBackgroundService)); | ||
serviceIntent.PutExtra("inputExtra", "Background Service"); | ||
StartService(serviceIntent); | ||
} | ||
|
||
public void StopService() | ||
{ | ||
var serviceIntent = new Intent(this, typeof(DriverBackgroundService)); | ||
StopService(serviceIntent); | ||
} | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/Rtl8812auNet.AndroidDemo/Platforms/MacCatalyst/AppDelegate.cs
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/Rtl8812auNet.AndroidDemo/Platforms/MacCatalyst/Info.plist
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/Rtl8812auNet.AndroidDemo/Platforms/MacCatalyst/Program.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/Rtl8812auNet.AndroidDemo/Platforms/Tizen/tizen-manifest.xml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.