From ee11d7ecd6c7e48d3cff7444e4bff8d574dc8039 Mon Sep 17 00:00:00 2001 From: min Date: Fri, 26 Sep 2025 21:10:55 -0400 Subject: [PATCH] fix safety center bypass maybe --- .../rip/min/digica/service/DigicaService.kt | 86 +++++++++++-------- .../res/xml/accessibility_service_config.xml | 6 +- gradle/libs.versions.toml | 8 +- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/rip/min/digica/service/DigicaService.kt b/app/src/main/java/rip/min/digica/service/DigicaService.kt index aa153b9..22486c1 100644 --- a/app/src/main/java/rip/min/digica/service/DigicaService.kt +++ b/app/src/main/java/rip/min/digica/service/DigicaService.kt @@ -2,13 +2,21 @@ package rip.min.digica.service import android.accessibilityservice.AccessibilityService import android.annotation.SuppressLint +import android.app.ActivityManager import android.content.ComponentName +import android.content.Intent import android.content.pm.PackageManager import android.os.Handler import android.provider.Settings import android.util.Log +import android.view.SurfaceControl import android.view.accessibility.AccessibilityEvent +import androidx.core.util.forEach +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import java.util.Calendar +import kotlin.toString @SuppressLint("AccessibilityPolicy") class DigicaService : AccessibilityService() { @@ -28,15 +36,43 @@ class DigicaService : AccessibilityService() { serviceLabel = info.loadLabel(packageManager).toString() } + override fun onAccessibilityEvent(event: AccessibilityEvent?) { if (event == null || event.packageName == null) return - if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { - val pkgName = event.packageName.toString() - val className = event.className + Log.d("DigicaService", "$event") - val commonSettingsRoot = rootInActiveWindow?.getChild(0)?.getChild(0)?.getChild(0) - ?.getChild(0)?.getChild(0) + // Get time + val cal = Calendar.getInstance() + val day = cal.get(Calendar.DAY_OF_WEEK) + val hour = cal.get(Calendar.HOUR_OF_DAY) + + // Is it late? + val lateHour = when (day) { + // No early classes on these days + // Late is 1:00AM + Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY -> 1 + // Need to wake up early + // Late is 12:00AM + else -> 0 + } + val isLate = hour >= lateHour && hour < 7 + + // Is date set automatically? + val autoDate = + Settings.Global.getInt(contentResolver, Settings.Global.AUTO_TIME) == 1 + && Settings.Global.getInt( + contentResolver, + Settings.Global.AUTO_TIME_ZONE + ) == 1 + + val pkgName = event.packageName.toString() + val className = event.className + + if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { + val commonSettingsRoot = + rootInActiveWindow?.getChild(0)?.getChild(0)?.getChild(0) + ?.getChild(0)?.getChild(0) // Is force stop dialog open? val forceStop = pkgName == "com.android.settings" @@ -66,47 +102,29 @@ class DigicaService : AccessibilityService() { && event.text.size == 3 && event.text[0].contains(serviceLabel) + // Is user in safety center? (can disable service) + val safetyCenter = pkgName == "com.google.android.permissioncontroller" + && className == "android.widget.FrameLayout" + // Is user trying to go on a banned app? val usingApp = pkgName == "com.zhiliaoapp.musically" || pkgName == "com.aliucord" || pkgName == "app.revanced.android.youtube" - // Get time - val cal = Calendar.getInstance() - val day = cal.get(Calendar.DAY_OF_WEEK) - val hour = cal.get(Calendar.HOUR_OF_DAY) - // Is it late? - val lateHour = when (day) { - // No early classes on these days - // Late is 1:00AM - Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY -> 1 - // Need to wake up early - // Late is 12:00AM - else -> 0 - } - val isLate = hour >= lateHour && hour < 7 + val attempting = (attemptingUninstall + || attemptingDisableService + || attemptingForceStop + || safetyCenter + || usingApp) - // Is date set automatically? - val autoDate = - Settings.Global.getInt(contentResolver, Settings.Global.AUTO_TIME) == 1 - && Settings.Global.getInt( - contentResolver, - Settings.Global.AUTO_TIME_ZONE - ) == 1 - - if ( - (isLate || !autoDate) && - (attemptingUninstall - || attemptingDisableService - || attemptingForceStop - || usingApp) - ) { + if ((isLate || !autoDate) && attempting) { // Stop them from doing that Log.i("DigicaService", "Preventing action") Log.d("DigicaService", event.toString()) leaveDelayed(100L) leaveDelayed(200L) + leaveDelayed(500L) } } } diff --git a/app/src/main/res/xml/accessibility_service_config.xml b/app/src/main/res/xml/accessibility_service_config.xml index f5d175d..5276bf5 100644 --- a/app/src/main/res/xml/accessibility_service_config.xml +++ b/app/src/main/res/xml/accessibility_service_config.xml @@ -1,9 +1,11 @@ \ No newline at end of file + tools:ignore="AccessibilityPolicy" /> \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 24ef57f..8e28203 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,13 @@ [versions] agp = "8.13.0" -kotlin = "2.0.21" +kotlin = "2.2.20" coreKtx = "1.17.0" junit = "4.13.2" junitVersion = "1.3.0" espressoCore = "3.7.0" -lifecycleRuntimeKtx = "2.6.1" -activityCompose = "1.8.0" -composeBom = "2024.09.00" +lifecycleRuntimeKtx = "2.9.4" +activityCompose = "1.11.0" +composeBom = "2025.09.01" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }