One Tablet, One Dongle, No Computer and No Root (7, Finale)
Previous: The iPhone Client | 中文版:安卓平板直接驱动
The last post in the series has the harshest constraints: a Pixel Tablet whose only USB-C port is occupied by the 4G dongle. No computer to help, no root, and with the dongle plugged in you can’t even plug in a charger.
The goal is to make the tablet a phone on its own:
- Make and receive calls, with audio through the tablet’s speaker and microphone;
- Send and receive SMS, with Chinese text and emoji coming through correctly;
- Call history, missed-call notifications, contact matching;
- Switch between two modes: “the tablet uses the SIM for internet” and “the SIM only handles calls and SMS”.
No dependence on the Raspberry Pi gateway from earlier posts. The app drives the module directly.
The constraints dictated the design
There was almost no room for free choices in this project. Every design decision was forced by some constraint:
| Constraint | Consequence |
|---|---|
| No adb binary on the tablet, and no root | The app implements the adb protocol itself, talking to the module’s debug service directly through Android’s USB Host API |
| No Android driver for the module’s serial ports | AT commands go over adb’s shell stream, same as the Mac version |
| Incoming call and new SMS notifications go to the USB AT port, where we can’t receive them | Call state and new SMS are polled, not waited for |
| Everything about voice routing lives on a RAM disk | Rebuild it before every call; cheap when it is already set up |
| The driver is a GPL derivative | Not bundled; the user imports it once |
| Android allows an app only one active recording | Take the module’s sound card away from Android and move the data ourselves in native code |
| The SIM holds only a few dozen SMS and rejects new ones when full | Treat the SIM as an inbox and drain it to the tablet periodically |
| The tablet has no earpiece, only a loudspeaker | Use communication mode for the mic so the system’s echo cancellation kicks in |
The third-to-last row is the main thread of this post; more on it below.
Getting it running
JAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew assembleDebug
adb install -r app/build/outputs/apk/debug/app-debug.apk
The tablet has a single USB port, and with the dongle in it you can’t plug in a computer, so debugging has to go over wireless:
adb mdns services # find the tablet's pairing service
adb pair <ip>:<port> # use the pairing code shown on the tablet
adb connect <ip>:<port>
Gotcha: the old adb that ships with the system can’t pair. Use the newer one from Android SDK platform-tools. The symptom is a pairing timeout; nothing tells you it’s a version problem.
Voice driver: in the app, choose “Import from folder”, or run the app once first and then push the driver into its private directory. Calls still connect without the driver, just with no audio.
One system setting you must change: in Developer options, disable USB audio routing, then unplug and replug the dongle.
adb shell settings put secure usb_audio_automatic_routing_disabled 1
Why this is needed is explained by a gotcha further down.
Writing our own adb client
It sounds scary, but it’s a few hundred lines. The adb wire protocol is simple: a handshake packet, optional key authentication, then four packet kinds for opening a stream, writing data, acknowledging, and closing. One USB connection multiplexes all the streams.
We use only the old framing (4 KiB payload, byte-sum checksum), which a debug service of this vintage is certain to accept. This particular dongle never asks for authentication.
Doing it ourselves also brought an unexpected performance win: each AT command is just one round trip on an already-open connection, whereas the Mac version spawns an adb shell process for every command. The difference is very noticeable.
The AT layer has the same structure as the Mac version: one long-lived read stream and one short write stream per command. Writes use octal escapes so that no byte (quotes, control characters) means anything special to the module’s shell. Before starting, we kill any leftover reader processes in the module; the “ghost reader” gotcha from part 5 is prevented up front here.
The old debug service doesn’t report exit codes (we ran into that in part 4), so the scripts print their own markers and the program checks the marker rather than a return value.
Polling cadence:
| Frequency | Command | Purpose |
|---|---|---|
| 1 s during a call, 2 s when idle | AT+CLCC |
Call state, and the only way to discover an incoming call |
| Every 20 s when idle | List and delete SMS | Drain the SIM inbox |
| About every 14 s when idle | A batch of status queries | Status bar and network page |
One firmware quirk: the call list contains an extra phantom data entry, so we only accept entries that are “type voice and have a number” (incoming ringing is the exception, since the number may be withheld). A call counts as hung up only after two consecutive polls don’t see it, with an 8-second grace period after dialing.
The biggest gotcha: one side is silent on every call
Symptom: Routing is fine and the call connects, but the “remote” level meter barely moves and the “local” meter doesn’t move at all.
Evidence: Call a service number that plays a fixed voice prompt and log the volume of both recordings second by second.
| Recordings open | Module downlink volume | Tablet mic |
|---|---|---|
| Module + tablet mic | 0.001–0.002 | 0.0000 |
| Module only | 0.28–0.39, peak 0.96 | — |
| Tablet mic only | — | 0.0038 (ambient noise) |
| Tablet mic + module | — | exactly 0 |
| Different recording source types | 0.0000 | 0.003–0.005 |
The table reads clearly: either one alone works, and with both open one of them is dead. And changing the recording source type only changes which side loses.
Android reports that every recording is “not silenced”, and the routing configuration is entirely correct.
Cause: Android gives an app only one active recording. If the module’s USB audio input and the tablet mic record at the same time, one of them is bound to get silence. This isn’t a bug; it’s the platform’s intended behavior.
One dead end we tried: the bridge program has a mode that streams audio out over an adb stream, bypassing the recording system. But on this firmware it can’t open the device and fails with errno = -22.
The only fix is to pull the problem out by the root: take the module’s sound card away from Android.
As soon as the module connects, we forcibly claim its USB audio control interface and its two streaming interfaces. That kicks out the system’s USB audio driver; from Android’s point of view, the sound card disappears. Then, when a call starts, we set the sample rate ourselves, submit the isochronous transfer requests ourselves, and move the data ourselves.
The specifics: 8000 Hz mono 16-bit, one 16-byte packet per millisecond on the high-speed bus; 4 requests in flight per direction, 8 packets (8 ms) per request. The two ends run on different clocks, so whenever the ring buffer backlog exceeds 200 ms it gets trimmed back to 60 ms. On shutdown you must discard and reap every request before releasing resources: until a request is reaped it belongs to the kernel, not to you.
Now Android sees only one recording: the tablet mic. The result is a downlink volume of 0.40 to 0.51, exactly 16000 bytes per second in each direction, and zero transfer errors.
Android sent all audio into the dongle
Symptom: Android recognized the dongle as a USB headset and also made it the communication device. In the audio logs, call output switched from the speaker to the “USB headset” within half a second. Music played by other apps went there too.
Cause: The module’s audio function looks exactly like a standard USB headset, and Android prefers headsets for both calls and media. That behavior is perfectly reasonable in itself; it’s just that this “headset” is for the person on the other end of the call.
The fix takes three steps together:
- The bridge pins the built-in speaker as both the communication device and the audio track’s preferred device;
- After we claim the USB interfaces, the sound card no longer exists in the system;
- But Android’s audio framework doesn’t notice that the driver has been unloaded. It keeps sending audio to a headset that no longer exists until the device re-enumerates. So you need to turn on “disable USB audio routing” and let the dongle re-enumerate once.
Step 3 is where that system setting from earlier comes from. This class of problem, “the framework cached something that has already disappeared”, has come up more than once across the series.
The other gotchas
Dialing cancelled its own voice route
Symptom: The call connected, but the screen showed a strange message: some operation failed “because the coroutine scope left the composition”. The log said “starting to dial without a voice route”, and there was no audio.
Cause: Every button launched its work in the UI’s own coroutine scope. Dialing switches to the in-call screen, the dial pad leaves the composition, and its scope gets cancelled, taking the half-built voice route down with it. Worse, the routing code reported “cancelled” as an ordinary failure, so the error message pointed nowhere near the real cause.
Fix: All module operations run in a scope that lives as long as the process, and cancellation exceptions must be rethrown as-is, never swallowed as failures.
This is a very easy mistake to make on Android and Compose: the lifecycle of the UI and the lifecycle of the work are two different things, and if you bind them wrongly, the work destroys itself the moment the user acts.
The driver was pushed, but the app said it couldn’t find it
Cause: The directory was created from the command line before the app’s first run, so it was owned by the shell user, and the app couldn’t read files in its own directory.
Fix: Run the app once so it creates the directory itself, then push; or just use the in-app import.
Command replies were treated as unsolicited notifications
An old bug found during the port: the Mac version handed every line that “looks like a notification” to the notification handler, even when it was precisely the reply to the command in flight. So on the Mac, querying SIM status always appeared to come back empty.
The tablet version’s approach: if a line’s prefix matches the command currently in flight, it’s a reply and stays with the reply.
(Incidentally, the Mac version still has this bug. By the seventh post of a project, there is always something in the “known but not yet fixed” pile.)
The module object also has a second lock, for multi-command sequences: the SMS flow switches character sets midway, and if a poll slips in at that moment it will read UCS2 hex as plain text.
Only IPv6 on the tablet in internet mode
Symptom: Right after switching to ECM mode, the tablet got the carrier’s IPv6 but no IPv4, and couldn’t reach IPv4-only services. After a while it fixed itself.
Cause: As soon as the network interface appears, the kernel configures IPv6 on its own; IPv4 relies on DHCP, and the module answers DHCP only after its own data connection is up. Ask too early and Android stays stuck in IPv6-only until it retries on its own.
Fix: Nothing can be done on the module side. When the program detects this state, the network page prompts the user to unplug and replug once. In the most recent test, IPv4 was up 31 seconds after tapping the button.
Two SMS gotchas inherited from the gateway
- Incoming call and new SMS notifications go to the USB AT port → fall back to polling, and where the config can be changed, set the notification port to “all”.
- A full SIM rejects new SMS → every sweep first saves messages locally on the tablet, and only then deletes them from the SIM. Do it in the wrong order and you lose messages.
One number, two conversations
You send to 138…, the reply comes back from +86138…, and a second conversation opens. We fold the country code prefix uniformly, across incoming, outgoing, call history and stored entries. Contact matching uses the same rules.
While the tablet holds the module, a computer can’t debug the module
With the dongle plugged into the tablet, its debug interface belongs exclusively to the app. That makes debugging awkward.
Fix: Add a permission-protected debug receiver to the app (only shell and system can invoke it) that forwards commands over the app’s own connection:
B="adb shell am broadcast -n <package>/.DebugReceiver -a <package>.DEBUG"
$B --es shell 'cat /proc/asound/cards' # run a command inside the module
$B --es at 'AT+CLCC' # send one AT command
$B --es dial 10086 / $B --es hangup 1 # go through the real dial/hang-up path
$B --es route 1 # build the voice route
$B --es usbdesc 1 # show interface and endpoint descriptors
adb logcat -s VoHiveDebug AudioBridge UsbAudio VoiceRoute
The audio bridge logs volume, peak and byte counts in both directions every second. Every audio problem above was diagnosed from those few numbers; not one was guessed by reading code.
Leaving a debug channel into a device you can’t even reach yourself looks like a waste of time early on. In practice it was the highest-return investment in this whole project.
Other features
- Two modes, not four: The module supports four networking modes, but only two make sense on the tablet: ECM (Android treats it as USB Ethernet), called “internet mode”, and QMI (Android can’t drive it), called “calls and SMS mode”. Switching reboots the module; the app expects the disconnect and reconnects automatically after re-enumeration, which takes about 30 seconds.
- State is owned by the tablet: SMS and call history are stored in the app’s private directory and held by a process-level controller. So switching modes, which reboots the module and disconnects and reconnects it, loses nothing.
- Contacts: Reads the system contacts and shows names in call history, conversations, the incoming-call screen and notifications; handles
tel:links, so tapping a number in the system contacts app dials out through it; unknown numbers can be handed to the system contacts app to save in one tap. It never writes to contacts itself.
Not done yet
I’m writing these down because the distance between “not done yet” and “done” is usually longer than it looks:
| Issue | Status |
|---|---|
| Uplink with a real person talking | Capture is running and byte counts are correct, but in a quiet room the volume after noise suppression is close to 0; the far end hasn’t yet confirmed hearing a voice |
| Real incoming calls | Detection, ringtone, full-screen UI and answering are all implemented, but not yet verified with a real incoming call |
| Long SMS | Segments show up as multiple bubbles; reassembly requires switching to PDU mode |
| Echo cancellation quality | Loudspeaker plus system echo cancellation, not yet evaluated in a real conversation |
| System telephony integration | Not hooked into Android’s telephony framework; rings using its own notification and full-screen UI |
After seven posts
The same dongle, four platforms, four completely different ways to drive it:
| Platform | Control channel | Call audio | Biggest gotcha |
|---|---|---|---|
| Raspberry Pi | Serial AT (fixed names via udev) | ALSA reading the USB sound card | Rebuilding the route for every call; the Wi-Fi calling stack |
| Mac | adb into the module | CoreAudio aggregate device | Clock domain contamination, mandatory signing |
| iPhone | HTTPS via the gateway | WebSocket PCM | CallKit lifecycle |
| Android tablet | The app’s own adb implementation | Native isochronous USB transfers | One recording per app |
Looking back, only five lessons kept recurring:
1. “Ready” must be confirmed out of band. A ready derived from an empty condition, a status endpoint with all four flags true that still couldn’t place a call, a sound card whose device node exists but reads nothing but zeros: status values are written by your own code; the facts have to be checked somewhere else.
2. When one shared underlying resource is read by multiple consumers, each loses half. Losing half the voice, losing half the events, two reader processes splitting the AT replies between them: three faces of the same bug. The way to find it is to bury a counter at each of two layers of the data path.
3. Don’t infer the other side’s policy from silence. I once wrote down “this is a carrier subscription problem”; in reality my own registration message was missing a header. Print the messages and check them line by line against the spec.
4. Don’t infer anything from a recording you can’t understand. First make sure you dialed the right number.
5. During a migration, a patch without test coverage is a patch you will lose. The same issue of incoming calls going to voicemail got fixed twice.
An accessory that sells for under a hundred yuan secondhand, with a complete LTE module inside. That is probably the thing most worth saying about this series: a lot of hardware that looks closed is simply hardware nobody has asked what it is.
The whole series
- What Is It, Really
- An SMS and eSIM Gateway on a Raspberry Pi
- VoWiFi from Scratch
- USB Handsets, Browser Calls and an ESP32
- On a Mac
- The iPhone Client
- An Android Tablet Drives It Directly (this post)
This series is a record of personal learning and technical research. The module’s voice driver is a GPL derivative; it is not distributed with the project and you need to provide it yourself. Please comply with local laws and regulations and your carrier’s terms of service.
Comments