Ignore touch down events near the edge of the screen for the purposes of pulling down the
windowshade.

This makes it happen less often when you pick up the device or push open the keyboard.
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 5cea28db..8a92757 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -38,4 +38,6 @@
     <dimen name="password_keyboard_key_height">56dip</dimen>
     <!-- Default correction for the space key in the password keyboard -->
     <dimen name="password_keyboard_spacebar_vertical_correction">4dip</dimen>
+    <!-- Margin at the edge of the screen to ignore touch events for in the windowshade. -->
+    <dimen name="status_bar_edge_ignore">5dp</dimen>
 </resources>
diff --git a/services/java/com/android/server/status/StatusBarService.java b/services/java/com/android/server/status/StatusBarService.java
index dab8b72..493bd93 100644
--- a/services/java/com/android/server/status/StatusBarService.java
+++ b/services/java/com/android/server/status/StatusBarService.java
@@ -206,6 +206,7 @@
     private boolean mTicking;
     
     // Tracking finger for opening/closing.
+    int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore
     boolean mTracking;
     VelocityTracker mVelocityTracker;
     
@@ -299,6 +300,8 @@
         mCloseView = (CloseDragHandle)mTrackingView.findViewById(R.id.close);
         mCloseView.mService = this;
 
+        mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
+
         // add the more icon for the notifications
         IconData moreData = IconData.makeIcon(null, context.getPackageName(),
                 R.drawable.stat_notify_more, 0, 42);
@@ -1204,8 +1207,10 @@
     }
     
     boolean interceptTouchEvent(MotionEvent event) {
-        if (SPEW) Log.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled="
+        if (SPEW) {
+            Log.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled="
                 + mDisabled);
+        }
 
         if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
             return false;
@@ -1214,7 +1219,7 @@
         final int statusBarSize = mStatusBarView.getHeight();
         final int hitSize = statusBarSize*2;
         if (event.getAction() == MotionEvent.ACTION_DOWN) {
-            int y = (int)event.getRawY();
+            final int y = (int)event.getRawY();
 
             if (!mExpanded) {
                 mViewDelta = statusBarSize - y;
@@ -1224,8 +1229,16 @@
             }
             if ((!mExpanded && y < hitSize) ||
                     (mExpanded && y > (mDisplay.getHeight()-hitSize))) {
-                prepareTracking(y, !mExpanded); // opening if we're not already fully visible
-                mVelocityTracker.addMovement(event);
+
+                // We drop events at the edge of the screen to make the windowshade come
+                // down by accident less, especially when pushing open a device with a keyboard
+                // that rotates (like g1 and droid)
+                int x = (int)event.getRawX();
+                final int edgeBorder = mEdgeBorder;
+                if (x >= edgeBorder && x < mDisplay.getWidth() - edgeBorder) {
+                    prepareTracking(y, !mExpanded);// opening if we're not already fully visible
+                    mVelocityTracker.addMovement(event);
+                }
             }
         } else if (mTracking) {
             mVelocityTracker.addMovement(event);
@@ -1771,10 +1784,15 @@
      * meantime, just update the things that we know change.
      */
     void updateResources() {
+        Resources res = mContext.getResources();
+
         mClearButton.setText(mContext.getText(R.string.status_bar_clear_all_button));
         mOngoingTitle.setText(mContext.getText(R.string.status_bar_ongoing_events_title));
         mLatestTitle.setText(mContext.getText(R.string.status_bar_latest_events_title));
         mNoNotificationsTitle.setText(mContext.getText(R.string.status_bar_no_notifications_title));
+
+        mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
+
         if (false) Log.v(TAG, "updateResources");
     }