commit a975a3e632771b8a2e03a1e6855fdcb8e1067151 Author: manchuwork Date: Sat Sep 27 01:17:19 2025 +0800 无障碍服务修改main activity状态 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/MarsCodeWorkspaceAppSettings.xml b/.idea/MarsCodeWorkspaceAppSettings.xml new file mode 100644 index 0000000..e2a065b --- /dev/null +++ b/.idea/MarsCodeWorkspaceAppSettings.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..97f0a8e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..74dd639 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..d8ab75b --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,48 @@ + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.loveerror.bested" + compileSdk = 36 + + defaultConfig { + applicationId = "com.loveerror.bested" + minSdk = 28 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + implementation(libs.androidx.preference) +// classpath('com.android.tools.build:gradle:8.1.0') + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/loveerror/bested/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/loveerror/bested/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..e706f0f --- /dev/null +++ b/app/src/androidTest/java/com/loveerror/bested/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.loveerror.bested + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.loveerror.bested", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..169ed4d --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/loveerror/bested/AccessibilityService.kt b/app/src/main/java/com/loveerror/bested/AccessibilityService.kt new file mode 100644 index 0000000..9d5423b --- /dev/null +++ b/app/src/main/java/com/loveerror/bested/AccessibilityService.kt @@ -0,0 +1,76 @@ +package com.loveerror.bested + +import android.accessibilityservice.AccessibilityService +import android.view.accessibility.AccessibilityEvent +import android.view.accessibility.AccessibilityNodeInfo + +class UIInspectorService : AccessibilityService() { + + + override fun onAccessibilityEvent(event: AccessibilityEvent?) { + when (event?.eventType) { + AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, + AccessibilityEvent.TYPE_VIEW_FOCUSED -> { + // 获取根节点 + val root = rootInActiveWindow + if (root != null) { + // 遍历所有节点 + traverseAccessibilityNodes(root) + } + } + } + } + + private fun traverseAccessibilityNodes(node: AccessibilityNodeInfo) { + // 处理当前节点信息 + processNodeInfo(node) + + // 遍历子节点 + for (i in 0 until node.childCount) { + val child = node.getChild(i) + if (child != null) { + traverseAccessibilityNodes(child) + } + } + } + + private fun processNodeInfo(node: AccessibilityNodeInfo) { + // 提取节点信息 + val nodeInfo = AccessibilityNodeInfoData( + packageName = node.packageName?.toString() ?: "", + className = node.className?.toString() ?: "", + text = node.text?.toString() ?: "", + contentDescription = node.contentDescription?.toString() ?: "", + isEnabled = node.isEnabled, + isVisible = node.isVisibleToUser, + activityName = getActiveActivityName(), // 获取当前Activity名称 + viewIdResourceName = node.viewIdResourceName ?: "" // View的资源名称 + + ) + + // 可以在这里处理节点信息,比如打印日志或存储 + println("Found view: $nodeInfo") + } + + private fun getActiveActivityName(): String { + // 通过根节点获取当前Activity名称 + val root = rootInActiveWindow + return root?.packageName?.toString() ?: "" + } + + override fun onInterrupt() { + // 服务中断时的处理 + } +} + +data class AccessibilityNodeInfoData( + val packageName: String, + val className: String, + val text: String, + val contentDescription: String, + val isEnabled: Boolean, + val isVisible: Boolean, + val activityName: String, // 当前Activity名称 + val viewIdResourceName: String // View的完整资源名称 + +) diff --git a/app/src/main/java/com/loveerror/bested/MainActivity.kt b/app/src/main/java/com/loveerror/bested/MainActivity.kt new file mode 100644 index 0000000..27bbb55 --- /dev/null +++ b/app/src/main/java/com/loveerror/bested/MainActivity.kt @@ -0,0 +1,72 @@ +package com.loveerror.bested +import android.accessibilityservice.AccessibilityServiceInfo +import android.content.BroadcastReceiver +import android.content.ComponentName +import android.content.Context +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import android.content.Intent +import android.content.IntentFilter +import android.os.Build +import android.provider.Settings +import android.view.accessibility.AccessibilityEvent +import android.view.accessibility.AccessibilityManager + +import android.widget.Button +import android.widget.TextView +import androidx.core.view.accessibility.AccessibilityManagerCompat + +class MainActivity : AppCompatActivity() { + private lateinit var accessibilityStateReceiver: BroadcastReceiver + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val btnEnableService = findViewById