6.6.1 - Alpha3 - 新增 currentComponent 方法; 提升 currentPackage/currentActivity 识别准确性
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"وحدة Pinyin لتحويل النصوص الصينية إلى بينيين (راجع وثائق المشروع > [البينيين الصيني](https://docs.autojs6.com/#/pinyin))",
|
"وحدة Pinyin لتحويل النصوص الصينية إلى بينيين (راجع وثائق المشروع > [البينيين الصيني](https://docs.autojs6.com/#/pinyin))",
|
||||||
"وحدة Pinyin4j لتحويل النصوص الصينية إلى بينيين (راجع وثائق المشروع > [البينيين الصيني](https://docs.autojs6.com/#/pinyin4j))",
|
"وحدة Pinyin4j لتحويل النصوص الصينية إلى بينيين (راجع وثائق المشروع > [البينيين الصيني](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"Pinyin module for Chinese Pinyin conversion (Refer to Project Documentation > [Chinese Pinyin](https://docs.autojs6.com/#/pinyin))",
|
"Pinyin module for Chinese Pinyin conversion (Refer to Project Documentation > [Chinese Pinyin](https://docs.autojs6.com/#/pinyin))",
|
||||||
"Pinyin4j module for Chinese Pinyin conversion (Refer to Project Documentation > [Chinese Pinyin](https://docs.autojs6.com/#/pinyin4j))",
|
"Pinyin4j module for Chinese Pinyin conversion (Refer to Project Documentation > [Chinese Pinyin](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"Módulo Pinyin para la conversión de pinyin en chino (Consulte la documentación del proyecto > [Pinyin chino](https://docs.autojs6.com/#/pinyin))",
|
"Módulo Pinyin para la conversión de pinyin en chino (Consulte la documentación del proyecto > [Pinyin chino](https://docs.autojs6.com/#/pinyin))",
|
||||||
"Módulo Pinyin4j para la conversión de pinyin en chino (Consulte la documentación del proyecto > [Pinyin chino](https://docs.autojs6.com/#/pinyin4j))",
|
"Módulo Pinyin4j para la conversión de pinyin en chino (Consulte la documentación del proyecto > [Pinyin chino](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"Module Pinyin pour la conversion du pinyin chinois (Consultez la documentation du projet > [Pinyin chinois](https://docs.autojs6.com/#/pinyin))",
|
"Module Pinyin pour la conversion du pinyin chinois (Consultez la documentation du projet > [Pinyin chinois](https://docs.autojs6.com/#/pinyin))",
|
||||||
"Module Pinyin4j pour la conversion du pinyin chinois (Consultez la documentation du projet > [Pinyin chinois](https://docs.autojs6.com/#/pinyin4j))",
|
"Module Pinyin4j pour la conversion du pinyin chinois (Consultez la documentation du projet > [Pinyin chinois](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"中国語のピンイン変換用の Pinyin モジュール (プロジェクトドキュメントを参照 > [中国語ピンイン](https://docs.autojs6.com/#/pinyin))",
|
"中国語のピンイン変換用の Pinyin モジュール (プロジェクトドキュメントを参照 > [中国語ピンイン](https://docs.autojs6.com/#/pinyin))",
|
||||||
"中国語のピンイン変換用の Pinyin4j モジュール (プロジェクトドキュメントを参照 > [中国語ピンイン](https://docs.autojs6.com/#/pinyin4j))",
|
"中国語のピンイン変換用の Pinyin4j モジュール (プロジェクトドキュメントを参照 > [中国語ピンイン](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"중국어 병음 변환을 위한 Pinyin 모듈 (프로젝트 문서 참고 > [중국어 병음](https://docs.autojs6.com/#/pinyin))",
|
"중국어 병음 변환을 위한 Pinyin 모듈 (프로젝트 문서 참고 > [중국어 병음](https://docs.autojs6.com/#/pinyin))",
|
||||||
"중국어 병음 변환을 위한 Pinyin4j 모듈 (프로젝트 문서 참고 > [중국어 병음](https://docs.autojs6.com/#/pinyin4j))",
|
"중국어 병음 변환을 위한 Pinyin4j 모듈 (프로젝트 문서 참고 > [중국어 병음](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"Модуль Pinyin для преобразования китайского пиньиня (См. документацию проекта > [Китайский Пиньинь](https://docs.autojs6.com/#/pinyin))",
|
"Модуль Pinyin для преобразования китайского пиньиня (См. документацию проекта > [Китайский Пиньинь](https://docs.autojs6.com/#/pinyin))",
|
||||||
"Модуль Pinyin4j для преобразования китайского пиньиня (См. документацию проекта > [Китайский Пиньинь](https://docs.autojs6.com/#/pinyin4j))",
|
"Модуль Pinyin4j для преобразования китайского пиньиня (См. документацию проекта > [Китайский Пиньинь](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"pinyin 模块, 用于汉语拼音转换 (参阅 项目文档 > [汉语拼音](https://docs.autojs6.com/#/pinyin))",
|
"pinyin 模块, 用于汉语拼音转换 (参阅 项目文档 > [汉语拼音](https://docs.autojs6.com/#/pinyin))",
|
||||||
"pinyin4j 模块, 用于汉语拼音转换 (参阅 项目文档 > [汉语拼音](https://docs.autojs6.com/#/pinyin4j))",
|
"pinyin4j 模块, 用于汉语拼音转换 (参阅 项目文档 > [汉语拼音](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
"UiObject#isSimilar 及 UiObjectCollection#isSimilar 方法, 用于确定控件或控件集合是否相似"
|
"UiObject#isSimilar 及 UiObjectCollection#isSimilar 方法, 用于确定控件或控件集合是否相似",
|
||||||
|
"currentComponent 全局方法, 用于获取当前活动的组件名称信息"
|
||||||
],
|
],
|
||||||
"fix": [
|
"fix": [
|
||||||
"部分环境因回退版本过低而无法正常编译项目的问题",
|
"部分环境因回退版本过低而无法正常编译项目的问题",
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
"UiObjectCollection 实例缺失自身方法及属性的问题"
|
"UiObjectCollection 实例缺失自身方法及属性的问题"
|
||||||
],
|
],
|
||||||
"improvement": [
|
"improvement": [
|
||||||
|
"提升 currentPackage/currentActivity 识别准确性 (优先级: Shizuku > Root > A11Y)",
|
||||||
"恢复日志活动窗口单个条目文本内容的双击或长按选择功能 _[`issue #280`](http://issues.autojs6.com/280)_",
|
"恢复日志活动窗口单个条目文本内容的双击或长按选择功能 _[`issue #280`](http://issues.autojs6.com/280)_",
|
||||||
"脚本项目识别在 project.json 损坏情况下尽可能还原关键信息",
|
"脚本项目识别在 project.json 损坏情况下尽可能还原关键信息",
|
||||||
"打包单文件时自动生成的包名后缀支持将简体中文转换为拼音 (支持多音字)",
|
"打包单文件时自动生成的包名后缀支持将简体中文转换为拼音 (支持多音字)",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"pinyin 模塊, 用於漢語拼音轉換 (參閲 項目文檔 > [漢語拼音](https://docs.autojs6.com/#/pinyin))",
|
"pinyin 模塊, 用於漢語拼音轉換 (參閲 項目文檔 > [漢語拼音](https://docs.autojs6.com/#/pinyin))",
|
||||||
"pinyin4j 模塊, 用於漢語拼音轉換 (參閲 項目文檔 > [漢語拼音](https://docs.autojs6.com/#/pinyin4j))",
|
"pinyin4j 模塊, 用於漢語拼音轉換 (參閲 項目文檔 > [漢語拼音](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$data": {
|
"$data": {
|
||||||
"v6.6.1": {
|
"v6.6.1": {
|
||||||
"released_date": "2024/12/27",
|
"released_date": "2025/01/01",
|
||||||
"feature": [
|
"feature": [
|
||||||
"pinyin 模組, 用於漢語拼音轉換 (參閱 專案文件 > [漢語拼音](https://docs.autojs6.com/#/pinyin))",
|
"pinyin 模組, 用於漢語拼音轉換 (參閱 專案文件 > [漢語拼音](https://docs.autojs6.com/#/pinyin))",
|
||||||
"pinyin4j 模組, 用於漢語拼音轉換 (參閱 專案文件 > [漢語拼音](https://docs.autojs6.com/#/pinyin4j))",
|
"pinyin4j 模組, 用於漢語拼音轉換 (參閱 專案文件 > [漢語拼音](https://docs.autojs6.com/#/pinyin4j))",
|
||||||
|
|||||||
@@ -8,4 +8,9 @@ interface IUserService {
|
|||||||
|
|
||||||
String execCommand(String command) = 2;
|
String execCommand(String command) = 2;
|
||||||
|
|
||||||
|
String currentPackage() = 11;
|
||||||
|
String currentActivity() = 12;
|
||||||
|
String currentComponent() = 13;
|
||||||
|
String currentComponentShort() = 14;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,58 +1,77 @@
|
|||||||
package org.autojs.autojs.core.shizuku;
|
package org.autojs.autojs.core.shizuku
|
||||||
|
|
||||||
import android.content.Context;
|
import android.app.ActivityManager
|
||||||
import android.os.RemoteException;
|
import android.content.ComponentName
|
||||||
import android.util.Log;
|
import android.content.Context
|
||||||
|
import android.os.RemoteException
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
import org.autojs.autojs.runtime.api.AbstractShell
|
||||||
|
import org.autojs.autojs.runtime.api.ProcessShell
|
||||||
|
|
||||||
import androidx.annotation.Keep;
|
class UserService : IUserService.Stub {
|
||||||
|
|
||||||
import org.autojs.autojs.runtime.api.AbstractShell;
|
private var mContext: Context? = null
|
||||||
import org.autojs.autojs.runtime.api.ProcessShell;
|
|
||||||
|
|
||||||
public class UserService extends IUserService.Stub {
|
@Suppress("DEPRECATION")
|
||||||
|
private val currentActivity: ComponentName?
|
||||||
|
get() {
|
||||||
|
val manager = mContext?.getSystemService(ActivityManager::class.java) ?: return null
|
||||||
|
val tasks = manager.getRunningTasks(1) ?: return null
|
||||||
|
if (tasks.isEmpty()) return null
|
||||||
|
return tasks[0].topActivity
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor is required.
|
* Constructor is required.
|
||||||
*/
|
*/
|
||||||
public UserService() {
|
constructor() {
|
||||||
Log.i("UserService", "constructor");
|
Log.i("UserService", "constructor")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with Context. This is only available from Shizuku API v13.
|
* Constructor with Context. This is only available from Shizuku API v13.
|
||||||
* <p>
|
*
|
||||||
* This method need to be annotated with {@link Keep} to prevent ProGuard from removing it.
|
*
|
||||||
|
* This method need to be annotated with [Keep] to prevent ProGuard from removing it.
|
||||||
*
|
*
|
||||||
* @param context Context created with createPackageContextAsUser
|
* @param context Context created with createPackageContextAsUser
|
||||||
* @see <a href="https://github.com/RikkaApps/Shizuku-API/blob/672f5efd4b33c2441dbf609772627e63417587ac/server-shared/src/main/java/rikka/shizuku/server/UserService.java#L66">code used to create the instance of this class</a>
|
* @see [code used to create the instance of this class](https://github.com/RikkaApps/Shizuku-API/blob/672f5efd4b33c2441dbf609772627e63417587ac/server-shared/src/main/java/rikka/shizuku/server/UserService.java.L66)
|
||||||
*/
|
*/
|
||||||
@Keep
|
@Keep
|
||||||
public UserService(Context context) {
|
constructor(context: Context) {
|
||||||
Log.i("UserService", "constructor with Context: context=" + context.toString());
|
Log.i("UserService", "constructor with Context: context=$context")
|
||||||
|
mContext = context
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reserved destroy method
|
* Reserved destroy method
|
||||||
*/
|
*/
|
||||||
@Override
|
override fun destroy() {
|
||||||
public void destroy() {
|
Log.i("UserService", "destroy")
|
||||||
Log.i("UserService", "destroy");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun exit() {
|
||||||
public void exit() {
|
destroy()
|
||||||
destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Throws(RemoteException::class)
|
||||||
public String execCommand(String command) throws RemoteException {
|
override fun execCommand(command: String): String {
|
||||||
try {
|
return try {
|
||||||
return ProcessShell
|
ProcessShell
|
||||||
.execCommand(command.split("\n"), ProcessShell.getShellProcess())
|
.execCommand(command.split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray(), ProcessShell.getShellProcess())
|
||||||
.toJson();
|
.toJson()
|
||||||
} catch (Exception e) {
|
} catch (e: Exception) {
|
||||||
return new AbstractShell.Result(1, e).toJson();
|
AbstractShell.Result(1, e).toJson()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun currentPackage() = currentActivity?.packageName ?: ""
|
||||||
|
|
||||||
|
override fun currentActivity() = currentActivity?.className ?: ""
|
||||||
|
|
||||||
|
override fun currentComponent() = currentActivity?.flattenToString() ?: ""
|
||||||
|
|
||||||
|
override fun currentComponentShort() = currentActivity?.flattenToShortString() ?: ""
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ open class RhinoJavaScriptEngine(private val scriptRuntime: ScriptRuntime, priva
|
|||||||
if (this is AutoJsContext) {
|
if (this is AutoJsContext) {
|
||||||
rhinoJavaScriptEngine = this@RhinoJavaScriptEngine
|
rhinoJavaScriptEngine = this@RhinoJavaScriptEngine
|
||||||
}
|
}
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
optimizationLevel = -1
|
optimizationLevel = -1
|
||||||
languageVersion = Context.VERSION_ES6
|
languageVersion = Context.VERSION_ES6
|
||||||
locale = Locale.getDefault()
|
locale = Locale.getDefault()
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ open class AndroidContextFactory(private val cacheDirectory: File) : ContextFact
|
|||||||
private fun setupContext(context: Context) {
|
private fun setupContext(context: Context) {
|
||||||
context.apply {
|
context.apply {
|
||||||
instructionObserverThreshold = 10000
|
instructionObserverThreshold = 10000
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
optimizationLevel = -1
|
optimizationLevel = -1
|
||||||
languageVersion = Context.VERSION_ES6
|
languageVersion = Context.VERSION_ES6
|
||||||
locale = Locale.getDefault()
|
locale = Locale.getDefault()
|
||||||
|
|||||||
@@ -67,30 +67,24 @@ public class Shell extends AbstractShell {
|
|||||||
private volatile boolean mInitialized = false;
|
private volatile boolean mInitialized = false;
|
||||||
private volatile boolean mWaitingExit = false;
|
private volatile boolean mWaitingExit = false;
|
||||||
private volatile String mCommandOutput = null;
|
private volatile String mCommandOutput = null;
|
||||||
private final boolean mShouldReadOutput;
|
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
|
|
||||||
|
public Shell(Context context, boolean root) {
|
||||||
|
super(context, root);
|
||||||
|
}
|
||||||
|
|
||||||
public Shell(Context context) {
|
public Shell(Context context) {
|
||||||
this(context, false);
|
this(context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shell(Context context, boolean root) {
|
public Shell(boolean root) {
|
||||||
this(context, root, true);
|
this(ScriptRuntime.getApplicationContext(), root);
|
||||||
}
|
|
||||||
|
|
||||||
public Shell(Context context, boolean root, boolean shouldReadOutput) {
|
|
||||||
super(context, root);
|
|
||||||
mShouldReadOutput = shouldReadOutput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shell() {
|
public Shell() {
|
||||||
this(false);
|
this(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shell(boolean root) {
|
|
||||||
this(ScriptRuntime.getApplicationContext(), root);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init(final String initialCommand) {
|
protected void init(final String initialCommand) {
|
||||||
Handler uiHandler = new Handler(mContext.getMainLooper());
|
Handler uiHandler = new Handler(mContext.getMainLooper());
|
||||||
|
|||||||
@@ -53,10 +53,8 @@ object WrappedShizuku {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val mUserServiceArgs = Shizuku.UserServiceArgs(ComponentName(BuildConfig.APPLICATION_ID, UserService::class.java.name))
|
private val mUserServiceArgs = Shizuku.UserServiceArgs(ComponentName(BuildConfig.APPLICATION_ID, UserService::class.java.name))
|
||||||
|
.processNameSuffix("shizuku-service-for-${BuildConfig.APPLICATION_ID.substringAfterLast(".")}")
|
||||||
.daemon(false)
|
.daemon(false)
|
||||||
.processNameSuffix("service-for-${BuildConfig.APPLICATION_ID.split(".").lastOrNull() ?: BuildConfig.APPLICATION_ID}")
|
|
||||||
.debuggable(BuildConfig.DEBUG)
|
|
||||||
.version(BuildConfig.VERSION_CODE)
|
|
||||||
|
|
||||||
private val mBinderReceivedListener = Shizuku.OnBinderReceivedListener {
|
private val mBinderReceivedListener = Shizuku.OnBinderReceivedListener {
|
||||||
if (Shizuku.isPreV11()) {
|
if (Shizuku.isPreV11()) {
|
||||||
|
|||||||
@@ -31,6 +31,27 @@ import java.util.function.Supplier
|
|||||||
@Suppress("unused", "UNUSED_PARAMETER")
|
@Suppress("unused", "UNUSED_PARAMETER")
|
||||||
class Auto(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), Invokable {
|
class Auto(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), Invokable {
|
||||||
|
|
||||||
|
override val selfAssignmentFunctions = listOf(
|
||||||
|
::start.name,
|
||||||
|
::stop.name,
|
||||||
|
::isRunning.name,
|
||||||
|
::exists.name,
|
||||||
|
::stateListener.name,
|
||||||
|
::registerEvent.name,
|
||||||
|
::registerEvents.name,
|
||||||
|
::removeEvent.name,
|
||||||
|
::removeEvents.name,
|
||||||
|
::waitFor.name,
|
||||||
|
::setMode.name,
|
||||||
|
::setFlags.name,
|
||||||
|
::setWindowFilter.name,
|
||||||
|
::launchSettings.name,
|
||||||
|
::clearCache.name,
|
||||||
|
::currentPackage.name,
|
||||||
|
::currentActivity.name,
|
||||||
|
::currentComponent.name,
|
||||||
|
)
|
||||||
|
|
||||||
override val selfAssignmentGetters = listOf<Pair<String, Supplier<Any?>>>(
|
override val selfAssignmentGetters = listOf<Pair<String, Supplier<Any?>>>(
|
||||||
"service" to Supplier {
|
"service" to Supplier {
|
||||||
scriptRuntime.accessibilityBridge.service
|
scriptRuntime.accessibilityBridge.service
|
||||||
@@ -52,24 +73,6 @@ class Auto(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
override val selfAssignmentFunctions = listOf(
|
|
||||||
::start.name,
|
|
||||||
::stop.name,
|
|
||||||
::isRunning.name,
|
|
||||||
::exists.name,
|
|
||||||
::stateListener.name,
|
|
||||||
::registerEvent.name,
|
|
||||||
::registerEvents.name,
|
|
||||||
::removeEvent.name,
|
|
||||||
::removeEvents.name,
|
|
||||||
::waitFor.name,
|
|
||||||
::setMode.name,
|
|
||||||
::setFlags.name,
|
|
||||||
::setWindowFilter.name,
|
|
||||||
::launchSettings.name,
|
|
||||||
::clearCache.name,
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun invoke(vararg args: Any?): Any = ensureArgumentsAtMost(args, 2) {
|
override fun invoke(vararg args: Any?): Any = ensureArgumentsAtMost(args, 2) {
|
||||||
when {
|
when {
|
||||||
it.isEmpty() -> invoke(null)
|
it.isEmpty() -> invoke(null)
|
||||||
@@ -134,21 +137,22 @@ class Auto(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime
|
|||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun stateListener(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsAtMost(args, 1) {
|
fun stateListener(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsAtMost(args, 1) {
|
||||||
val (listener) = it
|
val (listener) = it
|
||||||
scriptRuntime.accessibilityBridge.setAccessibilityListener(when {
|
scriptRuntime.accessibilityBridge.setAccessibilityListener(
|
||||||
listener.isJsNullish() -> null
|
when {
|
||||||
listener is AccessibilityServiceCallback -> listener
|
listener.isJsNullish() -> null
|
||||||
listener is ScriptableObject -> {
|
listener is AccessibilityServiceCallback -> listener
|
||||||
val adapter = NativeJavaObject.createInterfaceAdapter(
|
listener is ScriptableObject -> {
|
||||||
AccessibilityServiceCallback::class.java, listener
|
val adapter = NativeJavaObject.createInterfaceAdapter(
|
||||||
) as AccessibilityServiceCallback
|
AccessibilityServiceCallback::class.java, listener
|
||||||
|
) as AccessibilityServiceCallback
|
||||||
|
|
||||||
object : AccessibilityServiceCallback {
|
object : AccessibilityServiceCallback {
|
||||||
override fun onConnected() = adapter.onConnected()
|
override fun onConnected() = adapter.onConnected()
|
||||||
override fun onDisconnected() = adapter.onDisconnected()
|
override fun onDisconnected() = adapter.onDisconnected()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else -> throw WrappedIllegalArgumentException("Argument listener ($listener) is invalid for auto.setWindowFilter")
|
||||||
else -> throw WrappedIllegalArgumentException("Argument listener ($listener) is invalid for auto.setWindowFilter")
|
})
|
||||||
})
|
|
||||||
UNDEFINED
|
UNDEFINED
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,19 +161,20 @@ class Auto(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime
|
|||||||
fun registerEvent(scriptRuntime: ScriptRuntime, args: Array<out Any?>) = ensureArgumentsLength(args, 2) {
|
fun registerEvent(scriptRuntime: ScriptRuntime, args: Array<out Any?>) = ensureArgumentsLength(args, 2) {
|
||||||
val (name, listener) = it
|
val (name, listener) = it
|
||||||
require(!name.isJsNullish()) { "Argument \"name\" for auto.registerEvent cannot be nullish" }
|
require(!name.isJsNullish()) { "Argument \"name\" for auto.registerEvent cannot be nullish" }
|
||||||
scriptRuntime.automator.registerEvent(Context.toString(name), when {
|
scriptRuntime.automator.registerEvent(
|
||||||
listener.isJsNullish() -> null
|
Context.toString(name), when {
|
||||||
listener is AccessibilityEventCallback -> listener
|
listener.isJsNullish() -> null
|
||||||
listener is ScriptableObject -> {
|
listener is AccessibilityEventCallback -> listener
|
||||||
val adapter = NativeJavaObject.createInterfaceAdapter(
|
listener is ScriptableObject -> {
|
||||||
AccessibilityEventCallback::class.java, listener
|
val adapter = NativeJavaObject.createInterfaceAdapter(
|
||||||
) as AccessibilityEventCallback
|
AccessibilityEventCallback::class.java, listener
|
||||||
object : AccessibilityEventCallback {
|
) as AccessibilityEventCallback
|
||||||
override fun onAccessibilityEvent(event: AccessibilityEventWrapper) = adapter.onAccessibilityEvent(event)
|
object : AccessibilityEventCallback {
|
||||||
|
override fun onAccessibilityEvent(event: AccessibilityEventWrapper) = adapter.onAccessibilityEvent(event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else -> throw WrappedIllegalArgumentException("Argument listener ($listener) is invalid for auto.registerEvent")
|
||||||
else -> throw WrappedIllegalArgumentException("Argument listener ($listener) is invalid for auto.registerEvent")
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -262,6 +267,26 @@ class Auto(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime
|
|||||||
accessibilityTool.clearCache()
|
accessibilityTool.clearCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentPackage(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
scriptRuntime.info.latestPackage
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentActivity(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
scriptRuntime.info.latestActivity
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentComponent(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
val latestPackage = scriptRuntime.info.latestPackage.takeUnless { it.isEmpty() } ?: return@ensureArgumentsIsEmpty ""
|
||||||
|
val latestActivity = scriptRuntime.info.latestActivity.takeUnless { it.isEmpty() } ?: return@ensureArgumentsIsEmpty ""
|
||||||
|
"$latestPackage/$latestActivity"
|
||||||
|
}
|
||||||
|
|
||||||
private fun ensureA11yServiceStarted(scriptRuntime: ScriptRuntime, isForcibleRestart: Any?) {
|
private fun ensureA11yServiceStarted(scriptRuntime: ScriptRuntime, isForcibleRestart: Any?) {
|
||||||
if (isForcibleRestart !is Boolean) throw WrappedIllegalArgumentException("Argument isForcibleRestart must be of type Boolean")
|
if (isForcibleRestart !is Boolean) throw WrappedIllegalArgumentException("Argument isForcibleRestart must be of type Boolean")
|
||||||
scriptRuntime.accessibilityBridge.ensureServiceStarted(isForcibleRestart)
|
scriptRuntime.accessibilityBridge.ensureServiceStarted(isForcibleRestart)
|
||||||
|
|||||||
@@ -9,18 +9,22 @@ import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
|||||||
import org.autojs.autojs.extension.NumberExtensions.string
|
import org.autojs.autojs.extension.NumberExtensions.string
|
||||||
import org.autojs.autojs.extension.ScriptableExtensions.defineProp
|
import org.autojs.autojs.extension.ScriptableExtensions.defineProp
|
||||||
import org.autojs.autojs.extension.ScriptableExtensions.prop
|
import org.autojs.autojs.extension.ScriptableExtensions.prop
|
||||||
|
import org.autojs.autojs.extension.ScriptableObjectExtensions.inquire
|
||||||
import org.autojs.autojs.runtime.ScriptRuntime
|
import org.autojs.autojs.runtime.ScriptRuntime
|
||||||
import org.autojs.autojs.runtime.api.ScreenMetrics
|
import org.autojs.autojs.runtime.api.ScreenMetrics
|
||||||
import org.autojs.autojs.runtime.api.augment.Augmentable
|
import org.autojs.autojs.runtime.api.augment.Augmentable
|
||||||
|
import org.autojs.autojs.runtime.api.augment.automator.Auto
|
||||||
import org.autojs.autojs.runtime.api.augment.console.Console
|
import org.autojs.autojs.runtime.api.augment.console.Console
|
||||||
import org.autojs.autojs.runtime.api.augment.jsox.Numberx
|
import org.autojs.autojs.runtime.api.augment.jsox.Numberx
|
||||||
import org.autojs.autojs.runtime.api.augment.s13n.S13n
|
import org.autojs.autojs.runtime.api.augment.s13n.S13n
|
||||||
import org.autojs.autojs.runtime.api.augment.selector.Selector
|
import org.autojs.autojs.runtime.api.augment.selector.Selector
|
||||||
|
import org.autojs.autojs.runtime.api.augment.shell.Shell
|
||||||
|
import org.autojs.autojs.runtime.api.augment.shizuku.Shizuku
|
||||||
import org.autojs.autojs.runtime.api.augment.toast.Toast
|
import org.autojs.autojs.runtime.api.augment.toast.Toast
|
||||||
import org.autojs.autojs.runtime.api.augment.util.Util
|
import org.autojs.autojs.runtime.api.augment.util.Util
|
||||||
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
|
|
||||||
import org.autojs.autojs.runtime.exception.NotImplementedError
|
import org.autojs.autojs.runtime.exception.NotImplementedError
|
||||||
import org.autojs.autojs.runtime.exception.ShouldNeverHappenException
|
import org.autojs.autojs.runtime.exception.ShouldNeverHappenException
|
||||||
|
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
|
||||||
import org.autojs.autojs.util.RhinoUtils
|
import org.autojs.autojs.util.RhinoUtils
|
||||||
import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE
|
import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE
|
||||||
import org.autojs.autojs.util.RhinoUtils.UNDEFINED
|
import org.autojs.autojs.util.RhinoUtils.UNDEFINED
|
||||||
@@ -79,6 +83,7 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
|||||||
::getClip.name,
|
::getClip.name,
|
||||||
::currentPackage.name,
|
::currentPackage.name,
|
||||||
::currentActivity.name,
|
::currentActivity.name,
|
||||||
|
::currentComponent.name,
|
||||||
::wait.name,
|
::wait.name,
|
||||||
::waitForActivity.name,
|
::waitForActivity.name,
|
||||||
::waitForPackage.name,
|
::waitForPackage.name,
|
||||||
@@ -295,14 +300,50 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun currentPackage(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
fun currentPackage(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsAtMost(args, 1) { argList ->
|
||||||
scriptRuntime.info.latestPackage
|
val (o) = argList
|
||||||
|
when (parseComponentFetchMode(o)) {
|
||||||
|
ComponentFetchMode.ACCESSIBILITY -> Auto.currentPackage(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.SHIZUKU -> Shizuku.currentPackage(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.ROOT -> Shell.currentPackage(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.AUTOMATISM -> listOf(
|
||||||
|
{ Shizuku.currentPackage(scriptRuntime, emptyArray()) },
|
||||||
|
{ Shell.currentPackage(scriptRuntime, emptyArray()) },
|
||||||
|
{ Auto.currentPackage(scriptRuntime, emptyArray()) }
|
||||||
|
).firstNotNullOfOrNull { f -> f().takeUnless { it.isEmpty() } }.orEmpty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun currentActivity(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
fun currentActivity(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsAtMost(args, 1) { argList ->
|
||||||
scriptRuntime.info.latestActivity
|
val (o) = argList
|
||||||
|
when (parseComponentFetchMode(o)) {
|
||||||
|
ComponentFetchMode.ACCESSIBILITY -> Auto.currentActivity(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.SHIZUKU -> Shizuku.currentActivity(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.ROOT -> Shell.currentActivity(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.AUTOMATISM -> listOf(
|
||||||
|
{ Shizuku.currentActivity(scriptRuntime, emptyArray()) },
|
||||||
|
{ Shell.currentActivity(scriptRuntime, emptyArray()) },
|
||||||
|
{ Auto.currentActivity(scriptRuntime, emptyArray()) }
|
||||||
|
).firstNotNullOfOrNull { f -> f().takeUnless { it.isEmpty() } }.orEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentComponent(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsAtMost(args, 1) { argList ->
|
||||||
|
val (o) = argList
|
||||||
|
when (parseComponentFetchMode(o)) {
|
||||||
|
ComponentFetchMode.ACCESSIBILITY -> Auto.currentComponent(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.SHIZUKU -> Shizuku.currentComponent(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.ROOT -> Shell.currentComponent(scriptRuntime, emptyArray())
|
||||||
|
ComponentFetchMode.AUTOMATISM -> listOf(
|
||||||
|
{ Shizuku.currentComponent(scriptRuntime, emptyArray()) },
|
||||||
|
{ Shell.currentComponent(scriptRuntime, emptyArray()) },
|
||||||
|
{ Auto.currentComponent(scriptRuntime, emptyArray()) }
|
||||||
|
).firstNotNullOfOrNull { f -> f().takeUnless { it.isEmpty() } }.orEmpty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -647,6 +688,20 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
|||||||
else -> arrayOf(args.first())
|
else -> arrayOf(args.first())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseComponentFetchMode(o: Any?): ComponentFetchMode = when {
|
||||||
|
o.isJsNullish() -> ComponentFetchMode.AUTOMATISM
|
||||||
|
o is NativeObject -> parseComponentFetchMode(o.inquire(listOf("by", "mode"), ::coerceString, ""))
|
||||||
|
else -> when (coerceString(o, "").lowercase()) {
|
||||||
|
"", "auto", "automatic", "automatism" -> ComponentFetchMode.AUTOMATISM
|
||||||
|
"a11y", "accessibility" -> ComponentFetchMode.ACCESSIBILITY
|
||||||
|
"shizuku" -> ComponentFetchMode.SHIZUKU
|
||||||
|
"root" -> ComponentFetchMode.ROOT
|
||||||
|
else -> throw WrappedIllegalArgumentException("Unknown component fetch mode: ${coerceString(o)}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum class ComponentFetchMode { AUTOMATISM, ACCESSIBILITY, SHIZUKU, ROOT }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.autojs.autojs.runtime.api.augment.shell
|
package org.autojs.autojs.runtime.api.augment.shell
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import androidx.annotation.IntRange
|
import androidx.annotation.IntRange
|
||||||
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
||||||
@@ -16,6 +17,7 @@ import org.autojs.autojs.util.RhinoUtils.coerceBoolean
|
|||||||
import org.autojs.autojs.util.RhinoUtils.coerceIntNumber
|
import org.autojs.autojs.util.RhinoUtils.coerceIntNumber
|
||||||
import org.autojs.autojs.util.RhinoUtils.coerceString
|
import org.autojs.autojs.util.RhinoUtils.coerceString
|
||||||
import org.autojs.autojs.util.RhinoUtils.undefined
|
import org.autojs.autojs.util.RhinoUtils.undefined
|
||||||
|
import org.autojs.autojs.util.RootUtils
|
||||||
import org.mozilla.javascript.NativeArray
|
import org.mozilla.javascript.NativeArray
|
||||||
import org.mozilla.javascript.NativeObject
|
import org.mozilla.javascript.NativeObject
|
||||||
import org.mozilla.javascript.Undefined
|
import org.mozilla.javascript.Undefined
|
||||||
@@ -28,6 +30,9 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
|
|||||||
::getCommand.name,
|
::getCommand.name,
|
||||||
::fromIntent.name,
|
::fromIntent.name,
|
||||||
::kill.name,
|
::kill.name,
|
||||||
|
::currentPackage.name,
|
||||||
|
::currentActivity.name,
|
||||||
|
::currentComponent.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
override val globalAssignmentFunctions = listOf(
|
override val globalAssignmentFunctions = listOf(
|
||||||
@@ -56,6 +61,8 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
|
|||||||
|
|
||||||
companion object : FlexibleArray() {
|
companion object : FlexibleArray() {
|
||||||
|
|
||||||
|
private val TAG = Shell::class.java.simpleName
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun execCommand(scriptRuntime: ScriptRuntime, args: Array<out Any?>): AbstractShell.Result = ensureArgumentsLengthInRange(args, 1..3) { argList ->
|
fun execCommand(scriptRuntime: ScriptRuntime, args: Array<out Any?>): AbstractShell.Result = ensureArgumentsLengthInRange(args, 1..3) { argList ->
|
||||||
@@ -80,12 +87,56 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun kill(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = ensureArgumentsOnlyOne(args) { app ->
|
fun kill(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = ensureArgumentsOnlyOne(args) { app ->
|
||||||
|
if (!RootUtils.isRootAvailable()) return@ensureArgumentsOnlyOne false
|
||||||
when (val packageName = App.getPackageName(scriptRuntime, arrayOf(app))) {
|
when (val packageName = App.getPackageName(scriptRuntime, arrayOf(app))) {
|
||||||
null -> false
|
null -> false
|
||||||
else -> execCommand(scriptRuntime, arrayOf("am force-stop $packageName", true)).code == 0
|
else -> execCommand(scriptRuntime, arrayOf("am force-stop $packageName", true)).code == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentPackage(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
currentComponent(scriptRuntime, args).substringBefore("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentActivity(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
val component = currentComponent(scriptRuntime, args)
|
||||||
|
val className = component.substringAfterLast("/")
|
||||||
|
when {
|
||||||
|
className.startsWith(".") -> component
|
||||||
|
else -> className
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentComponent(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
if (!RootUtils.isRootAvailable()) return@ensureArgumentsIsEmpty ""
|
||||||
|
try {
|
||||||
|
val process = Runtime.getRuntime().exec("su -c dumpsys activity activities")
|
||||||
|
process.inputStream.bufferedReader().useLines { lines ->
|
||||||
|
val resumedActivityLine = lines.find {
|
||||||
|
it.contains("Resumed:") || it.contains("ResumedActivity")
|
||||||
|
}
|
||||||
|
resumedActivityLine?.let { line ->
|
||||||
|
Log.d(TAG, "Found Resumed Activity: $line")
|
||||||
|
line.split("\\s+".toRegex()).firstOrNull { part ->
|
||||||
|
part.contains("/")
|
||||||
|
}?.let { part ->
|
||||||
|
Log.d(TAG, "current activity part: $part")
|
||||||
|
return@ensureArgumentsIsEmpty part.replace("\\W+$".toRegex(), "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error reading current component", e)
|
||||||
|
}
|
||||||
|
return@ensureArgumentsIsEmpty ""
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun Menu(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsIsEmpty(args) {
|
fun Menu(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsIsEmpty(args) {
|
||||||
@@ -323,6 +374,17 @@ class Shell(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntim
|
|||||||
.replace(Regex("([a-z])([0-9])"), "$1-$2") // handle letters followed by numbers
|
.replace(Regex("([a-z])([0-9])"), "$1-$2") // handle letters followed by numbers
|
||||||
.lowercase()
|
.lowercase()
|
||||||
|
|
||||||
|
private fun completeActivityNames(name: String): String {
|
||||||
|
val parts = name.split("/")
|
||||||
|
if (parts.size == 2) {
|
||||||
|
val (packageName, activityName) = parts
|
||||||
|
if (activityName.startsWith(".")) {
|
||||||
|
return "$packageName/$packageName$activityName"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
data class CommandArgumentsData(val arguments: String = "", val withRoot: Boolean = false, val withExit: Boolean = false)
|
data class CommandArgumentsData(val arguments: String = "", val withRoot: Boolean = false, val withExit: Boolean = false)
|
||||||
|
|
||||||
data class CommandData(val command: String, @IntRange(0, 1) val withRoot: Int = 0)
|
data class CommandData(val command: String, @IntRange(0, 1) val withRoot: Int = 0)
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package org.autojs.autojs.runtime.api.augment.shizuku
|
|||||||
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
||||||
import org.autojs.autojs.runtime.ScriptRuntime
|
import org.autojs.autojs.runtime.ScriptRuntime
|
||||||
import org.autojs.autojs.runtime.api.AbstractShell
|
import org.autojs.autojs.runtime.api.AbstractShell
|
||||||
|
import org.autojs.autojs.runtime.api.WrappedShizuku
|
||||||
import org.autojs.autojs.runtime.api.augment.Augmentable
|
import org.autojs.autojs.runtime.api.augment.Augmentable
|
||||||
import org.autojs.autojs.runtime.api.augment.Invokable
|
import org.autojs.autojs.runtime.api.augment.Invokable
|
||||||
import org.autojs.autojs.runtime.api.augment.shell.Shell.Companion.getCommandData
|
import org.autojs.autojs.runtime.api.augment.app.App
|
||||||
|
import org.autojs.autojs.runtime.api.augment.shell.Shell
|
||||||
|
|
||||||
@Suppress("unused", "UNUSED_PARAMETER")
|
@Suppress("unused", "UNUSED_PARAMETER")
|
||||||
class Shizuku(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), Invokable {
|
class Shizuku(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), Invokable {
|
||||||
@@ -13,6 +15,10 @@ class Shizuku(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunt
|
|||||||
override val selfAssignmentFunctions = listOf(
|
override val selfAssignmentFunctions = listOf(
|
||||||
::execCommand.name,
|
::execCommand.name,
|
||||||
::getCommand.name,
|
::getCommand.name,
|
||||||
|
::kill.name,
|
||||||
|
::currentPackage.name,
|
||||||
|
::currentActivity.name,
|
||||||
|
::currentComponent.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun invoke(vararg args: Any?): AbstractShell.Result = execCommand(scriptRuntime, args)
|
override fun invoke(vararg args: Any?): AbstractShell.Result = execCommand(scriptRuntime, args)
|
||||||
@@ -22,13 +28,50 @@ class Shizuku(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunt
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun execCommand(scriptRuntime: ScriptRuntime, args: Array<out Any?>): AbstractShell.Result = ensureArgumentsLengthInRange(args, 1..3) { argList ->
|
fun execCommand(scriptRuntime: ScriptRuntime, args: Array<out Any?>): AbstractShell.Result = ensureArgumentsLengthInRange(args, 1..3) { argList ->
|
||||||
scriptRuntime.shizuku.execCommand(getCommandData(argList).command)
|
scriptRuntime.shizuku.execCommand(Shell.getCommandData(argList).command)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@RhinoRuntimeFunctionInterface
|
@RhinoRuntimeFunctionInterface
|
||||||
fun getCommand(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsLengthInRange(args, 1..3) { argList ->
|
fun getCommand(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsLengthInRange(args, 1..3) { argList ->
|
||||||
getCommandData(argList).command
|
Shell.getCommandData(argList).command
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun kill(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = ensureArgumentsOnlyOne(args) { app ->
|
||||||
|
if (!WrappedShizuku.isOperational()) return@ensureArgumentsOnlyOne false
|
||||||
|
when (val packageName = App.getPackageName(scriptRuntime, arrayOf(app))) {
|
||||||
|
null -> false
|
||||||
|
else -> execCommand(scriptRuntime, arrayOf("am force-stop $packageName")).code == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentPackage(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
when {
|
||||||
|
!WrappedShizuku.isOperational() -> ""
|
||||||
|
else -> WrappedShizuku.service?.currentPackage() ?: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentActivity(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
when {
|
||||||
|
!WrappedShizuku.isOperational() -> ""
|
||||||
|
else -> WrappedShizuku.service?.currentActivity() ?: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@RhinoRuntimeFunctionInterface
|
||||||
|
fun currentComponent(scriptRuntime: ScriptRuntime, args: Array<out Any?>): String = ensureArgumentsIsEmpty(args) {
|
||||||
|
when {
|
||||||
|
!WrappedShizuku.isOperational() -> ""
|
||||||
|
else -> WrappedShizuku.service?.currentComponent() ?: ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import androidx.preference.Preference.SummaryProvider
|
|||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import org.autojs.autojs.core.pref.Pref
|
import org.autojs.autojs.core.pref.Pref
|
||||||
import org.autojs.autojs.ui.common.NotAskAgainDialog
|
import org.autojs.autojs.ui.common.NotAskAgainDialog
|
||||||
import org.autojs.autojs.util.StringUtils.key
|
|
||||||
import org.autojs.autojs6.R
|
import org.autojs.autojs6.R
|
||||||
|
|
||||||
open class MaterialListPreference : MaterialDialogPreference {
|
open class MaterialListPreference : MaterialDialogPreference {
|
||||||
@@ -43,12 +42,12 @@ open class MaterialListPreference : MaterialDialogPreference {
|
|||||||
negativeText = getAttrString(a, R.styleable.MaterialListPreference_negativeText) ?: context.getString(R.string.dialog_button_cancel)
|
negativeText = getAttrString(a, R.styleable.MaterialListPreference_negativeText) ?: context.getString(R.string.dialog_button_cancel)
|
||||||
getAttrTextArray(a, R.styleable.MaterialListPreference_itemKeys)?.also { mItemKeys = it.toList() }
|
getAttrTextArray(a, R.styleable.MaterialListPreference_itemKeys)?.also { mItemKeys = it.toList() }
|
||||||
getAttrTextArray(a, R.styleable.MaterialListPreference_itemValues)?.also { mItemValues = it.toList() }
|
getAttrTextArray(a, R.styleable.MaterialListPreference_itemValues)?.also { mItemValues = it.toList() }
|
||||||
bundle.getString(key(R.string.key_pref_bundle_default_item), getAttrString(a, R.styleable.MaterialListPreference_itemDefaultKey))?.also { mItemDefaultKey = it }
|
bundle.getString(context.getString(R.string.key_pref_bundle_default_item), getAttrString(a, R.styleable.MaterialListPreference_itemDefaultKey))?.also { mItemDefaultKey = it }
|
||||||
getAttrString(a, R.styleable.MaterialListPreference_onConfirmPrompt)?.also { mConfirmedPrompt = it }
|
getAttrString(a, R.styleable.MaterialListPreference_onConfirmPrompt)?.also { mConfirmedPrompt = it }
|
||||||
a.recycle()
|
a.recycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle.getIntegerArrayList(key(R.string.key_pref_bundle_disabled_items))?.map { context.getString(it) }?.let { disables ->
|
bundle.getIntegerArrayList(context.getString(R.string.key_pref_bundle_disabled_items))?.map { context.getString(it) }?.let { disables ->
|
||||||
mItemKeys.forEachIndexed { index, it -> if (it in disables) mItemDisables += index }
|
mItemKeys.forEachIndexed { index, it -> if (it in disables) mItemDisables += index }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,10 +220,12 @@ public class CircularMenuWindow extends FloatyWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void savePosition() {
|
public void savePosition() {
|
||||||
int x = mActionViewWindowBridge.getX();
|
if (mActionViewWindowBridge != null) {
|
||||||
Pref.putFloatSync(KEY_POSITION_X_PERCENT, x / (float) ScreenMetrics.getDeviceScreenWidth());
|
int x = mActionViewWindowBridge.getX();
|
||||||
int y = mActionViewWindowBridge.getY();
|
Pref.putFloatSync(KEY_POSITION_X_PERCENT, x / (float) ScreenMetrics.getDeviceScreenWidth());
|
||||||
Pref.putFloatSync(KEY_POSITION_Y_PERCENT, y / (float) ScreenMetrics.getDeviceScreenHeight());
|
int y = mActionViewWindowBridge.getY();
|
||||||
|
Pref.putFloatSync(KEY_POSITION_Y_PERCENT, y / (float) ScreenMetrics.getDeviceScreenHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void savePosition(@NotNull Configuration configuration) {
|
public void savePosition(@NotNull Configuration configuration) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Fri Dec 27 19:33:23 CST 2024
|
#Wed Jan 01 11:40:23 CST 2025
|
||||||
BUILD_TIME=1735299203014
|
BUILD_TIME=1735702823631
|
||||||
COMPILE_SDK_VERSION=34
|
COMPILE_SDK_VERSION=34
|
||||||
JAVA_VERSION=23
|
JAVA_VERSION=23
|
||||||
JAVA_VERSION_MIN_RADICAL=0
|
JAVA_VERSION_MIN_RADICAL=0
|
||||||
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
|
|||||||
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
||||||
TARGET_SDK_VERSION=34
|
TARGET_SDK_VERSION=34
|
||||||
TARGET_SDK_VERSION_INRT=29
|
TARGET_SDK_VERSION_INRT=29
|
||||||
VERSION_BUILD=2929
|
VERSION_BUILD=2939
|
||||||
VERSION_NAME=6.6.1 Alpha2
|
VERSION_NAME=6.6.1 Alpha3
|
||||||
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
||||||
|
|||||||
Reference in New Issue
Block a user