wip: Android Gradle project, crash reports, docs, CI job, notices
This commit is contained in:
1 parent
47b7e02e81
commit
1b95e8b504
35 files changed
+1590
-9
No files matched your search
@@ -0,0 +1,6 @@
|
||||
.gradle/
|
||||
.kotlin/
|
||||
build/
|
||||
local.properties
|
||||
*.jks
|
||||
*.keystore
|
||||
@@ -0,0 +1,129 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
}
|
||||
|
||||
/** The Cargo workspace the native library comes from. */
|
||||
val workspace: File = rootDir.parentFile
|
||||
|
||||
/** `version` of crates/tsc-android, which is the app's version (docs/release.md). */
|
||||
val crateVersion: String = workspace.resolve("crates/tsc-android/Cargo.toml").readLines()
|
||||
.first { it.startsWith("version = ") }
|
||||
.substringAfter('"').substringBefore('"')
|
||||
|
||||
/** The version of `crate` in Cargo.lock. */
|
||||
fun lockedVersion(crate: String): String {
|
||||
val lines = workspace.resolve("Cargo.lock").readLines()
|
||||
val at = lines.indexOfFirst { it == "name = \"$crate\"" }
|
||||
require(at >= 0) { "$crate is not in Cargo.lock" }
|
||||
return lines[at + 1].substringAfter('"').substringBefore('"')
|
||||
}
|
||||
|
||||
/**
|
||||
* A release signing setting: a Gradle property (e.g. in
|
||||
* ~/.gradle/gradle.properties) or an environment variable (CI secrets).
|
||||
* Never stored in the repository.
|
||||
*/
|
||||
fun signing(property: String, env: String): String? =
|
||||
providers.gradleProperty(property).orElse(providers.environmentVariable(env)).orNull
|
||||
|
||||
val releaseStoreFile = signing("tsc.signing.storeFile", "TSC_SIGNING_STORE_FILE")
|
||||
|
||||
android {
|
||||
namespace = "io.github.faumaray.tsc"
|
||||
compileSdk = 36
|
||||
ndkVersion = "27.3.13750724"
|
||||
|
||||
defaultConfig {
|
||||
// Placeholder like the desktop app id (packaging/README.md); it cannot
|
||||
// change after the first upload to Google Play.
|
||||
applicationId = "io.github.faumaray.TsClient"
|
||||
minSdk = 29
|
||||
targetSdk = 36
|
||||
versionName = crateVersion
|
||||
// major * 1000000 + minor * 1000 + patch (docs/release.md).
|
||||
versionCode = crateVersion.split('.').map(String::toInt)
|
||||
.let { (major, minor, patch) -> major * 1_000_000 + minor * 1_000 + patch }
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
if (releaseStoreFile != null) {
|
||||
create("release") {
|
||||
storeFile = file(releaseStoreFile)
|
||||
storePassword = signing("tsc.signing.storePassword", "TSC_SIGNING_STORE_PASSWORD")
|
||||
keyAlias = signing("tsc.signing.keyAlias", "TSC_SIGNING_KEY_ALIAS")
|
||||
keyPassword = signing("tsc.signing.keyPassword", "TSC_SIGNING_KEY_PASSWORD")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
// Unsigned without the signing settings.
|
||||
signingConfig = signingConfigs.findByName("release")
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
packaging {
|
||||
// Stored uncompressed and page-aligned, loaded straight from the APK.
|
||||
jniLibs.useLegacyPackaging = false
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget.set(JvmTarget.JVM_17)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Must be the version of the rustls-platform-verifier-android crate.
|
||||
implementation("org.rustls:rustls-platform-verifier:${lockedVersion("rustls-platform-verifier-android")}")
|
||||
}
|
||||
|
||||
// libtsc_android.so, built with cargo-ndk into build/rust/<build type>/<abi>/
|
||||
// before the JNI libraries are merged. -Ptsc.skipCargo=true uses what is
|
||||
// there (e.g. built by CI in an earlier step).
|
||||
val abis = providers.gradleProperty("tsc.abis").getOrElse("arm64-v8a,x86_64")
|
||||
.split(',').map(String::trim).filter(String::isNotEmpty)
|
||||
val skipCargo = providers.gradleProperty("tsc.skipCargo").map(String::toBoolean).getOrElse(false)
|
||||
|
||||
for ((buildType, release) in listOf("debug" to false, "release" to true)) {
|
||||
val out = layout.buildDirectory.dir("rust/$buildType")
|
||||
val name = buildType.replaceFirstChar(Char::uppercase)
|
||||
val cargo = tasks.register<Exec>("cargoBuild$name") {
|
||||
group = "build"
|
||||
description = "Builds the Rust library for $abis with cargo-ndk ($buildType)."
|
||||
workingDir = workspace
|
||||
val command = mutableListOf("cargo", "ndk", "--platform", "29", "-o", out.get().asFile.path)
|
||||
abis.forEach { command += listOf("-t", it) }
|
||||
command += listOf("build", "-p", "tsc-android")
|
||||
if (release) command += "--release"
|
||||
commandLine(command)
|
||||
val ndk = android.ndkDirectory.path
|
||||
environment("ANDROID_NDK_HOME", ndk)
|
||||
// CMake (the bundled libopus) finds the NDK through this one.
|
||||
environment("ANDROID_NDK_ROOT", ndk)
|
||||
environment("ANDROID_HOME", android.sdkDirectory.path)
|
||||
// Slint compiles its Java helper against this.
|
||||
environment(
|
||||
"ANDROID_JAR",
|
||||
android.sdkDirectory.resolve("platforms/android-${android.compileSdk}/android.jar").path,
|
||||
)
|
||||
}
|
||||
android.sourceSets.getByName(buildType).jniLibs.srcDir(out)
|
||||
if (!skipCargo) {
|
||||
tasks.configureEach {
|
||||
if (this.name == "merge${name}JniLibFolders") dependsOn(cargo)
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
# Called from Rust through JNI by name.
|
||||
-keep class io.github.faumaray.tsc.Bridge { *; }
|
||||
-keep class io.github.faumaray.tsc.Native { *; }
|
||||
-keep class io.github.faumaray.tsc.TscApp { *; }
|
||||
|
||||
# rustls-platform-verifier's Kotlin component, also called from Rust.
|
||||
-keep class org.rustls.platformverifier.** { *; }
|
||||
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!-- Voice, and capturing what the device plays while sharing the screen. -->
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<!-- Slint renders with OpenGL ES. -->
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
|
||||
|
||||
<!--
|
||||
allowBackup=false: the database holds the TeamSpeak identity (a
|
||||
private key) and the Keystore key of the saved passwords cannot be
|
||||
restored on another device anyway.
|
||||
-->
|
||||
<application
|
||||
android:name=".TscApp"
|
||||
android:allowBackup="false"
|
||||
android:hasCode="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Tsc">
|
||||
|
||||
<!--
|
||||
The Rust UI runs in this NativeActivity (android.app.lib_name).
|
||||
Configuration changes (rotation, keyboard, dark mode) are handled
|
||||
by the native side instead of recreating the activity.
|
||||
-->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboard|keyboardHidden|navigation|uiMode|density|fontScale|locale|layoutDirection"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="tsc_android" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Keeps the microphone and the connection while in the background. -->
|
||||
<service
|
||||
android:name=".VoiceService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="microphone" />
|
||||
|
||||
<!-- Holds the MediaProjection while the screen is shared. -->
|
||||
<service
|
||||
android:name=".ScreenCaptureService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="mediaProjection" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,74 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
|
||||
/**
|
||||
* What the Rust library (crates/tsc-android/src/bridge.rs) calls, from any
|
||||
* thread. Keep the names and signatures in step with it.
|
||||
*/
|
||||
object Bridge {
|
||||
private val app: TscApp get() = TscApp.instance
|
||||
|
||||
@JvmStatic
|
||||
fun context(): Context = app
|
||||
|
||||
/** Ask for the microphone (voice) and notification (services) permissions. */
|
||||
@JvmStatic
|
||||
fun requestPermissions() {
|
||||
val activity = MainActivity.current?.get() ?: return
|
||||
val wanted = buildList {
|
||||
add(Manifest.permission.RECORD_AUDIO)
|
||||
if (Build.VERSION.SDK_INT >= 33) add(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}.filter { activity.checkSelfPermission(it) != PackageManager.PERMISSION_GRANTED }
|
||||
if (wanted.isNotEmpty()) {
|
||||
activity.runOnUiThread { activity.requestPermissions(wanted.toTypedArray(), 1) }
|
||||
}
|
||||
}
|
||||
|
||||
/** Run the voice service with this notification text; null stops it. */
|
||||
@JvmStatic
|
||||
fun setVoiceNotification(text: String?) {
|
||||
if (text == null) VoiceService.stop(app) else VoiceService.start(app, text)
|
||||
}
|
||||
|
||||
/** Ask the user to share the screen; the answer goes to Native.onScreenCaptureResult. */
|
||||
@JvmStatic
|
||||
fun requestScreenCapture(fps: Int, maxSize: Int) {
|
||||
val activity = MainActivity.current?.get()
|
||||
if (activity == null) {
|
||||
Native.onScreenCaptureResult(false, "the app is not in the foreground")
|
||||
return
|
||||
}
|
||||
activity.runOnUiThread { activity.requestScreenCapture(fps, maxSize) }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun stopScreenCapture() {
|
||||
ScreenCaptureService.stop(app)
|
||||
}
|
||||
|
||||
/** Capture what the device plays; false without a running screen capture. */
|
||||
@JvmStatic
|
||||
fun startSystemAudio(): Boolean = ScreenCaptureService.startAudio()
|
||||
|
||||
@JvmStatic
|
||||
fun stopSystemAudio() {
|
||||
ScreenCaptureService.stopAudio()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun secretGet(key: String): String? = SecretStore.get(app, key)
|
||||
|
||||
@JvmStatic
|
||||
fun secretSet(key: String, value: String) {
|
||||
SecretStore.set(app, key, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun secretDelete(key: String) {
|
||||
SecretStore.delete(app, key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import android.app.NativeActivity
|
||||
import android.content.Intent
|
||||
import android.media.projection.MediaProjectionManager
|
||||
import android.os.Bundle
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
/**
|
||||
* The window: a NativeActivity running `android_main` of libtsc_android.so
|
||||
* (the Slint UI). Kotlin only handles what needs an Activity: permission
|
||||
* prompts and the screen-capture consent dialog.
|
||||
*/
|
||||
class MainActivity : NativeActivity() {
|
||||
private var captureFps = 30
|
||||
private var captureMaxSize = 1920
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
current = WeakReference(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (current?.get() === this) current = null
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
/**
|
||||
* Back leaves the app like Home instead of finishing the activity, so the
|
||||
* window (and its state) stays while voice goes on in the background.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onBackPressed() {
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
|
||||
/** Show the system's "start recording or casting?" dialog. */
|
||||
fun requestScreenCapture(fps: Int, maxSize: Int) {
|
||||
captureFps = fps
|
||||
captureMaxSize = maxSize
|
||||
val manager = getSystemService(MediaProjectionManager::class.java)
|
||||
@Suppress("DEPRECATION")
|
||||
startActivityForResult(manager.createScreenCaptureIntent(), REQUEST_SCREEN_CAPTURE)
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
@Suppress("DEPRECATION")
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode != REQUEST_SCREEN_CAPTURE) return
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
// The service reports the outcome to Native.onScreenCaptureResult.
|
||||
ScreenCaptureService.start(this, resultCode, data, captureFps, captureMaxSize)
|
||||
} else {
|
||||
Native.onScreenCaptureResult(false, null)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val REQUEST_SCREEN_CAPTURE = 1001
|
||||
|
||||
/** The activity in front, if any. */
|
||||
@Volatile
|
||||
var current: WeakReference<MainActivity>? = null
|
||||
private set
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
/** Callbacks into the Rust library (crates/tsc-android/src/bridge.rs). */
|
||||
object Native {
|
||||
init {
|
||||
// Already loaded by the NativeActivity; this registers it for JNI
|
||||
// lookups from this class loader.
|
||||
System.loadLibrary("tsc_android")
|
||||
}
|
||||
|
||||
/** The user answered the screen-capture dialog (`error`: why it failed). */
|
||||
@JvmStatic
|
||||
external fun onScreenCaptureResult(granted: Boolean, error: String?)
|
||||
|
||||
/** An RGBA_8888 frame. Returns false when frames are no longer wanted. */
|
||||
@JvmStatic
|
||||
external fun onScreenFrame(
|
||||
pixels: ByteBuffer,
|
||||
width: Int,
|
||||
height: Int,
|
||||
rowStride: Int,
|
||||
timestampNs: Long,
|
||||
): Boolean
|
||||
|
||||
/** The projection ended (by the app, the user or the system). */
|
||||
@JvmStatic
|
||||
external fun onScreenCaptureStopped()
|
||||
|
||||
/**
|
||||
* `count` interleaved 48 kHz float samples of what the device plays.
|
||||
* Returns false when audio is no longer wanted.
|
||||
*/
|
||||
@JvmStatic
|
||||
external fun onSystemAudio(samples: FloatArray, count: Int, channels: Int, timestampNs: Long): Boolean
|
||||
|
||||
/** "Disconnect" in the voice notification. */
|
||||
@JvmStatic
|
||||
external fun onDisconnectVoice()
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
/** Notification channels and the notifications of the foreground services. */
|
||||
object Notifications {
|
||||
const val CHANNEL_VOICE = "voice"
|
||||
const val CHANNEL_SCREEN = "screen"
|
||||
|
||||
fun createChannels(context: Context) {
|
||||
val manager = context.getSystemService(NotificationManager::class.java)
|
||||
manager.createNotificationChannel(
|
||||
NotificationChannel(
|
||||
CHANNEL_VOICE,
|
||||
context.getString(R.string.channel_voice),
|
||||
NotificationManager.IMPORTANCE_LOW,
|
||||
),
|
||||
)
|
||||
manager.createNotificationChannel(
|
||||
NotificationChannel(
|
||||
CHANNEL_SCREEN,
|
||||
context.getString(R.string.channel_screen),
|
||||
NotificationManager.IMPORTANCE_LOW,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/** Tapping a notification brings the app back. */
|
||||
private fun openApp(context: Context): PendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
Intent(context, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT),
|
||||
PendingIntent.FLAG_IMMUTABLE,
|
||||
)
|
||||
|
||||
fun ongoing(
|
||||
context: Context,
|
||||
channel: String,
|
||||
text: String,
|
||||
actionTitle: String,
|
||||
action: PendingIntent,
|
||||
): Notification = Notification.Builder(context, channel)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getString(R.string.app_name))
|
||||
.setContentText(text)
|
||||
.setContentIntent(openApp(context))
|
||||
.setOngoing(true)
|
||||
.setCategory(Notification.CATEGORY_CALL)
|
||||
.addAction(Notification.Action.Builder(null, actionTitle, action).build())
|
||||
.build()
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import android.Manifest
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ServiceInfo
|
||||
import android.graphics.PixelFormat
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.hardware.display.VirtualDisplay
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioFormat
|
||||
import android.media.AudioPlaybackCaptureConfiguration
|
||||
import android.media.AudioRecord
|
||||
import android.media.ImageReader
|
||||
import android.media.projection.MediaProjection
|
||||
import android.media.projection.MediaProjectionManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.Display
|
||||
import android.view.Surface
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Screen sharing: holds the MediaProjection (a `mediaProjection` foreground
|
||||
* service, as Android requires), mirrors the display into an ImageReader and
|
||||
* hands each RGBA frame to Native.onScreenFrame; optionally captures what the
|
||||
* device plays (AudioPlaybackCapture) for Native.onSystemAudio.
|
||||
*/
|
||||
class ScreenCaptureService : Service() {
|
||||
private var projection: MediaProjection? = null
|
||||
private var display: VirtualDisplay? = null
|
||||
private var reader: ImageReader? = null
|
||||
private var worker: HandlerThread? = null
|
||||
|
||||
@Volatile
|
||||
private var audioRunning = false
|
||||
private var audioThread: Thread? = null
|
||||
|
||||
private val main = Handler(Looper.getMainLooper())
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (intent == null || intent.action == ACTION_STOP) {
|
||||
stopSelf()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
if (projection != null) return START_NOT_STICKY
|
||||
val stop = PendingIntent.getService(
|
||||
this,
|
||||
0,
|
||||
Intent(this, ScreenCaptureService::class.java).setAction(ACTION_STOP),
|
||||
PendingIntent.FLAG_IMMUTABLE,
|
||||
)
|
||||
val notification = Notifications.ongoing(
|
||||
this,
|
||||
Notifications.CHANNEL_SCREEN,
|
||||
getString(R.string.screen_sharing),
|
||||
getString(R.string.stop_sharing),
|
||||
stop,
|
||||
)
|
||||
try {
|
||||
// Must be in the foreground before getMediaProjection (Android 14).
|
||||
startForeground(ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION)
|
||||
val data = if (Build.VERSION.SDK_INT >= 33) {
|
||||
intent.getParcelableExtra(EXTRA_DATA, Intent::class.java)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
intent.getParcelableExtra(EXTRA_DATA)
|
||||
} ?: throw IllegalStateException("no projection data")
|
||||
val manager = getSystemService(MediaProjectionManager::class.java)
|
||||
val projection = manager.getMediaProjection(intent.getIntExtra(EXTRA_RESULT, 0), data)
|
||||
?: throw IllegalStateException("the projection was refused")
|
||||
this.projection = projection
|
||||
instance = this
|
||||
startVideo(projection, intent.getIntExtra(EXTRA_FPS, 30), intent.getIntExtra(EXTRA_MAX_SIZE, 1920))
|
||||
Native.onScreenCaptureResult(true, null)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "screen capture failed", e)
|
||||
Native.onScreenCaptureResult(false, e.message ?: e.toString())
|
||||
stopSelf()
|
||||
}
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
private fun startVideo(projection: MediaProjection, fps: Int, maxSize: Int) {
|
||||
val worker = HandlerThread("tsc-screen").also { it.start() }
|
||||
this.worker = worker
|
||||
val handler = Handler(worker.looper)
|
||||
// The user or the system can end the projection (status bar chip,
|
||||
// screen lock); registered before the virtual display (Android 14).
|
||||
projection.registerCallback(object : MediaProjection.Callback() {
|
||||
override fun onStop() {
|
||||
main.post { stopSelf() }
|
||||
}
|
||||
}, handler)
|
||||
|
||||
val metrics = resources.displayMetrics
|
||||
val screen = getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
|
||||
val mode = screen.mode
|
||||
// The mode is in the display's natural orientation; match the current
|
||||
// one. (Rotating while sharing letterboxes the picture.)
|
||||
val rotated = screen.rotation == Surface.ROTATION_90 || screen.rotation == Surface.ROTATION_270
|
||||
val (fullWidth, fullHeight) = if (rotated) {
|
||||
mode.physicalHeight to mode.physicalWidth
|
||||
} else {
|
||||
mode.physicalWidth to mode.physicalHeight
|
||||
}
|
||||
val scale = minOf(1.0, maxSize.toDouble() / max(fullWidth, fullHeight))
|
||||
// Even sizes, as video encoders want.
|
||||
val width = ((fullWidth * scale).roundToInt() / 2 * 2).coerceAtLeast(2)
|
||||
val height = ((fullHeight * scale).roundToInt() / 2 * 2).coerceAtLeast(2)
|
||||
|
||||
val reader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 3)
|
||||
this.reader = reader
|
||||
val interval = 1_000_000_000L / fps.coerceIn(1, 60)
|
||||
var last = 0L
|
||||
reader.setOnImageAvailableListener({ r ->
|
||||
val image = r.acquireLatestImage() ?: return@setOnImageAvailableListener
|
||||
try {
|
||||
// The display renders at its own rate; pass on at most `fps`.
|
||||
if (image.timestamp - last < interval) return@setOnImageAvailableListener
|
||||
last = image.timestamp
|
||||
val plane = image.planes[0]
|
||||
val wanted = Native.onScreenFrame(plane.buffer, image.width, image.height, plane.rowStride, image.timestamp)
|
||||
if (!wanted) main.post { stopSelf() }
|
||||
} finally {
|
||||
image.close()
|
||||
}
|
||||
}, handler)
|
||||
display = projection.createVirtualDisplay(
|
||||
"tsc-screen",
|
||||
width,
|
||||
height,
|
||||
metrics.densityDpi,
|
||||
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
|
||||
reader.surface,
|
||||
null,
|
||||
handler,
|
||||
)
|
||||
}
|
||||
|
||||
/** Capture media, game and unknown-usage playback as 48 kHz stereo float. */
|
||||
private fun startAudioCapture(): Boolean {
|
||||
val projection = projection ?: return false
|
||||
if (audioRunning) return true
|
||||
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||
return false
|
||||
}
|
||||
val config = AudioPlaybackCaptureConfiguration.Builder(projection)
|
||||
.addMatchingUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.addMatchingUsage(AudioAttributes.USAGE_GAME)
|
||||
.addMatchingUsage(AudioAttributes.USAGE_UNKNOWN)
|
||||
.build()
|
||||
val format = AudioFormat.Builder()
|
||||
.setEncoding(AudioFormat.ENCODING_PCM_FLOAT)
|
||||
.setSampleRate(SAMPLE_RATE)
|
||||
.setChannelMask(AudioFormat.CHANNEL_IN_STEREO)
|
||||
.build()
|
||||
val minimum = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_FLOAT)
|
||||
val record = try {
|
||||
AudioRecord.Builder()
|
||||
.setAudioFormat(format)
|
||||
.setAudioPlaybackCaptureConfig(config)
|
||||
// A tenth of a second.
|
||||
.setBufferSizeInBytes(max(minimum, SAMPLE_RATE / 10 * 2 * 4))
|
||||
.build()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "system audio capture unavailable", e)
|
||||
return false
|
||||
}
|
||||
audioRunning = true
|
||||
record.startRecording()
|
||||
audioThread = thread(name = "tsc-system-audio") {
|
||||
// 10 ms of stereo.
|
||||
val buffer = FloatArray(SAMPLE_RATE / 100 * 2)
|
||||
try {
|
||||
while (audioRunning) {
|
||||
val read = record.read(buffer, 0, buffer.size, AudioRecord.READ_BLOCKING)
|
||||
if (read < 0) break
|
||||
if (read > 0 && !Native.onSystemAudio(buffer, read, 2, System.nanoTime())) break
|
||||
}
|
||||
} finally {
|
||||
audioRunning = false
|
||||
record.stop()
|
||||
record.release()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun stopAudioCapture() {
|
||||
audioRunning = false
|
||||
audioThread?.join(500)
|
||||
audioThread = null
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (instance === this) instance = null
|
||||
stopAudioCapture()
|
||||
display?.release()
|
||||
display = null
|
||||
reader?.close()
|
||||
reader = null
|
||||
projection?.stop()
|
||||
projection = null
|
||||
worker?.quitSafely()
|
||||
worker = null
|
||||
Native.onScreenCaptureStopped()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "ScreenCaptureService"
|
||||
private const val ID = 2
|
||||
private const val SAMPLE_RATE = 48_000
|
||||
private const val ACTION_STOP = "io.github.faumaray.tsc.STOP_SHARING"
|
||||
private const val EXTRA_RESULT = "result"
|
||||
private const val EXTRA_DATA = "data"
|
||||
private const val EXTRA_FPS = "fps"
|
||||
private const val EXTRA_MAX_SIZE = "max_size"
|
||||
|
||||
@Volatile
|
||||
private var instance: ScreenCaptureService? = null
|
||||
|
||||
/** Start capturing with the consent the user just gave. */
|
||||
fun start(context: Context, resultCode: Int, data: Intent, fps: Int, maxSize: Int) {
|
||||
val intent = Intent(context, ScreenCaptureService::class.java)
|
||||
.putExtra(EXTRA_RESULT, resultCode)
|
||||
.putExtra(EXTRA_DATA, data)
|
||||
.putExtra(EXTRA_FPS, fps)
|
||||
.putExtra(EXTRA_MAX_SIZE, maxSize)
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
|
||||
fun stop(context: Context) {
|
||||
context.stopService(Intent(context, ScreenCaptureService::class.java))
|
||||
}
|
||||
|
||||
fun startAudio(): Boolean {
|
||||
val service = instance ?: return false
|
||||
return service.startAudioCapture()
|
||||
}
|
||||
|
||||
fun stopAudio() {
|
||||
instance?.stopAudioCapture()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import android.content.Context
|
||||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyProperties
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import java.security.KeyStore
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.spec.GCMParameterSpec
|
||||
|
||||
/**
|
||||
* Saved passwords (server, query), for the Rust side's `Secrets`.
|
||||
*
|
||||
* Each value is encrypted with AES-256-GCM under a key that never leaves the
|
||||
* Android Keystore (hardware-backed where available); the key name is the
|
||||
* associated data, so a value cannot be moved to another key. Only the
|
||||
* ciphertext is stored, in private preferences excluded from backups.
|
||||
*/
|
||||
object SecretStore {
|
||||
private const val TAG = "SecretStore"
|
||||
private const val KEYSTORE = "AndroidKeyStore"
|
||||
private const val KEY_ALIAS = "tsc-secrets"
|
||||
private const val PREFS = "secrets"
|
||||
private const val TRANSFORMATION = "AES/GCM/NoPadding"
|
||||
private const val IV_BYTES = 12
|
||||
private const val TAG_BITS = 128
|
||||
|
||||
private fun key(): SecretKey {
|
||||
val keyStore = KeyStore.getInstance(KEYSTORE).apply { load(null) }
|
||||
(keyStore.getKey(KEY_ALIAS, null) as? SecretKey)?.let { return it }
|
||||
val generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, KEYSTORE)
|
||||
generator.init(
|
||||
KeyGenParameterSpec.Builder(
|
||||
KEY_ALIAS,
|
||||
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT,
|
||||
)
|
||||
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
|
||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
||||
.setKeySize(256)
|
||||
.build(),
|
||||
)
|
||||
return generator.generateKey()
|
||||
}
|
||||
|
||||
private fun prefs(context: Context) = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
|
||||
/** The value, or null if none is saved or it cannot be decrypted. */
|
||||
@Synchronized
|
||||
fun get(context: Context, name: String): String? {
|
||||
val stored = prefs(context).getString(name, null) ?: return null
|
||||
return try {
|
||||
val bytes = Base64.decode(stored, Base64.NO_WRAP)
|
||||
val cipher = Cipher.getInstance(TRANSFORMATION)
|
||||
cipher.init(Cipher.DECRYPT_MODE, key(), GCMParameterSpec(TAG_BITS, bytes, 0, IV_BYTES))
|
||||
cipher.updateAAD(name.toByteArray())
|
||||
String(cipher.doFinal(bytes, IV_BYTES, bytes.size - IV_BYTES), Charsets.UTF_8)
|
||||
} catch (e: Exception) {
|
||||
// E.g. the key was lost (the device's lock screen was reset).
|
||||
Log.w(TAG, "cannot decrypt $name", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun set(context: Context, name: String, value: String) {
|
||||
val cipher = Cipher.getInstance(TRANSFORMATION)
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key())
|
||||
cipher.updateAAD(name.toByteArray())
|
||||
val sealed = cipher.iv + cipher.doFinal(value.toByteArray(Charsets.UTF_8))
|
||||
check(cipher.iv.size == IV_BYTES)
|
||||
prefs(context).edit().putString(name, Base64.encodeToString(sealed, Base64.NO_WRAP)).commit()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun delete(context: Context, name: String) {
|
||||
prefs(context).edit().remove(name).commit()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import android.app.Application
|
||||
|
||||
/** The process's application object; the Rust side reaches Android through it. */
|
||||
class TscApp : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
instance = this
|
||||
Notifications.createChannels(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
lateinit var instance: TscApp
|
||||
private set
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package io.github.faumaray.tsc
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ServiceInfo
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
|
||||
/**
|
||||
* Foreground service while a voice connection exists: Android keeps the
|
||||
* process, the network and (type microphone) the microphone of an app in
|
||||
* the background only this way. The Rust side starts, updates and stops it.
|
||||
*/
|
||||
class VoiceService : Service() {
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (intent?.action == ACTION_DISCONNECT) {
|
||||
Native.onDisconnectVoice()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
val text = intent?.getStringExtra(EXTRA_TEXT) ?: getString(R.string.voice_connected)
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
startForeground(ID, notification(this, text), ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE)
|
||||
} else {
|
||||
startForeground(ID, notification(this, text))
|
||||
}
|
||||
running = this
|
||||
} catch (e: RuntimeException) {
|
||||
// E.g. no microphone permission (Android 14 refuses the type):
|
||||
// voice then works only while the app is in front.
|
||||
Log.w(TAG, "voice service cannot run in the foreground", e)
|
||||
stopSelf()
|
||||
}
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (running === this) running = null
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "VoiceService"
|
||||
private const val ID = 1
|
||||
private const val EXTRA_TEXT = "text"
|
||||
private const val ACTION_DISCONNECT = "io.github.faumaray.tsc.DISCONNECT"
|
||||
|
||||
@Volatile
|
||||
private var running: VoiceService? = null
|
||||
|
||||
private fun notification(context: Context, text: String): Notification {
|
||||
val disconnect = PendingIntent.getService(
|
||||
context,
|
||||
0,
|
||||
Intent(context, VoiceService::class.java).setAction(ACTION_DISCONNECT),
|
||||
PendingIntent.FLAG_IMMUTABLE,
|
||||
)
|
||||
return Notifications.ongoing(
|
||||
context,
|
||||
Notifications.CHANNEL_VOICE,
|
||||
text,
|
||||
context.getString(R.string.disconnect),
|
||||
disconnect,
|
||||
)
|
||||
}
|
||||
|
||||
/** Start the service, or update its notification when it runs. */
|
||||
fun start(context: Context, text: String) {
|
||||
val service = running
|
||||
if (service != null) {
|
||||
service.getSystemService(NotificationManager::class.java)
|
||||
.notify(ID, notification(service, text))
|
||||
return
|
||||
}
|
||||
try {
|
||||
context.startForegroundService(
|
||||
Intent(context, VoiceService::class.java).putExtra(EXTRA_TEXT, text),
|
||||
)
|
||||
} catch (e: RuntimeException) {
|
||||
// Not allowed from the background (Android 12+). Voice is
|
||||
// connected from the UI, so this should not happen.
|
||||
Log.w(TAG, "cannot start the voice service", e)
|
||||
}
|
||||
}
|
||||
|
||||
fun stop(context: Context) {
|
||||
context.stopService(Intent(context, VoiceService::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Placeholder icon (packaging/linux/io.github.faumaray.TsClient.svg): a
|
||||
speech bubble with sound waves, sized for the adaptive icon's safe zone.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="128"
|
||||
android:viewportHeight="128">
|
||||
<group
|
||||
android:pivotX="64"
|
||||
android:pivotY="64"
|
||||
android:scaleX="0.8"
|
||||
android:scaleY="0.8"
|
||||
android:translateY="-5">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M36,40h56a8,8 0,0 1,8 8v28a8,8 0,0 1,-8 8H60l-16,14v-14h-8a8,8 0,0 1,-8 -8V48a8,8 0,0 1,8 -8z" />
|
||||
<path
|
||||
android:pathData="M52,56v12M64,50v24M76,56v12"
|
||||
android:strokeWidth="5"
|
||||
android:strokeColor="#FF238636"
|
||||
android:strokeLineCap="round" />
|
||||
</group>
|
||||
</vector>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Monochrome speech bubble with sound waves (status bar, themed icon). -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="128"
|
||||
android:viewportHeight="128">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M36,40h56a8,8 0,0 1,8 8v28a8,8 0,0 1,-8 8H60l-16,14v-14h-8a8,8 0,0 1,-8 -8V48a8,8 0,0 1,8 -8z M49.5,56a2.5,2.5 0,0 1,5 0v12a2.5,2.5 0,0 1,-5 0z M61.5,50a2.5,2.5 0,0 1,5 0v24a2.5,2.5 0,0 1,-5 0z M73.5,56a2.5,2.5 0,0 1,5 0v12a2.5,2.5 0,0 1,-5 0z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_notification" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="window_background">#FF1C1C1C</color>
|
||||
<!-- The placeholder icon's green (packaging/linux/*.svg). -->
|
||||
<color name="ic_launcher_background">#FF238636</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Placeholder product name (packaging/README.md). -->
|
||||
<string name="app_name">TS Client</string>
|
||||
<string name="channel_voice">Voice connection</string>
|
||||
<string name="channel_screen">Screen sharing</string>
|
||||
<string name="voice_connected">Connected to voice</string>
|
||||
<string name="disconnect">Disconnect</string>
|
||||
<string name="screen_sharing">Sharing your screen</string>
|
||||
<string name="stop_sharing">Stop sharing</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- The Slint UI draws the whole window. -->
|
||||
<style name="Theme.Tsc" parent="@android:style/Theme.DeviceDefault.NoActionBar">
|
||||
<item name="android:windowBackground">@color/window_background</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
plugins {
|
||||
id("com.android.application") version "8.13.2" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.3.21" apply false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
|
||||
android.useAndroidX=false
|
||||
android.nonTransitiveRClass=true
|
||||
kotlin.code.style=official
|
||||
# ABIs the Rust library is built for (cargo-ndk names), e.g. only
|
||||
# -Ptsc.abis=arm64-v8a for a phone.
|
||||
tsc.abis=arm64-v8a,x86_64
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+94
@@ -0,0 +1,94 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,24 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
// The Kotlin half of rustls-platform-verifier (the Rust code checks
|
||||
// TLS certificates against the Android trust store through it).
|
||||
maven {
|
||||
url = uri("https://raw.githubusercontent.com/rustls/rustls-platform-verifier/maven-archive/android-release-support/maven/")
|
||||
content { includeGroup("org.rustls") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "tsc"
|
||||
include(":app")
|
||||
Reference in new issue
Block a user