mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-05 19:42:20 +02:00
Improve applying list of suspended apps
This commit is contained in:
parent
9cfe14fbaa
commit
422e823c29
4 changed files with 15 additions and 3 deletions
|
@ -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?
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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…
Add table
Add a link
Reference in a new issue