fix: VolatileBox dead lock issue
This commit is contained in:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 214
|
||||
versionName "3.0.0 Alpha15"
|
||||
versionCode 215
|
||||
versionName "3.0.0 Alpha16"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.autojs.core.accessibility.SimpleActionAutomator;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.autojs.runtime.api.UI;
|
||||
import com.stardust.concurrent.VolatileDispose;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.util.ClipboardUtil;
|
||||
import com.stardust.autojs.core.util.ProcessShell;
|
||||
@@ -237,7 +238,7 @@ public class ScriptRuntime {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
return ClipboardUtil.getClipOrEmpty(mUiHandler.getContext()).toString();
|
||||
}
|
||||
final VolatileBox<String> clip = new VolatileBox<>("");
|
||||
final VolatileDispose<String> clip = new VolatileDispose<>();
|
||||
mUiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.support.annotation.RequiresApi;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.concurrent.VolatileDispose;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
|
||||
/**
|
||||
@@ -110,7 +111,7 @@ public class GlobalActionAutomator {
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private boolean gesturesWithHandler(GestureDescription description) {
|
||||
final VolatileBox<Boolean> result = new VolatileBox<>(false);
|
||||
final VolatileDispose<Boolean> result = new VolatileDispose<>();
|
||||
mService.dispatchGesture(description, new AccessibilityService.GestureResultCallback() {
|
||||
@Override
|
||||
public void onCompleted(GestureDescription gestureDescription) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.stardust.concurrent;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/28.
|
||||
*/
|
||||
|
||||
public class VolatileDispose<T> {
|
||||
|
||||
private volatile T mValue;
|
||||
|
||||
public T blockedGet() {
|
||||
synchronized (this) {
|
||||
if (mValue != null) {
|
||||
return mValue;
|
||||
}
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public T blockedGetOrThrow(Class<? extends RuntimeException> exception) {
|
||||
synchronized (this) {
|
||||
if (mValue != null) {
|
||||
return mValue;
|
||||
}
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
try {
|
||||
throw exception.newInstance();
|
||||
} catch (InstantiationException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
} catch (IllegalAccessException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setAndNotify(T value) {
|
||||
synchronized (this) {
|
||||
mValue = value;
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user