diff --git a/host-agent/android/app/build.gradle b/host-agent/android/app/build.gradle index 97ec05c..120fb0a 100644 --- a/host-agent/android/app/build.gradle +++ b/host-agent/android/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId 'de.hackersoft.ariaagent' minSdk 26 targetSdk 33 // 33 vermeidet die Foreground-Service-Typ-Pflicht von 34 - versionCode 4 - versionName '0.0.0.4' + versionCode 5 + versionName '0.0.0.5' } // Fester Signaturschlüssel: jeder Build signiert mit DEMSELBEN Key, damit diff --git a/host-agent/android/app/src/main/AndroidManifest.xml b/host-agent/android/app/src/main/AndroidManifest.xml index ba6755b..e03e3c6 100644 --- a/host-agent/android/app/src/main/AndroidManifest.xml +++ b/host-agent/android/app/src/main/AndroidManifest.xml @@ -3,6 +3,8 @@ + + @@ -30,7 +32,7 @@ + android:foregroundServiceType="dataSync|mediaProjection" /> = 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 { @@ -52,7 +65,7 @@ class AgentService : Service() { // (ForegroundServiceDidNotStartInTimeException). Der Projection-Intent kommt // per startForegroundService, obwohl der Dienst schon laeuft -> hier IMMER // zuerst startForeground aufrufen (idempotent). - startForeground(NOTIF_ID, buildNotification(status)) + startForegroundDataSync(status) if (intent?.action == ACTION_PROJECTION) { val code = intent.getIntExtra(EXTRA_RESULT_CODE, 0) @@ -60,10 +73,24 @@ class AgentService : Service() { val data = intent.getParcelableExtra(EXTRA_RESULT_DATA) if (code != 0 && data != null) { 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) - updateNotification("$status · Bildschirm-Zugriff aktiv") + if (ScreenCapturer.active) { + updateNotification("$status · Bildschirm-Zugriff aktiv") + } else { + updateNotification("Bildschirm-Fehler: ${ScreenCapturer.lastError}") + } } catch (e: Throwable) { - ScreenCapturer.lastError = e.message ?: e.javaClass.simpleName + ScreenCapturer.lastError = "${e.javaClass.simpleName}: ${e.message}" updateNotification("Bildschirm-Fehler: ${ScreenCapturer.lastError}") } }