6.7.0 - Alpha23 - 替换 Kotlin 中的 Object() 锁为 Any() 或 CountDownLatch
This commit is contained in:
@@ -9,6 +9,7 @@ import org.autojs.autojs.rhino.AutoJsContext
|
|||||||
import org.autojs.autojs.runtime.ScriptRuntime
|
import org.autojs.autojs.runtime.ScriptRuntime
|
||||||
import org.autojs.autojs.util.RhinoUtils.isMainThread
|
import org.autojs.autojs.util.RhinoUtils.isMainThread
|
||||||
import org.mozilla.javascript.Context
|
import org.mozilla.javascript.Context
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
import java.util.concurrent.CopyOnWriteArrayList
|
||||||
import kotlin.concurrent.Volatile
|
import kotlin.concurrent.Volatile
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ class Loopers(val scriptRuntime: ScriptRuntime) : MessageQueue.IdleHandler {
|
|||||||
private var mLooperQuitHandlers = ThreadLocal<CopyOnWriteArrayList<LooperQuitHandler>>()
|
private var mLooperQuitHandlers = ThreadLocal<CopyOnWriteArrayList<LooperQuitHandler>>()
|
||||||
private var mTimers = scriptRuntime.timers
|
private var mTimers = scriptRuntime.timers
|
||||||
private var mThreads = scriptRuntime.threads
|
private var mThreads = scriptRuntime.threads
|
||||||
private val mLock = Object()
|
private val mServantLooperReady = CountDownLatch(1)
|
||||||
|
|
||||||
private var mMaxWaitId: ThreadLocal<Int> = object : ThreadLocal<Int>() {
|
private var mMaxWaitId: ThreadLocal<Int> = object : ThreadLocal<Int>() {
|
||||||
override fun initialValue() = 0
|
override fun initialValue() = 0
|
||||||
@@ -44,16 +45,10 @@ class Loopers(val scriptRuntime: ScriptRuntime) : MessageQueue.IdleHandler {
|
|||||||
get() {
|
get() {
|
||||||
if (mServantLooper == null) {
|
if (mServantLooper == null) {
|
||||||
initServantThread()
|
initServantThread()
|
||||||
synchronized(mLock) {
|
try {
|
||||||
try {
|
mServantLooperReady.await()
|
||||||
try {
|
} catch (_: InterruptedException) {
|
||||||
mLock.wait()
|
/* Ignored. */
|
||||||
} finally {
|
|
||||||
mLock.notify()
|
|
||||||
}
|
|
||||||
} catch (ex: InterruptedException) {
|
|
||||||
/* Ignored. */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mServantLooper!!
|
return mServantLooper!!
|
||||||
@@ -160,9 +155,7 @@ class Loopers(val scriptRuntime: ScriptRuntime) : MessageQueue.IdleHandler {
|
|||||||
ThreadCompat {
|
ThreadCompat {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
mServantLooper = Looper.myLooper()
|
mServantLooper = Looper.myLooper()
|
||||||
synchronized(mLock) {
|
mServantLooperReady.countDown()
|
||||||
mLock.notifyAll()
|
|
||||||
}
|
|
||||||
Looper.loop()
|
Looper.loop()
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.google.mlkit.vision.barcode.BarcodeScannerOptions
|
|||||||
import com.google.mlkit.vision.barcode.BarcodeScanning
|
import com.google.mlkit.vision.barcode.BarcodeScanning
|
||||||
import com.google.mlkit.vision.common.InputImage
|
import com.google.mlkit.vision.common.InputImage
|
||||||
import org.autojs.autojs.core.image.ImageWrapper
|
import org.autojs.autojs.core.image.ImageWrapper
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import com.google.mlkit.vision.barcode.common.Barcode as MLKitBarcode
|
import com.google.mlkit.vision.barcode.common.Barcode as MLKitBarcode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +25,7 @@ class Barcode {
|
|||||||
|
|
||||||
val scanner = BarcodeScanning.getClient(options)
|
val scanner = BarcodeScanning.getClient(options)
|
||||||
val inputImage = InputImage.fromBitmap(image.bitmap, 0)
|
val inputImage = InputImage.fromBitmap(image.bitmap, 0)
|
||||||
|
val scanCompletedSignal = CountDownLatch(1)
|
||||||
|
|
||||||
var results: List<WrappedBarcode>? = null
|
var results: List<WrappedBarcode>? = null
|
||||||
|
|
||||||
@@ -32,22 +35,20 @@ class Barcode {
|
|||||||
onlyOneResult -> barcodes.firstOrNull()?.let { results = listOf(WrappedBarcode(it)) }
|
onlyOneResult -> barcodes.firstOrNull()?.let { results = listOf(WrappedBarcode(it)) }
|
||||||
else -> results = barcodes.map { WrappedBarcode(it) }
|
else -> results = barcodes.map { WrappedBarcode(it) }
|
||||||
}
|
}
|
||||||
lockNotify()
|
scanCompletedSignal.countDown()
|
||||||
}
|
}
|
||||||
.addOnFailureListener { e ->
|
.addOnFailureListener { e ->
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
lockNotify()
|
scanCompletedSignal.countDown()
|
||||||
}
|
}
|
||||||
.addOnCanceledListener { lockNotify() }
|
.addOnCanceledListener { scanCompletedSignal.countDown() }
|
||||||
.addOnCompleteListener { lockNotify() }
|
.addOnCompleteListener { scanCompletedSignal.countDown() }
|
||||||
|
|
||||||
while (!resultScan.isComplete) {
|
while (!resultScan.isComplete) {
|
||||||
synchronized(lock) {
|
try {
|
||||||
try {
|
scanCompletedSignal.await(50, TimeUnit.MILLISECONDS)
|
||||||
lock.wait(50)
|
} catch (_: InterruptedException) {
|
||||||
} catch (_: InterruptedException) {
|
/* Ignored. */
|
||||||
/* Ignored. */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,12 +60,8 @@ class Barcode {
|
|||||||
return results ?: emptyList()
|
return results ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun lockNotify() = synchronized(lock) { lock.notify() }
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val lock = Object()
|
|
||||||
|
|
||||||
private val TAG: String = Companion::class.java.simpleName
|
private val TAG: String = Companion::class.java.simpleName
|
||||||
|
|
||||||
const val TYPE_NAME_UNKNOWN = "TYPE_NAME_UNKNOWN"
|
const val TYPE_NAME_UNKNOWN = "TYPE_NAME_UNKNOWN"
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import com.google.mlkit.vision.text.TextRecognition
|
|||||||
import com.google.mlkit.vision.text.TextRecognizer
|
import com.google.mlkit.vision.text.TextRecognizer
|
||||||
import com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions
|
import com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions
|
||||||
import org.autojs.autojs.core.image.ImageWrapper
|
import org.autojs.autojs.core.image.ImageWrapper
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by SuperMonster003 on Mar 18, 2023.
|
* Created by SuperMonster003 on Mar 18, 2023.
|
||||||
@@ -34,22 +36,21 @@ class OcrMLKit {
|
|||||||
if (bitmap.isRecycled) return emptyList<OcrResult>().also { image.shoot() }
|
if (bitmap.isRecycled) return emptyList<OcrResult>().also { image.shoot() }
|
||||||
|
|
||||||
val inputImage = InputImage.fromBitmap(bitmap, 0)
|
val inputImage = InputImage.fromBitmap(bitmap, 0)
|
||||||
|
val detectCompletedSignal = CountDownLatch(1)
|
||||||
val result = recognizer!!.process(inputImage)
|
val result = recognizer!!.process(inputImage)
|
||||||
.addOnCanceledListener { lockNotify() }
|
.addOnCanceledListener { detectCompletedSignal.countDown() }
|
||||||
.addOnCompleteListener { lockNotify() }
|
.addOnCompleteListener { detectCompletedSignal.countDown() }
|
||||||
.addOnSuccessListener { lockNotify() }
|
.addOnSuccessListener { detectCompletedSignal.countDown() }
|
||||||
.addOnFailureListener { e: Exception ->
|
.addOnFailureListener { e: Exception ->
|
||||||
Log.w(TAG, "Failed to detect: ${e.message}")
|
Log.w(TAG, "Failed to detect: ${e.message}")
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
lockNotify()
|
detectCompletedSignal.countDown()
|
||||||
}
|
}
|
||||||
while (!result.isComplete) {
|
while (!result.isComplete) {
|
||||||
synchronized(lock) {
|
try {
|
||||||
try {
|
detectCompletedSignal.await(50, TimeUnit.MILLISECONDS)
|
||||||
lock.wait(50)
|
} catch (_: InterruptedException) {
|
||||||
} catch (_: InterruptedException) {
|
/* Ignored. */
|
||||||
/* Ignored. */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
image.shoot()
|
image.shoot()
|
||||||
@@ -77,12 +78,8 @@ class OcrMLKit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun lockNotify() = synchronized(lock) { lock.notify() }
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val lock = Object()
|
|
||||||
|
|
||||||
private val TAG: String = Companion::class.java.simpleName
|
private val TAG: String = Companion::class.java.simpleName
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,21 +48,16 @@ class Plugins(private val context: Context, private val runtime: PluginRuntime)
|
|||||||
)
|
)
|
||||||
packages.putIfAbsent(packageName, packageContext)?.let { packageContext = it }
|
packages.putIfAbsent(packageName, packageContext)?.let { packageContext = it }
|
||||||
|
|
||||||
val lock = Object()
|
return try {
|
||||||
synchronized(lock) {
|
val plugin = Plugin.load(context, packageContext, runtime, runtime.topLevelScope)
|
||||||
try {
|
val scriptCacheDir = getScriptCacheDir(packageName)
|
||||||
val plugin = Plugin.load(context, packageContext, runtime, runtime.topLevelScope)
|
copyAssetDir(packageContext.context.assets, plugin.assetsScriptDir, scriptCacheDir.path)
|
||||||
val scriptCacheDir = getScriptCacheDir(packageName)
|
plugin.mainScriptPath = File(scriptCacheDir, "index.js").path
|
||||||
copyAssetDir(packageContext.context.assets, plugin.assetsScriptDir, scriptCacheDir.path)
|
bindService(plugin)
|
||||||
plugin.mainScriptPath = File(scriptCacheDir, "index.js").path
|
mPlugins[packageName] = plugin
|
||||||
bindService(plugin)
|
plugin
|
||||||
mPlugins[packageName] = plugin
|
} catch (e: Exception) {
|
||||||
lock.notify()
|
throw PluginLoadException(e)
|
||||||
return plugin
|
|
||||||
} catch (e: Exception) {
|
|
||||||
lock.notify()
|
|
||||||
throw PluginLoadException(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class ScriptPromiseAdapter : Resolvable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val UNSET = Object()
|
private val UNSET = Any()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import org.autojs.autojs.util.ClipboardUtils
|
|||||||
import org.autojs.autojs.util.RootUtils
|
import org.autojs.autojs.util.RootUtils
|
||||||
import org.autojs.autojs.util.ViewUtils
|
import org.autojs.autojs.util.ViewUtils
|
||||||
import org.autojs.autojs6.R
|
import org.autojs.autojs6.R
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
|
||||||
interface CommandBasedPermissionItemHelper : PermissionItemHelper, IPermissionRootItem, IPermissionShizukuItem, IPermissionAdbItem {
|
interface CommandBasedPermissionItemHelper : PermissionItemHelper, IPermissionRootItem, IPermissionShizukuItem, IPermissionAdbItem {
|
||||||
|
|
||||||
@@ -92,17 +93,21 @@ interface CommandBasedPermissionItemHelper : PermissionItemHelper, IPermissionRo
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun withAdb(action: ACTION): Boolean {
|
fun withAdb(action: ACTION): Boolean {
|
||||||
val lock = Object()
|
val dialogDismissSignal = CountDownLatch(1)
|
||||||
|
|
||||||
AdbDialogBuilder(context, getCommand(action))
|
AdbDialogBuilder(context, getCommand(action))
|
||||||
.setChecker(object : AdbDialogBuilder.Checker {
|
.setChecker(object : AdbDialogBuilder.Checker {
|
||||||
override fun check() = has()
|
override fun check() = has()
|
||||||
})
|
})
|
||||||
.build()
|
.build()
|
||||||
.dismissListener { synchronized(lock) { lock.notify() } }
|
.dismissListener { dialogDismissSignal.countDown() }
|
||||||
.let { Handler(Looper.getMainLooper()).post { it.show() } }
|
.let { Handler(Looper.getMainLooper()).post { it.show() } }
|
||||||
|
|
||||||
synchronized(lock) { lock.wait() }
|
try {
|
||||||
|
dialogDismissSignal.await()
|
||||||
|
} catch (_: InterruptedException) {
|
||||||
|
/* Ignored. */
|
||||||
|
}
|
||||||
|
|
||||||
return has()
|
return has()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Sat Mar 07 19:14:09 CST 2026
|
#Sat Mar 07 21:17:02 CST 2026
|
||||||
BUILD_TIME=1772882049270
|
BUILD_TIME=1772889422226
|
||||||
COMPILE_SDK_VERSION=36
|
COMPILE_SDK_VERSION=36
|
||||||
IMAGE_QUANT_CMAKE_VERSION=3.22.1
|
IMAGE_QUANT_CMAKE_VERSION=3.22.1
|
||||||
IMAGE_QUANT_NDK_VERSION=26.1.10909125
|
IMAGE_QUANT_NDK_VERSION=26.1.10909125
|
||||||
@@ -27,6 +27,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=36
|
TARGET_SDK_VERSION=36
|
||||||
TARGET_SDK_VERSION_INRT=29
|
TARGET_SDK_VERSION_INRT=29
|
||||||
VERSION_BUILD=3780
|
VERSION_BUILD=3781
|
||||||
VERSION_NAME=6.7.0 Alpha23
|
VERSION_NAME=6.7.0 Alpha23
|
||||||
VSCODE_EXT_REQUIRED_VERSION=1.0.13
|
VSCODE_EXT_REQUIRED_VERSION=1.0.13
|
||||||
|
|||||||
Reference in New Issue
Block a user