Widget tap: invisible trampoline with own task affinity (was revealing MainActivity under it)

This commit is contained in:
avi 2026-09-17 20:51:19 -05:00
commit 8489c407cc
2 changed files with 45 additions and 0 deletions

View file

@ -35,6 +35,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".widget.StartRecordingActivity"
android:exported="false"
android:excludeFromRecents="true"
android:noHistory="true"
android:taskAffinity=""
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<service
android:name=".recording.RecordingService"
android:exported="false"

View file

@ -0,0 +1,37 @@
package com.shonar.widget
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.shonar.MainActivity
import com.shonar.recording.RecordingPermissionHelper
import com.shonar.recording.RecordingService
/**
* Invisible trampoline for the widget tap. A widget broadcast into a cold
* process is subject to battery-optimization throttling (the tap could sit
* ~10s before the service woke up). An activity start is exempt: the
* process gets full priority and startForegroundService from an activity
* context always satisfies Android 12+ FGS-start rules.
*
* Forwards to RecordingService.START (or MainActivity when the mic
* permission is missing) and finishes before the first frame draws, so
* there is no visible flash.
*/
class StartRecordingActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!RecordingPermissionHelper.hasRecordAudio(this)) {
startActivity(
Intent(this, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setAction(RecordingService.ACTION_START),
)
} else {
RecordingService.command(this, RecordingService.ACTION_START)
}
ShonarWidgetUpdater.refresh(this)
finish()
}
}