Merge "Fix deadlock which causing ANR"
am: 4b2247d506
Change-Id: I1a74685364f63255607c78d2a16329b88e39de90
This commit is contained in:
@@ -106,6 +106,8 @@ public final class Magnifier {
|
|||||||
// Lock to synchronize between the UI thread and the thread that handles pixel copy results.
|
// Lock to synchronize between the UI thread and the thread that handles pixel copy results.
|
||||||
// Only sync mWindow writes from UI thread with mWindow reads from sPixelCopyHandlerThread.
|
// Only sync mWindow writes from UI thread with mWindow reads from sPixelCopyHandlerThread.
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
// The lock used to synchronize the UI and render threads when a #dismiss is performed.
|
||||||
|
private final Object mDestroyLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a magnifier.
|
* Initializes a magnifier.
|
||||||
@@ -173,7 +175,7 @@ public final class Magnifier {
|
|||||||
mParentSurface.mSurface,
|
mParentSurface.mSurface,
|
||||||
mWindowWidth, mWindowHeight, mWindowElevation, mWindowCornerRadius,
|
mWindowWidth, mWindowHeight, mWindowElevation, mWindowCornerRadius,
|
||||||
Handler.getMain() /* draw the magnifier on the UI thread */, mLock,
|
Handler.getMain() /* draw the magnifier on the UI thread */, mLock,
|
||||||
mCallback);
|
mDestroyLock, mCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
performPixelCopy(startX, startY, true /* update window position */);
|
performPixelCopy(startX, startY, true /* update window position */);
|
||||||
@@ -187,9 +189,11 @@ public final class Magnifier {
|
|||||||
*/
|
*/
|
||||||
public void dismiss() {
|
public void dismiss() {
|
||||||
if (mWindow != null) {
|
if (mWindow != null) {
|
||||||
synchronized (mLock) {
|
synchronized (mDestroyLock) {
|
||||||
mWindow.destroy();
|
synchronized (mLock) {
|
||||||
mWindow = null;
|
mWindow.destroy();
|
||||||
|
mWindow = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mPrevPosInView.x = NONEXISTENT_PREVIOUS_CONFIG_VALUE;
|
mPrevPosInView.x = NONEXISTENT_PREVIOUS_CONFIG_VALUE;
|
||||||
mPrevPosInView.y = NONEXISTENT_PREVIOUS_CONFIG_VALUE;
|
mPrevPosInView.y = NONEXISTENT_PREVIOUS_CONFIG_VALUE;
|
||||||
@@ -478,14 +482,16 @@ public final class Magnifier {
|
|||||||
// is performed on the UI thread and a frame callback on the render thread.
|
// is performed on the UI thread and a frame callback on the render thread.
|
||||||
// When both mLock and mDestroyLock need to be held at the same time,
|
// When both mLock and mDestroyLock need to be held at the same time,
|
||||||
// mDestroyLock should be acquired before mLock in order to avoid deadlocks.
|
// mDestroyLock should be acquired before mLock in order to avoid deadlocks.
|
||||||
private final Object mDestroyLock = new Object();
|
private final Object mDestroyLock;
|
||||||
|
|
||||||
InternalPopupWindow(final Context context, final Display display,
|
InternalPopupWindow(final Context context, final Display display,
|
||||||
final Surface parentSurface,
|
final Surface parentSurface,
|
||||||
final int width, final int height, final float elevation, final float cornerRadius,
|
final int width, final int height, final float elevation, final float cornerRadius,
|
||||||
final Handler handler, final Object lock, final Callback callback) {
|
final Handler handler, final Object lock, final Object destroyLock,
|
||||||
|
final Callback callback) {
|
||||||
mDisplay = display;
|
mDisplay = display;
|
||||||
mLock = lock;
|
mLock = lock;
|
||||||
|
mDestroyLock = destroyLock;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
|
||||||
mContentWidth = width;
|
mContentWidth = width;
|
||||||
|
|||||||
Reference in New Issue
Block a user