Pick several audio sources at once, with the apps' own icons

The phone had no way to choose which apps a stream carries: the
studio's audio picker added one source and closed, and Android's app
list had names only. The picker now marks what is mixed in already
(stream.audio_sources) and switches a source on or off with a tap, so
several apps (and the microphone, desktop audio, test tones) are picked
in one go; Done closes it. Android's launchable apps come with their
icons: Kotlin draws each app's icon once per installed version into a
96 px PNG in the cache and hands over its path (AudioApp::icon), which
the picker shows. The shared window's audio is not offered on Android,
which shares the whole screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 18:30:04 +03:00
1 parent 1eabbb4704
commit ecb0e11668
7 files changed
+144 -47

No files matched your search

@@ -4,7 +4,11 @@ import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import java.io.File
/**
* What the Rust library (crates/voelin-android/src/bridge.rs) calls, from any
@@ -88,7 +92,10 @@ object Bridge {
ScreenCaptureService.stopInput(id)
}
/** Launchable apps other than us, as "label<TAB>package" lines sorted by label. */
/**
* Launchable apps other than us, as "label<TAB>package<TAB>icon" lines
* sorted by label; the icon is a PNG in our cache (empty if it has none).
*/
@JvmStatic
fun launchableApps(): String {
val pm = app.packageManager
@@ -100,12 +107,37 @@ object Bridge {
pm.queryIntentActivities(launcher, 0)
}
val separators = Regex("[\t\n]")
val icons = File(app.cacheDir, "app-icons").apply { mkdirs() }
return activities
.map { it.activityInfo.packageName to it.loadLabel(pm).toString() }
.filter { it.first != app.packageName }
.distinctBy { it.first }
.sortedBy { it.second.lowercase() }
.joinToString("\n") { (packageName, label) -> label.replace(separators, " ") + "\t" + packageName }
.filter { it.activityInfo.packageName != app.packageName }
.distinctBy { it.activityInfo.packageName }
.map { Triple(it, it.activityInfo.packageName, it.loadLabel(pm).toString()) }
.sortedBy { it.third.lowercase() }
.joinToString("\n") { (info, packageName, label) ->
val icon = appIcon(pm, info, packageName, icons)?.path.orEmpty()
label.replace(separators, " ") + "\t" + packageName + "\t" + icon
}
}
private const val ICON_SIZE = 96
/** The app's icon as a PNG in `dir`, drawn once per installed version. */
private fun appIcon(pm: PackageManager, info: ResolveInfo, packageName: String, dir: File): File? {
val version = info.activityInfo.applicationInfo.sourceDir?.let { File(it).lastModified() } ?: 0L
val file = File(dir, "$packageName-$version.png")
if (file.exists()) return file
return try {
val bitmap = Bitmap.createBitmap(ICON_SIZE, ICON_SIZE, Bitmap.Config.ARGB_8888)
info.loadIcon(pm).apply { setBounds(0, 0, ICON_SIZE, ICON_SIZE) }.draw(Canvas(bitmap))
file.outputStream().use { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
bitmap.recycle()
// Icons of earlier versions.
dir.listFiles { f -> f.name.startsWith("$packageName-") && f.name != file.name }?.forEach { it.delete() }
file
} catch (e: Exception) {
file.delete()
null
}
}
/** The cameras, as CameraCapture.list describes them. */