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 {
|
override fun onDisableRequested(context: Context, intent: Intent?): CharSequence {
|
||||||
runAsync {
|
runAsync {
|
||||||
val logic = DefaultAppLogic.with(context)
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
|
action = TriedDisablingDeviceAdminAction,
|
||||||
if (logic.database.config().getOwnDeviceId().waitForNullableValue() != null) {
|
appLogic = DefaultAppLogic.with(context),
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
TriedDisablingDeviceAdminAction,
|
)
|
||||||
logic
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.getString(R.string.admin_disable_warning)
|
return context.getString(R.string.admin_disable_warning)
|
||||||
|
|
|
@ -470,10 +470,11 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
||||||
if (deviceEntry != null) {
|
if (deviceEntry != null) {
|
||||||
if (deviceEntry.currentAppVersion != currentAppVersion) {
|
if (deviceEntry.currentAppVersion != currentAppVersion) {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
UpdateDeviceStatusAction.empty.copy(
|
action = UpdateDeviceStatusAction.empty.copy(
|
||||||
newAppVersion = currentAppVersion
|
newAppVersion = currentAppVersion
|
||||||
),
|
),
|
||||||
appLogic
|
appLogic = appLogic,
|
||||||
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -503,10 +504,11 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
||||||
|
|
||||||
if (deviceEntry?.considerRebootManipulation == true) {
|
if (deviceEntry?.considerRebootManipulation == true) {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
UpdateDeviceStatusAction.empty.copy(
|
action = UpdateDeviceStatusAction.empty.copy(
|
||||||
didReboot = true
|
didReboot = true
|
||||||
),
|
),
|
||||||
appLogic
|
appLogic = appLogic,
|
||||||
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -546,7 +548,11 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes != UpdateDeviceStatusAction.empty) {
|
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()) {
|
if (appLogic.fullVersion.shouldProvideFullVersionFunctions.waitForNonNullValue()) {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
appLogic = appLogic,
|
appLogic = appLogic,
|
||||||
action = SignOutAtDeviceAction
|
action = SignOutAtDeviceAction,
|
||||||
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
|
|
|
@ -82,14 +82,15 @@ class SyncInstalledAppsLogic(val appLogic: AppLogic) {
|
||||||
// save the changes
|
// save the changes
|
||||||
if (itemsToRemove.isNotEmpty()) {
|
if (itemsToRemove.isNotEmpty()) {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
RemoveInstalledAppsAction(packageNames = itemsToRemove.keys.toList()),
|
action = RemoveInstalledAppsAction(packageNames = itemsToRemove.keys.toList()),
|
||||||
appLogic
|
appLogic = appLogic,
|
||||||
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemsToAdd.isNotEmpty()) {
|
if (itemsToAdd.isNotEmpty()) {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
AddInstalledAppsAction(
|
action = AddInstalledAppsAction(
|
||||||
apps = itemsToAdd.map {
|
apps = itemsToAdd.map {
|
||||||
(_, app) ->
|
(_, app) ->
|
||||||
|
|
||||||
|
@ -101,7 +102,8 @@ class SyncInstalledAppsLogic(val appLogic: AppLogic) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
appLogic
|
appLogic = appLogic,
|
||||||
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,13 +104,14 @@ class UsedTimeItemBatchUpdateHelper(
|
||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
AddUsedTimeAction(
|
action = AddUsedTimeAction(
|
||||||
categoryId = childCategoryId,
|
categoryId = childCategoryId,
|
||||||
timeToAdd = timeToAdd,
|
timeToAdd = timeToAdd,
|
||||||
dayOfEpoch = date.dayOfEpoch,
|
dayOfEpoch = date.dayOfEpoch,
|
||||||
extraTimeToSubtract = extraTimeToSubtract
|
extraTimeToSubtract = extraTimeToSubtract
|
||||||
),
|
),
|
||||||
logic
|
appLogic = logic,
|
||||||
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
)
|
)
|
||||||
|
|
||||||
timeToAdd = 0
|
timeToAdd = 0
|
||||||
|
|
|
@ -40,14 +40,47 @@ import java.io.StringWriter
|
||||||
object ApplyActionUtil {
|
object ApplyActionUtil {
|
||||||
private const val LOG_TAG = "ApplyActionUtil"
|
private const val LOG_TAG = "ApplyActionUtil"
|
||||||
|
|
||||||
suspend fun applyAppLogicAction(action: AppLogicAction, appLogic: AppLogic) {
|
suspend fun applyAppLogicAction(
|
||||||
applyAppLogicAction(action, appLogic.database, appLogic.syncUtil, appLogic.manipulationLogic)
|
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 {
|
Threads.database.executeAndWait {
|
||||||
database.transaction().use {
|
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 (isSyncEnabled(database)) {
|
||||||
if (action is AddUsedTimeAction) {
|
if (action is AddUsedTimeAction) {
|
||||||
|
|
|
@ -89,8 +89,9 @@ object ManageDeviceDefaultUser {
|
||||||
if (fullVersion) {
|
if (fullVersion) {
|
||||||
runAsync {
|
runAsync {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
SignOutAtDeviceAction,
|
action = SignOutAtDeviceAction,
|
||||||
auth.logic
|
appLogic = auth.logic,
|
||||||
|
ignoreIfDeviceIsNotConfigured = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -73,7 +73,8 @@ data class OfflineModeStatus(
|
||||||
try {
|
try {
|
||||||
ApplyActionUtil.applyAppLogicAction(
|
ApplyActionUtil.applyAppLogicAction(
|
||||||
action = action,
|
action = action,
|
||||||
appLogic = appLogic
|
appLogic = appLogic,
|
||||||
|
ignoreIfDeviceIsNotConfigured = false
|
||||||
)
|
)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue