Merge "Revert "Make AwesomePlayer's reset process more verbose to track down ANRs (again)"" into honeycomb
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index e26fd6f..790a040 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -350,6 +350,7 @@
     private ZoomManager mZoomManager;
 
     private Rect mGLRectViewport = new Rect();
+    private boolean mGLViewportEmpty = false;
 
     /**
      *  Transportation object for returning WebView across thread boundaries.
@@ -4075,7 +4076,8 @@
         }
 
         if (canvas.isHardwareAccelerated()) {
-            int functor = nativeGetDrawGLFunction(mGLRectViewport, getScale(), extras);
+            int functor = nativeGetDrawGLFunction(mGLViewportEmpty ? null : mGLRectViewport,
+                    getScale(), extras);
             ((HardwareCanvas) canvas).callDrawGLFunction(functor);
         } else {
             DrawFilter df = null;
@@ -5159,16 +5161,21 @@
 
     void setGLRectViewport() {
         // Use the getGlobalVisibleRect() to get the intersection among the parents
-        getGlobalVisibleRect(mGLRectViewport);
-
-        // Then need to invert the Y axis, just for GL
-        View rootView = getRootView();
-        int rootViewHeight = rootView.getHeight();
-        int savedWebViewBottom = mGLRectViewport.bottom;
-        mGLRectViewport.bottom = rootViewHeight - mGLRectViewport.top - getVisibleTitleHeight();
-        mGLRectViewport.top = rootViewHeight - savedWebViewBottom;
-
-        nativeUpdateDrawGLFunction(mGLRectViewport);
+        // visible == false means we're clipped - send a null rect down to indicate that
+        // we should not draw
+        boolean visible = getGlobalVisibleRect(mGLRectViewport);
+        if (visible) {
+            // Then need to invert the Y axis, just for GL
+            View rootView = getRootView();
+            int rootViewHeight = rootView.getHeight();
+            int savedWebViewBottom = mGLRectViewport.bottom;
+            mGLRectViewport.bottom = rootViewHeight - mGLRectViewport.top - getVisibleTitleHeight();
+            mGLRectViewport.top = rootViewHeight - savedWebViewBottom;
+            mGLViewportEmpty = false;
+        } else {
+            mGLViewportEmpty = true;
+        }
+        nativeUpdateDrawGLFunction(mGLViewportEmpty ? null : mGLRectViewport);
     }
 
     /**
@@ -6828,7 +6835,7 @@
                     previouslyFocusedRect);
         } else {
             result = super.requestFocus(direction, previouslyFocusedRect);
-            if (mWebViewCore.getSettings().getNeedInitialFocus()) {
+            if (mWebViewCore.getSettings().getNeedInitialFocus() && !isInTouchMode()) {
                 // For cases such as GMail, where we gain focus from a direction,
                 // we want to move to the first available link.
                 // FIXME: If there are no visible links, we may not want to
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index b739d83..d8a7f9d 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -1690,7 +1690,7 @@
         int contextLen = contextEnd - contextStart;
         char[] buf = TemporaryBuffer.obtain(contextLen);
         TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
-        int result = getTextRunCursor(buf, 0, contextLen, flags, offset, cursorOpt);
+        int result = getTextRunCursor(buf, 0, contextLen, flags, offset - contextStart, cursorOpt);
         TemporaryBuffer.recycle(buf);
         return result;
     }
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index 64c209a..4c659d4 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -24,9 +24,9 @@
 /**
  * Captures frames from an image stream as an OpenGL ES texture.
  *
- * <p>The image stream may come from either video playback or camera preview.  A SurfaceTexture may
- * be used in place of a SurfaceHolder when specifying the output destination of a MediaPlayer or
- * Camera object.  This will cause all the frames from that image stream to be sent to the
+ * <p>The image stream may come from either camera preview.  A SurfaceTexture may be used in place
+ * of a SurfaceHolder when specifying the output destination of a {@link android.hardware.Camera}
+ * object.  Doing so will cause all the frames from the image stream to be sent to the
  * SurfaceTexture object rather than to the device's display.  When {@link #updateTexImage} is
  * called, the contents of the texture object specified when the SurfaceTexture was created is
  * updated to contain the most recent image from the image stream.  This may cause some frames of
@@ -34,6 +34,11 @@
  *
  * <p>The texture object uses the GL_TEXTURE_EXTERNAL_OES texture target, which is defined by the
  * OES_EGL_image_external OpenGL ES extension.  This limits how the texture may be used.
+ *
+ * <p>SurfaceTexture objects may be created on any thread.  {@link #updateTexImage} may only be
+ * called on the thread with the OpenGL ES context that contains the texture object.  The
+ * frame-available callback is called on an arbitrary thread, so unless special care is taken {@link
+ * #updateTexImage} should not be called directly from the callback.
  */
 public class SurfaceTexture {
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
index 14a2f90..eaa5cc9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
@@ -97,8 +97,6 @@
     // Fitts' Law assistance for LatinIME; TODO: replace with a more general approach
     private static final boolean FAKE_SPACE_BAR = true;
 
-    public static final int LIGHTS_ON_DELAY = 5000;
-
     // The height of the bar, as definied by the build.  It may be taller if we're plugged
     // into hdmi.
     int mNaturalBarHeight = -1;
@@ -391,6 +389,12 @@
             new View.OnTouchListener() {
                 public boolean onTouch(View v, MotionEvent ev) {
                     if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+                        // even though setting the systemUI visibility below will turn these views
+                        // on, we need them to come up faster so that they can catch this motion
+                        // event
+                        mShadow.setVisibility(View.GONE);
+                        mBarContents.setVisibility(View.VISIBLE);
+
                         try {
                             mBarService.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
                         } catch (RemoteException ex) {
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index 19e7fae..a7f7866 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -1069,6 +1069,8 @@
 
         cdmaDataConnectionState = newCdmaDataConnectionState;
         networkType = newNetworkType;
+        // this new state has been applied - forget it until we get a new new state
+        newNetworkType = 0;
 
         newSS.setStateOutOfService(); // clean slate for next time
 
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
index c107d17..bb99e45 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
@@ -957,6 +957,9 @@
 
         gprsState = newGPRSState;
         networkType = newNetworkType;
+        // this new state has been applied - forget it until we get a new new state
+        newNetworkType = 0;
+
 
         newSS.setStateOutOfService(); // clean slate for next time