Merge change 8757 into donut

* changes:
  Support x509-user-cert mime type in browser.
diff --git a/api/current.xml b/api/current.xml
index dd13db5..5350b3e 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -991,17 +991,6 @@
  visibility="public"
 >
 </field>
-<field name="SHUTDOWN"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value="&quot;android.permission.SHUTDOWN&quot;"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="SIGNAL_PERSISTENT_PROCESSES"
  type="java.lang.String"
  transient="false"
@@ -1024,17 +1013,6 @@
  visibility="public"
 >
 </field>
-<field name="STOP_APP_SWITCHES"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value="&quot;android.permission.STOP_APP_SWITCHES&quot;"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="SUBSCRIBED_FEEDS_READ"
  type="java.lang.String"
  transient="false"
@@ -28402,17 +28380,6 @@
  visibility="public"
 >
 </field>
-<field name="BACKUP_SERVICE"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value="&quot;backup&quot;"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="BIND_AUTO_CREATE"
  type="int"
  transient="false"
@@ -29258,19 +29225,6 @@
 <parameter name="mode" type="int">
 </parameter>
 </method>
-<method name="getSharedPrefsFile"
- return="java.io.File"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="name" type="java.lang.String">
-</parameter>
-</method>
 <method name="getSystemService"
  return="java.lang.Object"
  abstract="false"
@@ -29885,70 +29839,6 @@
 </parameter>
 </method>
 </interface>
-<interface name="IIntentReceiver"
- abstract="true"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<implements name="android.os.IInterface">
-</implements>
-<method name="performReceive"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="intent" type="android.content.Intent">
-</parameter>
-<parameter name="resultCode" type="int">
-</parameter>
-<parameter name="data" type="java.lang.String">
-</parameter>
-<parameter name="extras" type="android.os.Bundle">
-</parameter>
-<parameter name="ordered" type="boolean">
-</parameter>
-<exception name="RemoteException" type="android.os.RemoteException">
-</exception>
-</method>
-</interface>
-<interface name="IIntentSender"
- abstract="true"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<implements name="android.os.IInterface">
-</implements>
-<method name="send"
- return="int"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="code" type="int">
-</parameter>
-<parameter name="intent" type="android.content.Intent">
-</parameter>
-<parameter name="resolvedType" type="java.lang.String">
-</parameter>
-<parameter name="finishedReceiver" type="android.content.IIntentReceiver">
-</parameter>
-<exception name="RemoteException" type="android.os.RemoteException">
-</exception>
-</method>
-</interface>
 <class name="Intent"
  extends="java.lang.Object"
  abstract="false"
@@ -34120,26 +34010,6 @@
 >
 <implements name="android.os.Parcelable">
 </implements>
-<constructor name="IntentSender"
- type="android.content.IntentSender"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="protected"
->
-<parameter name="target" type="android.content.IIntentSender">
-</parameter>
-</constructor>
-<constructor name="IntentSender"
- type="android.content.IntentSender"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="protected"
->
-<parameter name="target" type="android.os.IBinder">
-</parameter>
-</constructor>
 <method name="describeContents"
  return="int"
  abstract="false"
@@ -47396,17 +47266,6 @@
 <parameter name="entryName" type="java.lang.String">
 </parameter>
 </method>
-<method name="getLearner"
- return="android.gesture.Learner"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
 <method name="getOrientationStyle"
  return="int"
  abstract="false"
@@ -48675,15 +48534,6 @@
 >
 </field>
 </class>
-<class name="Learner"
- extends="java.lang.Object"
- abstract="true"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility=""
->
-</class>
 <class name="OrientedBoundingBox"
  extends="java.lang.Object"
  abstract="false"
@@ -118597,19 +118447,6 @@
 <parameter name="mode" type="int">
 </parameter>
 </method>
-<method name="getSharedPrefsFile"
- return="java.io.File"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="name" type="java.lang.String">
-</parameter>
-</method>
 <method name="getSystemService"
  return="java.lang.Object"
  abstract="false"
@@ -141959,7 +141796,7 @@
  value="2"
  static="true"
  final="true"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </field>
@@ -141985,6 +141822,17 @@
  visibility="public"
 >
 </field>
+<field name="SURFACE_FROZEN"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="2"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="SURFACE_HIDDEN"
  type="int"
  transient="false"
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 3b9db8d..2fb3f79 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -203,7 +203,6 @@
     mNativeWindowSurface->setSwapRectangle(updateRect.left,
             updateRect.top, updateRect.width(), updateRect.height());
 
-    glEnable(GL_SCISSOR_TEST);
     glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
             updateRect.height());
 
@@ -219,6 +218,10 @@
         GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
         GLint x = xc - offset;
 
+        glDisable(GL_SCISSOR_TEST);
+        glClear(GL_COLOR_BUFFER_BIT);
+
+        glEnable(GL_SCISSOR_TEST);
         glDisable(GL_BLEND);
         glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
         glDrawTexiOES(x,                 yc, 0, mAndroid[1].w, mAndroid[1].h);
diff --git a/cmds/bootanimation/bootanimation_main.cpp b/cmds/bootanimation/bootanimation_main.cpp
index 675ea81..a8359c4 100644
--- a/cmds/bootanimation/bootanimation_main.cpp
+++ b/cmds/bootanimation/bootanimation_main.cpp
@@ -16,6 +16,8 @@
 
 #define LOG_TAG "BootAnimation"
 
+#include <cutils/properties.h>
+
 #include <utils/IPCThreadState.h>
 #include <utils/ProcessState.h>
 #include <utils/IServiceManager.h>
@@ -41,12 +43,20 @@
     setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
 #endif
 
-    sp<ProcessState> proc(ProcessState::self());
-    ProcessState::self()->startThreadPool();
+    char value[PROPERTY_VALUE_MAX];
+    property_get("debug.sf.nobootanimation", value, "0");
+    int noBootAnimation = atoi(value);
+    LOGI_IF(noBootAnimation,  "boot animation disabled");
+    if (!noBootAnimation) {
 
-    // create the boot animation object
-    sp<BootAnimation> boot = new BootAnimation();
+        sp<ProcessState> proc(ProcessState::self());
+        ProcessState::self()->startThreadPool();
 
-    IPCThreadState::self()->joinThreadPool();
+        // create the boot animation object
+        sp<BootAnimation> boot = new BootAnimation();
+
+        IPCThreadState::self()->joinThreadPool();
+
+    }
     return 0;
 }
diff --git a/core/java/android/accessibilityservice/AccessibilityService.java b/core/java/android/accessibilityservice/AccessibilityService.java
index a3456c7..79bd6e7 100644
--- a/core/java/android/accessibilityservice/AccessibilityService.java
+++ b/core/java/android/accessibilityservice/AccessibilityService.java
@@ -163,6 +163,10 @@
         }
     }
 
+    /**
+     * Implement to return the implementation of the internal accessibility
+     * service interface.  Subclasses should not override.
+     */
     @Override
     public final IBinder onBind(Intent intent) {
         return new IEventListenerWrapper(this);
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index ba6cc32..3aeac53 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -1085,6 +1085,14 @@
             reply.writeInt(result);
             return true;
         }
+        case KILL_APPLICATION_WITH_UID_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            String pkg = data.readString();
+            int uid = data.readInt();
+            killApplicationWithUid(pkg, uid);
+            reply.writeNoException();
+            return true;
+        }
         }
         
         return super.onTransact(code, data, reply, flags);
@@ -2368,6 +2376,17 @@
         data.recycle();
         return result;
     }
+    public void killApplicationWithUid(String pkg, int uid) throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeString(pkg);
+        data.writeInt(uid);
+        mRemote.transact(KILL_APPLICATION_WITH_UID_TRANSACTION, data, reply, 0);
+        reply.readException();
+        data.recycle();
+        reply.recycle();
+    }
         
     private IBinder mRemote;
 }
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 95b376c..b1b5282 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -266,6 +266,8 @@
             Intent intent, String resolvedType, IBinder resultTo,
             String resultWho, int requestCode, boolean onlyIfNeeded)
             throws RemoteException;
+
+    public void killApplicationWithUid(String pkg, int uid) throws RemoteException;
         
     /*
      * Private non-Binder interfaces
@@ -421,4 +423,5 @@
     int REGISTER_ACTIVITY_WATCHER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+92;
     int UNREGISTER_ACTIVITY_WATCHER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+93;
     int START_ACTIVITY_IN_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+94;
+    int KILL_APPLICATION_WITH_UID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+95;
 }
diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java
index f9c38f9..f7479bc 100644
--- a/core/java/android/app/PendingIntent.java
+++ b/core/java/android/app/PendingIntent.java
@@ -273,11 +273,6 @@
         return null;
     }
 
-    private class IntentSenderWrapper extends IntentSender {
-        protected IntentSenderWrapper(IIntentSender target) {
-            super(target);
-        }
-    }
     /**
      * Retrieve a IntentSender object that wraps the existing sender of the PendingIntent
      *
@@ -285,7 +280,7 @@
      *
      */
     public IntentSender getIntentSender() {
-        return new IntentSenderWrapper(mTarget);
+        return new IntentSender(mTarget);
     }
 
     /**
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index dd70130..e991bc6 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -51,6 +51,7 @@
 import android.view.ContextThemeWrapper;
 import android.view.Gravity;
 import android.view.KeyEvent;
+import android.view.Menu;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewConfiguration;
@@ -244,7 +245,12 @@
         }
         return success;
     }
-    
+
+    private boolean isInRealAppSearch() {
+        return !mGlobalSearchMode
+                && (mPreviousComponents == null || mPreviousComponents.isEmpty());
+    }
+
     /**
      * Called in response to a press of the hard search button in
      * {@link #onKeyDown(int, KeyEvent)}, this method toggles between in-app
@@ -535,7 +541,7 @@
         // we dismiss the entire dialog instead
         mSearchAutoComplete.setDropDownDismissedOnCompletion(false);
 
-        if (mGlobalSearchMode) {
+        if (!isInRealAppSearch()) {
             mSearchAutoComplete.setDropDownAlwaysVisible(true);  // fill space until results come in
         } else {
             mSearchAutoComplete.setDropDownAlwaysVisible(false);
@@ -662,7 +668,40 @@
         }
         mVoiceButton.setVisibility(visibility);
     }
-    
+
+    /*
+     * Menu.
+     */
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        // Show search settings menu item if anyone handles the intent for it
+        Intent settingsIntent = new Intent(SearchManager.INTENT_ACTION_SEARCH_SETTINGS);
+        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        PackageManager pm = getContext().getPackageManager();
+        ActivityInfo activityInfo = settingsIntent.resolveActivityInfo(pm, 0);
+        if (activityInfo != null) {
+            settingsIntent.setClassName(activityInfo.applicationInfo.packageName,
+                    activityInfo.name);
+            CharSequence label = activityInfo.loadLabel(getContext().getPackageManager());
+            menu.add(Menu.NONE, Menu.NONE, Menu.NONE, label)
+                    .setIcon(android.R.drawable.ic_menu_preferences)
+                    .setAlphabeticShortcut('P')
+                    .setIntent(settingsIntent);
+            return true;
+        }
+        return super.onCreateOptionsMenu(menu);
+    }
+
+    @Override
+    public boolean onMenuOpened(int featureId, Menu menu) {
+        // The menu shows up above the IME, regardless of whether it is in front
+        // of the drop-down or not. This looks weird when there is no IME, so
+        // we make sure it is visible.
+        mSearchAutoComplete.ensureImeVisible();
+        return super.onMenuOpened(featureId, menu);
+    }
+
     /**
      * Listeners of various types
      */
@@ -1259,10 +1298,13 @@
                 launchGlobalSearchIntent(intent);
             } else {
                 getContext().startActivity(intent);
-                // in global search mode, SearchDialogWrapper#performActivityResuming
+                // If the search switches to a different activity,
+                // SearchDialogWrapper#performActivityResuming
                 // will handle hiding the dialog when the next activity starts, but for
-                // in-app search, we still need to dismiss the dialog.
-                dismiss();
+                // real in-app search, we still need to dismiss the dialog.
+                if (isInRealAppSearch()) {
+                    dismiss();
+                }
             }
         } catch (RuntimeException ex) {
             Log.e(LOG_TAG, "Failed launch activity: " + intent, ex);
@@ -1401,13 +1443,13 @@
             return;
         }
         if (DBG) Log.d(LOG_TAG, "Switching to " + componentName);
-        
-        ComponentName previous = mLaunchComponent;
+
+        pushPreviousComponent(mLaunchComponent);
         if (!show(componentName, mAppSearchData, false)) {
             Log.w(LOG_TAG, "Failed to switch to source " + componentName);
+            popPreviousComponent();
             return;
         }
-        pushPreviousComponent(previous);
 
         String query = intent.getStringExtra(SearchManager.QUERY);
         setUserQuery(query);
@@ -1701,6 +1743,12 @@
                 if (mSearchDialog.backToPreviousComponent()) {
                     return true;
                 }
+                // If the drop-down obscures the keyboard, the user wouldn't see anything
+                // happening when pressing back, so we dismiss the entire dialog instead.
+                if (isInputMethodNotNeeded()) {
+                    mSearchDialog.cancel();
+                    return true;
+                }
                 return false; // will dismiss soft keyboard if necessary
             }
             return false;
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 9e37ae4..25b5de3 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1283,7 +1283,8 @@
      * Use with {@link #getSystemService} to retrieve an
      * {@blink android.backup.IBackupManager IBackupManager} for communicating
      * with the backup mechanism.
-     *
+     * @hide
+     * 
      * @see #getSystemService
      */
     public static final String BACKUP_SERVICE = "backup";
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index 45a082a..15612ce 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -135,6 +135,7 @@
         return mBase.getPackageCodePath();
     }
 
+    /** @hide */
     @Override
     public File getSharedPrefsFile(String name) {
         return mBase.getSharedPrefsFile(name);
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index a5f298c..29ec71e 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -2390,7 +2390,7 @@
     /**
      * Create an intent from a URI.  This URI may encode the action,
      * category, and other intent fields, if it was returned by
-     * {@link #toUri}..  If the Intent was not generate by toUri(), its data
+     * {@link #toUri}.  If the Intent was not generate by toUri(), its data
      * will be the entire URI and its action will be ACTION_VIEW.
      *
      * <p>The URI given here must not be relative -- that is, it must include
diff --git a/core/java/android/content/IntentSender.java b/core/java/android/content/IntentSender.java
index 4da49d9..0e4d984 100644
--- a/core/java/android/content/IntentSender.java
+++ b/core/java/android/content/IntentSender.java
@@ -52,6 +52,9 @@
  * categories, and components, and same flags), it will receive a IntentSender
  * representing the same token if that is still valid.
  *
+ * <p>Instances of this class can not be made directly, but rather must be
+ * created from an existing {@link android.app.PendingIntent} with
+ * {@link android.app.PendingIntent#getIntentSender() PendingIntent.getIntentSender()}.
  */
 public class IntentSender implements Parcelable {
     private final IIntentSender mTarget;
@@ -245,11 +248,13 @@
         return b != null ? new IntentSender(b) : null;
     }
 
-    protected IntentSender(IIntentSender target) {
+    /** @hide */
+    public IntentSender(IIntentSender target) {
         mTarget = target;
     }
 
-    protected IntentSender(IBinder target) {
+    /** @hide */
+    public IntentSender(IBinder target) {
         mTarget = IIntentSender.Stub.asInterface(target);
     }
 }
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 9ca11cd..0a42a6f 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -131,8 +131,9 @@
     public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
     
     /**
-     * Value for {@link #flags}: this is set of the application has set
-     * its android:targetSdkVersion to something >= the current SDK version.
+     * Value for {@link #flags}: this is set of the application has specified
+     * {@link android.R.styleable#AndroidManifestApplication_testOnly
+     * android:testOnly} to be true.
      */
     public static final int FLAG_TEST_ONLY = 1<<8;
 
diff --git a/core/java/android/gesture/GestureLibrary.java b/core/java/android/gesture/GestureLibrary.java
index a29c2c8..ec2e78c 100644
--- a/core/java/android/gesture/GestureLibrary.java
+++ b/core/java/android/gesture/GestureLibrary.java
@@ -35,6 +35,7 @@
         return false;
     }
 
+    /** @hide */
     public Learner getLearner() {
         return mStore.getLearner();
     }
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 4bc929b..5100fff 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -107,8 +107,14 @@
     public static final int SURFACE_HIDDEN    = 0x01;
     
     /** Freeze the surface. Equivalent to calling freeze() */ 
+    public static final int SURFACE_FROZEN     = 0x02;
+
+    /**
+     * @deprecated use {@link #SURFACE_FROZEN} instead.
+     */
+    @Deprecated
     public static final int SURACE_FROZEN     = 0x02;
-    
+
     /** Enable dithering when compositing this surface */
     public static final int SURFACE_DITHER    = 0x04;
 
diff --git a/core/java/android/view/ViewDebug.java b/core/java/android/view/ViewDebug.java
index 46aea02..4baf612 100644
--- a/core/java/android/view/ViewDebug.java
+++ b/core/java/android/view/ViewDebug.java
@@ -16,6 +16,7 @@
 
 package android.view;
 
+import android.util.Config;
 import android.util.Log;
 import android.util.DisplayMetrics;
 import android.content.res.Resources;
@@ -140,7 +141,9 @@
     public static boolean consistencyCheckEnabled = false;
 
     static {
-        Debug.setFieldsOn(ViewDebug.class, true);
+        if (Config.DEBUG) {        
+	        Debug.setFieldsOn(ViewDebug.class, true);
+	    }
     }
 
     /**
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index 6848a55..456f8ed 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -104,6 +104,7 @@
     private View mDropDownAnchorView;  // view is retrieved lazily from id once needed
     private int mDropDownWidth;
     private int mDropDownHeight;
+    private final Rect mTempRect = new Rect();
 
     private Drawable mDropDownListHighlight;
 
@@ -209,8 +210,7 @@
     private void onClickImpl() {
         // If the dropdown is showing, bring it back in front of the soft
         // keyboard when the user touches the text field.
-        if (mPopup.isShowing() &&
-                mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED) {
+        if (mPopup.isShowing() && isInputMethodNotNeeded()) {
             ensureImeVisible();
         }
     }
@@ -1103,6 +1103,13 @@
     }
 
     /**
+     * @hide internal used only here and SearchDialog
+     */
+    public boolean isInputMethodNotNeeded() {
+        return mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
+    }
+
+    /**
      * <p>Displays the drop down on screen.</p>
      */
     public void showDropDown() {
@@ -1111,7 +1118,7 @@
         int widthSpec = 0;
         int heightSpec = 0;
 
-        boolean noInputMethod = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
+        boolean noInputMethod = isInputMethodNotNeeded();
 
         if (mPopup.isShowing()) {
             if (mDropDownWidth == ViewGroup.LayoutParams.FILL_PARENT) {
@@ -1317,7 +1324,15 @@
                 getDropDownAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations);
 
         if (mDropDownAlwaysVisible) {
-            return maxHeight;
+            // getMaxAvailableHeight() subtracts the padding, so we put it back,
+            // to get the available height for the whole window
+            int padding = 0;
+            Drawable background = mPopup.getBackground();
+            if (background != null) {
+                background.getPadding(mTempRect);
+                padding = mTempRect.top + mTempRect.bottom;
+            }
+            return maxHeight + padding;
         }
 
         return mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED,
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index 24c0e2a..e19a93d 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -432,7 +432,7 @@
             width = resolveSize(width, widthMeasureSpec);
 
             if (offsetHorizontalAxis) {
-                    for (int i = 0; i < count; i++) {
+                for (int i = 0; i < count; i++) {
                     View child = getChildAt(i);
                     if (child.getVisibility() != GONE) {
                         LayoutParams params = (LayoutParams) child.getLayoutParams();
@@ -486,10 +486,14 @@
                     View child = getChildAt(i);
                     if (child.getVisibility() != GONE && child != ignore) {
                         LayoutParams params = (LayoutParams) child.getLayoutParams();
-                        params.mLeft += horizontalOffset;
-                        params.mRight += horizontalOffset;
-                        params.mTop += verticalOffset;
-                        params.mBottom += verticalOffset;
+                        if (horizontalGravity) {
+                            params.mLeft += horizontalOffset;
+                            params.mRight += horizontalOffset;
+                        }
+                        if (verticalGravity) {
+                            params.mTop += verticalOffset;
+                            params.mBottom += verticalOffset;
+                        }
                     }
                 }
             }
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index e16db61..4558660 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -833,7 +833,8 @@
         android:protectionLevel="signature" />
 
     <!-- Allows an application to call the activity manager shutdown() API
-         to put the higher-level system there into a shutdown state. -->
+         to put the higher-level system there into a shutdown state.
+         @hide -->
     <permission android:name="android.permission.SHUTDOWN"
         android:label="@string/permlab_shutdown"
         android:description="@string/permdesc_shutdown"
@@ -842,7 +843,8 @@
     <!-- Allows an application to tell the activity manager to temporarily
          stop application switches, putting it into a special mode that
          prevents applications from immediately switching away from some
-         critical UI such as the home screen. -->
+         critical UI such as the home screen.
+         @hide -->
     <permission android:name="android.permission.STOP_APP_SWITCHES"
         android:label="@string/permlab_stopAppSwitches"
         android:description="@string/permdesc_stopAppSwitches"
diff --git a/core/res/res/drawable/expander_ic_maximized.9.png b/core/res/res/drawable/expander_ic_maximized.9.png
index 778255a..465cabd 100644
--- a/core/res/res/drawable/expander_ic_maximized.9.png
+++ b/core/res/res/drawable/expander_ic_maximized.9.png
Binary files differ
diff --git a/core/res/res/drawable/expander_ic_minimized.9.png b/core/res/res/drawable/expander_ic_minimized.9.png
index 5235c18..9967ecb 100644
--- a/core/res/res/drawable/expander_ic_minimized.9.png
+++ b/core/res/res/drawable/expander_ic_minimized.9.png
Binary files differ
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
index eec645e..ab02fa0 100644
--- a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
+++ b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
@@ -197,6 +197,9 @@
             LOGW("ro.sf.lcd_density not defined, using 160 dpi by default.");
             strcpy(property, "160");
         }
+    } else {
+        /* for the emulator case, reset the dpi values too */
+        mDpiX = mDpiY = atoi(property);
     }
     mDensity = atoi(property) * (1.0f/160.0f);
 
diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp
index fb25663..97dfecc 100644
--- a/libs/surfaceflinger/SurfaceFlinger.cpp
+++ b/libs/surfaceflinger/SurfaceFlinger.cpp
@@ -691,9 +691,14 @@
 
         // some layers might have been removed, so
         // we need to update the regions they're exposing.
-        size_t c = mRemovedLayers.size();
+        const SortedVector<LayerBase*>& removedLayers(mRemovedLayers);
+        size_t c = removedLayers.size();
         if (c) {
             mVisibleRegionsDirty = true;
+            while (c--) {
+                mDirtyRegionRemovedLayer.orSelf(
+                        removedLayers[c]->visibleRegionScreen);
+            }
         }
 
         const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
@@ -733,17 +738,15 @@
         layer->validateVisibility(planeTransform);
 
         // start with the whole surface at its current location
-        const Layer::State& s = layer->drawingState();
-        const Rect bounds(layer->visibleBounds());
+        const Layer::State& s(layer->drawingState());
 
         // handle hidden surfaces by setting the visible region to empty
         Region opaqueRegion;
         Region visibleRegion;
         Region coveredRegion;
-        if (UNLIKELY((s.flags & ISurfaceComposer::eLayerHidden) || !s.alpha)) {
-            visibleRegion.clear();
-        } else {
+        if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
             const bool translucent = layer->needsBlending();
+            const Rect bounds(layer->visibleBounds());
             visibleRegion.set(bounds);
             coveredRegion = visibleRegion;
 
@@ -790,12 +793,16 @@
         layer->setVisibleRegion(visibleRegion);
         layer->setCoveredRegion(coveredRegion);
 
-        // If a secure layer is partially visible, lockdown the screen!
+        // If a secure layer is partially visible, lock-down the screen!
         if (layer->isSecure() && !visibleRegion.isEmpty()) {
             secureFrameBuffer = true;
         }
     }
 
+    // invalidate the areas where a layer was removed
+    dirtyRegion.orSelf(mDirtyRegionRemovedLayer);
+    mDirtyRegionRemovedLayer.clear();
+
     mSecureFrameBuffer = secureFrameBuffer;
     opaqueRegion = aboveOpaqueLayers;
 }
diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h
index 15913f2..0d63e1d 100644
--- a/libs/surfaceflinger/SurfaceFlinger.h
+++ b/libs/surfaceflinger/SurfaceFlinger.h
@@ -351,6 +351,7 @@
                 // Can only accessed from the main thread, these members
                 // don't need synchronization
                 Region                      mDirtyRegion;
+                Region                      mDirtyRegionRemovedLayer;
                 Region                      mInvalidRegion;
                 Region                      mWormholeRegion;
                 Client*                     mLastScheduledBroadcast;
diff --git a/packages/SettingsProvider/res/values-cs/defaults.xml b/packages/SettingsProvider/res/values-cs/defaults.xml
deleted file mode 100644
index a7c01b3..0000000
--- a/packages/SettingsProvider/res/values-cs/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"mobil,bluetooth,wifi"</string>
-    <string name="def_location_providers_allowed">"gps"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-cs/strings.xml b/packages/SettingsProvider/res/values-cs/strings.xml
index dc75a92..2b089d9 100644
--- a/packages/SettingsProvider/res/values-cs/strings.xml
+++ b/packages/SettingsProvider/res/values-cs/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"Paměť pro nastavení"</string>
+    <string name="app_label" msgid="4567566098528588863">"Paměť pro nastavení"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values-de/defaults.xml b/packages/SettingsProvider/res/values-de/defaults.xml
deleted file mode 100644
index f85d3f0..0000000
--- a/packages/SettingsProvider/res/values-de/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"Mobilfunk, Bluetooth, WLAN"</string>
-    <string name="def_location_providers_allowed">"GPS"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-de/strings.xml b/packages/SettingsProvider/res/values-de/strings.xml
index 50c8a14..a293522 100644
--- a/packages/SettingsProvider/res/values-de/strings.xml
+++ b/packages/SettingsProvider/res/values-de/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"Einstellungsspeicher"</string>
+    <string name="app_label" msgid="4567566098528588863">"Einstellungsspeicher"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values-es/defaults.xml b/packages/SettingsProvider/res/values-es/defaults.xml
deleted file mode 100644
index a64805a..0000000
--- a/packages/SettingsProvider/res/values-es/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"móvil,bluetooth,wifi"</string>
-    <string name="def_location_providers_allowed">"gps"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-es/strings.xml b/packages/SettingsProvider/res/values-es/strings.xml
index d30d195..de3958b 100644
--- a/packages/SettingsProvider/res/values-es/strings.xml
+++ b/packages/SettingsProvider/res/values-es/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"Almacenamiento de configuración"</string>
+    <string name="app_label" msgid="4567566098528588863">"Almacenamiento de configuración"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values-fr/defaults.xml b/packages/SettingsProvider/res/values-fr/defaults.xml
deleted file mode 100644
index 56334cc..0000000
--- a/packages/SettingsProvider/res/values-fr/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"cellulaire, Bluetooth, Wi-Fi"</string>
-    <string name="def_location_providers_allowed">"gps"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-fr/strings.xml b/packages/SettingsProvider/res/values-fr/strings.xml
index 686ec8b..7a1386a 100644
--- a/packages/SettingsProvider/res/values-fr/strings.xml
+++ b/packages/SettingsProvider/res/values-fr/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"Stockage des paramètres"</string>
+    <string name="app_label" msgid="4567566098528588863">"Stockage des paramètres"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values-it/defaults.xml b/packages/SettingsProvider/res/values-it/defaults.xml
deleted file mode 100644
index 19c0896..0000000
--- a/packages/SettingsProvider/res/values-it/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"cellulare,bluetooth,wifi"</string>
-    <string name="def_location_providers_allowed">"gps"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-it/strings.xml b/packages/SettingsProvider/res/values-it/strings.xml
index 29e462f..f88a654 100644
--- a/packages/SettingsProvider/res/values-it/strings.xml
+++ b/packages/SettingsProvider/res/values-it/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"Archiviazione impostazioni"</string>
+    <string name="app_label" msgid="4567566098528588863">"Archiviazione impostazioni"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values-nl/defaults.xml b/packages/SettingsProvider/res/values-nl/defaults.xml
deleted file mode 100644
index 625235a..0000000
--- a/packages/SettingsProvider/res/values-nl/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"mobiel,bluetooth,wifi"</string>
-    <string name="def_location_providers_allowed">"gps"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-nl/strings.xml b/packages/SettingsProvider/res/values-nl/strings.xml
index b37b535..7a0e416 100644
--- a/packages/SettingsProvider/res/values-nl/strings.xml
+++ b/packages/SettingsProvider/res/values-nl/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"Opslagruimte voor instellingen"</string>
+    <string name="app_label" msgid="4567566098528588863">"Opslagruimte voor instellingen"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values-pl/defaults.xml b/packages/SettingsProvider/res/values-pl/defaults.xml
deleted file mode 100644
index b60832e..0000000
--- a/packages/SettingsProvider/res/values-pl/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"komórka,bluetooth,wifi"</string>
-    <string name="def_location_providers_allowed">"gps"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-pl/strings.xml b/packages/SettingsProvider/res/values-pl/strings.xml
index 4ab1e91..ccff82e3 100644
--- a/packages/SettingsProvider/res/values-pl/strings.xml
+++ b/packages/SettingsProvider/res/values-pl/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"Pamięć ustawień"</string>
+    <string name="app_label" msgid="4567566098528588863">"Pamięć ustawień"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values-zh-rTW/defaults.xml b/packages/SettingsProvider/res/values-zh-rTW/defaults.xml
deleted file mode 100644
index fdbba88..0000000
--- a/packages/SettingsProvider/res/values-zh-rTW/defaults.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="def_airplane_mode_radios">"手機,藍牙,wifi"</string>
-    <string name="def_location_providers_allowed">"gps"</string>
-    <!-- no translation found for def_backup_transport (6764822064303377157) -->
-    <skip />
-</resources>
diff --git a/packages/SettingsProvider/res/values-zh-rTW/strings.xml b/packages/SettingsProvider/res/values-zh-rTW/strings.xml
index b24144a..0700a76 100644
--- a/packages/SettingsProvider/res/values-zh-rTW/strings.xml
+++ b/packages/SettingsProvider/res/values-zh-rTW/strings.xml
@@ -15,5 +15,5 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label">"設定儲存空間"</string>
+    <string name="app_label" msgid="4567566098528588863">"設定儲存空間"</string>
 </resources>
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index f8adaa1..f60ea57 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -21,7 +21,7 @@
     <integer name="def_screen_off_timeout">60000</integer>
     <bool name="def_airplane_mode_on">false</bool>
     <!-- Comma-separated list of bluetooth, wifi, and cell. -->
-    <string name="def_airplane_mode_radios">cell,bluetooth,wifi</string>
+    <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi</string>
     <bool name="def_auto_time">true</bool>
     <bool name="def_accelerometer_rotation">true</bool>
     <!-- Default screen brightness, from 0 to 255.  102 is 40%. -->
@@ -35,7 +35,7 @@
          Network location is off by default because it requires
          user opt-in via Setup Wizard or Settings.  
     -->
-    <string name="def_location_providers_allowed">gps</string>
+    <string name="def_location_providers_allowed" translatable="false">gps</string>
     <!--  0 == mobile, 1 == wifi. -->
     <integer name="def_network_preference">1</integer>
     <bool name="def_usb_mass_storage_enabled">true</bool>
@@ -43,5 +43,5 @@
     <bool name="def_networks_available_notification_on">true</bool>
     
     <bool name="def_backup_enabled">false</bool>
-    <string name="def_backup_transport"></string>
+    <string name="def_backup_transport" translatable="false"></string>
 </resources>
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 4afa03e..b39f2f6 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -60,7 +60,6 @@
 import android.os.Binder;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Debug;
 import android.os.HandlerThread;
 import android.os.Parcel;
 import android.os.RemoteException;
@@ -1826,6 +1825,11 @@
             ps = mSettings.peekPackageLP(pkg.packageName);
             updatedPkg = mSettings.mDisabledSysPackages.get(pkg.packageName);
         }
+        // Verify certificates first
+        if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) {
+            Log.i(TAG, "Failed verifying certificates for package:" + pkg.packageName);
+            return null;
+        }
         if (updatedPkg != null) {
             // An updated system app will not have the PARSE_IS_SYSTEM flag set initially
             parseFlags |= PackageParser.PARSE_IS_SYSTEM;
@@ -1843,16 +1847,19 @@
                         return null;
                     } else {
                         // Delete the older apk pointed to by ps
+                        // At this point, its safely assumed that package installation for
+                        // apps in system partition will go through. If not there won't be a working
+                        // version of the app
+                        synchronized (mPackages) {
+                            // Just remove the loaded entries from package lists.
+                            mPackages.remove(ps.name);
+                        }
                         deletePackageResourcesLI(ps.name, ps.codePathString, ps.resourcePathString);
                         mSettings.enableSystemPackageLP(ps.name);
                     }
                 }
             }
         }
-        if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) {
-            Log.i(TAG, "Failed verifying certificates for package:" + pkg.packageName);
-            return null;
-        }
         // The apk is forward locked (not public) if its code and resources
         // are kept in different files.
         if (ps != null && !ps.codePath.equals(ps.resourcePath)) {
@@ -2132,7 +2139,7 @@
                 pkg.applicationInfo.packageName,
                 pkg.applicationInfo.processName,
                 pkg.applicationInfo.uid);
-        pkg.applicationInfo.publicSourceDir = pkgSetting.resourcePathString;
+        pkg.applicationInfo.publicSourceDir = destResourceFile.toString();
 
         File dataPath;
         if (mPlatformPackage == pkg) {
@@ -2259,15 +2266,26 @@
             pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST;
         }
 
+        // We don't expect installation to fail beyond this point,
         if ((scanMode&SCAN_MONITOR) != 0) {
             pkg.mPath = destCodeFile.getAbsolutePath();
             mAppDirs.put(pkg.mPath, pkg);
         }
 
+        // Request the ActivityManager to kill the process(only for existing packages)
+        // so that we do not end up in a confused state while the user is still using the older
+        // version of the application while the new one gets installed.
+        IActivityManager am = ActivityManagerNative.getDefault();
+        if ((am != null) && ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING ) != 0)) {
+            try {
+                am.killApplicationWithUid(pkg.applicationInfo.packageName,
+                        pkg.applicationInfo.uid);
+            } catch (RemoteException e) {
+            }
+        }
         synchronized (mPackages) {
-            // We don't expect installation to fail beyond this point
             // Add the new setting to mSettings
-            mSettings.insertPackageSettingLP(pkgSetting, pkg.packageName, suid);
+            mSettings.insertPackageSettingLP(pkgSetting, pkg, destCodeFile, destResourceFile);
             // Add the new setting to mPackages
             mPackages.put(pkg.applicationInfo.packageName, pkg);
             int N = pkg.providers.size();
@@ -2955,7 +2973,8 @@
         }
         
         if ((addedPermission || replace) && !ps.permissionsFixed &&
-                (ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
+                ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) ||
+                ((ps.pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)){
             // This is the first that we have heard about this package, so the
             // permissions we have now selected are fixed until explicitly
             // changed.
@@ -4156,7 +4175,9 @@
     private void removePackageDataLI(PackageParser.Package p, PackageRemovedInfo outInfo, 
             int flags) {
         String packageName = p.packageName;
-        outInfo.removedPackage = packageName;
+        if (outInfo != null) {
+            outInfo.removedPackage = packageName;
+        }
         removePackageLI(p, true);
         // Retrieve object to delete permissions for shared user later on
         PackageSetting deletedPs;
@@ -4178,7 +4199,9 @@
                 dataDir.delete();
             }
             synchronized (mPackages) {
-                outInfo.removedUid = mSettings.removePackageLP(packageName);                
+                if (outInfo != null) {
+                    outInfo.removedUid = mSettings.removePackageLP(packageName);
+                }
             }
         }
         synchronized (mPackages) {
@@ -4253,7 +4276,7 @@
         }
         return true;
     }
-    
+
     private void deletePackageResourcesLI(String packageName,
             String sourceDir, String publicSourceDir) {
         File sourceFile = new File(sourceDir);
@@ -4283,7 +4306,9 @@
             Log.w(TAG, "Package " + p.packageName + " has no applicationInfo.");
             return false;
         }
-        outInfo.uid = applicationInfo.uid;
+        if (outInfo != null) {
+            outInfo.uid = applicationInfo.uid;
+        }
 
         // Delete package data from internal structures and also remove data if flag is set
         removePackageDataLI(p, outInfo, flags);
@@ -5460,7 +5485,7 @@
         String resourcePathString;
         private long timeStamp;
         private String timeStampString = "0";
-        final int versionCode;
+        int versionCode;
 
         PackageSignatures signatures = new PackageSignatures();
 
@@ -5698,10 +5723,6 @@
             final String name = pkg.packageName;
             PackageSetting p = getPackageLP(name, sharedUser, codePath,
                     resourcePath, pkg.mVersionCode, pkgFlags, create, add);
-
-            if (p != null) {
-                p.pkg = pkg;
-            }
             return p;
         }
         
@@ -5849,22 +5870,18 @@
             if (p != null) {
                 if (!p.codePath.equals(codePath)) {
                     // Check to see if its a disabled system app
-                    PackageSetting ps = mDisabledSysPackages.get(name);
-                    if((ps != null) && ((ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0)) {
+                    if((p != null) && ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0)) {
                         // This is an updated system app with versions in both system
                         // and data partition. Just let the most recent version
                         // take precedence.
-                        return p;
+                        Log.w(TAG, "Trying to update system app code path from " +
+                                p.codePathString + " to " + codePath.toString());
                     } else {
                         // Let the app continue with previous uid if code path changes.
                         reportSettingsProblem(Log.WARN,
                                 "Package " + name + " codePath changed from " + p.codePath
                                 + " to " + codePath + "; Retaining data and using new code from " +
                                 codePath);
-                        p.codePath = codePath;
-                        p.resourcePath = resourcePath;
-                        p.codePathString = codePath.toString();
-                        p.resourcePathString = resourcePath.toString();
                     }
                 } else if (p.sharedUser != sharedUser) {
                     reportSettingsProblem(Log.WARN,
@@ -5888,8 +5905,29 @@
                 if (sharedUser != null) {
                     p.userId = sharedUser.userId;
                 } else if (MULTIPLE_APPLICATION_UIDS) {
-                    // Assign new user id
-                    p.userId = newUserIdLP(p);
+                    // Clone the setting here for disabled system packages
+                    PackageSetting dis = mDisabledSysPackages.get(name);
+                    if (dis != null) {
+                        // For disabled packages a new setting is created
+                        // from the existing user id. This still has to be
+                        // added to list of user id's
+                        // Copy signatures from previous setting
+                        if (dis.signatures.mSignatures != null) {
+                            p.signatures.mSignatures = dis.signatures.mSignatures.clone();
+                        }
+                        p.userId = dis.userId;
+                        // Clone permissions
+                        p.grantedPermissions = new HashSet<String>(dis.grantedPermissions);
+                        p.loadedPermissions = new HashSet<String>(dis.loadedPermissions);
+                        // Clone component info
+                        p.disabledComponents = new HashSet<String>(dis.disabledComponents);
+                        p.enabledComponents = new HashSet<String>(dis.enabledComponents);
+                        // Add new setting to list of user ids
+                        addUserIdLP(p.userId, p, name);
+                    } else {
+                        // Assign new user id
+                        p.userId = newUserIdLP(p);
+                    }
                 } else {
                     p.userId = FIRST_APPLICATION_UID;
                 }
@@ -5901,15 +5939,39 @@
                 if (add) {
                     // Finish adding new package by adding it and updating shared 
                     // user preferences
-                    insertPackageSettingLP(p, name, sharedUser);
+                    addPackageSettingLP(p, name, sharedUser);
                 }
             }
             return p;
         }
-        
+
+        private void insertPackageSettingLP(PackageSetting p, PackageParser.Package pkg,
+                File codePath, File resourcePath) {
+            p.pkg = pkg;
+            // Update code path if needed
+            if (!codePath.toString().equalsIgnoreCase(p.codePathString)) {
+                Log.w(TAG, "Code path for pkg : " + p.pkg.packageName +
+                        " changing form " + p.codePathString + " to " + codePath);
+                p.codePath = codePath;
+                p.codePathString = codePath.toString();
+            }
+            //Update resource path if needed
+            if (!resourcePath.toString().equalsIgnoreCase(p.resourcePathString)) {
+                Log.w(TAG, "Resource path for pkg : " + p.pkg.packageName +
+                        " changing form " + p.resourcePathString + " to " + resourcePath);
+                p.resourcePath = resourcePath;
+                p.resourcePathString = resourcePath.toString();
+            }
+            // Update version code if needed
+             if (pkg.mVersionCode != p.versionCode) {
+                p.versionCode = pkg.mVersionCode;
+            }
+            addPackageSettingLP(p, pkg.packageName, p.sharedUser);
+        }
+
         // Utility method that adds a PackageSetting to mPackages and
         // completes updating the shared user attributes
-        private void insertPackageSettingLP(PackageSetting p, String name,
+        private void addPackageSettingLP(PackageSetting p, String name,
                 SharedUserSetting sharedUser) {
             mPackages.put(name, p);
             if (sharedUser != null) {
@@ -6002,7 +6064,7 @@
                 }
                 if (mUserIds.get(index) != null) {
                     reportSettingsProblem(Log.ERROR,
-                            "Adding duplicate shared id: " + uid
+                            "Adding duplicate user id: " + uid
                             + " name=" + name);
                     return false;
                 }
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 81a715d..5ea59ca 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -4736,7 +4736,30 @@
             Binder.restoreCallingIdentity(callingId);
         }
     }
-    
+
+    /*
+     * The pkg name and uid have to be specified.
+     * @see android.app.IActivityManager#killApplicationWithUid(java.lang.String, int)
+     */
+    public void killApplicationWithUid(String pkg, int uid) {
+        if (pkg == null) {
+            return;
+        }
+        // Make sure the uid is valid.
+        if (uid < 0) {
+            Log.w(TAG, "Invalid uid specified for pkg : " + pkg);
+            return;
+        }
+        int callerUid = Binder.getCallingUid();
+        // Only the system server can kill an application
+        if (callerUid == Process.SYSTEM_UID) {
+            uninstallPackageLocked(pkg, uid, false);
+        } else {
+            throw new SecurityException(callerUid + " cannot kill pkg: " +
+                    pkg);
+        }
+    }
+
     private void restartPackageLocked(final String packageName, int uid) {
         uninstallPackageLocked(packageName, uid, false);
         Intent intent = new Intent(Intent.ACTION_PACKAGE_RESTARTED,
diff --git a/test-runner/android/test/IsolatedContext.java b/test-runner/android/test/IsolatedContext.java
index 2866666..859b2e5 100644
--- a/test-runner/android/test/IsolatedContext.java
+++ b/test-runner/android/test/IsolatedContext.java
@@ -13,6 +13,7 @@
 import android.net.Uri;
 
 import java.util.List;
+import java.io.File;
 
 /**
      * A mock context which prevents its users from talking to the rest of the device while
@@ -82,4 +83,8 @@
         return null;
     }
 
+    @Override
+    public File getFilesDir() {
+        return new File("/dev/null");
+    }
 }
diff --git a/test-runner/android/test/mock/MockContext.java b/test-runner/android/test/mock/MockContext.java
index b83a44d6..9fb1e61 100644
--- a/test-runner/android/test/mock/MockContext.java
+++ b/test-runner/android/test/mock/MockContext.java
@@ -110,6 +110,7 @@
         throw new UnsupportedOperationException();
     }
 
+    /** @hide */
     @Override
     public File getSharedPrefsFile(String name) {
         throw new UnsupportedOperationException();