mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
feat: Add automatic recording functionality on boot
This commit is contained in:
parent
2e9f1c7ade
commit
a0bf2d03eb
@ -47,6 +47,7 @@
|
|||||||
</receiver>
|
</receiver>
|
||||||
<service
|
<service
|
||||||
android:name=".services.AudioRecorderService"
|
android:name=".services.AudioRecorderService"
|
||||||
|
android:exported="false"
|
||||||
android:foregroundServiceType="microphone" />
|
android:foregroundServiceType="microphone" />
|
||||||
|
|
||||||
<!-- Change locale for Android <= 12 -->
|
<!-- Change locale for Android <= 12 -->
|
||||||
|
@ -19,7 +19,7 @@ data class AppSettings(
|
|||||||
val showAdvancedSettings: Boolean = false,
|
val showAdvancedSettings: Boolean = false,
|
||||||
val theme: Theme = Theme.SYSTEM,
|
val theme: Theme = Theme.SYSTEM,
|
||||||
val lastRecording: RecordingInformation? = null,
|
val lastRecording: RecordingInformation? = null,
|
||||||
val bootBehavior: BootBehavior? = BootBehavior.SHOW_NOTIFICATION,
|
val bootBehavior: BootBehavior? = BootBehavior.START_RECORDING,
|
||||||
) {
|
) {
|
||||||
fun setShowAdvancedSettings(showAdvancedSettings: Boolean): AppSettings {
|
fun setShowAdvancedSettings(showAdvancedSettings: Boolean): AppSettings {
|
||||||
return copy(showAdvancedSettings = showAdvancedSettings)
|
return copy(showAdvancedSettings = showAdvancedSettings)
|
||||||
|
@ -45,8 +45,15 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("BootReceiver.startRecording()")
|
||||||
val intent = Intent(context, AudioRecorderService::class.java).apply {
|
val intent = Intent(context, AudioRecorderService::class.java).apply {
|
||||||
action = "init"
|
action = "init"
|
||||||
|
|
||||||
|
putExtra(
|
||||||
|
"startImmediately",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
if (settings.notificationSettings != null) {
|
if (settings.notificationSettings != null) {
|
||||||
putExtra(
|
putExtra(
|
||||||
"notificationDetails",
|
"notificationDetails",
|
||||||
@ -61,7 +68,6 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ContextCompat.startForegroundService(context, intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
context.bindService(intent, connection, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showNotification(context: Context) {
|
private fun showNotification(context: Context) {
|
||||||
@ -98,8 +104,11 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("BootReceiver.onReceive()")
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
context.dataStore.data.collectLatest { settings ->
|
context.dataStore.data.collectLatest { settings ->
|
||||||
|
println("BootBehavior: ${settings.bootBehavior}")
|
||||||
when (settings.bootBehavior) {
|
when (settings.bootBehavior) {
|
||||||
AppSettings.BootBehavior.CONTINUE_RECORDING -> {
|
AppSettings.BootBehavior.CONTINUE_RECORDING -> {
|
||||||
if (AudioRecorderExporter.hasRecordingsAvailable(context)) {
|
if (AudioRecorderExporter.hasRecordingsAvailable(context)) {
|
||||||
|
@ -58,10 +58,21 @@ abstract class IntervalRecorderService : ExtraRecorderInformationService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fetchCounterValue() {
|
||||||
|
val files = outputFolder.listFiles()?.filter {
|
||||||
|
val name = it.nameWithoutExtension
|
||||||
|
|
||||||
|
name.toIntOrNull() != null
|
||||||
|
}?.toList() ?: emptyList()
|
||||||
|
|
||||||
|
counter = files.size
|
||||||
|
}
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
super.start()
|
super.start()
|
||||||
|
|
||||||
outputFolder.mkdirs()
|
outputFolder.mkdirs()
|
||||||
|
fetchCounterValue()
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
dataStore.data.collectLatest { preferenceSettings ->
|
dataStore.data.collectLatest { preferenceSettings ->
|
||||||
|
@ -55,10 +55,10 @@ abstract class RecorderService : Service() {
|
|||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
"initStart" -> {
|
if (intent.getBooleanExtra("startImmediately", false)) {
|
||||||
startRecording()
|
startRecording()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"changeState" -> {
|
"changeState" -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user