Fix two crashes that prevent a fresh install from launching - #123
Conversation
1. UnsatisfiedLinkError: libusb1.0.so / libsodium.so / libopus.so are
linked into libWfbngRtl8812.so and libVideoNative.so via absolute
paths in each module's CMakeLists.txt, but nothing placed them
under a jniLibs source set, so AGP never packaged them into the
APK and the dynamic linker couldn't find them at runtime. Only
surfaces on a genuinely fresh install/device with no cached APK
already carrying them (e.g. from a properly configured CI/release
build) to mask the gap. Fixed by adding the prebuilt libraries
(already present in each module's src/main/cpp/libs/<abi>/) to a
standard src/main/jniLibs/<abi>/ source set for both modules.
2. SIGABRT in Aggregator::Aggregator ("Unable to open gs.key") /
USB adapter lock false-refusal: WfbngLink.hpp/.cpp hardcoded both
the gs.key path and the USB advisory lock directory as
/data/user/0/com.openipc.pixelpilot/..., which is only correct for
the default applicationId running as Android's default user (id
0). Under a different applicationId (a fork/rebrand) or a
non-default user profile (secondary user, work profile, Samsung
Secure Folder, ...), that path doesn't exist, so opening gs.key
fails outright, and the USB lock (see UsbDeviceLock.h) either
silently degrades to no exclusivity or -- once the directory
happens to resolve to a stale lock from an earlier process -- falsely
reports "in use". Fixed by resolving both from
Context.getFilesDir() via JNI once in the constructor instead.
Verified on-device (Galaxy Tab S7 FE, RTL8812AU): a fresh install now
launches and opens the USB adapter successfully
("USB adapter <id> locked for exclusive access") instead of crashing
or falsely refusing the adapter.
PR Summary by QodoFix fresh-install native loading and app data path crashes
AI Description
Diagram
High-Level Assessment
Files changed (8)
|
Code Review by Qodo
1. Library callers can hit a native crash
|
| jclass contextClass = env->GetObjectClass(context); | ||
| jmethodID getFilesDirMethod = env->GetMethodID(contextClass, "getFilesDir", "()Ljava/io/File;"); | ||
| jobject filesDir = env->CallObjectMethod(context, getFilesDirMethod); |
There was a problem hiding this comment.
1. Library callers can hit a native crash 🐞 Bug ☼ Reliability
resolveFilesDir passes context and each returned JNI object into subsequent calls without checking for null values or pending exceptions. A caller constructing WfbNgLink with a null context now reaches GetObjectClass and continues through invalid JNI results, potentially aborting initialization instead of reporting a controlled Java error.
Agent Prompt
## Issue description
The new files-directory resolver dereferences the constructor's `Context` without validating it and continues after JNI lookup or invocation failures. This can turn a null context or pending Java exception into an uncontrolled native failure.
## Issue Context
`WfbNgLink` exposes a public constructor that forwards its argument directly to `nativeInitialize`. Validate the context before native initialization and stop immediately after any JNI exception or null result, preferably by throwing a clear Java exception rather than continuing with invalid JNI values.
## Fix Focus Areas
- app/wfbngrtl8812/src/main/cpp/WfbngLink.cpp[55-66]
- app/wfbngrtl8812/src/main/java/com/openipc/wfbngrtl8812/WfbNgLink.java[53-55]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
UnsatisfiedLinkError: libusb1.0.so / libsodium.so / libopus.so are
linked into libWfbngRtl8812.so and libVideoNative.so via absolute
paths in each module's CMakeLists.txt, but nothing placed them
under a jniLibs source set, so AGP never packaged them into the
APK and the dynamic linker couldn't find them at runtime. Only
surfaces on a genuinely fresh install/device with no cached APK
already carrying them (e.g. from a properly configured CI/release
build) to mask the gap. Fixed by adding the prebuilt libraries
(already present in each module's src/main/cpp/libs//) to a
standard src/main/jniLibs// source set for both modules.
SIGABRT in Aggregator::Aggregator ("Unable to open gs.key") /
USB adapter lock false-refusal: WfbngLink.hpp/.cpp hardcoded both
the gs.key path and the USB advisory lock directory as
/data/user/0/com.openipc.pixelpilot/..., which is only correct for
the default applicationId running as Android's default user (id
0). Under a different applicationId (a fork/rebrand) or a
non-default user profile (secondary user, work profile, Samsung
Secure Folder, ...), that path doesn't exist, so opening gs.key
fails outright, and the USB lock (see UsbDeviceLock.h) either
silently degrades to no exclusivity or -- once the directory
happens to resolve to a stale lock from an earlier process -- falsely
reports "in use". Fixed by resolving both from
Context.getFilesDir() via JNI once in the constructor instead.
Verified on-device (Galaxy Tab S7 FE, RTL8812AU): a fresh install now
launches and opens the USB adapter successfully
("USB adapter locked for exclusive access") instead of crashing
or falsely refusing the adapter.
🤖 Generated with Claude Code