fix: requestScreenCapture() dead lock if request activity destroyed

This commit is contained in:
hyb1996
2018-03-15 20:22:13 +08:00
parent 9679830c75
commit 976e78e07d
4 changed files with 67 additions and 5 deletions

View File

@@ -42,6 +42,29 @@ public class VolatileDispose<T> {
return mValue;
}
public T blockedGetOrThrow(Class<? extends RuntimeException> exception, long timeout, T defaultValue) {
synchronized (this) {
if (mValue != null) {
return mValue;
}
try {
this.wait(timeout);
} catch (InterruptedException e) {
try {
throw exception.newInstance();
} catch (InstantiationException e1) {
throw new RuntimeException(e1);
} catch (IllegalAccessException e1) {
throw new RuntimeException(e1);
}
}
if (mValue == null) {
return defaultValue;
}
}
return mValue;
}
public void setAndNotify(T value) {
synchronized (this) {
mValue = value;