Skip to content

Commit 559e1cd

Browse files
6.6.1 - Alpha3 - 提升浮动窗口当前包名及当前活动名的识别准确性
1 parent 42f36d9 commit 559e1cd

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

.changelog/lang_zh-Hans.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"UiObjectCollection 实例缺失自身方法及属性的问题"
1818
],
1919
"improvement": [
20+
"提升浮动窗口当前包名及当前活动名的识别准确性 (优先级: Shizuku > Root > A11Y)",
2021
"提升 currentPackage/currentActivity 识别准确性 (优先级: Shizuku > Root > A11Y)",
2122
"恢复日志活动窗口单个条目文本内容的双击或长按选择功能 _[`issue #280`](http://issues.autojs6.com/280)_",
2223
"脚本项目识别在 project.json 损坏情况下尽可能还原关键信息",

app/src/main/java/org/autojs/autojs/core/accessibility/SimpleActionAutomator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.autojs.autojs.runtime.ScriptRuntime
2626
import org.autojs.autojs.runtime.accessibility.AccessibilityConfig
2727
import org.autojs.autojs.runtime.api.ScreenMetrics
2828
import org.autojs.autojs.runtime.api.ScriptPromiseAdapter
29+
import org.autojs.autojs.runtime.api.augment.global.Global
2930
import org.autojs.autojs.util.DeveloperUtils
3031
import java.lang.ref.WeakReference
3132
import java.util.concurrent.atomic.AtomicInteger
@@ -52,7 +53,7 @@ class SimpleActionAutomator(private val accessibilityBridge: AccessibilityBridge
5253
}
5354

5455
private val isRunningPackageSelf
55-
get() = DeveloperUtils.isSelfPackage(accessibilityBridge.infoProvider.latestPackage)
56+
get() = DeveloperUtils.isSelfPackage(Global.currentPackage(scriptRuntime, emptyArray()))
5657

5758
private var mScreenMetrics: ScreenMetrics? = null
5859
private val mScriptRuntime = WeakReference(scriptRuntime)

app/src/main/java/org/autojs/autojs/runtime/api/WrappedShizuku.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ object WrappedShizuku {
117117
false.also { if (e.message?.contains(Regex("binder .+n[o']t been received", RegexOption.IGNORE_CASE)) == false) e.printStackTrace() }
118118
}
119119

120+
@JvmStatic
120121
@ScriptInterface
121122
fun isOperational(): Boolean = isRunning() && hasPermission()
122123

app/src/main/java/org/autojs/autojs/runtime/api/augment/shell/Shell.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,23 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
9797
@JvmStatic
9898
@RhinoRuntimeFunctionInterface
9999
fun currentPackage(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
100-
currentComponent(scriptRuntime, args).substringBefore("/")
100+
currentPackageRhino()
101101
}
102102

103+
@JvmStatic
104+
fun currentPackageRhino(): String = currentComponentRhino().substringBefore("/")
105+
103106
@JvmStatic
104107
@RhinoRuntimeFunctionInterface
105108
fun currentActivity(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
106-
val component = currentComponent(scriptRuntime, args)
109+
currentActivityRhino()
110+
}
111+
112+
@JvmStatic
113+
fun currentActivityRhino(): String {
114+
val component = currentComponentRhino()
107115
val className = component.substringAfterLast("/")
108-
when {
116+
return when {
109117
className.startsWith(".") -> component
110118
else -> className
111119
}
@@ -114,7 +122,12 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
114122
@JvmStatic
115123
@RhinoRuntimeFunctionInterface
116124
fun currentComponent(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
117-
if (!RootUtils.isRootAvailable()) return@ensureArgumentsIsEmpty ""
125+
currentComponentRhino()
126+
}
127+
128+
@JvmStatic
129+
fun currentComponentRhino(): String {
130+
if (!RootUtils.isRootAvailable()) return ""
118131
try {
119132
val process = Runtime.getRuntime().exec("su -c dumpsys activity activities")
120133
process.inputStream.bufferedReader().useLines { lines ->
@@ -127,14 +140,14 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
127140
part.contains("/")
128141
}?.let { part ->
129142
Log.d(TAG, "current activity part: $part")
130-
return@ensureArgumentsIsEmpty part.replace("\\W+$".toRegex(), "")
143+
return part.replace("\\W+$".toRegex(), "")
131144
}
132145
}
133146
}
134147
} catch (e: Exception) {
135148
Log.e(TAG, "Error reading current component", e)
136149
}
137-
return@ensureArgumentsIsEmpty ""
150+
return ""
138151
}
139152

140153
@JvmStatic

app/src/main/java/org/autojs/autojs/ui/floating/CircularMenu.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.content.res.ColorStateList;
55
import android.content.res.Configuration;
6+
import android.os.RemoteException;
67
import android.text.TextUtils;
78
import android.view.ContextThemeWrapper;
89
import android.view.View;
@@ -24,6 +25,8 @@
2425
import org.autojs.autojs.model.explorer.ExplorerDirPage;
2526
import org.autojs.autojs.model.explorer.Explorers;
2627
import org.autojs.autojs.model.script.Scripts;
28+
import org.autojs.autojs.runtime.api.WrappedShizuku;
29+
import org.autojs.autojs.runtime.api.augment.shell.Shell;
2730
import org.autojs.autojs.tool.Func1;
2831
import org.autojs.autojs.ui.enhancedfloaty.FloatyService;
2932
import org.autojs.autojs.ui.enhancedfloaty.FloatyWindow;
@@ -173,9 +176,7 @@ private void setupBindingListeners() {
173176
mSettingsDialog.dismiss();
174177
}
175178

176-
ActivityInfoProvider infoProvider = AutoJs.getInstance().getInfoProvider();
177-
mRunningPackage = infoProvider.getLatestPackageByUsageStatsIfGranted();
178-
mRunningActivity = infoProvider.getLatestActivity();
179+
applyComponentInformation();
179180

180181
// noinspection CodeBlock2Expr
181182
mSettingsDialog = new CircularMenuOperationDialogBuilder(mContext)
@@ -212,6 +213,26 @@ private void setupBindingListeners() {
212213
});
213214
}
214215

216+
private void applyComponentInformation() {
217+
if (WrappedShizuku.isOperational() && WrappedShizuku.service != null) {
218+
try {
219+
mRunningPackage = WrappedShizuku.service.currentPackage();
220+
mRunningActivity = WrappedShizuku.service.currentActivity();
221+
return;
222+
} catch (RemoteException ignored) {
223+
224+
}
225+
}
226+
if (RootUtils.isRootAvailable()) {
227+
mRunningPackage = Shell.currentPackageRhino();
228+
mRunningActivity = Shell.currentActivityRhino();
229+
return;
230+
}
231+
ActivityInfoProvider infoProvider = AutoJs.getInstance().getInfoProvider();
232+
mRunningPackage = infoProvider.getLatestPackageByUsageStatsIfGranted();
233+
mRunningActivity = infoProvider.getLatestActivity();
234+
}
235+
215236
@NonNull
216237
private View.OnClickListener onCircularMenuItemClick(View.OnClickListener listener) {
217238
return v -> {

version.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#Wed Jan 01 11:40:23 CST 2025
2-
BUILD_TIME=1735702823631
1+
#Wed Jan 01 12:09:07 CST 2025
2+
BUILD_TIME=1735704547526
33
COMPILE_SDK_VERSION=34
44
JAVA_VERSION=23
55
JAVA_VERSION_MIN_RADICAL=0

0 commit comments

Comments
 (0)