6.6.1 - Alpha3 - 提升浮动窗口当前包名及当前活动名的识别准确性
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -97,15 +97,23 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun currentPackage(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||
currentComponent(scriptRuntime, args).substringBefore("/")
|
||||
currentPackageRhino()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun currentPackageRhino(): String = currentComponentRhino().substringBefore("/")
|
||||
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun currentActivity(scriptRuntime: ScriptRuntime, args: Array<out Any?>): 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<out Any?>): 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
|
||||
|
||||
@@ -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 -> {
|
||||
|
||||
Reference in New Issue
Block a user