prevent force stop
This commit is contained in:
parent
81fad83f1e
commit
0b96b5bb52
|
@ -1,4 +1,3 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||
|
|
|
@ -7,12 +7,15 @@ import android.os.Handler
|
|||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import androidx.collection.emptyLongSet
|
||||
import java.util.Calendar
|
||||
|
||||
class DigicaService : AccessibilityService() {
|
||||
private lateinit var appLabel: String
|
||||
private lateinit var serviceLabel: String
|
||||
|
||||
private var wasLastViewingAppInfo = false
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
|
@ -29,15 +32,31 @@ class DigicaService : AccessibilityService() {
|
|||
|
||||
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
|
||||
val pkgName = event.packageName.toString()
|
||||
val className = event.className;
|
||||
|
||||
// Is force stop dialog possibly open?
|
||||
val possiblyForceStop = pkgName == "com.android.settings"
|
||||
&& className == "androidx.compose.ui.window.DialogWrapper"
|
||||
|
||||
// Check if we are on App info page in settings
|
||||
if (pkgName == "com.android.settings") {
|
||||
if (className == "com.android.settings.spa.SpaActivity"
|
||||
&& event.text.getOrNull(0) == "App info"
|
||||
) wasLastViewingAppInfo = true;
|
||||
// If we did not switch to what is maybe the force stop dialog,
|
||||
// reset the flag
|
||||
else if (!possiblyForceStop)
|
||||
wasLastViewingAppInfo = false;
|
||||
}
|
||||
|
||||
// Is user trying to uninstall this app?
|
||||
val attemptingUninstall = pkgName == "com.google.android.packageinstaller"
|
||||
&& event.className == "android.app.AlertDialog"
|
||||
&& className == "android.app.AlertDialog"
|
||||
&& event.text.getOrNull(0) == appLabel
|
||||
|
||||
// Is user trying to disable the service?
|
||||
val attemptingDisableService = pkgName == "com.android.settings"
|
||||
&& event.className == "android.app.AlertDialog"
|
||||
&& className == "android.app.AlertDialog"
|
||||
&& event.text.size == 3
|
||||
&& event.text[0].contains(serviceLabel)
|
||||
|
||||
|
@ -46,6 +65,9 @@ class DigicaService : AccessibilityService() {
|
|||
|| pkgName == "com.aliucord"
|
||||
|| pkgName == "app.revanced.android.youtube"
|
||||
|
||||
// Is user trying to force stop?
|
||||
val attemptingForceStop = possiblyForceStop && wasLastViewingAppInfo;
|
||||
|
||||
// Get time
|
||||
val cal = Calendar.getInstance()
|
||||
val day = cal.get(Calendar.DAY_OF_WEEK)
|
||||
|
@ -65,12 +87,16 @@ class DigicaService : AccessibilityService() {
|
|||
// 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
|
||||
&& Settings.Global.getInt(
|
||||
contentResolver,
|
||||
Settings.Global.AUTO_TIME_ZONE
|
||||
) == 1
|
||||
|
||||
if (
|
||||
(isLate || !autoDate) &&
|
||||
(attemptingUninstall
|
||||
|| attemptingDisableService
|
||||
|| attemptingForceStop
|
||||
|| usingApp)
|
||||
) {
|
||||
// Stop them from doing that
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/accessibility_service_description"
|
||||
android:accessibilityEventTypes="typeAllMask"
|
||||
android:accessibilityEventTypes="typeWindowStateChanged"
|
||||
android:accessibilityFlags="flagDefault"
|
||||
android:accessibilityFeedbackType="feedbackGeneric"
|
||||
android:notificationTimeout="0"
|
||||
android:canRetrieveWindowContent="true"
|
||||
android:canRetrieveWindowContent="false"
|
||||
android:settingsActivity="rip.min.digica.MainActivity"
|
||||
/>
|
Loading…
Reference in New Issue