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

Pull initial Digirig support #382

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

bxlentpartyon
Copy link

Pull Digirig support into master.

charlieb and others added 5 commits July 22, 2024 22:10
I'm going to base the new AfskProto protocol implementation on the
existing KissProto.  Make a copy of KissProto and commit it separately
to ensure that it's clear what I've changed.
This includes the changes that I needed to make to Charlie's original
commit, as well as the changes I made to the copied KissProto
implementation.  The UI stuff on the app looks mostly correct at this
point, and I believe the bones are there to get packet tx/rx working.
@penguin359
Copy link
Contributor

While testing a build of this PR, I am getting an immediate crash when I try to "Start Tracking" after enabling DigiRig in the settings. I have not had a chance to dig deeper yet:

08-03 01:45:12.579 31590 31590 D APRSdroid.Service: onStartCommand: Intent { act=org.aprsdroid.app.SERVICE
cmp=org.aprsdroid.app/.AprsService }, 0, 1
08-03 01:45:12.593 31590 31590 D APRSdroid.Service: addPost: null - APRS Service started: SmartBeaconingΓäó Position,
Audio (AFSK), Digirig.
08-03 01:45:12.610 31590 31590 E AndroidRuntime: Process: org.aprsdroid.app, PID: 31590
08-03 01:45:12.610 31590 31590 E AndroidRuntime: java.lang.RuntimeException: Unable to start service
org.aprsdroid.app.AprsService@60daa5c with Intent { act=org.aprsdroid.app.SERVICE cmp=org.aprsdroid.app/.AprsService
}: java.lang.IllegalArgumentException: org.aprsdroid.app: Targeting S+ (version 31 and above) requires that one of
FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
08-03 01:45:12.610 31590 31590 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: org.aprsdroid.app:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a
PendingIntent.
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at org.aprsdroid.app.DigiRig.<init>(DigiRig.scala:60)
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at
org.aprsdroid.app.AprsBackend$$anonfun$8.apply(AprsBackend.scala:102)
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at
org.aprsdroid.app.AprsBackend$$anonfun$8.apply(AprsBackend.scala:102)
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at
org.aprsdroid.app.AprsBackend$.instanciateUploader(AprsBackend.scala:170)
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at org.aprsdroid.app.AprsService.startPoster(AprsService.scala:175)
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at org.aprsdroid.app.AprsService.handleStart(AprsService.scala:164)
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at org.aprsdroid.app.AprsService.onStartCommand(AprsService.scala:96)

@penguin359
Copy link
Contributor

OK, well, I was able to bypass that crash by adding a PendingIntent.FLAG_IMMUTABLE to the PendingIntent(), but now it is crashing further down while requesting permissions. I did see the pop-up asking me to grant permission to access the AIOC adapter I have attached:

08-03 02:04:03.286  4903  4903 D APRSdroid.Storage: open(): instanciating StorageDatabase
08-03 02:04:03.305  4903  4903 D APRSdroid.Service: addPost: null - APRS Service started: SmartBeaconingΓäó Position,
Audio (AFSK), Digirig.
08-03 02:04:03.321  4903  4903 D APRSdroid.Digirig: Digirig.requestPermissions
08-03 02:04:03.325  4903  4903 I APRSdroid.Digirig: Found USB device 1209:7388, requesting permissions.
08-03 02:04:03.326  4903  4927 D APRSdroid.AfskDemod: running...
08-03 02:04:03.330  4903  4903 D APRSdroid.Digirig: onReceive: Intent { act=org.aprsdroid.app.DigiRig.PERM flg=0x10 }
08-03 02:04:03.334  4903  4903 E AndroidRuntime: Process: org.aprsdroid.app, PID: 4903
08-03 02:04:03.334  4903  4903 E AndroidRuntime: java.lang.RuntimeException: Error receiving broadcast Intent {
act=org.aprsdroid.app.DigiRig.PERM flg=0x10 } in org.aprsdroid.app.DigiRig$$anon$1@631ed9e
08-03 02:04:03.334  4903  4903 E AndroidRuntime:        at org.aprsdroid.app.DigiRig$$anon$1.onReceive(DigiRig.scala:81)

@bxlentpartyon
Copy link
Author

bxlentpartyon commented Aug 4, 2024

It sounds like you might not be testing with a Digirig?

Please let me know if I'm wrong about that, and I'll definitely look into it. However, if your issues are with different hardware, I think they should be considered a separate effort from this PR.

@penguin359
Copy link
Contributor

penguin359 commented Aug 4, 2024

You are correct that I am not using a DigiRig for my testing. I am trying to get it to work with AIOC, however the two crashes I posted don't seem to have anything to do with the hardware, but with how PendingIntents are handles on newer Android API levels. What version of Android did you develop this under?

I am using a Pixel 7 Pro with Android 13 (API Level 33). Can you try this under the Android Emulator with API level 13? You will need to set up USB passthrough which seems possible, but I haven't done it before myself.

@penguin359
Copy link
Contributor

penguin359 commented Aug 4, 2024

OK, I finally understand what the crash is. The fix is merely that you need to pass a flag in when creating the PendingIntent for the broadcast receiver. The fourth argument can no longer just be zero as of API level 31. This is due to a security change in the Android 12 (API level 31) where they made the default to be immutable and added a flag for selecting it explicitly to be mutable rather than immutable. My mistake in trying to fix the first crash is that I set the flag to be immutable which doesn't work in this situation leading to the second crash I posted above.

To sum up, please add PendingIntent.FLAG_MUTABLE to the flags (4th argument) of PendingIntent.getBroadcast() and that will prevent a hard crash on Android 12 and newer. Then, also verify that Android 11 and older still works.

You can read more about that here: PendingIntent.FLAG_MUTABLE

penguin359 added a commit to penguin359/aprsdroid that referenced this pull request Aug 4, 2024
Starting with API level 31, a flag for mutable or immutable intent is
now required or an exception will be generated crashing the app. This
fixes a crash seen in PR ge0rg#382
@bxlentpartyon
Copy link
Author

bxlentpartyon commented Aug 4, 2024

I'll test this on my device, but I'd still argue that building for a different Android target than the official release is outside the scope of the work that I'm doing here. I specifically set up my environment to build exactly like the production version so that I didn't have to fight with issues that don't exist in production.

@penguin359
Copy link
Contributor

penguin359 commented Aug 5, 2024

I am a little confused at to what you are referring to. I am building the for the official SDK target that the upstream APRSdroid is targeted for. The targetSdkVersion in build.gradle is API level 33 which means it must follow all requirements of that API version. The specific crash I was hitting is documented in the officlal Android documentation under PendingIntent.FLAG_MUTABLE. This issue has nothing to do with the DigiRig hardware support itself, but how PendingIntent needs to be used with a BroadcastReceiver. Here is the crash as I hit it describing the issue:

08-03 01:45:12.610 31590 31590 E AndroidRuntime: java.lang.RuntimeException: Unable to start service
org.aprsdroid.app.AprsService@60daa5c with Intent { act=org.aprsdroid.app.SERVICE cmp=org.aprsdroid.app/.AprsService
}: java.lang.IllegalArgumentException: org.aprsdroid.app: Targeting S+ (version 31 and above) requires that one of
FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
08-03 01:45:12.610 31590 31590 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: org.aprsdroid.app:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a
PendingIntent.
08-03 01:45:12.610 31590 31590 E AndroidRuntime:        at org.aprsdroid.app.DigiRig.<init>(DigiRig.scala:60)

What Android version are you testing under? This crash will only be seen under Android 12 (API level 31) and newer. If you are testing under an older Android release, you won't see any crash and this patch shouldn't change any behavior, although I haven't been able to test it yet under older Android.

@penguin359
Copy link
Contributor

I apologize if I've confused things by bringing up the AIOC board, but my recent comments related to the crash I am seeing are not specific to that board. I've sent you a PR with the fix I am talking about in bxlentpartyon#1 and I expect it to be a simple patch to review. This issue should also affect the DigiRig on newer Android versions.

I am also trying to expand your code to support the AIOC board that I have, but that is above and beyond what is in your PR and I am not expecting you to have to do anything. Once I can get this board also working, I'll create a PR to send to either you or @ge0rg, if your PR is approved and merged in by that time. This is great progress you have made and I am pleased to help beta test the code on my set-up!

@bxlentpartyon
Copy link
Author

I got myself confused looking at the error that you hit here - I'm now understanding that this is an actual issue with my branch, just not one that I'm hitting, because I'm using a pretty old device. I will pick your commit on top of my branch so that it gets included with this PR, since I do believe that it probably belongs with it.

Apologies for the confusion here!

bxlentpartyon and others added 2 commits August 6, 2024 20:02
I originally had some hacky code in here to _hopfeully_ ensure that the
RTS signal was raise while packets were being transmitted, but it was
only a best-guess attempt.  This commit implements an
OnPlaybackPositionUpdateListener to tell us exactly when the audio for a
packet has finished playing, so we know exactly when to clear the RTS
signal.
Starting with API level 31, a flag for mutable or immutable intent is
now required or an exception will be generated crashing the app. This
fixes a crash seen in PR ge0rg#382
@bxlentpartyon
Copy link
Author

Branch has been updated - I'm still doing some testing, but, as you mentioned, the patch is pretty simple, so I'm not concerned that pulling it in is going to have unintended side-effects.

Thanks for the additional improvement here!

@skteagle
Copy link

Any update on this? I just found this branch and seems like this is exactly the problem I am facing on my Alinco DR-735T and Digirig trying to run on my Samsung A9+.

@bxlentpartyon
Copy link
Author

I don't think I ever ran my own build with @penguin359's fix for this, so that is likely why you're still seeing the issue. I will try to run a build tonight with the fix in place and post another release.

@bxlentpartyon
Copy link
Author

bxlentpartyon commented Oct 3, 2024

I realized after looking at this some more that I did actually post a more recent release, but I didn't link it over on the issue, or on here. Did you try this release:

https://github.com/bxlentpartyon/aprsdroid/releases/tag/digirig-v1.1

Or just the one that I linked over in #382 a while back? @skteagle

@skteagle
Copy link

skteagle commented Oct 3, 2024

I did download and tried to install that release. I am getting this invalid error when I try and install that version.
Screenshot_20241003_085848_Package installer

@adamberson
Copy link

adamberson commented Oct 22, 2024

Thanks for these efforts, I've been watching for a while. I tested the 1.1 build.

On several occasions I had a situation where upon transmission I get:
USB device detached
APRS Service Stopped

Presumably RF is putting the digirig/phone into a bad state so the transmitter stays keyed indefinitely which is discussed in the digirig troubleshooting.

Likely this can't be solved in APRSDroid, but it's a potential problem with RTS control that people should be aware of. If you've already lost control of the port/RTS then presumably this won't work, but I wonder if there could be other locations in the code where it would make sense to attempt setRTS(false) - e.g. upon termination of the UsbThread or during some other crash handling.

@na7q
Copy link
Contributor

na7q commented Oct 22, 2024

Thanks for these efforts, I've been watching for a while. I tested the 1.1 build.

On several occasions I had a situation where upon transmission I get: USB device detached APRS Service Stopped

Presumably RF is putting the digirig/phone into a bad state so the transmitter stays keyed indefinitely which is discussed in the digirig troubleshooting.

Likely this can't be solved in APRSDroid, but it's a potential problem with RTS control that people should be aware of. If you've already lost control of the port/RTS then presumably this won't work, but I wonder if there could be other locations in the code where it would make sense to attempt setRTS(false) - e.g. upon termination of the UsbThread or during some other crash handling.

Definitely would need a ferrite with this kind of setup.

@kd2var
Copy link

kd2var commented Dec 14, 2024

Would anyone happen to have any idea why offline mapping doesn’t work with this version of APRSdroid? It won’t load my map file. I wish they would just merge this branch into the main branch and put out an updated apk

@na7q
Copy link
Contributor

na7q commented Dec 15, 2024

Would anyone happen to have any idea why offline mapping doesn’t work with this version of APRSdroid? It won’t load my map file. I wish they would just merge this branch into the main branch and put out an updated apk

I have been releasing updated versions of APRSdroid (unofficial) which supports mbtiles mapping. It's not as simple as the old school offline maps version was. The reason offline maps is broken is due to the old mapsforge and Android changes. In my build I have a simple workaround. I also have added many features. Feel free to reach out if you need help. Email is on QRZ.

@gunnardave
Copy link

gunnardave commented Dec 15, 2024

Indeed @kd2var, @na7q has generously looked into the problem for what is probably a small niche of us who need offline maps for SIM-less devices (so updates to it are done via a host on USB). I have unfortunately not been able to test his work around because my device is storage constrained and I don't have much space to put MBTiles on it nor free up much space for them in parallel. Several other apps I use still rely on Mapsforge basemap files so they have to stay. It would be an ideal situation if APRSdroid could support V5 of Mapsforge and I could update them all in one swoop but that is seemingly a dead end. So I'm still on an old version of APRSdroid along with keeping V3 Mapsforge files for the time being. They are very old but for my purposes the lack of updates is not critical yet. And none of the bugs in APRSdroid are anything more than annoyances either. So it goes. 73, AC0VH

@na7q
Copy link
Contributor

na7q commented Dec 20, 2024

Digirig support has been added to my builds. I don't have a way to test it, so you're on your own there.

https://na7q.com/wp-content/uploads/2024/12/aprsdroid-release-noapi.apk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants