Suppress boot config errors
This commit is contained in:
@@ -29,12 +29,7 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
else PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
else PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
||||||
private val userEnabled get() = app.pref.getBoolean(KEY, false)
|
private val userEnabled get() = app.pref.getBoolean(KEY, false)
|
||||||
fun onUserSettingUpdated(shouldStart: Boolean) {
|
fun onUserSettingUpdated(shouldStart: Boolean) {
|
||||||
enabled = shouldStart && try {
|
enabled = shouldStart && config?.startables?.isEmpty() == false
|
||||||
config
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.w(e)
|
|
||||||
null
|
|
||||||
}?.startables?.isEmpty() == false
|
|
||||||
}
|
}
|
||||||
private fun onConfigUpdated(isNotEmpty: Boolean) {
|
private fun onConfigUpdated(isNotEmpty: Boolean) {
|
||||||
enabled = isNotEmpty && userEnabled
|
enabled = isNotEmpty && userEnabled
|
||||||
@@ -46,14 +41,12 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
DataInputStream(configFile.inputStream()).use { it.readBytes().toParcelable() }
|
DataInputStream(configFile.inputStream()).use { it.readBytes().toParcelable() }
|
||||||
} catch (_: FileNotFoundException) {
|
} catch (_: FileNotFoundException) {
|
||||||
null
|
null
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.d("Boot config corrupted", e)
|
||||||
|
null
|
||||||
}
|
}
|
||||||
private fun updateConfig(work: Config.() -> Unit) = synchronized(BootReceiver) {
|
private fun updateConfig(work: Config.() -> Unit) = synchronized(BootReceiver) {
|
||||||
val config = try {
|
val config = config ?: Config()
|
||||||
config
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.i("Boot config corrupted", e)
|
|
||||||
null
|
|
||||||
} ?: Config()
|
|
||||||
config.work()
|
config.work()
|
||||||
DataOutputStream(configFile.outputStream()).use { it.write(config.toByteArray()) }
|
DataOutputStream(configFile.outputStream()).use { it.write(config.toByteArray()) }
|
||||||
config
|
config
|
||||||
@@ -85,12 +78,7 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
private var started = false
|
private var started = false
|
||||||
private fun startIfNecessary() {
|
private fun startIfNecessary() {
|
||||||
if (started) return
|
if (started) return
|
||||||
val config = try {
|
val config = synchronized(BootReceiver) { config }
|
||||||
synchronized(BootReceiver) { config }
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.w(e)
|
|
||||||
null
|
|
||||||
}
|
|
||||||
if (config == null || config.startables.isEmpty()) {
|
if (config == null || config.startables.isEmpty()) {
|
||||||
enabled = false
|
enabled = false
|
||||||
} else for (startable in config.startables.values) startable.start(app)
|
} else for (startable in config.startables.values) startable.start(app)
|
||||||
|
|||||||
Reference in New Issue
Block a user