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