mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 09:49:25 +02:00
Add option for stricter overlay permission checking
This commit is contained in:
parent
fadb22b90c
commit
b86a4937ea
10 changed files with 23 additions and 12 deletions
|
@ -250,4 +250,5 @@ object ExperimentalFlags {
|
||||||
const val SYNC_RELATED_NOTIFICATIONS = 32768L
|
const val SYNC_RELATED_NOTIFICATIONS = 32768L
|
||||||
const val INSTANCE_ID_FG_APP_DETECTION = 65536L
|
const val INSTANCE_ID_FG_APP_DETECTION = 65536L
|
||||||
// private const val OBSOLETE_DISABLE_FG_APP_DETECTION_FALLBACK = 131072L
|
// private const val OBSOLETE_DISABLE_FG_APP_DETECTION_FALLBACK = 131072L
|
||||||
|
const val STRICT_OVERLAY_CHECKING = 0x40000L
|
||||||
}
|
}
|
|
@ -36,7 +36,7 @@ abstract class PlatformIntegration(
|
||||||
abstract fun getLauncherAppPackageName(): String?
|
abstract fun getLauncherAppPackageName(): String?
|
||||||
abstract fun getCurrentProtectionLevel(): ProtectionLevel
|
abstract fun getCurrentProtectionLevel(): ProtectionLevel
|
||||||
abstract fun getForegroundAppPermissionStatus(): RuntimePermissionStatus
|
abstract fun getForegroundAppPermissionStatus(): RuntimePermissionStatus
|
||||||
abstract fun getDrawOverOtherAppsPermissionStatus(): RuntimePermissionStatus
|
abstract fun getDrawOverOtherAppsPermissionStatus(strictChecking: Boolean): RuntimePermissionStatus
|
||||||
abstract fun getNotificationAccessPermissionStatus(): NewPermissionStatus
|
abstract fun getNotificationAccessPermissionStatus(): NewPermissionStatus
|
||||||
abstract fun isAccessibilityServiceEnabled(): Boolean
|
abstract fun isAccessibilityServiceEnabled(): Boolean
|
||||||
abstract fun disableDeviceAdmin()
|
abstract fun disableDeviceAdmin()
|
||||||
|
|
|
@ -173,7 +173,7 @@ class AndroidIntegration(context: Context): PlatformIntegration(maximumProtectio
|
||||||
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDrawOverOtherAppsPermissionStatus(): RuntimePermissionStatus = overlay.getOverlayPermissionStatus()
|
override fun getDrawOverOtherAppsPermissionStatus(strictChecking: Boolean): RuntimePermissionStatus = overlay.getOverlayPermissionStatus(strictChecking)
|
||||||
|
|
||||||
override fun getNotificationAccessPermissionStatus(): NewPermissionStatus {
|
override fun getNotificationAccessPermissionStatus(): NewPermissionStatus {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
@ -761,7 +761,7 @@ class AndroidIntegration(context: Context): PlatformIntegration(maximumProtectio
|
||||||
}
|
}
|
||||||
SystemPermission.Overlay -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
SystemPermission.Overlay -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (
|
if (
|
||||||
overlay.getOverlayPermissionStatus() == RuntimePermissionStatus.NotGranted &&
|
overlay.getOverlayPermissionStatus(true) == RuntimePermissionStatus.NotGranted &&
|
||||||
confirmationLevel == SystemPermissionConfirmationLevel.None
|
confirmationLevel == SystemPermissionConfirmationLevel.None
|
||||||
) {
|
) {
|
||||||
PermissionInfoConfirmDialog.newInstance(SystemPermission.Overlay)
|
PermissionInfoConfirmDialog.newInstance(SystemPermission.Overlay)
|
||||||
|
|
|
@ -43,7 +43,7 @@ class OverlayUtil(private var application: Application) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getOverlayPermissionStatus() == RuntimePermissionStatus.NotGranted) {
|
if (getOverlayPermissionStatus(false) == RuntimePermissionStatus.NotGranted) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,15 +89,15 @@ class OverlayUtil(private var application: Application) {
|
||||||
|
|
||||||
fun isOverlayShown() = currentView?.root?.isShown ?: false
|
fun isOverlayShown() = currentView?.root?.isShown ?: false
|
||||||
|
|
||||||
fun getOverlayPermissionStatus() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
fun getOverlayPermissionStatus(strictChecking: Boolean) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
if (checkAppOp() || Settings.canDrawOverlays(application))
|
if (checkAppOp(strictChecking) || Settings.canDrawOverlays(application))
|
||||||
RuntimePermissionStatus.Granted
|
RuntimePermissionStatus.Granted
|
||||||
else
|
else
|
||||||
RuntimePermissionStatus.NotGranted
|
RuntimePermissionStatus.NotGranted
|
||||||
else
|
else
|
||||||
RuntimePermissionStatus.NotRequired
|
RuntimePermissionStatus.NotRequired
|
||||||
|
|
||||||
private fun checkAppOp(): Boolean {
|
private fun checkAppOp(strictChecking: Boolean): Boolean {
|
||||||
if (systemOverlayOp == null) return false
|
if (systemOverlayOp == null) return false
|
||||||
|
|
||||||
val mode1 = AppOps.getOpMode(systemOverlayOp, appsOpsManager, application)
|
val mode1 = AppOps.getOpMode(systemOverlayOp, appsOpsManager, application)
|
||||||
|
@ -108,6 +108,7 @@ class OverlayUtil(private var application: Application) {
|
||||||
|
|
||||||
val mode2 = appsOpsManager.checkOpNoThrow(systemOverlayOp, Process.myUid(), application.packageName)
|
val mode2 = appsOpsManager.checkOpNoThrow(systemOverlayOp, Process.myUid(), application.packageName)
|
||||||
|
|
||||||
return mode2 == AppOpsManager.MODE_ALLOWED || mode2 == AppOpsManager.MODE_IGNORED
|
return if (strictChecking) mode2 == AppOpsManager.MODE_ALLOWED
|
||||||
|
else mode2 == AppOpsManager.MODE_ALLOWED || mode2 == AppOpsManager.MODE_IGNORED
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -68,7 +68,7 @@ class DummyIntegration(
|
||||||
return foregroundAppPermission
|
return foregroundAppPermission
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDrawOverOtherAppsPermissionStatus(): RuntimePermissionStatus {
|
override fun getDrawOverOtherAppsPermissionStatus(strictChecking: Boolean): RuntimePermissionStatus {
|
||||||
return drawOverOtherApps
|
return drawOverOtherApps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -874,6 +874,7 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
||||||
|
|
||||||
private suspend fun getUpdateDeviceStatusAction(): UpdateDeviceStatusAction {
|
private suspend fun getUpdateDeviceStatusAction(): UpdateDeviceStatusAction {
|
||||||
val deviceEntry = appLogic.deviceEntry.waitForNullableValue()
|
val deviceEntry = appLogic.deviceEntry.waitForNullableValue()
|
||||||
|
val useStrictChecking = appLogic.database.config().isExperimentalFlagsSetAsync(ExperimentalFlags.STRICT_OVERLAY_CHECKING).waitForNonNullValue()
|
||||||
|
|
||||||
var changes = UpdateDeviceStatusAction.empty
|
var changes = UpdateDeviceStatusAction.empty
|
||||||
|
|
||||||
|
@ -881,7 +882,7 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
||||||
val protectionLevel = appLogic.platformIntegration.getCurrentProtectionLevel()
|
val protectionLevel = appLogic.platformIntegration.getCurrentProtectionLevel()
|
||||||
val usageStatsPermission = appLogic.platformIntegration.getForegroundAppPermissionStatus()
|
val usageStatsPermission = appLogic.platformIntegration.getForegroundAppPermissionStatus()
|
||||||
val notificationAccess = appLogic.platformIntegration.getNotificationAccessPermissionStatus()
|
val notificationAccess = appLogic.platformIntegration.getNotificationAccessPermissionStatus()
|
||||||
val overlayPermission = appLogic.platformIntegration.getDrawOverOtherAppsPermissionStatus()
|
val overlayPermission = appLogic.platformIntegration.getDrawOverOtherAppsPermissionStatus(useStrictChecking)
|
||||||
val accessibilityService = appLogic.platformIntegration.isAccessibilityServiceEnabled()
|
val accessibilityService = appLogic.platformIntegration.isAccessibilityServiceEnabled()
|
||||||
val qOrLater = AndroidVersion.qOrLater
|
val qOrLater = AndroidVersion.qOrLater
|
||||||
|
|
||||||
|
|
|
@ -201,6 +201,12 @@ data class DiagnoseExperimentalFlagItem(
|
||||||
enableFlags = ExperimentalFlags.INSTANCE_ID_FG_APP_DETECTION,
|
enableFlags = ExperimentalFlags.INSTANCE_ID_FG_APP_DETECTION,
|
||||||
disableFlags = ExperimentalFlags.INSTANCE_ID_FG_APP_DETECTION,
|
disableFlags = ExperimentalFlags.INSTANCE_ID_FG_APP_DETECTION,
|
||||||
enable = { true }
|
enable = { true }
|
||||||
|
),
|
||||||
|
DiagnoseExperimentalFlagItem(
|
||||||
|
label = R.string.diagnose_exf_soc,
|
||||||
|
enableFlags = ExperimentalFlags.STRICT_OVERLAY_CHECKING,
|
||||||
|
disableFlags = ExperimentalFlags.STRICT_OVERLAY_CHECKING,
|
||||||
|
enable = { true }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* TimeLimit Copyright <C> 2019 - 2021 Jonas Lochmann
|
* TimeLimit Copyright <C> 2019 - 2022 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -106,7 +106,7 @@ class SetupDevicePermissionsFragment : Fragment() {
|
||||||
binding.notificationAccessPermission = platform.getNotificationAccessPermissionStatus()
|
binding.notificationAccessPermission = platform.getNotificationAccessPermissionStatus()
|
||||||
binding.protectionLevel = platform.getCurrentProtectionLevel()
|
binding.protectionLevel = platform.getCurrentProtectionLevel()
|
||||||
binding.usageStatsAccess = platform.getForegroundAppPermissionStatus()
|
binding.usageStatsAccess = platform.getForegroundAppPermissionStatus()
|
||||||
binding.overlayPermission = platform.getDrawOverOtherAppsPermissionStatus()
|
binding.overlayPermission = platform.getDrawOverOtherAppsPermissionStatus(true)
|
||||||
binding.accessibilityServiceEnabled = platform.isAccessibilityServiceEnabled()
|
binding.accessibilityServiceEnabled = platform.isAccessibilityServiceEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -530,6 +530,7 @@
|
||||||
<string name="diagnose_exf_esb">Overlay und Home-Button nicht zum Sperren verwenden</string>
|
<string name="diagnose_exf_esb">Overlay und Home-Button nicht zum Sperren verwenden</string>
|
||||||
<string name="diagnose_exf_srn">Toasts zur Synchronisation anzeigen</string>
|
<string name="diagnose_exf_srn">Toasts zur Synchronisation anzeigen</string>
|
||||||
<string name="diagnose_exf_ifd">neue App-Erkennungs-Methode verwenden</string>
|
<string name="diagnose_exf_ifd">neue App-Erkennungs-Methode verwenden</string>
|
||||||
|
<string name="diagnose_exf_soc">strengere Prüfung der Überlagerungs-Berechtigung aktivieren</string>
|
||||||
|
|
||||||
<string name="diagnose_bg_task_loop_ex">Hintergrundaufgabenschleifenfehler</string>
|
<string name="diagnose_bg_task_loop_ex">Hintergrundaufgabenschleifenfehler</string>
|
||||||
|
|
||||||
|
|
|
@ -583,6 +583,7 @@
|
||||||
<string name="diagnose_exf_esb">Do not use a overlay or the home button for blocking</string>
|
<string name="diagnose_exf_esb">Do not use a overlay or the home button for blocking</string>
|
||||||
<string name="diagnose_exf_srn">Show sync related toasts</string>
|
<string name="diagnose_exf_srn">Show sync related toasts</string>
|
||||||
<string name="diagnose_exf_ifd">Use new App detection method</string>
|
<string name="diagnose_exf_ifd">Use new App detection method</string>
|
||||||
|
<string name="diagnose_exf_soc">Enable strict overlay permission check</string>
|
||||||
|
|
||||||
<string name="diagnose_bg_task_loop_ex">Background task loop exception</string>
|
<string name="diagnose_bg_task_loop_ex">Background task loop exception</string>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue