mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 14:55: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 {
|
||||
return when (type) {
|
||||
BatchType.INTERNAL -> true
|
||||
BatchType.CUSTOM -> getCustomDefinedFolder().canWrite() && getCustomDefinedFolder().canRead()
|
||||
BatchType.MEDIA -> {
|
||||
if (SUPPORTS_SCOPED_STORAGE) {
|
||||
return true
|
||||
}
|
||||
try {
|
||||
return when (type) {
|
||||
BatchType.INTERNAL -> true
|
||||
BatchType.CUSTOM -> getCustomDefinedFolder().canWrite() && getCustomDefinedFolder().canRead()
|
||||
BatchType.MEDIA -> {
|
||||
if (SUPPORTS_SCOPED_STORAGE) {
|
||||
return true
|
||||
}
|
||||
|
||||
return PermissionHelper.hasGranted(
|
||||
context,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
) &&
|
||||
PermissionHelper.hasGranted(
|
||||
context,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
return PermissionHelper.hasGranted(
|
||||
context,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
) &&
|
||||
PermissionHelper.hasGranted(
|
||||
context,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (error: NullPointerException) {
|
||||
error.printStackTrace()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -581,6 +586,10 @@ abstract class BatchesFolder(
|
||||
MEDIA,
|
||||
}
|
||||
|
||||
class InaccessibleError : RuntimeException() {
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun requiredBytesForOneMinuteOfRecording(appSettings: AppSettings): Long {
|
||||
// 350 MiB sounds like a good default
|
||||
|
@ -65,6 +65,8 @@ abstract class IntervalRecorderService<I, B : BatchesFolder> :
|
||||
|
||||
if (!batchesFolder.checkIfFolderIsAccessible()) {
|
||||
onBatchesFolderNotAccessible()
|
||||
|
||||
throw AvoidErrorDialogError()
|
||||
}
|
||||
|
||||
createTimer()
|
||||
|
@ -1,13 +1,11 @@
|
||||
package app.myzel394.alibi.services
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.ActivityManager
|
||||
import android.app.Notification
|
||||
import android.content.Intent
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import androidx.lifecycle.LifecycleService
|
||||
import app.myzel394.alibi.NotificationHelper
|
||||
import app.myzel394.alibi.enums.RecorderState
|
||||
@ -63,7 +61,16 @@ abstract class RecorderService : LifecycleService() {
|
||||
|
||||
startForegroundService()
|
||||
changeState(RecorderState.RECORDING)
|
||||
start()
|
||||
|
||||
try {
|
||||
start()
|
||||
} catch (error: RuntimeException) {
|
||||
error.printStackTrace()
|
||||
|
||||
if (error !is AvoidErrorDialogError) {
|
||||
onError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
if (showRecorderError)
|
||||
RecorderErrorDialog(
|
||||
onClose = {
|
||||
showRecorderError = false
|
||||
},
|
||||
)
|
||||
|
||||
if (showBatchesInaccessibleError)
|
||||
BatchesInaccessibleDialog(
|
||||
onClose = {
|
||||
showBatchesInaccessibleError = false
|
||||
},
|
||||
)
|
||||
else if (showRecorderError)
|
||||
RecorderErrorDialog(
|
||||
onClose = {
|
||||
showRecorderError = false
|
||||
},
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user