Browse Source

Improve applying list of suspended apps

master
Jonas Lochmann 3 weeks ago
parent
commit
422e823c29
Signed by: Jonas Lochmann <git@inkompetenz.org> GPG Key ID: 8B8C9AEE10FA5B36

+ 1
- 0
app/src/main/java/io/timelimit/android/integration/platform/PlatformIntegration.kt View File

@@ -26,6 +26,7 @@ abstract class PlatformIntegration(
val maximumProtectionLevel: ProtectionLevel
) {
abstract fun getLocalApps(deviceId: String): Collection<App>
abstract fun getLocalAppPackageNames(): List<String>
abstract fun getLocalAppActivities(deviceId: String): Collection<AppActivity>
abstract fun getLocalAppTitle(packageName: String): String?
abstract fun getAppIcon(packageName: String): Drawable?

+ 3
- 1
app/src/main/java/io/timelimit/android/integration/platform/android/AndroidIntegration.kt View File

@@ -92,6 +92,8 @@ class AndroidIntegration(context: Context): PlatformIntegration(maximumProtectio
return AndroidIntegrationApps.getLocalApps(deviceId, context)
}

override fun getLocalAppPackageNames(): List<String> = context.packageManager.getInstalledApplications(0).map { it.packageName }

override fun getLocalAppActivities(deviceId: String): Collection<AppActivity> {
return AndroidIntegrationApps.getLocalAppActivities(deviceId, context)
}
@@ -424,7 +426,7 @@ class AndroidIntegration(context: Context): PlatformIntegration(maximumProtectio
}

override fun stopSuspendingForAllApps() {
setSuspendedApps(context.packageManager.getInstalledApplications(0).map { it.packageName }, false)
setSuspendedApps(getLocalAppPackageNames(), false)
}

override fun setLockTaskPackages(packageNames: List<String>): Boolean {

+ 2
- 0
app/src/main/java/io/timelimit/android/integration/platform/dummy/DummyIntegration.kt View File

@@ -38,6 +38,8 @@ class DummyIntegration(
return localApps.map{ it.copy(deviceId = deviceId) }
}

override fun getLocalAppPackageNames(): List<String> = localApps.map { it.packageName }

override fun getLocalAppTitle(packageName: String): String? {
return localApps.find { it.packageName == packageName }?.title
}

+ 9
- 2
app/src/main/java/io/timelimit/android/logic/SuspendAppsLogic.kt View File

@@ -147,8 +147,15 @@ class SuspendAppsLogic(private val appLogic: AppLogic) {
}

private fun applySuspendedApps(packageNames: List<String>) {
appLogic.platformIntegration.stopSuspendingForAllApps()
appLogic.platformIntegration.setSuspendedApps(packageNames, true)
if (packageNames.isEmpty()) {
appLogic.platformIntegration.stopSuspendingForAllApps()
} else {
val allApps = appLogic.platformIntegration.getLocalAppPackageNames()
val appsToNotBlock = allApps.subtract(packageNames)

appLogic.platformIntegration.setSuspendedApps(appsToNotBlock.toList(), false)
appLogic.platformIntegration.setSuspendedApps(packageNames, true)
}
}

init {

Loading…
Cancel
Save