fix safety center bypass maybe

This commit is contained in:
minish 2025-09-26 21:10:55 -04:00
parent 70b269254a
commit ee11d7ecd6
Signed by: min
SSH Key Fingerprint: SHA256:mf+pUTmK92Y57BuCjlkBdd82LqztTfDCQIUp0fCKABc
3 changed files with 60 additions and 40 deletions

View File

@ -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)
}
}
}

View File

@ -1,9 +1,11 @@
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:description="@string/accessibility_service_description"
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityEventTypes="typeWindowStateChanged|typeViewClicked"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="0"
android:canRetrieveWindowContent="true"
android:isAccessibilityTool="true"
android:settingsActivity="rip.min.digica.MainActivity"
/>
tools:ignore="AccessibilityPolicy" />

View File

@ -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" }