From 559e1cd2376573a5832e8294f3289763fc1f34d2 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Wed, 1 Jan 2025 12:11:24 +0800 Subject: [PATCH] =?UTF-8?q?6.6.1=20-=20Alpha3=20-=20=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E6=B5=AE=E5=8A=A8=E7=AA=97=E5=8F=A3=E5=BD=93=E5=89=8D=E5=8C=85?= =?UTF-8?q?=E5=90=8D=E5=8F=8A=E5=BD=93=E5=89=8D=E6=B4=BB=E5=8A=A8=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E8=AF=86=E5=88=AB=E5=87=86=E7=A1=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 1 + .../accessibility/SimpleActionAutomator.kt | 3 ++- .../autojs/runtime/api/WrappedShizuku.kt | 1 + .../autojs/runtime/api/augment/shell/Shell.kt | 25 ++++++++++++----- .../autojs/ui/floating/CircularMenu.java | 27 ++++++++++++++++--- version.properties | 4 +-- 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 293908e4..14b5d918 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -17,6 +17,7 @@ "UiObjectCollection 实例缺失自身方法及属性的问题" ], "improvement": [ + "提升浮动窗口当前包名及当前活动名的识别准确性 (优先级: Shizuku > Root > A11Y)", "提升 currentPackage/currentActivity 识别准确性 (优先级: Shizuku > Root > A11Y)", "恢复日志活动窗口单个条目文本内容的双击或长按选择功能 _[`issue #280`](http://issues.autojs6.com/280)_", "脚本项目识别在 project.json 损坏情况下尽可能还原关键信息", diff --git a/app/src/main/java/org/autojs/autojs/core/accessibility/SimpleActionAutomator.kt b/app/src/main/java/org/autojs/autojs/core/accessibility/SimpleActionAutomator.kt index 7231a34b..d2026247 100644 --- a/app/src/main/java/org/autojs/autojs/core/accessibility/SimpleActionAutomator.kt +++ b/app/src/main/java/org/autojs/autojs/core/accessibility/SimpleActionAutomator.kt @@ -26,6 +26,7 @@ import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.accessibility.AccessibilityConfig import org.autojs.autojs.runtime.api.ScreenMetrics import org.autojs.autojs.runtime.api.ScriptPromiseAdapter +import org.autojs.autojs.runtime.api.augment.global.Global import org.autojs.autojs.util.DeveloperUtils import java.lang.ref.WeakReference import java.util.concurrent.atomic.AtomicInteger @@ -52,7 +53,7 @@ class SimpleActionAutomator(private val accessibilityBridge: AccessibilityBridge } private val isRunningPackageSelf - get() = DeveloperUtils.isSelfPackage(accessibilityBridge.infoProvider.latestPackage) + get() = DeveloperUtils.isSelfPackage(Global.currentPackage(scriptRuntime, emptyArray())) private var mScreenMetrics: ScreenMetrics? = null private val mScriptRuntime = WeakReference(scriptRuntime) diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/WrappedShizuku.kt b/app/src/main/java/org/autojs/autojs/runtime/api/WrappedShizuku.kt index bada59d0..ccc8a437 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/WrappedShizuku.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/WrappedShizuku.kt @@ -117,6 +117,7 @@ object WrappedShizuku { false.also { if (e.message?.contains(Regex("binder .+n[o']t been received", RegexOption.IGNORE_CASE)) == false) e.printStackTrace() } } + @JvmStatic @ScriptInterface fun isOperational(): Boolean = isRunning() && hasPermission() diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/shell/Shell.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/shell/Shell.kt index 3c096416..c56ab0e1 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/shell/Shell.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/shell/Shell.kt @@ -97,15 +97,23 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim @JvmStatic @RhinoRuntimeFunctionInterface fun currentPackage(scriptRuntime: ScriptRuntime, args: Array): String = ensureArgumentsIsEmpty(args) { - currentComponent(scriptRuntime, args).substringBefore("/") + currentPackageRhino() } + @JvmStatic + fun currentPackageRhino(): String = currentComponentRhino().substringBefore("/") + @JvmStatic @RhinoRuntimeFunctionInterface fun currentActivity(scriptRuntime: ScriptRuntime, args: Array): String = ensureArgumentsIsEmpty(args) { - val component = currentComponent(scriptRuntime, args) + currentActivityRhino() + } + + @JvmStatic + fun currentActivityRhino(): String { + val component = currentComponentRhino() val className = component.substringAfterLast("/") - when { + return when { className.startsWith(".") -> component else -> className } @@ -114,7 +122,12 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim @JvmStatic @RhinoRuntimeFunctionInterface fun currentComponent(scriptRuntime: ScriptRuntime, args: Array): String = ensureArgumentsIsEmpty(args) { - if (!RootUtils.isRootAvailable()) return@ensureArgumentsIsEmpty "" + currentComponentRhino() + } + + @JvmStatic + fun currentComponentRhino(): String { + if (!RootUtils.isRootAvailable()) return "" try { val process = Runtime.getRuntime().exec("su -c dumpsys activity activities") process.inputStream.bufferedReader().useLines { lines -> @@ -127,14 +140,14 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim part.contains("/") }?.let { part -> Log.d(TAG, "current activity part: $part") - return@ensureArgumentsIsEmpty part.replace("\\W+$".toRegex(), "") + return part.replace("\\W+$".toRegex(), "") } } } } catch (e: Exception) { Log.e(TAG, "Error reading current component", e) } - return@ensureArgumentsIsEmpty "" + return "" } @JvmStatic diff --git a/app/src/main/java/org/autojs/autojs/ui/floating/CircularMenu.java b/app/src/main/java/org/autojs/autojs/ui/floating/CircularMenu.java index 651e709a..2f7de8b2 100644 --- a/app/src/main/java/org/autojs/autojs/ui/floating/CircularMenu.java +++ b/app/src/main/java/org/autojs/autojs/ui/floating/CircularMenu.java @@ -3,6 +3,7 @@ package org.autojs.autojs.ui.floating; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Configuration; +import android.os.RemoteException; import android.text.TextUtils; import android.view.ContextThemeWrapper; import android.view.View; @@ -24,6 +25,8 @@ import org.autojs.autojs.core.record.Recorder; import org.autojs.autojs.model.explorer.ExplorerDirPage; import org.autojs.autojs.model.explorer.Explorers; import org.autojs.autojs.model.script.Scripts; +import org.autojs.autojs.runtime.api.WrappedShizuku; +import org.autojs.autojs.runtime.api.augment.shell.Shell; import org.autojs.autojs.tool.Func1; import org.autojs.autojs.ui.enhancedfloaty.FloatyService; import org.autojs.autojs.ui.enhancedfloaty.FloatyWindow; @@ -173,9 +176,7 @@ public class CircularMenu implements Recorder.OnStateChangedListener, LayoutInsp mSettingsDialog.dismiss(); } - ActivityInfoProvider infoProvider = AutoJs.getInstance().getInfoProvider(); - mRunningPackage = infoProvider.getLatestPackageByUsageStatsIfGranted(); - mRunningActivity = infoProvider.getLatestActivity(); + applyComponentInformation(); // noinspection CodeBlock2Expr mSettingsDialog = new CircularMenuOperationDialogBuilder(mContext) @@ -212,6 +213,26 @@ public class CircularMenu implements Recorder.OnStateChangedListener, LayoutInsp }); } + private void applyComponentInformation() { + if (WrappedShizuku.isOperational() && WrappedShizuku.service != null) { + try { + mRunningPackage = WrappedShizuku.service.currentPackage(); + mRunningActivity = WrappedShizuku.service.currentActivity(); + return; + } catch (RemoteException ignored) { + + } + } + if (RootUtils.isRootAvailable()) { + mRunningPackage = Shell.currentPackageRhino(); + mRunningActivity = Shell.currentActivityRhino(); + return; + } + ActivityInfoProvider infoProvider = AutoJs.getInstance().getInfoProvider(); + mRunningPackage = infoProvider.getLatestPackageByUsageStatsIfGranted(); + mRunningActivity = infoProvider.getLatestActivity(); + } + @NonNull private View.OnClickListener onCircularMenuItemClick(View.OnClickListener listener) { return v -> { diff --git a/version.properties b/version.properties index f379af7c..d7ccd569 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Wed Jan 01 11:40:23 CST 2025 -BUILD_TIME=1735702823631 +#Wed Jan 01 12:09:07 CST 2025 +BUILD_TIME=1735704547526 COMPILE_SDK_VERSION=34 JAVA_VERSION=23 JAVA_VERSION_MIN_RADICAL=0