Squashed commit of the following:

commit db5e372421bd6f3731085f702423221ce64e10f5
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Use home button before opening lockscreen in all cases

commit 19c64cbbfd29060cc6e4abc08fa7eb0de841f46c
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Add new database schema file

commit 244162a7654f966ec55e08e185e1bccb59461c7e
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Fix showing if accessibility service enabled

commit 6f562ec8ff95a797e150b5bb990f0586f6e372dc
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Fix compiling

commit c6464c2114230e9bef40ff8425f3d28fce1ff120
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Add managing accessibility service to device config screen

commit f13925c805a03f570cfe8fdae6ab2ce5f80644e4
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Add accessibility service to device setup

commit 39ff80da6553efe228fd429b2f39d6e8fca6f4f1
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Squashed commit of the following:

    commit 52fa115b2f
    Author: Jonas L <jonas@determapp.de>
    Date:   Mon Mar 25 00:00:00 2019 +0000

        Squashed commit of the following:

        commit bb5606826a0b108df334968657d87fff3762afe8
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Hide overlay permission

        commit a0c0fe3624a86d9d7eee2c0486fa086a4a5ee064
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Add warning to overlay if shown for a longer time

        commit 0705ee57374a0257e97f5dfd4bbde3428ec58933
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Allow ignoring warning of overlay manipulation

        commit 2685be2de0bdb2eb56b2514cc8a6dfc05eec923e
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Add overlay permission to update device status action

        commit dde4f800b8ab1331a22b6a702341edd3d595748c
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Add draw over other apps permission to device screen

        commit 0d54e76cc23cb3f534c88533ce962cb84f68f105
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Add column for the overlay permission

        commit 42da690ae823a9fead00e98d7a2d74ea7df406fe
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Add UI to grant overlay permission to the setup screen

        commit 5b8697bc79c773666c2ca2be3201f0998da64169
        Author: Jonas L <jonas@determapp.de>
        Date:   Mon Mar 25 00:00:00 2019 +0000

            Add using draw over other apps permission

commit bcfb6a779f15732c948833a03b330539ea4694a6
Author: Jonas L <jonas@determapp.de>
Date:   Mon Mar 25 00:00:00 2019 +0000

    Add basically popup window blocking workaround
This commit is contained in:
Jonas L 2019-03-25 00:00:00 +00:00
parent 52fa115b2f
commit 399c39628b
27 changed files with 1056 additions and 47 deletions

View file

@ -31,11 +31,13 @@ import io.timelimit.android.date.DateInTimezone
import io.timelimit.android.date.getMinuteOfWeek
import io.timelimit.android.integration.platform.AppStatusMessage
import io.timelimit.android.integration.platform.ProtectionLevel
import io.timelimit.android.integration.platform.android.AccessibilityService
import io.timelimit.android.integration.platform.android.AndroidIntegrationApps
import io.timelimit.android.livedata.*
import io.timelimit.android.sync.actions.UpdateDeviceStatusAction
import io.timelimit.android.sync.actions.apply.ApplyActionUtil
import io.timelimit.android.util.TimeTextUtil
import kotlinx.coroutines.delay
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import java.util.*
@ -134,6 +136,22 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
private val appTitleCache = QueryAppTitleCache(appLogic.platformIntegration)
private suspend fun openLockscreen(blockedAppPackageName: String) {
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
title = appTitleCache.query(blockedAppPackageName),
text = appLogic.context.getString(R.string.background_logic_opening_lockscreen)
))
appLogic.platformIntegration.setShowBlockingOverlay(true)
if (appLogic.platformIntegration.isAccessibilityServiceEnabled()) {
AccessibilityService.instance?.showHomescreen()
delay(100)
}
appLogic.platformIntegration.showAppLockScreen(blockedAppPackageName)
}
private suspend fun backgroundServiceLoop() {
val realTime = RealTime.newInstance()
@ -257,22 +275,12 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
if (category == null) {
usedTimeUpdateHelper?.commit(appLogic)
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
title = appTitleCache.query(foregroundAppPackageName),
text = appLogic.context.getString(R.string.background_logic_opening_lockscreen)
))
appLogic.platformIntegration.setSuspendedApps(listOf(foregroundAppPackageName), true)
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
appLogic.platformIntegration.setShowBlockingOverlay(true)
openLockscreen(foregroundAppPackageName)
} else if (category.temporarilyBlocked or (parentCategory?.temporarilyBlocked == true)) {
usedTimeUpdateHelper?.commit(appLogic)
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
title = appTitleCache.query(foregroundAppPackageName),
text = appLogic.context.getString(R.string.background_logic_opening_lockscreen)
))
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
appLogic.platformIntegration.setShowBlockingOverlay(true)
openLockscreen(foregroundAppPackageName)
} else {
// disable time limits temporarily feature
if (realTime.shouldTrustTimeTemporarily && nowTimestamp < deviceUserEntry.disableLimitsUntil) {
@ -297,12 +305,7 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
) {
usedTimeUpdateHelper?.commit(appLogic)
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
title = appTitleCache.query(foregroundAppPackageName),
text = appLogic.context.getString(R.string.background_logic_opening_lockscreen)
))
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
appLogic.platformIntegration.setShowBlockingOverlay(true)
openLockscreen(foregroundAppPackageName)
} else {
// check time limits
val rules = timeLimitRules.get(category.id).waitForNonNullValue()
@ -325,12 +328,7 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
if (!isCurrentDevice) {
usedTimeUpdateHelper?.commit(appLogic)
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
title = appTitleCache.query(foregroundAppPackageName),
text = appLogic.context.getString(R.string.background_logic_opening_lockscreen)
))
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
appLogic.platformIntegration.setShowBlockingOverlay(true)
openLockscreen(foregroundAppPackageName)
} else if (realTime.shouldTrustTimeTemporarily) {
val usedTimes = usedTimesOfCategoryAndWeekByFirstDayOfWeek.get(Pair(category.id, nowDate.dayOfEpoch - nowDate.dayOfWeek)).waitForNonNullValue()
val parentUsedTimes = parentCategory?.let {
@ -439,25 +437,14 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
newUsedTimeItemBatchUpdateHelper.commit(appLogic)
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
title = appTitleCache.query(foregroundAppPackageName),
text = appLogic.context.getString(R.string.background_logic_opening_lockscreen)
))
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
appLogic.platformIntegration.setShowBlockingOverlay(true)
}
openLockscreen(foregroundAppPackageName) }
}
} else {
// if should not trust the time temporarily
usedTimeUpdateHelper?.commit(appLogic)
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
title = appTitleCache.query(foregroundAppPackageName),
text = appLogic.context.getString(R.string.background_logic_opening_lockscreen)
))
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
appLogic.platformIntegration.setShowBlockingOverlay(true)
openLockscreen(foregroundAppPackageName)
}
}
}
@ -561,6 +548,7 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
val usageStatsPermission = appLogic.platformIntegration.getForegroundAppPermissionStatus()
val notificationAccess = appLogic.platformIntegration.getNotificationAccessPermissionStatus()
val overlayPermission = appLogic.platformIntegration.getOverlayPermissionStatus()
val accessibilityService = appLogic.platformIntegration.isAccessibilityServiceEnabled()
var changes = UpdateDeviceStatusAction.empty
@ -592,6 +580,12 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
)
}
if (accessibilityService != deviceEntry.accessibilityServiceEnabled) {
changes = changes.copy(
newAccessibilityServiceEnabled = accessibilityService
)
}
if (changes != UpdateDeviceStatusAction.empty) {
ApplyActionUtil.applyAppLogicAction(
action = changes,