Merge change 27364 into eclair

* changes:
  Improve logging code to dump more detaild rs object info.  Fix bug with predefined elements not being recreated for contexts after one was destroyed. Add stricter type enforcement.
diff --git a/core/java/android/provider/Im.java b/core/java/android/provider/Im.java
index d5cc2207..d3e2820 100644
--- a/core/java/android/provider/Im.java
+++ b/core/java/android/provider/Im.java
@@ -896,12 +896,21 @@
         String BODY = "body";
 
         /**
-         * The date this message is sent or received
+         * The date this message is sent or received. This represents the display date for
+         * the message.
          * <P>Type: INTEGER</P>
          */
         String DATE = "date";
 
         /**
+         * The real date for this message. While 'date' can be modified by the client
+         * to account for server time skew, the real_date is the original timestamp set
+         * by the server for incoming messages.
+         * <P>Type: INTEGER</P>
+         */
+        String REAL_DATE = "real_date";
+
+        /**
          * Message Type, see {@link MessageType}
          * <P>Type: INTEGER</P>
          */
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 2b6313d..1cd4506 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2405,7 +2405,6 @@
         public static final String[] SETTINGS_TO_BACKUP = {
             ADB_ENABLED,
             ALLOW_MOCK_LOCATION,
-            INSTALL_NON_MARKET_APPS,
             PARENTAL_CONTROL_ENABLED,
             PARENTAL_CONTROL_REDIRECT_URL,
             USB_MASS_STORAGE_ENABLED,
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 90985e0..07034af 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -3689,6 +3689,7 @@
 
         switch (action) {
             case MotionEvent.ACTION_DOWN: {
+                mPreventDrag = PREVENT_DRAG_NO;
                 if (!mScroller.isFinished()) {
                     // stop the current scroll animation, but if this is
                     // the start of a fling, allow it to add to the current
@@ -3896,19 +3897,15 @@
                         mTouchMode = TOUCH_DONE_MODE;
                         doDoubleTap();
                         break;
-                    case TOUCH_SHORTPRESS_START_MODE:
-                    case TOUCH_SHORTPRESS_MODE:
-                        mPrivateHandler.removeMessages(SWITCH_TO_SHORTPRESS);
-                        mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
-                        mTouchMode = TOUCH_DONE_MODE;
-                        doShortPress();
-                        break;
                     case TOUCH_SELECT_MODE:
                         commitCopy();
                         mTouchSelection = false;
                         break;
                     case TOUCH_INIT_MODE: // tap
+                    case TOUCH_SHORTPRESS_START_MODE:
+                    case TOUCH_SHORTPRESS_MODE:
                         mPrivateHandler.removeMessages(SWITCH_TO_SHORTPRESS);
+                        mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
                         if ((deltaX * deltaX + deltaY * deltaY) > mTouchSlopSquare) {
                             Log.w(LOGTAG, "Miss a drag as we are waiting for" +
                                     " WebCore's response for touch down.");
@@ -3928,10 +3925,15 @@
                                 mPreventDrag = PREVENT_DRAG_NO;
                             }
                             if (mPreventDrag == PREVENT_DRAG_NO) {
-                                mPrivateHandler.sendMessageDelayed(
-                                        mPrivateHandler.obtainMessage(
-                                        RELEASE_SINGLE_TAP),
-                                        ViewConfiguration.getDoubleTapTimeout());
+                                if (mTouchMode == TOUCH_INIT_MODE) {
+                                    mPrivateHandler.sendMessageDelayed(
+                                            mPrivateHandler.obtainMessage(
+                                            RELEASE_SINGLE_TAP),
+                                            ViewConfiguration.getDoubleTapTimeout());
+                                } else {
+                                    mTouchMode = TOUCH_DONE_MODE;
+                                    doShortPress();
+                                }
                             }
                             break;
                         }
diff --git a/core/java/com/google/android/mms/pdu/PduComposer.java b/core/java/com/google/android/mms/pdu/PduComposer.java
index 2aa5e48..8940945 100644
--- a/core/java/com/google/android/mms/pdu/PduComposer.java
+++ b/core/java/com/google/android/mms/pdu/PduComposer.java
@@ -850,8 +850,7 @@
         PositionMarker ctStart = mStack.mark();
 
         // This contentTypeIdentifier should be used for type of attachment...
-        String contentType = new String(
-                mPduHeader.getTextString(PduHeaders.CONTENT_TYPE));
+        String contentType = new String(mPduHeader.getTextString(PduHeaders.CONTENT_TYPE));
         Integer contentTypeIdentifier = mContentTypeMap.get(contentType);
         if (contentTypeIdentifier == null) {
             // content type is mandatory
@@ -862,7 +861,7 @@
 
         // content-type parameter: start
         PduBody body = ((SendReq) mPdu).getBody();
-        if (null == body) {
+        if (null == body || body.getPartsNum() == 0) {
             // empty message
             appendUintvarInteger(0);
             mStack.pop();
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 9cf5324..60a2ecb1 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1123,10 +1123,11 @@
         android:protectionLevel="signature" />
 
     <!-- Allows applications to set a live wallpaper.
-         @hide -->
+         @hide XXX Change to signature once the picker is moved to its
+         own apk as Ghod Intended. -->
     <permission android:name="android.permission.SET_WALLPAPER_COMPONENT"
         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
-        android:protectionLevel="signature" />
+        android:protectionLevel="signatureOrSystem" />
 
     <application android:process="system"
                  android:persistent="true"
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index a5a8cc9..872b2bc 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -1743,7 +1743,7 @@
         if (Res_GETPACKAGE(resID)+1 == 0) {
             LOGW("No package identifier when getting name for resource number 0x%08x", resID);
         } else {
-            LOGW("Resources don't contain pacakge for resource number 0x%08x", resID);
+            LOGW("Resources don't contain package for resource number 0x%08x", resID);
         }
         return false;
     }
@@ -1793,7 +1793,7 @@
         if (Res_GETPACKAGE(resID)+1 == 0) {
             LOGW("No package identifier when getting name for resource number 0x%08x", resID);
         } else {
-            LOGW("Resources don't contain pacakge for resource number 0x%08x", resID);
+            LOGW("Resources don't contain package for resource number 0x%08x", resID);
         }
         return BAD_INDEX;
     }
diff --git a/media/java/android/media/MiniThumbFile.java b/media/java/android/media/MiniThumbFile.java
index c607218..def0288 100644
--- a/media/java/android/media/MiniThumbFile.java
+++ b/media/java/android/media/MiniThumbFile.java
@@ -215,7 +215,6 @@
                 r.write(data);
                 r.seek(pos);
                 r.writeByte(1);  // we have data in this slot
-                mChannel.force(true);
             }
         } catch (IOException ex) {
             Log.e(TAG, "couldn't save mini thumbnail data for "
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index cb917db..15290c1 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -637,6 +637,9 @@
                 IBackupTransport transport = getTransport(mCurrentTransport);
                 if (transport == null) {
                     Log.v(TAG, "Backup requested but no transport available");
+                    synchronized (mQueueLock) {
+                        mBackupOrRestoreInProgress = false;
+                    }
                     mWakelock.release();
                     break;
                 }
@@ -671,6 +674,9 @@
                         (new PerformBackupThread(transport, queue, oldJournal)).start();
                     } else {
                         Log.v(TAG, "Backup requested but nothing pending");
+                        synchronized (mQueueLock) {
+                            mBackupOrRestoreInProgress = false;
+                        }
                         mWakelock.release();
                     }
                 }
@@ -1686,6 +1692,9 @@
                 }
 
                 // Last but not least, release the cpu
+                synchronized (mQueueLock) {
+                    mBackupOrRestoreInProgress = false;
+                }
                 mWakelock.release();
             }
         }
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 8ebbc93..228d25e 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -4174,7 +4174,7 @@
             final int N = mWindows.size();
             for (int i=0; i<N; i++) {
                 WindowState w = (WindowState)mWindows.get(i);
-                if (w.isVisibleLw() && !w.isDisplayedLw()) {
+                if (w.isVisibleLw() && !w.isDrawnLw()) {
                     return;
                 }
             }
@@ -7664,6 +7664,16 @@
                         || mAnimating);
         }
 
+        /**
+         * Returns true if the window has a surface that it has drawn a
+         * complete UI in to.
+         */
+        public boolean isDrawnLw() {
+            final AppWindowToken atoken = mAppToken;
+            return mSurface != null && !mDestroying
+                && !mDrawPending && !mCommitDrawPending;
+        }
+
         public boolean fillsScreenLw(int screenWidth, int screenHeight,
                                    boolean shownFrame, boolean onlyOpaque) {
             if (mSurface == null) {
@@ -8268,10 +8278,10 @@
                     continue;
                 }
                 if (DEBUG_VISIBILITY) {
-                    Log.v(TAG, "Win " + win + ": isDisplayed="
-                            + win.isDisplayedLw()
+                    Log.v(TAG, "Win " + win + ": isDrawn="
+                            + win.isDrawnLw()
                             + ", isAnimating=" + win.isAnimating());
-                    if (!win.isDisplayedLw()) {
+                    if (!win.isDrawnLw()) {
                         Log.v(TAG, "Not displayed: s=" + win.mSurface
                                 + " pv=" + win.mPolicyVisibility
                                 + " dp=" + win.mDrawPending
@@ -8284,7 +8294,7 @@
                     }
                 }
                 numInteresting++;
-                if (win.isDisplayedLw()) {
+                if (win.isDrawnLw()) {
                     if (!win.isAnimating()) {
                         numVisible++;
                     }
@@ -9007,7 +9017,6 @@
                         || !win.mRelayoutCalled
                         || win.mRootToken.hidden
                         || (atoken != null && atoken.hiddenRequested)
-                        || !win.mPolicyVisibility
                         || win.mAttachedHidden
                         || win.mExiting || win.mDestroying;
 
@@ -9217,10 +9226,10 @@
                                 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
                                 && !w.mExiting && !w.mDestroying) {
                             if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
-                                Log.v(TAG, "Eval win " + w + ": isDisplayed="
-                                        + w.isDisplayedLw()
+                                Log.v(TAG, "Eval win " + w + ": isDrawn="
+                                        + w.isDrawnLw()
                                         + ", isAnimating=" + w.isAnimating());
-                                if (!w.isDisplayedLw()) {
+                                if (!w.isDrawnLw()) {
                                     Log.v(TAG, "Not displayed: s=" + w.mSurface
                                             + " pv=" + w.mPolicyVisibility
                                             + " dp=" + w.mDrawPending
@@ -9233,7 +9242,7 @@
                             if (w != atoken.startingWindow) {
                                 if (!atoken.freezingScreen || !w.mAppFreezing) {
                                     atoken.numInterestingWindows++;
-                                    if (w.isDisplayedLw()) {
+                                    if (w.isDrawnLw()) {
                                         atoken.numDrawnWindows++;
                                         if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG,
                                                 "tokenMayBeDrawn: " + atoken
@@ -9242,7 +9251,7 @@
                                         tokenMayBeDrawn = true;
                                     }
                                 }
-                            } else if (w.isDisplayedLw()) {
+                            } else if (w.isDrawnLw()) {
                                 atoken.startingDisplayed = true;
                             }
                         }
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
index ffaa1cd..93b48a9 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
@@ -246,8 +246,7 @@
     @Override
     protected boolean isApnTypeActive(String type) {
         return (isApnTypeAvailable(type) &&
-                mCdmaPhone.mSST.getCurrentCdmaDataConnectionState() ==
-                ServiceState.STATE_IN_SERVICE);
+                (state == State.CONNECTED || state == State.INITING));
     }
 
     @Override
@@ -261,8 +260,7 @@
     }
 
     protected String[] getActiveApnTypes() {
-        if (mCdmaPhone.mSST.getCurrentCdmaDataConnectionState() ==
-                ServiceState.STATE_IN_SERVICE) {
+        if (state == State.CONNECTED || state == State.INITING) {
             return mSupportedApnTypes.clone();
         }
         return new String[0];
@@ -626,6 +624,15 @@
     }
 
     /**
+     * @override com.android.intenral.telephony.DataConnectionTracker
+     */
+    @Override
+    protected void onEnableNewApn() {
+        // for cdma we only use this when default data is enabled..
+        onTrySetupData(Phone.REASON_DATA_ENABLED);
+    }
+
+    /**
      * @override com.android.internal.telephony.DataConnectionTracker
      */
     protected boolean onTrySetupData(String reason) {
diff --git a/tests/BrowserPowerTest/src/com/android/browserpowertest/PowerMeasurement.java b/tests/BrowserPowerTest/src/com/android/browserpowertest/PowerMeasurement.java
index 861e37b..32763b3 100644
--- a/tests/BrowserPowerTest/src/com/android/browserpowertest/PowerMeasurement.java
+++ b/tests/BrowserPowerTest/src/com/android/browserpowertest/PowerMeasurement.java
@@ -21,7 +21,7 @@
         super(PKG_NAME, PowerTestActivity.class);
     }
 
-    public void testPageLoad() throws Throwable {
+    public void testPageLoadStaticNYTimes() throws Throwable {
         Instrumentation mInst = getInstrumentation();
         PowerTestActivity act = getActivity();