Automated import from //branches/donutburger/...@141001,141001
diff --git a/api/current.xml b/api/current.xml
index d3b12d4..e5910c8 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -135270,7 +135270,7 @@
 >
 <parameter name="targetView" type="android.view.View">
 </parameter>
-<parameter name="dummyMode" type="boolean">
+<parameter name="fullEditor" type="boolean">
 </parameter>
 </constructor>
 <method name="beginBatchEdit"
@@ -136700,6 +136700,8 @@
 >
 <parameter name="target" type="android.view.inputmethod.InputConnection">
 </parameter>
+<parameter name="mutable" type="boolean">
+</parameter>
 </constructor>
 <method name="beginBatchEdit"
  return="boolean"
@@ -136945,6 +136947,19 @@
 <parameter name="end" type="int">
 </parameter>
 </method>
+<method name="setTarget"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="target" type="android.view.inputmethod.InputConnection">
+</parameter>
+</method>
 </class>
 <interface name="InputMethod"
  abstract="true"
diff --git a/core/java/android/app/ApplicationContext.java b/core/java/android/app/ApplicationContext.java
index ecef38f..55fce49 100644
--- a/core/java/android/app/ApplicationContext.java
+++ b/core/java/android/app/ApplicationContext.java
@@ -2723,10 +2723,8 @@
                     mTimestamp = mFileStatus.mtime;
                 }
                 
-                // Writing was successful, delete the backup file
-                if (!mBackupFile.delete()) {
-                    Log.e(TAG, "Couldn't delete new backup file " + mBackupFile);
-                }
+                // Writing was successful, delete the backup file if there is one.
+                mBackupFile.delete();
                 return true;
             } catch (XmlPullParserException e) {
                 Log.w(TAG, "writeFileLocked: Got exception:", e);
diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java
index deca910..11de3e2 100644
--- a/core/java/android/view/inputmethod/BaseInputConnection.java
+++ b/core/java/android/view/inputmethod/BaseInputConnection.java
@@ -51,7 +51,6 @@
     static final Object COMPOSING = new ComposingText();
     
     final InputMethodManager mIMM;
-    final Handler mH;
     final View mTargetView;
     final boolean mDummyMode;
     
@@ -60,19 +59,17 @@
     Editable mEditable;
     KeyCharacterMap mKeyCharacterMap;
     
-    BaseInputConnection(InputMethodManager mgr, boolean dummyMode) {
+    BaseInputConnection(InputMethodManager mgr, boolean fullEditor) {
         mIMM = mgr;
         mTargetView = null;
-        mH = null;
-        mDummyMode = dummyMode;
+        mDummyMode = !fullEditor;
     }
     
-    public BaseInputConnection(View targetView, boolean dummyMode) {
+    public BaseInputConnection(View targetView, boolean fullEditor) {
         mIMM = (InputMethodManager)targetView.getContext().getSystemService(
                 Context.INPUT_METHOD_SERVICE);
-        mH = targetView.getHandler();
         mTargetView = targetView;
-        mDummyMode = dummyMode;
+        mDummyMode = !fullEditor;
     }
     
     public static final void removeComposingSpans(Spannable text) {
@@ -403,7 +400,7 @@
      */
     public boolean sendKeyEvent(KeyEvent event) {
         synchronized (mIMM.mH) {
-            Handler h = mH;
+            Handler h = mTargetView != null ? mTargetView.getHandler() : null;
             if (h == null) {
                 if (mIMM.mServedView != null) {
                     h = mIMM.mServedView.getHandler();
diff --git a/core/java/android/view/inputmethod/InputConnectionWrapper.java b/core/java/android/view/inputmethod/InputConnectionWrapper.java
index e3d5e62..210559a 100644
--- a/core/java/android/view/inputmethod/InputConnectionWrapper.java
+++ b/core/java/android/view/inputmethod/InputConnectionWrapper.java
@@ -24,9 +24,21 @@
  * and have fun!
  */
 public class InputConnectionWrapper implements InputConnection {
-    private final InputConnection mTarget;
+    private InputConnection mTarget;
+    final boolean mMutable;
     
-    public InputConnectionWrapper(InputConnection target) {
+    public InputConnectionWrapper(InputConnection target, boolean mutable) {
+        mMutable = mutable;
+        mTarget = target;
+    }
+
+    /**
+     * Change the target of the input connection.
+     */
+    public void setTarget(InputConnection target) {
+        if (mTarget != null && !mMutable) {
+            throw new SecurityException("not mutable");
+        }
         mTarget = target;
     }
     
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 4de9eef..dc2d3ed 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -188,7 +188,7 @@
  * </ul>
  */
 public final class InputMethodManager {
-    static final boolean DEBUG = false;
+    static final boolean DEBUG = true;
     static final String TAG = "InputMethodManager";
 
     static final Object mInstanceSync = new Object();
@@ -426,7 +426,7 @@
         }
     };    
     
-    final InputConnection mDummyInputConnection = new BaseInputConnection(this, true);
+    final InputConnection mDummyInputConnection = new BaseInputConnection(this, false);
     
     InputMethodManager(IInputMethodManager service, Looper looper) {
         mService = service;
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 965d900..0563687 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -41,8 +41,10 @@
 import android.view.ViewDebug;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
+import android.view.inputmethod.BaseInputConnection;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputConnection;
+import android.view.inputmethod.InputConnectionWrapper;
 import android.view.inputmethod.InputMethodManager;
 import android.view.ContextMenu.ContextMenuInfo;
 
@@ -429,6 +431,9 @@
 
     private float mDensityScale;
 
+    private InputConnection mDefInputConnection;
+    private InputConnectionWrapper mPublicInputConnection;
+    
     /**
      * Interface definition for a callback to be invoked when the list or grid
      * has been scrolled.
@@ -2932,7 +2937,46 @@
             // InputConnection to proxy to.  Unfortunately this means we pretty
             // much need to make it as soon as a list view gets focus.
             createTextFilter(false);
-            return mTextFilter.onCreateInputConnection(outAttrs);
+            if (mPublicInputConnection == null) {
+                mDefInputConnection = new BaseInputConnection(this, false);
+                mPublicInputConnection = new InputConnectionWrapper(
+                        mTextFilter.onCreateInputConnection(outAttrs), true) {
+                    @Override
+                    public boolean reportFullscreenMode(boolean enabled) {
+                        // Use our own input connection, since it is
+                        // the "real" one the IME is talking with.
+                        return mDefInputConnection.reportFullscreenMode(enabled);
+                    }
+
+                    @Override
+                    public boolean performEditorAction(int editorAction) {
+                        // The editor is off in its own window; we need to be
+                        // the one that does this.
+                        if (editorAction == EditorInfo.IME_ACTION_DONE) {
+                            InputMethodManager imm = (InputMethodManager)
+                                    getContext().getSystemService(
+                                            Context.INPUT_METHOD_SERVICE);
+                            if (imm != null) {
+                                imm.hideSoftInputFromWindow(getWindowToken(), 0);
+                            }
+                            return true;
+                        }
+                        return false;
+                    }
+
+                    @Override
+                    public boolean sendKeyEvent(KeyEvent event) {
+                        // Use our own input connection, since the filter
+                        // text view may not be shown in a window so has
+                        // no ViewRoot to dispatch events with.
+                        return mDefInputConnection.sendKeyEvent(event);
+                    }
+                };
+            }
+            outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
+                    | EditorInfo.TYPE_TEXT_VARIATION_FILTER;
+            outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
+            return mPublicInputConnection;
         }
         return null;
     }
@@ -3019,14 +3063,16 @@
     }
 
     /**
-     * For our text watcher that associated with the text filter
+     * For our text watcher that is associated with the text filter.  Does
+     * nothing.
      */
     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
     }
 
     /**
-     * For our text watcher that associated with the text filter. Performs the actual
-     * filtering as the text changes.
+     * For our text watcher that is associated with the text filter. Performs
+     * the actual filtering as the text changes, and takes care of hiding and
+     * showing the popup displaying the currently entered filter text.
      */
     public void onTextChanged(CharSequence s, int start, int before, int count) {
         if (mPopup != null && isTextFilterEnabled()) {
@@ -3038,7 +3084,7 @@
                 mFiltered = true;
             } else if (showing && length == 0) {
                 // Remove the filter popup if the user has cleared all text
-                mPopup.dismiss();
+                dismissPopup();
                 mFiltered = false;
             }
             if (mAdapter instanceof Filterable) {
@@ -3055,7 +3101,8 @@
     }
 
     /**
-     * For our text watcher that associated with the text filter
+     * For our text watcher that is associated with the text filter.  Does
+     * nothing.
      */
     public void afterTextChanged(Editable s) {
     }
diff --git a/core/java/com/android/internal/widget/EditableInputConnection.java b/core/java/com/android/internal/widget/EditableInputConnection.java
index f2ec064..ad329d1 100644
--- a/core/java/com/android/internal/widget/EditableInputConnection.java
+++ b/core/java/com/android/internal/widget/EditableInputConnection.java
@@ -33,7 +33,7 @@
     private final TextView mTextView;
 
     public EditableInputConnection(TextView textview) {
-        super(textview, false);
+        super(textview, true);
         mTextView = textview;
     }