6.7.0 - Alpha17 - Fine tuning
This commit is contained in:
@@ -37,6 +37,7 @@ import org.autojs.autojs.execution.ScriptExecution.AbstractScriptExecution
|
||||
import org.autojs.autojs.inrt.autojs.LoopBasedJavaScriptEngineWithDecryption
|
||||
import org.autojs.autojs.runtime.ScriptRuntime
|
||||
import org.autojs.autojs.script.ScriptSource
|
||||
import org.autojs.autojs.util.IntentUtils.startSafely
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
import org.mozilla.javascript.ContinuationPending
|
||||
@@ -184,10 +185,10 @@ class ScriptExecuteActivity : AppCompatActivity(), OnActivityResultDelegate.Dele
|
||||
mScriptEngine.setTag(ScriptEngine.TAG_SOURCE, mScriptSource)
|
||||
mExecutionListener!!.onStart(mScriptExecution)
|
||||
|
||||
if (isInrt) {
|
||||
(mScriptEngine as LoopBasedJavaScriptEngineWithDecryption).execute(mScriptSource, executeCallback)
|
||||
} else {
|
||||
if (!isInrt) {
|
||||
(mScriptEngine as LoopBasedJavaScriptEngine).execute(mScriptSource, executeCallback)
|
||||
} else {
|
||||
(mScriptEngine as LoopBasedJavaScriptEngineWithDecryption).execute(mScriptSource, executeCallback)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,11 +305,10 @@ class ScriptExecuteActivity : AppCompatActivity(), OnActivityResultDelegate.Dele
|
||||
@JvmStatic
|
||||
fun execute(context: Context, manager: ScriptEngineManager, task: ScriptExecutionTask): ActivityScriptExecution {
|
||||
val execution = ActivityScriptExecution(manager, task)
|
||||
val i = Intent(context, ScriptExecuteActivity::class.java)
|
||||
Intent(context, ScriptExecuteActivity::class.java)
|
||||
.putExtra(EXTRA_EXECUTION_ID, execution.id)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.addFlags(task.config.intentFlags)
|
||||
context.startActivity(i)
|
||||
.startSafely(context)
|
||||
return execution
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Intent
|
||||
import android.provider.Settings
|
||||
import androidx.core.net.toUri
|
||||
import org.autojs.autojs.ui.main.drawer.PermissionItemHelper
|
||||
import org.autojs.autojs.util.IntentUtils.start
|
||||
import org.autojs.autojs.util.RomUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
@@ -39,15 +40,14 @@ class VivoBackgroundPopupPermission(
|
||||
|
||||
val intents = listOf(
|
||||
// Vivo permission detail page (commonly works on many models).
|
||||
// zh-CN: Vivo 权限详情页(较多机型可用).
|
||||
// zh-CN: Vivo 权限详情页 (较多机型可用).
|
||||
Intent()
|
||||
.setClassName(
|
||||
"com.vivo.permissionmanager",
|
||||
"com.vivo.permissionmanager.activity.SoftPermissionDetailActivity",
|
||||
)
|
||||
.setAction("secure.intent.action.softPermissionDetail")
|
||||
.putExtra("packagename", pkg)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
.putExtra("packagename", pkg),
|
||||
|
||||
// Older models may use PurviewTabActivity.
|
||||
// zh-CN: 老机型可能使用 PurviewTabActivity.
|
||||
@@ -57,8 +57,7 @@ class VivoBackgroundPopupPermission(
|
||||
"com.vivo.permissionmanager.activity.PurviewTabActivity",
|
||||
)
|
||||
.putExtra("packagename", pkg)
|
||||
.putExtra("tabId", "1")
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
.putExtra("tabId", "1"),
|
||||
|
||||
// Some ROMs expose a background start manager page.
|
||||
// zh-CN: 部分 ROM 暴露了后台启动管理页.
|
||||
@@ -66,8 +65,7 @@ class VivoBackgroundPopupPermission(
|
||||
.setClassName(
|
||||
"com.vivo.permissionmanager",
|
||||
"com.vivo.permissionmanager.activity.BgStartUpManagerActivity",
|
||||
)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
),
|
||||
)
|
||||
|
||||
return tryStartActivities(intents) || openAppDetails()
|
||||
@@ -76,7 +74,6 @@ class VivoBackgroundPopupPermission(
|
||||
private fun openAppDetails(): Boolean = Intent()
|
||||
.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
.setData("package:${context.packageName}".toUri())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.let { tryStartActivity(it) }
|
||||
|
||||
/**
|
||||
@@ -110,7 +107,7 @@ class VivoBackgroundPopupPermission(
|
||||
|
||||
// /**
|
||||
// * Check whether this looks like a vivo/iQOO device.
|
||||
// * zh-CN: 判断是否为 vivo/iQOO 设备(经验判断).
|
||||
// * zh-CN: 判断是否为 vivo/iQOO 设备 (经验判断).
|
||||
// */
|
||||
// private fun isVivoLikeDevice(): Boolean {
|
||||
// val brand = (Build.BRAND ?: "").lowercase()
|
||||
@@ -128,7 +125,7 @@ class VivoBackgroundPopupPermission(
|
||||
private fun tryStartActivity(i: Intent): Boolean = runCatching {
|
||||
val pm = context.packageManager
|
||||
i.resolveActivity(pm) ?: return@runCatching false
|
||||
context.startActivity(i)
|
||||
i.start(context)
|
||||
true
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Process
|
||||
import android.provider.Settings
|
||||
import androidx.core.net.toUri
|
||||
import org.autojs.autojs.ui.main.drawer.PermissionItemHelper
|
||||
import org.autojs.autojs.util.IntentUtils.start
|
||||
import org.autojs.autojs.util.RomUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
@@ -46,8 +47,7 @@ class XiaomiBackgroundPopupPermission(
|
||||
"com.miui.securitycenter",
|
||||
"com.miui.permcenter.permissions.PermissionsEditorActivity",
|
||||
)
|
||||
.putExtra("extra_pkgname", pkg)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
.putExtra("extra_pkgname", pkg),
|
||||
|
||||
// Some MIUI versions use AppPermissionsEditorActivity.
|
||||
// zh-CN: 部分 MIUI 版本使用 AppPermissionsEditorActivity.
|
||||
@@ -56,8 +56,7 @@ class XiaomiBackgroundPopupPermission(
|
||||
"com.miui.securitycenter",
|
||||
"com.miui.permcenter.permissions.AppPermissionsEditorActivity",
|
||||
)
|
||||
.putExtra("extra_pkgname", pkg)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
.putExtra("extra_pkgname", pkg),
|
||||
)
|
||||
|
||||
return tryStartActivities(intents) || openAppDetails()
|
||||
@@ -66,12 +65,11 @@ class XiaomiBackgroundPopupPermission(
|
||||
private fun openAppDetails(): Boolean = Intent()
|
||||
.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
.setData("package:${context.packageName}".toUri())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.let { tryStartActivity(it) }
|
||||
|
||||
/**
|
||||
* Check MIUI "background start activity" app-op (commonly op=10021).
|
||||
* zh-CN: 检查 MIUI "后台启动界面" 的 AppOps 状态(常见 op=10021).
|
||||
* zh-CN: 检查 MIUI "后台启动界面" 的 AppOps 状态 (常见 op=10021).
|
||||
*/
|
||||
private fun isMiuiBgStartPermissionGranted(context: Context): Boolean {
|
||||
val ops = context.getSystemService(Context.APP_OPS_SERVICE) as? AppOpsManager ?: return true
|
||||
@@ -96,7 +94,7 @@ class XiaomiBackgroundPopupPermission(
|
||||
|
||||
// /**
|
||||
// * Check whether this looks like a Xiaomi/Redmi/POCO device.
|
||||
// * zh-CN: 判断是否为 Xiaomi/Redmi/POCO 设备(经验判断).
|
||||
// * zh-CN: 判断是否为 Xiaomi/Redmi/POCO 设备 (经验判断).
|
||||
// */
|
||||
// private fun isXiaomiLikeDevice(): Boolean {
|
||||
// val brand = (Build.BRAND ?: "").lowercase()
|
||||
@@ -114,7 +112,7 @@ class XiaomiBackgroundPopupPermission(
|
||||
private fun tryStartActivity(i: Intent): Boolean = runCatching {
|
||||
val pm = context.packageManager
|
||||
i.resolveActivity(pm) ?: return@runCatching false
|
||||
context.startActivity(i)
|
||||
i.start(context)
|
||||
true
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
@@ -124,7 +122,7 @@ class XiaomiBackgroundPopupPermission(
|
||||
private companion object {
|
||||
|
||||
// MIUI app-op code for background start activity (commonly 10021).
|
||||
// zh-CN: MIUI 后台启动界面常见的 AppOps 编号(通常为 10021).
|
||||
// zh-CN: MIUI 后台启动界面常见的 AppOps 编号 (通常为 10021).
|
||||
private const val OP_BACKGROUND_START_ACTIVITY = 10021
|
||||
|
||||
}
|
||||
|
||||
@@ -113,6 +113,26 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
|
||||
private val presetAnimations = listOf("default", "activity", "dialog", "inputMethod", "toast", "translucent")
|
||||
|
||||
private val customJsPropertiesForBuild: Set<String> = setOf(
|
||||
"preset",
|
||||
"inputHint",
|
||||
"inputPrefill",
|
||||
"items",
|
||||
"progress",
|
||||
"checkBoxPrompt",
|
||||
"checkBoxChecked",
|
||||
"customView",
|
||||
"stubborn",
|
||||
"theme",
|
||||
"linkify",
|
||||
"onBackKey",
|
||||
"onBackPressed",
|
||||
"dimAmount",
|
||||
"animation",
|
||||
"keepScreenOn",
|
||||
"inputSingleLine",
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun build(scriptRuntime: ScriptRuntime, args: Array<out Any?>): JsDialog = ensureArgumentsAtMost(args, 1) { argList ->
|
||||
@@ -460,23 +480,27 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
|
||||
private fun applyDialogProperty(builder: JsDialogBuilder, name: String, value: Any?) {
|
||||
when (val propertySetter = propertySetterMap[name]) {
|
||||
CVT_DEFAULT -> invokeMethod(builder, name, arrayOf(value))
|
||||
CVT_DEFAULT -> invokeJavaMethod(builder, name, arrayOf(value))
|
||||
CVT_DEFAULT_STRICT_BOOLEAN -> {
|
||||
if (value == true) {
|
||||
invokeMethod(builder, name, emptyArray())
|
||||
invokeJavaMethod(builder, name, emptyArray())
|
||||
}
|
||||
}
|
||||
CVT_COLOR_INT -> {
|
||||
val colorInt = Colors.toIntRhino(value)
|
||||
invokeMethod(builder, name, arrayOf(colorInt))
|
||||
invokeJavaMethod(builder, name, arrayOf(colorInt))
|
||||
}
|
||||
is String -> when (propertySetter) {
|
||||
in propertySetterMap -> {
|
||||
applyDialogProperty(builder, propertySetter, value)
|
||||
}
|
||||
else -> invokeMethod(builder, propertySetter, arrayOf(value))
|
||||
else -> invokeJavaMethod(builder, propertySetter, arrayOf(value))
|
||||
}
|
||||
else -> {
|
||||
if (!customJsPropertiesForBuild.contains(name)) {
|
||||
invokeJavaMethod(builder, name, arrayOf(value))
|
||||
}
|
||||
}
|
||||
else -> invokeMethod(builder, name, arrayOf(value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,13 +790,13 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun invokeMethod(builder: JsDialogBuilder, key: String, argsForMethod: Array<out Any?>) {
|
||||
private fun invokeJavaMethod(builder: JsDialogBuilder, key: String, argsForMethod: Array<out Any?>) {
|
||||
val methods = builder.javaClass.methods
|
||||
val targetMethodsForName = methods.filter {
|
||||
it.name == key
|
||||
}
|
||||
if (targetMethodsForName.isEmpty()) {
|
||||
return
|
||||
require(targetMethodsForName.isNotEmpty()) {
|
||||
"Method key \"$key\" for dialogs.build is not a valid method name"
|
||||
}
|
||||
val targetMethodsForParamCount = targetMethodsForName.filter {
|
||||
it.parameterCount == argsForMethod.size
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.autojs.autojs.runtime.api.augment.shell
|
||||
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import androidx.annotation.IntRange
|
||||
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
||||
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
|
||||
@@ -65,7 +65,7 @@ public class RootUtils {
|
||||
private static boolean isSuPresentFast() {
|
||||
try {
|
||||
// 1. Check common su paths.
|
||||
// zh-CN: 1. 检查常见 su 路径.
|
||||
// zh-CN: 检查常见 su 路径.
|
||||
for (String path : COMMON_SU_PATHS) {
|
||||
if (isExecutableFile(path)) {
|
||||
return true;
|
||||
@@ -73,7 +73,7 @@ public class RootUtils {
|
||||
}
|
||||
|
||||
// 2. Check su in PATH environment.
|
||||
// zh-CN: 2. 检查 PATH 环境中的 su.
|
||||
// zh-CN: 检查 PATH 环境中的 su.
|
||||
String envPath = System.getenv("PATH");
|
||||
if (envPath != null && !envPath.isEmpty()) {
|
||||
String[] paths = envPath.split(":");
|
||||
|
||||
@@ -67,6 +67,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.autojs.autojs.app.GlobalAppContext
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.runtime.ScriptRuntime
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.StringUtils.key
|
||||
import org.autojs.autojs6.R
|
||||
@@ -303,7 +304,7 @@ object ViewUtils {
|
||||
if (systemUiHeightInset in 1..maxReasonable) return systemUiHeightInset
|
||||
|
||||
// Otherwise, try to remove an estimated nav bar height (dimen only).
|
||||
// zh-CN: 否则尝试减去导航栏估值(仅 dimen), 再次校验.
|
||||
// zh-CN: 否则尝试减去导航栏估值 (仅 dimen), 再次校验.
|
||||
val navBar = getNavigationBarHeightByDimen(context, withComputedOnPreR = false).coerceAtLeast(0)
|
||||
val guess = (systemUiHeightInset - navBar).coerceAtLeast(0)
|
||||
|
||||
@@ -1155,7 +1156,11 @@ object ViewUtils {
|
||||
|
||||
@JvmStatic
|
||||
fun showSnack(view: View, stringRes: Int, isLong: Boolean) {
|
||||
Snackbar.make(view, stringRes, if (isLong) Snackbar.LENGTH_LONG else Snackbar.LENGTH_SHORT).show()
|
||||
try {
|
||||
Snackbar.make(view, stringRes, if (isLong) Snackbar.LENGTH_LONG else Snackbar.LENGTH_SHORT).show()
|
||||
} catch (e: IllegalStateException) {
|
||||
ScriptRuntime.popException(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -1163,14 +1168,30 @@ object ViewUtils {
|
||||
|
||||
@JvmStatic
|
||||
fun showSnack(view: View, string: CharSequence, isLong: Boolean) {
|
||||
Snackbar.make(view, string, if (isLong) Snackbar.LENGTH_LONG else Snackbar.LENGTH_SHORT).show()
|
||||
try {
|
||||
Snackbar.make(view, string, if (isLong) Snackbar.LENGTH_LONG else Snackbar.LENGTH_SHORT).show()
|
||||
} catch (e: IllegalStateException) {
|
||||
ScriptRuntime.popException(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun showSnack(view: View, stringRes: Int, duration: Int) = Snackbar.make(view, stringRes, duration).show()
|
||||
fun showSnack(view: View, stringRes: Int, duration: Int) {
|
||||
try {
|
||||
Snackbar.make(view, stringRes, duration).show()
|
||||
} catch (e: IllegalStateException) {
|
||||
ScriptRuntime.popException(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun showSnack(view: View, string: CharSequence, duration: Int) = Snackbar.make(view, string, duration).show()
|
||||
fun showSnack(view: View, string: CharSequence, duration: Int) {
|
||||
try {
|
||||
Snackbar.make(view, string, duration).show()
|
||||
} catch (e: IllegalStateException) {
|
||||
ScriptRuntime.popException(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
fun setKeepScreenOnWhenInForegroundDisabled() {
|
||||
Pref.putString(R.string.key_keep_screen_on_when_in_foreground, key(R.string.key_keep_screen_on_when_in_foreground_disabled))
|
||||
|
||||
Reference in New Issue
Block a user