From bb00f53b949c7e25a03d3755d2554d1068120c36 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 11 Jan 2012 17:08:14 -0500 Subject: [PATCH] Bug 713011 - Add a check to ensure we are running on the correct thread. r=blassey --- mobile/android/base/ui/PanZoomController.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mobile/android/base/ui/PanZoomController.java b/mobile/android/base/ui/PanZoomController.java index 3b0d8c27043..7a85f83ba68 100644 --- a/mobile/android/base/ui/PanZoomController.java +++ b/mobile/android/base/ui/PanZoomController.java @@ -124,6 +124,8 @@ public class PanZoomController private final Axis mX; private final Axis mY; + private Thread mMainThread; + /* The timer that handles flings or bounces. */ private Timer mAnimationTimer; /* The runnable being scheduled by the animation timer. */ @@ -141,12 +143,23 @@ public class PanZoomController mX = new AxisX(mSubscroller); mY = new AxisY(mSubscroller); + mMainThread = GeckoApp.mAppContext.getMainLooper().getThread(); + checkMainThread(); + mState = PanZoomState.NOTHING; GeckoAppShell.registerGeckoEventListener(MESSAGE_ZOOM_RECT, this); GeckoAppShell.registerGeckoEventListener(MESSAGE_ZOOM_PAGE, this); } + // for debugging bug 713011; it can be taken out once that is resolved. + private void checkMainThread() { + if (mMainThread != Thread.currentThread()) { + // log with full stack trace + Log.e(LOGTAG, "Uh-oh, we're running on the wrong thread!", new Exception()); + } + } + public void handleMessage(String event, JSONObject message) { Log.i(LOGTAG, "Got message: " + event); try { @@ -198,6 +211,7 @@ public class PanZoomController /** This function must be called from the UI thread. */ @SuppressWarnings("fallthrough") public void abortAnimation() { + checkMainThread(); // this happens when gecko changes the viewport on us or if the device is rotated. // if that's the case, abort any animation in progress and re-zoom so that the page // snaps to edges. for other cases (where the user's finger(s) are down) don't do @@ -631,6 +645,8 @@ public class PanZoomController } private void finishAnimation() { + checkMainThread(); + Log.d(LOGTAG, "Finishing animation at " + mController.getViewportMetrics()); stopAnimationTimer();