mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Properly handle errors when starting recording fails
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
df9443eb9b
commit
721a3daeb6
@ -441,23 +441,28 @@ abstract class BatchesFolder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun checkIfFolderIsAccessible(): Boolean {
|
fun checkIfFolderIsAccessible(): Boolean {
|
||||||
return when (type) {
|
try {
|
||||||
BatchType.INTERNAL -> true
|
return when (type) {
|
||||||
BatchType.CUSTOM -> getCustomDefinedFolder().canWrite() && getCustomDefinedFolder().canRead()
|
BatchType.INTERNAL -> true
|
||||||
BatchType.MEDIA -> {
|
BatchType.CUSTOM -> getCustomDefinedFolder().canWrite() && getCustomDefinedFolder().canRead()
|
||||||
if (SUPPORTS_SCOPED_STORAGE) {
|
BatchType.MEDIA -> {
|
||||||
return true
|
if (SUPPORTS_SCOPED_STORAGE) {
|
||||||
}
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return PermissionHelper.hasGranted(
|
return PermissionHelper.hasGranted(
|
||||||
context,
|
context,
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||||
) &&
|
) &&
|
||||||
PermissionHelper.hasGranted(
|
PermissionHelper.hasGranted(
|
||||||
context,
|
context,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error: NullPointerException) {
|
||||||
|
error.printStackTrace()
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,6 +586,10 @@ abstract class BatchesFolder(
|
|||||||
MEDIA,
|
MEDIA,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class InaccessibleError : RuntimeException() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun requiredBytesForOneMinuteOfRecording(appSettings: AppSettings): Long {
|
fun requiredBytesForOneMinuteOfRecording(appSettings: AppSettings): Long {
|
||||||
// 350 MiB sounds like a good default
|
// 350 MiB sounds like a good default
|
||||||
|
@ -65,6 +65,8 @@ abstract class IntervalRecorderService<I, B : BatchesFolder> :
|
|||||||
|
|
||||||
if (!batchesFolder.checkIfFolderIsAccessible()) {
|
if (!batchesFolder.checkIfFolderIsAccessible()) {
|
||||||
onBatchesFolderNotAccessible()
|
onBatchesFolderNotAccessible()
|
||||||
|
|
||||||
|
throw AvoidErrorDialogError()
|
||||||
}
|
}
|
||||||
|
|
||||||
createTimer()
|
createTimer()
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package app.myzel394.alibi.services
|
package app.myzel394.alibi.services
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.ActivityManager
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.content.ContextCompat.getSystemService
|
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import app.myzel394.alibi.NotificationHelper
|
import app.myzel394.alibi.NotificationHelper
|
||||||
import app.myzel394.alibi.enums.RecorderState
|
import app.myzel394.alibi.enums.RecorderState
|
||||||
@ -63,7 +61,16 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
|
|
||||||
startForegroundService()
|
startForegroundService()
|
||||||
changeState(RecorderState.RECORDING)
|
changeState(RecorderState.RECORDING)
|
||||||
start()
|
|
||||||
|
try {
|
||||||
|
start()
|
||||||
|
} catch (error: RuntimeException) {
|
||||||
|
error.printStackTrace()
|
||||||
|
|
||||||
|
if (error !is AvoidErrorDialogError) {
|
||||||
|
onError()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun stopRecording() {
|
suspend fun stopRecording() {
|
||||||
@ -194,4 +201,9 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Throw this error if you show a dialog yourself.
|
||||||
|
// This will prevent the service from showing their generic error dialog.
|
||||||
|
class AvoidErrorDialogError : RuntimeException()
|
||||||
}
|
}
|
@ -356,17 +356,16 @@ fun RecorderEventsHandler(
|
|||||||
progress = processingProgress,
|
progress = processingProgress,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (showRecorderError)
|
|
||||||
RecorderErrorDialog(
|
|
||||||
onClose = {
|
|
||||||
showRecorderError = false
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if (showBatchesInaccessibleError)
|
if (showBatchesInaccessibleError)
|
||||||
BatchesInaccessibleDialog(
|
BatchesInaccessibleDialog(
|
||||||
onClose = {
|
onClose = {
|
||||||
showBatchesInaccessibleError = false
|
showBatchesInaccessibleError = false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
else if (showRecorderError)
|
||||||
|
RecorderErrorDialog(
|
||||||
|
onClose = {
|
||||||
|
showRecorderError = false
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user