Merge "Fix bug 5394020 - Menus are pretty sluggish to bring up"
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index 3bd0f76..ad2283e 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -117,6 +117,11 @@
                 outSize.x = getRawWidth();
                 outSize.y = getRawHeight();
             }
+            if (false) {
+                RuntimeException here = new RuntimeException("here");
+                here.fillInStackTrace();
+                Slog.v(TAG, "Returning display size: " + outSize, here);
+            }
             if (DEBUG_DISPLAY_SIZE && doCompat) Slog.v(
                     TAG, "Returning display size: " + outSize);
         } catch (RemoteException e) {
diff --git a/core/res/res/drawable-hdpi/list_selector_background_disabled.9.png b/core/res/res/drawable-hdpi/list_selector_background_disabled.9.png
old mode 100755
new mode 100644
index 9e1c42a..f8092ea
--- a/core/res/res/drawable-hdpi/list_selector_background_disabled.9.png
+++ b/core/res/res/drawable-hdpi/list_selector_background_disabled.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/list_selector_background_focus.9.png b/core/res/res/drawable-hdpi/list_selector_background_focus.9.png
old mode 100755
new mode 100644
index 5563c80..3a21d35
--- a/core/res/res/drawable-hdpi/list_selector_background_focus.9.png
+++ b/core/res/res/drawable-hdpi/list_selector_background_focus.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/list_selector_background_longpress.9.png b/core/res/res/drawable-hdpi/list_selector_background_longpress.9.png
old mode 100755
new mode 100644
index 72d3a08..19558e9
--- a/core/res/res/drawable-hdpi/list_selector_background_longpress.9.png
+++ b/core/res/res/drawable-hdpi/list_selector_background_longpress.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/list_selector_background_pressed.9.png b/core/res/res/drawable-hdpi/list_selector_background_pressed.9.png
old mode 100755
new mode 100644
index 7568b30..0f3b444
--- a/core/res/res/drawable-hdpi/list_selector_background_pressed.9.png
+++ b/core/res/res/drawable-hdpi/list_selector_background_pressed.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/list_selector_background_disabled.9.png b/core/res/res/drawable-mdpi/list_selector_background_disabled.9.png
index 43c36cb..dbe3953 100644
--- a/core/res/res/drawable-mdpi/list_selector_background_disabled.9.png
+++ b/core/res/res/drawable-mdpi/list_selector_background_disabled.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/list_selector_background_focus.9.png b/core/res/res/drawable-mdpi/list_selector_background_focus.9.png
index 53a7eac..da625af 100644
--- a/core/res/res/drawable-mdpi/list_selector_background_focus.9.png
+++ b/core/res/res/drawable-mdpi/list_selector_background_focus.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/list_selector_background_longpress.9.png b/core/res/res/drawable-mdpi/list_selector_background_longpress.9.png
index 0818761..fbf7ef0 100644
--- a/core/res/res/drawable-mdpi/list_selector_background_longpress.9.png
+++ b/core/res/res/drawable-mdpi/list_selector_background_longpress.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/list_selector_background_pressed.9.png b/core/res/res/drawable-mdpi/list_selector_background_pressed.9.png
index 8bd86b2..dd2a024 100644
--- a/core/res/res/drawable-mdpi/list_selector_background_pressed.9.png
+++ b/core/res/res/drawable-mdpi/list_selector_background_pressed.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/list_selector_background_disabled.9.png b/core/res/res/drawable-xhdpi/list_selector_background_disabled.9.png
index d599976..980bbd7 100644
--- a/core/res/res/drawable-xhdpi/list_selector_background_disabled.9.png
+++ b/core/res/res/drawable-xhdpi/list_selector_background_disabled.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/list_selector_background_focus.9.png b/core/res/res/drawable-xhdpi/list_selector_background_focus.9.png
index 17987f3..79c4577 100644
--- a/core/res/res/drawable-xhdpi/list_selector_background_focus.9.png
+++ b/core/res/res/drawable-xhdpi/list_selector_background_focus.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/list_selector_background_longpress.9.png b/core/res/res/drawable-xhdpi/list_selector_background_longpress.9.png
index 5a64592..73fc783 100644
--- a/core/res/res/drawable-xhdpi/list_selector_background_longpress.9.png
+++ b/core/res/res/drawable-xhdpi/list_selector_background_longpress.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/list_selector_background_pressed.9.png b/core/res/res/drawable-xhdpi/list_selector_background_pressed.9.png
index 1593577..5b3ebe1 100644
--- a/core/res/res/drawable-xhdpi/list_selector_background_pressed.9.png
+++ b/core/res/res/drawable-xhdpi/list_selector_background_pressed.9.png
Binary files differ
diff --git a/services/java/com/android/server/wm/DragState.java b/services/java/com/android/server/wm/DragState.java
index 25cc259..73cd64e 100644
--- a/services/java/com/android/server/wm/DragState.java
+++ b/services/java/com/android/server/wm/DragState.java
@@ -274,7 +274,8 @@
         final int myPid = Process.myPid();
 
         // Move the surface to the given touch
-        if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, ">>> OPEN TRANSACTION notifyMoveLw");
+        if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
+                WindowManagerService.TAG, ">>> OPEN TRANSACTION notifyMoveLw");
         Surface.openTransaction();
         try {
             mSurface.setPosition(x - mThumbOffsetX, y - mThumbOffsetY);
@@ -283,7 +284,8 @@
                     (int)(x - mThumbOffsetX) + "," + (int)(y - mThumbOffsetY) + ")");
         } finally {
             Surface.closeTransaction();
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
+            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
+                    WindowManagerService.TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
         }
 
         // Tell the affected window
diff --git a/services/java/com/android/server/wm/ScreenRotationAnimation.java b/services/java/com/android/server/wm/ScreenRotationAnimation.java
index e25638f..91576e7 100644
--- a/services/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -81,7 +81,7 @@
         mOriginalHeight = originalHeight;
 
         if (!inTransaction) {
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
+            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
                     ">>> OPEN TRANSACTION ScreenRotationAnimation");
             Surface.openTransaction();
         }
@@ -117,7 +117,7 @@
                     mSurface = null;
                     return;
                 }
-        
+
                 Paint paint = new Paint(0);
                 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
                 c.drawBitmap(screenshot, 0, 0, paint);
@@ -127,7 +127,7 @@
         } finally {
             if (!inTransaction) {
                 Surface.closeTransaction();
-                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
+                if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
                         "<<< CLOSE TRANSACTION ScreenRotationAnimation");
             }
     
@@ -254,7 +254,7 @@
         mEnterAnimation.restrictDuration(maxAnimationDuration);
         mEnterAnimation.scaleCurrentDuration(animationScale);
 
-        if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
+        if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
                 ">>> OPEN TRANSACTION ScreenRotationAnimation.dismiss");
         Surface.openTransaction();
 
@@ -266,7 +266,7 @@
             Slog.w(TAG, "Unable to allocate black surface", e);
         } finally {
             Surface.closeTransaction();
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
+            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
                     "<<< CLOSE TRANSACTION ScreenRotationAnimation.dismiss");
         }
 
diff --git a/services/java/com/android/server/wm/Session.java b/services/java/com/android/server/wm/Session.java
index 10882f9..03b7546 100644
--- a/services/java/com/android/server/wm/Session.java
+++ b/services/java/com/android/server/wm/Session.java
@@ -278,7 +278,8 @@
 
             // Make the surface visible at the proper location
             final Surface surface = mService.mDragState.mSurface;
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, ">>> OPEN TRANSACTION performDrag");
+            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
+                    WindowManagerService.TAG, ">>> OPEN TRANSACTION performDrag");
             Surface.openTransaction();
             try {
                 surface.setPosition(touchX - thumbCenterX,
@@ -288,7 +289,8 @@
                 surface.show();
             } finally {
                 Surface.closeTransaction();
-                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "<<< CLOSE TRANSACTION performDrag");
+                if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
+                        WindowManagerService.TAG, "<<< CLOSE TRANSACTION performDrag");
             }
         }
 
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 595c256..0a9ef3d 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -169,6 +169,7 @@
     static final boolean DEBUG_SCREENSHOT = false;
     static final boolean SHOW_SURFACE_ALLOC = false;
     static final boolean SHOW_TRANSACTIONS = false;
+    static final boolean SHOW_LIGHT_TRANSACTIONS = false || SHOW_TRANSACTIONS;
     static final boolean HIDE_STACK_CRAWLS = true;
 
     static final boolean PROFILE_ORIENTATION = false;
@@ -2369,7 +2370,7 @@
             synchronized (mWindowMap) {
                 WindowState w = windowForClientLocked(session, client, false);
                 if ((w != null) && (w.mSurface != null)) {
-                    if (SHOW_TRANSACTIONS) Slog.i(TAG,
+                    if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                             ">>> OPEN TRANSACTION setTransparentRegion");
                     Surface.openTransaction();
                     try {
@@ -2378,7 +2379,7 @@
                         w.mSurface.setTransparentRegionHint(region);
                     } finally {
                         Surface.closeTransaction();
-                        if (SHOW_TRANSACTIONS) Slog.i(TAG,
+                        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                                 "<<< CLOSE TRANSACTION setTransparentRegion");
                     }
                 }
@@ -4905,7 +4906,8 @@
                 }
             }
 
-            if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                    ">>> OPEN TRANSACTION showStrictModeViolation");
             Surface.openTransaction();
             try {
                 if (mStrictModeFlash == null) {
@@ -4914,7 +4916,8 @@
                 mStrictModeFlash.setVisibility(on);
             } finally {
                 Surface.closeTransaction();
-                if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
+                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                        "<<< CLOSE TRANSACTION showStrictModeViolation");
             }
         }
     }
@@ -5231,7 +5234,7 @@
         mInputManager.setDisplayOrientation(0, rotation);
 
         if (!inTransaction) {
-            if (SHOW_TRANSACTIONS) Slog.i(TAG,
+            if (SHOW_TRANSACTIONS)  Slog.i(TAG,
                     ">>> OPEN TRANSACTION setRotationUnchecked");
             Surface.openTransaction();
         }
@@ -5246,7 +5249,7 @@
         } finally {
             if (!inTransaction) {
                 Surface.closeTransaction();
-                if (SHOW_TRANSACTIONS) Slog.i(TAG,
+                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                         "<<< CLOSE TRANSACTION setRotationUnchecked");
             }
         }
@@ -5843,6 +5846,10 @@
         final DisplayMetrics dm = mDisplayMetrics;
         mAppDisplayWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
         mAppDisplayHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
+        if (false) {
+            Slog.i(TAG, "Set app display size: " + mAppDisplayWidth
+                    + " x " + mAppDisplayHeight);
+        }
         mDisplay.getMetricsWithSize(dm, mAppDisplayWidth, mAppDisplayHeight);
 
         mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm,
@@ -5860,8 +5867,8 @@
 
         // Compute the screen layout size class.
         int screenLayout;
-        int longSize = dw;
-        int shortSize = dh;
+        int longSize = mAppDisplayWidth;
+        int shortSize = mAppDisplayHeight;
         if (longSize < shortSize) {
             int tmp = longSize;
             longSize = shortSize;
@@ -6847,7 +6854,7 @@
 
     private void rebuildBlackFrame(boolean inTransaction) {
         if (!inTransaction) {
-            if (SHOW_TRANSACTIONS) Slog.i(TAG,
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                     ">>> OPEN TRANSACTION rebuildBlackFrame");
             Surface.openTransaction();
         }
@@ -6882,7 +6889,7 @@
         } finally {
             if (!inTransaction) {
                 Surface.closeTransaction();
-                if (SHOW_TRANSACTIONS) Slog.i(TAG,
+                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                         "<<< CLOSE TRANSACTION rebuildBlackFrame");
             }
         }
@@ -7354,7 +7361,8 @@
             createWatermark = true;
         }
 
-        if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
+        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
 
         Surface.openTransaction();
 
@@ -8463,7 +8471,8 @@
 
         Surface.closeTransaction();
 
-        if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
+        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
 
         if (mWatermark != null) {
             mWatermark.drawIfNeeded();
diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java
index 47f74fb..e921818 100644
--- a/services/java/com/android/server/wm/WindowState.java
+++ b/services/java/com/android/server/wm/WindowState.java
@@ -57,6 +57,7 @@
 final class WindowState implements WindowManagerPolicy.WindowState {
     static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
     static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
+    static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
     static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
 
     final WindowManagerService mService;
@@ -671,7 +672,7 @@
                 WindowManagerService.TAG, "Got surface: " + mSurface
                 + ", set left=" + mFrame.left + " top=" + mFrame.top
                 + ", animLayer=" + mAnimLayer);
-            if (SHOW_TRANSACTIONS) {
+            if (SHOW_LIGHT_TRANSACTIONS) {
                 Slog.i(WindowManagerService.TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
                 WindowManagerService.logSurface(this, "CREATE pos=(" + mFrame.left
                         + "," + mFrame.top + ") (" +
@@ -700,7 +701,8 @@
                 mLastHidden = true;
             } finally {
                 Surface.closeTransaction();
-                if (SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
+                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
+                        "<<< CLOSE TRANSACTION createSurfaceLocked");
             }
             if (WindowManagerService.localLOGV) Slog.v(
                     WindowManagerService.TAG, "Created surface " + this);
diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java
index c2b9e4f..4f50d24 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java
@@ -18,13 +18,17 @@
 
 import android.content.ContentValues;
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.database.SQLException;
 import android.net.Uri;
+import android.os.AsyncResult;
 import android.os.Message;
+import android.preference.PreferenceManager;
 import android.provider.Telephony;
 import android.util.Log;
 
 import com.android.internal.telephony.CommandsInterface;
+import com.android.internal.telephony.OperatorInfo;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneNotifier;
 import com.android.internal.telephony.PhoneProxy;
@@ -41,6 +45,18 @@
     /** Secondary SMSDispatcher for 3GPP format messages. */
     SMSDispatcher m3gppSMS;
 
+    /**
+     * Small container class used to hold information relevant to
+     * the carrier selection process. operatorNumeric can be ""
+     * if we are looking for automatic selection. operatorAlphaLong is the
+     * corresponding operator name.
+     */
+    private static class NetworkSelectMessage {
+        public Message message;
+        public String operatorNumeric;
+        public String operatorAlphaLong;
+    }
+
     // Constructors
     public CDMALTEPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) {
         super(context, ci, notifier, false);
@@ -48,6 +64,20 @@
     }
 
     @Override
+    public void handleMessage (Message msg) {
+        AsyncResult ar;
+        Message onComplete;
+        switch (msg.what) {
+            // handle the select network completion callbacks.
+            case EVENT_SET_NETWORK_MANUAL_COMPLETE:
+                handleSetSelectNetwork((AsyncResult) msg.obj);
+                break;
+            default:
+                super.handleMessage(msg);
+        }
+    }
+
+    @Override
     protected void initSstIcc() {
         mSST = new CdmaLteServiceStateTracker(this);
         mIccRecords = new CdmaLteUiccRecords(this);
@@ -109,6 +139,58 @@
     }
 
     @Override
+    public void
+    selectNetworkManually(OperatorInfo network,
+            Message response) {
+        // wrap the response message in our own message along with
+        // the operator's id.
+        NetworkSelectMessage nsm = new NetworkSelectMessage();
+        nsm.message = response;
+        nsm.operatorNumeric = network.getOperatorNumeric();
+        nsm.operatorAlphaLong = network.getOperatorAlphaLong();
+
+        // get the message
+        Message msg = obtainMessage(EVENT_SET_NETWORK_MANUAL_COMPLETE, nsm);
+
+        mCM.setNetworkSelectionModeManual(network.getOperatorNumeric(), msg);
+    }
+
+    /**
+     * Used to track the settings upon completion of the network change.
+     */
+    private void handleSetSelectNetwork(AsyncResult ar) {
+        // look for our wrapper within the asyncresult, skip the rest if it
+        // is null.
+        if (!(ar.userObj instanceof NetworkSelectMessage)) {
+            if (DBG) Log.d(LOG_TAG, "unexpected result from user object.");
+            return;
+        }
+
+        NetworkSelectMessage nsm = (NetworkSelectMessage) ar.userObj;
+
+        // found the object, now we send off the message we had originally
+        // attached to the request.
+        if (nsm.message != null) {
+            if (DBG) Log.d(LOG_TAG, "sending original message to recipient");
+            AsyncResult.forMessage(nsm.message, ar.result, ar.exception);
+            nsm.message.sendToTarget();
+        }
+
+        // open the shared preferences editor, and write the value.
+        // nsm.operatorNumeric is "" if we're in automatic.selection.
+        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
+        SharedPreferences.Editor editor = sp.edit();
+        editor.putString(NETWORK_SELECTION_KEY, nsm.operatorNumeric);
+        editor.putString(NETWORK_SELECTION_NAME_KEY, nsm.operatorAlphaLong);
+
+        // commit and log the result.
+        if (! editor.commit()) {
+            Log.e(LOG_TAG, "failed to commit network selection preference");
+        }
+
+    }
+
+    @Override
     public boolean updateCurrentCarrierInProvider() {
         if (mIccRecords != null) {
             try {