fix safety center bypass maybe
This commit is contained in:
parent
70b269254a
commit
ee11d7ecd6
|
@ -2,13 +2,21 @@ package rip.min.digica.service
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityService
|
import android.accessibilityservice.AccessibilityService
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.ActivityManager
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.SurfaceControl
|
||||||
import android.view.accessibility.AccessibilityEvent
|
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 java.util.Calendar
|
||||||
|
import kotlin.toString
|
||||||
|
|
||||||
@SuppressLint("AccessibilityPolicy")
|
@SuppressLint("AccessibilityPolicy")
|
||||||
class DigicaService : AccessibilityService() {
|
class DigicaService : AccessibilityService() {
|
||||||
|
@ -28,14 +36,42 @@ class DigicaService : AccessibilityService() {
|
||||||
serviceLabel = info.loadLabel(packageManager).toString()
|
serviceLabel = info.loadLabel(packageManager).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
|
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
|
||||||
if (event == null || event.packageName == null) return
|
if (event == null || event.packageName == null) return
|
||||||
|
|
||||||
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
|
Log.d("DigicaService", "$event")
|
||||||
|
|
||||||
|
// 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 pkgName = event.packageName.toString()
|
||||||
val className = event.className
|
val className = event.className
|
||||||
|
|
||||||
val commonSettingsRoot = rootInActiveWindow?.getChild(0)?.getChild(0)?.getChild(0)
|
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
|
||||||
|
val commonSettingsRoot =
|
||||||
|
rootInActiveWindow?.getChild(0)?.getChild(0)?.getChild(0)
|
||||||
?.getChild(0)?.getChild(0)
|
?.getChild(0)?.getChild(0)
|
||||||
|
|
||||||
// Is force stop dialog open?
|
// Is force stop dialog open?
|
||||||
|
@ -66,47 +102,29 @@ class DigicaService : AccessibilityService() {
|
||||||
&& event.text.size == 3
|
&& event.text.size == 3
|
||||||
&& event.text[0].contains(serviceLabel)
|
&& 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?
|
// Is user trying to go on a banned app?
|
||||||
val usingApp = pkgName == "com.zhiliaoapp.musically"
|
val usingApp = pkgName == "com.zhiliaoapp.musically"
|
||||||
|| pkgName == "com.aliucord"
|
|| pkgName == "com.aliucord"
|
||||||
|| pkgName == "app.revanced.android.youtube"
|
|| 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 attempting = (attemptingUninstall
|
||||||
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
|
|
||||||
|
|
||||||
// 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
|
|| attemptingDisableService
|
||||||
|| attemptingForceStop
|
|| attemptingForceStop
|
||||||
|
|| safetyCenter
|
||||||
|| usingApp)
|
|| usingApp)
|
||||||
) {
|
|
||||||
|
if ((isLate || !autoDate) && attempting) {
|
||||||
// Stop them from doing that
|
// Stop them from doing that
|
||||||
Log.i("DigicaService", "Preventing action")
|
Log.i("DigicaService", "Preventing action")
|
||||||
Log.d("DigicaService", event.toString())
|
Log.d("DigicaService", event.toString())
|
||||||
leaveDelayed(100L)
|
leaveDelayed(100L)
|
||||||
leaveDelayed(200L)
|
leaveDelayed(200L)
|
||||||
|
leaveDelayed(500L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
<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:description="@string/accessibility_service_description"
|
||||||
android:accessibilityEventTypes="typeWindowStateChanged"
|
android:accessibilityEventTypes="typeWindowStateChanged|typeViewClicked"
|
||||||
android:accessibilityFlags="flagDefault"
|
android:accessibilityFlags="flagDefault"
|
||||||
android:accessibilityFeedbackType="feedbackGeneric"
|
android:accessibilityFeedbackType="feedbackGeneric"
|
||||||
android:notificationTimeout="0"
|
android:notificationTimeout="0"
|
||||||
android:canRetrieveWindowContent="true"
|
android:canRetrieveWindowContent="true"
|
||||||
|
android:isAccessibilityTool="true"
|
||||||
android:settingsActivity="rip.min.digica.MainActivity"
|
android:settingsActivity="rip.min.digica.MainActivity"
|
||||||
/>
|
tools:ignore="AccessibilityPolicy" />
|
|
@ -1,13 +1,13 @@
|
||||||
[versions]
|
[versions]
|
||||||
agp = "8.13.0"
|
agp = "8.13.0"
|
||||||
kotlin = "2.0.21"
|
kotlin = "2.2.20"
|
||||||
coreKtx = "1.17.0"
|
coreKtx = "1.17.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
junitVersion = "1.3.0"
|
junitVersion = "1.3.0"
|
||||||
espressoCore = "3.7.0"
|
espressoCore = "3.7.0"
|
||||||
lifecycleRuntimeKtx = "2.6.1"
|
lifecycleRuntimeKtx = "2.9.4"
|
||||||
activityCompose = "1.8.0"
|
activityCompose = "1.11.0"
|
||||||
composeBom = "2024.09.00"
|
composeBom = "2025.09.01"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
|
|
Loading…
Reference in New Issue