Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b84ee3b9c | ||
|
|
c86cd59b5c | ||
|
|
96012dc986 | ||
|
|
80d7f62eaa | ||
|
|
5f5234ee62 | ||
|
|
28e58089aa |
@@ -6,3 +6,6 @@ local.properties
|
|||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
captures/
|
captures/
|
||||||
|
|
||||||
|
# Signaturschluessel — NUR lokal, niemals ins oeffentliche Repo (Backup machen!)
|
||||||
|
aria-agent.keystore
|
||||||
|
|||||||
@@ -11,13 +11,33 @@ android {
|
|||||||
applicationId 'de.hackersoft.ariaagent'
|
applicationId 'de.hackersoft.ariaagent'
|
||||||
minSdk 26
|
minSdk 26
|
||||||
targetSdk 33 // 33 vermeidet die Foreground-Service-Typ-Pflicht von 34
|
targetSdk 33 // 33 vermeidet die Foreground-Service-Typ-Pflicht von 34
|
||||||
versionCode 2
|
versionCode 5
|
||||||
versionName '0.0.0.2'
|
versionName '0.0.0.5'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fester Signaturschlüssel: jeder Build signiert mit DEMSELBEN Key, damit
|
||||||
|
// Android neue APKs als Update derselben App akzeptiert (sonst "Konflikt mit
|
||||||
|
// bestehendem Paket"). Die Keystore-Datei liegt NUR lokal (gitignored, nicht
|
||||||
|
// im oeffentlichen Repo) — UNBEDINGT sichern, sonst brechen kuenftige Updates.
|
||||||
|
def ariaKeystore = rootProject.file('aria-agent.keystore')
|
||||||
|
signingConfigs {
|
||||||
|
aria {
|
||||||
|
if (ariaKeystore.exists()) {
|
||||||
|
storeFile ariaKeystore
|
||||||
|
storePassword 'ariaagent'
|
||||||
|
keyAlias 'aria'
|
||||||
|
keyPassword 'ariaagent'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
debug {
|
||||||
|
if (ariaKeystore.exists()) signingConfig signingConfigs.aria
|
||||||
|
}
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
|
if (ariaKeystore.exists()) signingConfig signingConfigs.aria
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
@@ -30,7 +32,7 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".AgentService"
|
android:name=".AgentService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:foregroundServiceType="dataSync" />
|
android:foregroundServiceType="dataSync|mediaProjection" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".BootReceiver"
|
android:name=".BootReceiver"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.app.PendingIntent
|
|||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
@@ -43,7 +44,19 @@ class AgentService : Service() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
createChannel()
|
createChannel()
|
||||||
startForeground(NOTIF_ID, buildNotification("startet …"))
|
startForegroundDataSync("startet …")
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Normaler Vordergrund-Start (Typ dataSync). mediaProjection wird NUR beim
|
||||||
|
* Projizieren gesetzt — auf Android 14 darf man diesen Typ sonst nicht ohne
|
||||||
|
* Projection-Token verwenden. */
|
||||||
|
private fun startForegroundDataSync(text: String) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 29) {
|
||||||
|
startForeground(NOTIF_ID, buildNotification(text),
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
||||||
|
} else {
|
||||||
|
startForeground(NOTIF_ID, buildNotification(text))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
@@ -52,7 +65,7 @@ class AgentService : Service() {
|
|||||||
// (ForegroundServiceDidNotStartInTimeException). Der Projection-Intent kommt
|
// (ForegroundServiceDidNotStartInTimeException). Der Projection-Intent kommt
|
||||||
// per startForegroundService, obwohl der Dienst schon laeuft -> hier IMMER
|
// per startForegroundService, obwohl der Dienst schon laeuft -> hier IMMER
|
||||||
// zuerst startForeground aufrufen (idempotent).
|
// zuerst startForeground aufrufen (idempotent).
|
||||||
startForeground(NOTIF_ID, buildNotification(status))
|
startForegroundDataSync(status)
|
||||||
|
|
||||||
if (intent?.action == ACTION_PROJECTION) {
|
if (intent?.action == ACTION_PROJECTION) {
|
||||||
val code = intent.getIntExtra(EXTRA_RESULT_CODE, 0)
|
val code = intent.getIntExtra(EXTRA_RESULT_CODE, 0)
|
||||||
@@ -60,10 +73,24 @@ class AgentService : Service() {
|
|||||||
val data = intent.getParcelableExtra<Intent>(EXTRA_RESULT_DATA)
|
val data = intent.getParcelableExtra<Intent>(EXTRA_RESULT_DATA)
|
||||||
if (code != 0 && data != null) {
|
if (code != 0 && data != null) {
|
||||||
try {
|
try {
|
||||||
|
// Android verlangt beim Projizieren einen Vordergrund-Dienst vom
|
||||||
|
// Typ mediaProjection — VOR getMediaProjection() setzen, sonst
|
||||||
|
// SecurityException (FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION).
|
||||||
|
if (Build.VERSION.SDK_INT >= 29) {
|
||||||
|
startForeground(
|
||||||
|
NOTIF_ID, buildNotification("Bildschirm-Zugriff aktiv"),
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION or
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,
|
||||||
|
)
|
||||||
|
}
|
||||||
ScreenCapturer.start(applicationContext, code, data)
|
ScreenCapturer.start(applicationContext, code, data)
|
||||||
updateNotification("$status · Bildschirm-Zugriff aktiv")
|
if (ScreenCapturer.active) {
|
||||||
|
updateNotification("$status · Bildschirm-Zugriff aktiv")
|
||||||
|
} else {
|
||||||
|
updateNotification("Bildschirm-Fehler: ${ScreenCapturer.lastError}")
|
||||||
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
ScreenCapturer.lastError = e.message ?: e.javaClass.simpleName
|
ScreenCapturer.lastError = "${e.javaClass.simpleName}: ${e.message}"
|
||||||
updateNotification("Bildschirm-Fehler: ${ScreenCapturer.lastError}")
|
updateNotification("Bildschirm-Fehler: ${ScreenCapturer.lastError}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,16 +126,23 @@ class RvsClient(
|
|||||||
&& !target.equals(config.displayName(), true)) return
|
&& !target.equals(config.displayName(), true)) return
|
||||||
|
|
||||||
val action = payload.optString("action")
|
val action = payload.optString("action")
|
||||||
val result: JSONObject = when {
|
// WICHTIG: JEDE Aktion muss ein host_result liefern — auch bei Exception
|
||||||
!config.controlEnabled ->
|
// ODER OutOfMemoryError (Throwable!). Sonst bekommt ARIA statt einer
|
||||||
err("Steuerung ist in der Agent-App deaktiviert (Schalter 'Steuerung erlauben').")
|
// Fehlermeldung nur einen Timeout (kein Result kommt zurueck).
|
||||||
action == "info" -> doInfo()
|
val result: JSONObject = try {
|
||||||
action == "screenshot" -> doScreenshot()
|
when {
|
||||||
action == "ui_dump" -> doUiDump()
|
!config.controlEnabled ->
|
||||||
action in listOf("ui_tap", "ui_text", "ui_swipe", "ui_key",
|
err("Steuerung ist in der Agent-App deaktiviert (Schalter 'Steuerung erlauben').")
|
||||||
"app_launch", "app_list", "notify") ->
|
action == "info" -> doInfo()
|
||||||
err("Aktion '$action' kommt in Meilenstein 3 (noch nicht implementiert).")
|
action == "screenshot" -> doScreenshot()
|
||||||
else -> err("Aktion '$action' unbekannt.")
|
action == "ui_dump" -> doUiDump()
|
||||||
|
action in listOf("ui_tap", "ui_text", "ui_swipe", "ui_key",
|
||||||
|
"app_launch", "app_list", "notify") ->
|
||||||
|
err("Aktion '$action' kommt in Meilenstein 3 (noch nicht implementiert).")
|
||||||
|
else -> err("Aktion '$action' unbekannt.")
|
||||||
|
}
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
err("Fehler bei '$action': ${t.javaClass.simpleName}: ${t.message}")
|
||||||
}
|
}
|
||||||
result.put("requestId", payload.optString("requestId"))
|
result.put("requestId", payload.optString("requestId"))
|
||||||
result.put("hostId", config.hostId())
|
result.put("hostId", config.hostId())
|
||||||
@@ -153,7 +160,7 @@ class RvsClient(
|
|||||||
"einmalig 'Bildschirm-Zugriff erlauben' antippen.$why")
|
"einmalig 'Bildschirm-Zugriff erlauben' antippen.$why")
|
||||||
}
|
}
|
||||||
val png = ScreenCapturer.capture()
|
val png = ScreenCapturer.capture()
|
||||||
?: return err("Screenshot fehlgeschlagen (kein Frame). Ist der Bildschirm an?")
|
?: return err("Screenshot fehlgeschlagen: ${ScreenCapturer.lastError ?: "unbekannt"}")
|
||||||
val b64 = android.util.Base64.encodeToString(png, android.util.Base64.NO_WRAP)
|
val b64 = android.util.Base64.encodeToString(png, android.util.Base64.NO_WRAP)
|
||||||
val res = JSONObject().put("format", "png").put("bytes", png.size).put("base64", b64)
|
val res = JSONObject().put("format", "png").put("bytes", png.size).put("base64", b64)
|
||||||
return JSONObject().put("ok", true).put("result", res)
|
return JSONObject().put("ok", true).put("result", res)
|
||||||
|
|||||||
@@ -23,10 +23,16 @@ import java.io.ByteArrayOutputStream
|
|||||||
* Danach laeuft ein stiller VirtualDisplay -> ImageReader, aus dem `capture()`
|
* Danach laeuft ein stiller VirtualDisplay -> ImageReader, aus dem `capture()`
|
||||||
* bei Bedarf das aktuelle Bild als PNG zieht. Kein Google-Dienst.
|
* bei Bedarf das aktuelle Bild als PNG zieht. Kein Google-Dienst.
|
||||||
*
|
*
|
||||||
|
* Aufgenommen wird direkt in GEKAPPTER Aufloesung (max. 1280 lange Seite): die
|
||||||
|
* MediaProjection skaliert den Bildschirminhalt auf die VirtualDisplay-Groesse.
|
||||||
|
* Das haelt Speicher/Zeit klein (kein 10-MB-Vollbild-Bitmap -> kein OOM/Timeout).
|
||||||
|
*
|
||||||
* Der Zugriff geht bei App-Kill / Neustart verloren und muss neu erlaubt werden
|
* Der Zugriff geht bei App-Kill / Neustart verloren und muss neu erlaubt werden
|
||||||
* (Android-Sicherheit — Projection-Token ist nicht persistierbar).
|
* (Android-Sicherheit — Projection-Token ist nicht persistierbar).
|
||||||
*/
|
*/
|
||||||
object ScreenCapturer {
|
object ScreenCapturer {
|
||||||
|
private const val MAX_SIDE = 1280
|
||||||
|
|
||||||
private var projection: MediaProjection? = null
|
private var projection: MediaProjection? = null
|
||||||
private var reader: ImageReader? = null
|
private var reader: ImageReader? = null
|
||||||
private var vdisplay: VirtualDisplay? = null
|
private var vdisplay: VirtualDisplay? = null
|
||||||
@@ -56,9 +62,12 @@ object ScreenCapturer {
|
|||||||
val wm = ctx.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
val wm = ctx.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
wm.defaultDisplay.getRealMetrics(metrics)
|
wm.defaultDisplay.getRealMetrics(metrics)
|
||||||
w = metrics.widthPixels
|
|
||||||
h = metrics.heightPixels
|
|
||||||
dpi = metrics.densityDpi
|
dpi = metrics.densityDpi
|
||||||
|
// Direkt gekappt aufnehmen (lange Seite <= MAX_SIDE), Seitenverhaeltnis wahren.
|
||||||
|
val longSide = maxOf(metrics.widthPixels, metrics.heightPixels)
|
||||||
|
val scale = if (longSide > MAX_SIDE) MAX_SIDE.toFloat() / longSide else 1f
|
||||||
|
w = (metrics.widthPixels * scale).toInt().coerceAtLeast(1)
|
||||||
|
h = (metrics.heightPixels * scale).toInt().coerceAtLeast(1)
|
||||||
|
|
||||||
handlerThread = HandlerThread("aria-capture").also { it.start() }
|
handlerThread = HandlerThread("aria-capture").also { it.start() }
|
||||||
handler = Handler(handlerThread!!.looper)
|
handler = Handler(handlerThread!!.looper)
|
||||||
@@ -94,50 +103,47 @@ object ScreenCapturer {
|
|||||||
handler = null
|
handler = null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** PNG-Bytes des aktuellen Bildschirms, oder null. Wartet kurz auf einen Frame. */
|
/** PNG-Bytes des aktuellen Bildschirms, oder null (Grund in lastError). */
|
||||||
fun capture(): ByteArray? {
|
fun capture(): ByteArray? {
|
||||||
val r = reader ?: return null
|
val r = reader ?: run { lastError = "kein aktiver Bildschirm-Reader"; return null }
|
||||||
var image: Image? = null
|
var image: Image? = null
|
||||||
var tries = 0
|
var tries = 0
|
||||||
while (tries < 20) {
|
// Bis ~3s auf den ersten Frame warten (frischer VirtualDisplay braucht evtl. kurz).
|
||||||
|
while (tries < 37) {
|
||||||
image = r.acquireLatestImage()
|
image = r.acquireLatestImage()
|
||||||
if (image != null) break
|
if (image != null) break
|
||||||
try { Thread.sleep(80) } catch (_: InterruptedException) {}
|
try { Thread.sleep(80) } catch (_: InterruptedException) {}
|
||||||
tries++
|
tries++
|
||||||
}
|
}
|
||||||
if (image == null) return null
|
if (image == null) {
|
||||||
|
lastError = "kein Frame erhalten (Bildschirm an? evtl. DRM-geschuetzter Inhalt)"
|
||||||
|
return null
|
||||||
|
}
|
||||||
return try {
|
return try {
|
||||||
val plane = image.planes[0]
|
val plane = image.planes[0]
|
||||||
val buffer = plane.buffer
|
val buffer = plane.buffer
|
||||||
val pixelStride = plane.pixelStride
|
val pixelStride = plane.pixelStride
|
||||||
val rowStride = plane.rowStride
|
val rowStride = plane.rowStride
|
||||||
val rowPadding = rowStride - pixelStride * w
|
val rowPadding = rowStride - pixelStride * w
|
||||||
val padded = Bitmap.createBitmap(
|
val bmpW = w + (if (pixelStride > 0) rowPadding / pixelStride else 0)
|
||||||
w + (if (pixelStride > 0) rowPadding / pixelStride else 0),
|
val bmp = Bitmap.createBitmap(bmpW, h, Bitmap.Config.ARGB_8888)
|
||||||
h, Bitmap.Config.ARGB_8888,
|
bmp.copyPixelsFromBuffer(buffer)
|
||||||
)
|
|
||||||
padded.copyPixelsFromBuffer(buffer)
|
|
||||||
val cropped = if (rowPadding == 0) padded else Bitmap.createBitmap(padded, 0, 0, w, h)
|
|
||||||
val scaled = downscale(cropped, 1280)
|
|
||||||
val out = ByteArrayOutputStream()
|
val out = ByteArrayOutputStream()
|
||||||
scaled.compress(Bitmap.CompressFormat.PNG, 100, out)
|
if (rowPadding == 0) {
|
||||||
if (scaled !== cropped) scaled.recycle()
|
bmp.compress(Bitmap.CompressFormat.PNG, 100, out)
|
||||||
if (cropped !== padded) cropped.recycle()
|
} else {
|
||||||
padded.recycle()
|
val cropped = Bitmap.createBitmap(bmp, 0, 0, w, h)
|
||||||
|
cropped.compress(Bitmap.CompressFormat.PNG, 100, out)
|
||||||
|
cropped.recycle()
|
||||||
|
}
|
||||||
|
bmp.recycle()
|
||||||
|
lastError = null
|
||||||
out.toByteArray()
|
out.toByteArray()
|
||||||
} catch (_: Exception) {
|
} catch (t: Throwable) {
|
||||||
|
lastError = "Encode-Fehler: ${t.javaClass.simpleName}: ${t.message}"
|
||||||
null
|
null
|
||||||
} finally {
|
} finally {
|
||||||
try { image?.close() } catch (_: Exception) {}
|
try { image?.close() } catch (_: Exception) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun downscale(src: Bitmap, maxSide: Int): Bitmap {
|
|
||||||
val longSide = maxOf(src.width, src.height)
|
|
||||||
if (longSide <= maxSide) return src
|
|
||||||
val scale = maxSide.toFloat() / longSide
|
|
||||||
return Bitmap.createScaledBitmap(
|
|
||||||
src, (src.width * scale).toInt(), (src.height * scale).toInt(), true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ OUT_MAX_CHARS_HARD = int(os.environ.get("OUT_MAX_CHARS_HARD", "200000") or "2000
|
|||||||
FILE_MAX_BYTES = int(os.environ.get("FILE_MAX_BYTES", str(10 * 1024 * 1024)) or str(10 * 1024 * 1024))
|
FILE_MAX_BYTES = int(os.environ.get("FILE_MAX_BYTES", str(10 * 1024 * 1024)) or str(10 * 1024 * 1024))
|
||||||
|
|
||||||
# Version (wird von release_agent.sh beim Release gesetzt).
|
# Version (wird von release_agent.sh beim Release gesetzt).
|
||||||
AGENT_VERSION = "0.0.0.2"
|
AGENT_VERSION = "0.0.0.5"
|
||||||
|
|
||||||
HEARTBEAT_SEC = 25
|
HEARTBEAT_SEC = 25
|
||||||
CAPS = ["exec", "read", "write", "info", "screenshot"]
|
CAPS = ["exec", "read", "write", "info", "screenshot"]
|
||||||
|
|||||||
Reference in New Issue
Block a user