Widget tap: invisible trampoline with own task affinity (was revealing MainActivity under it)
This commit is contained in:
parent
7f9b9c2e5c
commit
8489c407cc
2 changed files with 45 additions and 0 deletions
|
|
@ -35,6 +35,14 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</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
|
<service
|
||||||
android:name=".recording.RecordingService"
|
android:name=".recording.RecordingService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue