mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 17:59:51 +02:00
Fix crash when remotely removing a device at which a limited app is running
This commit is contained in:
parent
cf6d1e8f62
commit
b6b68691de
8 changed files with 69 additions and 27 deletions
|
@ -41,14 +41,11 @@ class AdminReceiver: DeviceAdminReceiver() {
|
|||
|
||||
override fun onDisableRequested(context: Context, intent: Intent?): CharSequence {
|
||||
runAsync {
|
||||
val logic = DefaultAppLogic.with(context)
|
||||
|
||||
if (logic.database.config().getOwnDeviceId().waitForNullableValue() != null) {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
TriedDisablingDeviceAdminAction,
|
||||
logic
|
||||
)
|
||||
}
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
action = TriedDisablingDeviceAdminAction,
|
||||
appLogic = DefaultAppLogic.with(context),
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
}
|
||||
|
||||
return context.getString(R.string.admin_disable_warning)
|
||||
|
|
|
@ -470,10 +470,11 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
|||
if (deviceEntry != null) {
|
||||
if (deviceEntry.currentAppVersion != currentAppVersion) {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
UpdateDeviceStatusAction.empty.copy(
|
||||
action = UpdateDeviceStatusAction.empty.copy(
|
||||
newAppVersion = currentAppVersion
|
||||
),
|
||||
appLogic
|
||||
appLogic = appLogic,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -503,10 +504,11 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
|||
|
||||
if (deviceEntry?.considerRebootManipulation == true) {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
UpdateDeviceStatusAction.empty.copy(
|
||||
action = UpdateDeviceStatusAction.empty.copy(
|
||||
didReboot = true
|
||||
),
|
||||
appLogic
|
||||
appLogic = appLogic,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -546,7 +548,11 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
|||
}
|
||||
|
||||
if (changes != UpdateDeviceStatusAction.empty) {
|
||||
ApplyActionUtil.applyAppLogicAction(changes, appLogic)
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
action = changes,
|
||||
appLogic = appLogic,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,8 @@ class DefaultUserLogic(private val appLogic: AppLogic) {
|
|||
if (appLogic.fullVersion.shouldProvideFullVersionFunctions.waitForNonNullValue()) {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
appLogic = appLogic,
|
||||
action = SignOutAtDeviceAction
|
||||
action = SignOutAtDeviceAction,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
} else {
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
|
|
@ -82,14 +82,15 @@ class SyncInstalledAppsLogic(val appLogic: AppLogic) {
|
|||
// save the changes
|
||||
if (itemsToRemove.isNotEmpty()) {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
RemoveInstalledAppsAction(packageNames = itemsToRemove.keys.toList()),
|
||||
appLogic
|
||||
action = RemoveInstalledAppsAction(packageNames = itemsToRemove.keys.toList()),
|
||||
appLogic = appLogic,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
}
|
||||
|
||||
if (itemsToAdd.isNotEmpty()) {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
AddInstalledAppsAction(
|
||||
action = AddInstalledAppsAction(
|
||||
apps = itemsToAdd.map {
|
||||
(_, app) ->
|
||||
|
||||
|
@ -101,7 +102,8 @@ class SyncInstalledAppsLogic(val appLogic: AppLogic) {
|
|||
)
|
||||
}
|
||||
),
|
||||
appLogic
|
||||
appLogic = appLogic,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,13 +104,14 @@ class UsedTimeItemBatchUpdateHelper(
|
|||
// do nothing
|
||||
} else {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
AddUsedTimeAction(
|
||||
action = AddUsedTimeAction(
|
||||
categoryId = childCategoryId,
|
||||
timeToAdd = timeToAdd,
|
||||
dayOfEpoch = date.dayOfEpoch,
|
||||
extraTimeToSubtract = extraTimeToSubtract
|
||||
),
|
||||
logic
|
||||
appLogic = logic,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
|
||||
timeToAdd = 0
|
||||
|
|
|
@ -40,14 +40,47 @@ import java.io.StringWriter
|
|||
object ApplyActionUtil {
|
||||
private const val LOG_TAG = "ApplyActionUtil"
|
||||
|
||||
suspend fun applyAppLogicAction(action: AppLogicAction, appLogic: AppLogic) {
|
||||
applyAppLogicAction(action, appLogic.database, appLogic.syncUtil, appLogic.manipulationLogic)
|
||||
suspend fun applyAppLogicAction(
|
||||
action: AppLogicAction,
|
||||
appLogic: AppLogic,
|
||||
ignoreIfDeviceIsNotConfigured: Boolean
|
||||
) {
|
||||
applyAppLogicAction(
|
||||
action = action,
|
||||
database = appLogic.database,
|
||||
syncUtil = appLogic.syncUtil,
|
||||
manipulationLogic = appLogic.manipulationLogic,
|
||||
ignoreIfDeviceIsNotConfigured = ignoreIfDeviceIsNotConfigured
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun applyAppLogicAction(action: AppLogicAction, database: Database, syncUtil: SyncUtil, manipulationLogic: ManipulationLogic) {
|
||||
private suspend fun applyAppLogicAction(
|
||||
action: AppLogicAction,
|
||||
database: Database,
|
||||
syncUtil: SyncUtil,
|
||||
manipulationLogic: ManipulationLogic,
|
||||
ignoreIfDeviceIsNotConfigured: Boolean
|
||||
) {
|
||||
// uncomment this if you need to know what's dispatching an action
|
||||
/*
|
||||
if (BuildConfig.DEBUG) {
|
||||
try {
|
||||
throw Exception()
|
||||
} catch (ex: Exception) {
|
||||
Log.d(LOG_TAG, "handling action: $action", ex)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Threads.database.executeAndWait {
|
||||
database.transaction().use {
|
||||
LocalDatabaseAppLogicActionDispatcher.dispatchAppLogicActionSync(action, database.config().getOwnDeviceIdSync()!!, database, manipulationLogic)
|
||||
val ownDeviceId = database.config().getOwnDeviceIdSync()
|
||||
|
||||
if (ownDeviceId == null && ignoreIfDeviceIsNotConfigured) {
|
||||
return@executeAndWait
|
||||
}
|
||||
|
||||
LocalDatabaseAppLogicActionDispatcher.dispatchAppLogicActionSync(action, ownDeviceId!!, database, manipulationLogic)
|
||||
|
||||
if (isSyncEnabled(database)) {
|
||||
if (action is AddUsedTimeAction) {
|
||||
|
|
|
@ -89,8 +89,9 @@ object ManageDeviceDefaultUser {
|
|||
if (fullVersion) {
|
||||
runAsync {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
SignOutAtDeviceAction,
|
||||
auth.logic
|
||||
action = SignOutAtDeviceAction,
|
||||
appLogic = auth.logic,
|
||||
ignoreIfDeviceIsNotConfigured = true
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -73,7 +73,8 @@ data class OfflineModeStatus(
|
|||
try {
|
||||
ApplyActionUtil.applyAppLogicAction(
|
||||
action = action,
|
||||
appLogic = appLogic
|
||||
appLogic = appLogic,
|
||||
ignoreIfDeviceIsNotConfigured = false
|
||||
)
|
||||
} catch (ex: Exception) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue