Getting things ready…
Getting things ready…
An Android library that lets a call app record calls. Your app reports when a call starts and ends; the library records the audio to an .m4a file, and helps you list, play and clean up what it recorded.
CallRecorder recorder = new CallRecorder(context, outputDir, listener);
recorder.onCallActive("+911234567890", CallRecorder.OUT); // call connected
recorder.onCallEnded(); // call ended
recorder.release(); // onDestroy
Early release. Call-audio capture depends on the phone maker, and the library is not yet verified on many handsets. The microphone mode works everywhere; the call-stream modes need testing on your device. Reports of what works and what does not are very welcome.
Five steps from nothing to a recorded call. The library is Java and works from Kotlin too. Your app still asks the user for the RECORD_AUDIO permission at runtime, as any app that records audio must.
It is published through JitPack, so add that repository and the dependency.
// settings.gradle (or your root build.gradle)
repositories { maven { url 'https://jitpack.io' } }
// app/build.gradle
dependencies { implementation 'com.github.Youbal-oops:callrec:0.3.0' }
Give it a context, the folder to record into, and a listener that hears what happened. Use getExternalFilesDir("Recordings") for the folder: the recorder process can write there and other apps cannot read it.
// The app's own folder on shared storage. The shell-user recorder can write
// here, and other apps cannot read it.
String outputDir = getExternalFilesDir("Recordings").getAbsolutePath();
CallRecorder recorder = new CallRecorder(this, outputDir, new CallRecorder.Listener() {
@Override public void onRecordingStarted() { /* show a "recording" dot */ }
@Override public void onRecordingSaved(String path, String source, int seconds, int audiblePercent) {
// a finished .m4a is at path
}
@Override public void onRecordingSilent(String path, String source, int seconds, int audiblePercent) {
// a file was made but it is effectively silent: treat it as a failed capture
}
@Override public void onShizukuUnavailable() { /* send the user to your setup screen */ }
@Override public void onError(String message) { /* log or show it */ }
});
// Optional: choose how to record (default is Mode.AUTO)
// new CallRecorder(this, outputDir, listener, CallRecorder.Mode.BUILTIN);
The library does not watch calls itself. Your app is the one that knows, usually from an InCallService, so it reports when the call connects and when it ends.
// Say when the call connects. Direction is CallRecorder.IN, OUT or UNKNOWN.
recorder.onCallActive("+911234567890", CallRecorder.OUT);
// Say when it ends. The recording is saved and your listener is told.
recorder.onCallEnded();
// When the service or activity that owns the recorder goes away.
recorder.release();
This is how the reference app does it, only starting once the call is really connected:
// From Callrec Phone's InCallService: start once the call is actually connected.
if (call.getState() != Call.STATE_ACTIVE) return;
recorder.onCallActive(numberOf(call), incoming(call) ? CallRecorder.IN : CallRecorder.OUT);
Recording both sides of a call needs a one-time setup on the phone. Ask the library where the user is, then show the right next step. See Setup state below.
List what was recorded, show sizes, delete one, or clear out old ones. See Recordings below.
Android only lets system apps capture the other person's voice during a call. The library offers four ways to record, and Mode.AUTO (the default) picks the best one that is available: the Shizuku app, then built-in access, then the microphone.
| Mode | What it needs | What it hears |
|---|---|---|
| AUTO | Nothing in particular; it picks from the rows below | The best available |
| SHIZUKU | The Shizuku app installed and started, and your app authorised in it | Both sides, on any audio route (earpiece, speaker, headset) |
| BUILTIN | A one-time pairing with the phone's own wireless debugging (Android 11+), then Start after each restart | Both sides, with no other app |
| MIC | Only RECORD_AUDIO | The far side only on speakerphone; headsets bypass the mic |
The simple fallback. Always available, but it can only hear the other person when the phone is on speaker.
Records through Shizuku's shell-user service. It cannot be embedded, because Android does not let an app grant itself that access, so it is installed once, separately.
The same idea as Shizuku, built into the library. It pairs with the phone's own wireless debugging and starts a small recorder process itself.
CallRecorderSetup answers “what should I tell the user to do next?”, so your setup screen can show the right step instead of a generic “Shizuku not ready”. All calls are safe on the main thread.
switch (CallRecorderSetup.state(context)) {
case NOT_INSTALLED: // offer CallRecorderSetup.shizukuIntent(context); mic mode still works
case NOT_RUNNING: // wireless debugging, then Start in Shizuku (again after every reboot)
case NEEDS_PERMISSION: // CallRecorderSetup.requestPermission(requestCode)
case READY: // call audio can be recorded
}
Also available: isShizukuInstalled, shizukuIntent (opens Shizuku, or its download page) and guideIntent (Shizuku's own setup guide).
BuiltinAccess records call audio without the Shizuku app. It pairs once with the phone's own wireless debugging (Android 11+) using the six-digit code the phone shows, then starts a small recorder process as the shell user. CallRecorder talks to that process through a few files in your app's own folder.
BuiltinAccess.state(context); // UNSUPPORTED, NOT_PAIRED, STOPPED, RUNNING
BuiltinAccess.discoverPairing(context, listener); // reports the port of the "pair with code" dialog
BuiltinAccess.pair(context, port, "123456", listener); // pairs, then starts the recorder
BuiltinAccess.start(context, listener); // after a restart (wireless debugging must be on)
BuiltinAccess.stop(context); BuiltinAccess.forget(context);
discoverPairing.pair, which pairs and starts the recorder.start again with wireless debugging on. state() tells you when to show a “start again” button.RecordingStore reads the folder you record into. It only ever touches files named by this library, so it is safe to point at a shared folder.
RecordingStore store = new RecordingStore(outputDir);
for (RecordingInfo r : store.list()) { // newest first
r.direction; r.number; r.startedAt; r.sizeBytes; r.file;
}
store.totalBytes();
store.delete(recording);
store.deleteOlderThan(30, System.currentTimeMillis()); // days <= 0 keeps everything
Every file is named {in|out|call}_{number}_{yyyyMMdd-HHmmss}.m4a, and RecordingInfo.parse reads that back into a direction, number, start time and size. Audio is encoded as 16 kHz mono AAC.
For the curious, and for anyone auditing it. The built-in recorder is a separate process the app starts over the phone's own wireless debugging, so it runs as the shell user, which is what lets it capture call audio.
your app this phone, as the shell user
┌─────────────────┐ a few files in your ┌────────────────────────┐
│ CallRecorder │ app's own folder │ ShellServer │
│ └ Builtin │ ──► cmd token/id/verb ──► └ RecorderService │
│ Recorder │ ◄── res id/answer │ · tries audio │
│ │ ◄── alive a time, 1/sec │ sources in order │
└─────────────────┘ │ · drops one that │
│ opens but is mute│
no sockets, no binder, no hidden APIs │ · encodes 16 kHz │
in the channel itself │ mono AAC (.m4a) │
└────────────────────────┘
| Class | Job |
|---|---|
| CallRecorder | The facade. Your app calls onCallActive and onCallEnded; it picks an engine and reports to your listener. |
| MicRecorder | Records the device microphone in-process. |
| ShizukuRecorder | Client for RecorderService, which runs in the Shizuku process under the shell identity. |
| BuiltinRecorder | Records through the ShellServer that BuiltinAccess started. |
| RecorderService | Runs as the shell user. Tries audio sources in order, drops one that opens but stays silent, and encodes the winner. Audio read while probing is kept, so the opening words are not lost. |
| ShellServer | The recorder process for built-in access. Runs RecorderService and is reached through ControlChannel files instead of binder. |
| ControlChannel | How the app talks to that process: cmd, res and alive files in a folder both can reach. One request is in flight at a time. |
| AdbKeys / AdbManager | The identity this phone presents to its own wireless debugging, created once and kept in the app's private storage, and the connection that uses it. |
| RecordingStore / RecordingInfo | List, delete and expire the recordings. |
CLASSPATH=base.apk app_process /system/bin --nice-name=callrec_server \
dev.youbal.callrec.lib.ShellServer DIR TOKEN APK
Requests to the recorder carry a random secret kept in the app's private storage, so another app on the phone cannot give it orders.
The library declares what it needs and merges it into your app. It talks only to 127.0.0.1 and discovers the local pairing dialog; nothing in it contacts any other server.
| Dependency | Version | Licence / note |
|---|---|---|
| Shizuku api + provider | 13.1.5 | MIT (RikkaApps). Client only; the Shizuku app is installed separately |
| libadb-android | 3.1.1 | Apache-2.0 option |
| spake2-android | via libadb-android | LGPL-3.0, used unmodified |
| Conscrypt | 2.5.3 | Apache-2.0 |
| Bouncy Castle (bcprov) | 1.81 | MIT |
| Permission | Why |
|---|---|
| RECORD_AUDIO | Recording. Your app requests it at runtime. |
| moe.shizuku.manager.permission.API_V23 | Talking to the Shizuku app. |
| INTERNET | Android requires it for any socket, even one to the phone itself. Used only for 127.0.0.1. |
| ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, CHANGE_WIFI_MULTICAST_STATE | Finding the local pairing dialog for built-in access. |
Whether call audio can be captured at all depends on the phone maker. Not yet verified on many handsets, so test on yours.
Like Shizuku, the recorder process does not survive a restart. Wireless debugging has to be on, with Wi-Fi connected, while it is started again.
ShellContext reports itself as com.android.shell using hidden ActivityThread APIs through reflection, so it may break on future Android versions.
Recording and the law. Recording calls may require the consent of all parties. You are responsible for complying with applicable law, and for telling people when you record them.
STACK
Measured from the project's own source: 23 files.
Libraries & tools