am b940659f: am 94eb3d0f: Merge "Plumb whether an input view is actually visible or not through from the IME to the status bar." into honeycomb

* commit 'b940659f415d536966f1bb8af4d5281efa3a7f7a':
  Plumb whether an input view is actually visible or not through from the IME to the status bar.
diff --git a/api/current.xml b/api/current.xml
index f541ae0..e060ffb 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -95677,6 +95677,17 @@
  visibility="public"
 >
 </constructor>
+<method name="getBackDisposition"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getCandidatesHiddenVisibility"
  return="int"
  abstract="false"
@@ -96402,6 +96413,19 @@
 <parameter name="charCode" type="char">
 </parameter>
 </method>
+<method name="setBackDisposition"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="disposition" type="int">
+</parameter>
+</method>
 <method name="setCandidatesView"
  return="void"
  abstract="false"
@@ -96528,6 +96552,39 @@
  visibility="public"
 >
 </method>
+<field name="BACK_DISPOSITION_DEFAULT"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="BACK_DISPOSITION_WILL_DISMISS"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="2"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="BACK_DISPOSITION_WILL_NOT_DISMISS"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 </class>
 <class name="InputMethodService.InputMethodImpl"
  extends="android.inputmethodservice.AbstractInputMethodService.AbstractInputMethodImpl"
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 255eb6c..a99256f 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -219,7 +219,34 @@
 public class InputMethodService extends AbstractInputMethodService {
     static final String TAG = "InputMethodService";
     static final boolean DEBUG = false;
-    
+
+    /**
+     * The back button will close the input window.
+     */
+    public static final int BACK_DISPOSITION_DEFAULT = 0;  // based on window
+
+    /**
+     * This input method will not consume the back key.
+     */
+    public static final int BACK_DISPOSITION_WILL_NOT_DISMISS = 1; // back
+
+    /**
+     * This input method will consume the back key.
+     */
+    public static final int BACK_DISPOSITION_WILL_DISMISS = 2; // down
+
+    /**
+     * @hide
+     * The IME is active.  It may or may not be visible.
+     */
+    public static final int IME_ACTIVE = 0x1;
+
+    /**
+     * @hide
+     * The IME is visible.
+     */
+    public static final int IME_VISIBLE = 0x2;
+
     InputMethodManager mImm;
     
     int mTheme = 0;
@@ -271,6 +298,7 @@
     boolean mIsInputViewShown;
     
     int mStatusIcon;
+    int mBackDisposition;
 
     final Insets mTmpInsets = new Insets();
     final int[] mTmpLocation = new int[2];
@@ -394,9 +422,9 @@
                 showWindow(true);
             }
             // If user uses hard keyboard, IME button should always be shown.
-            if (!onEvaluateInputViewShown()) {
-                mImm.setIMEButtonVisible(mToken, true);
-            }
+            boolean showing = onEvaluateInputViewShown();
+            mImm.setImeWindowStatus(mToken, IME_ACTIVE | (showing ? IME_VISIBLE : 0),
+                    mBackDisposition);
             if (resultReceiver != null) {
                 resultReceiver.send(wasVis != isInputViewShown()
                         ? InputMethodManager.RESULT_SHOWN
@@ -704,9 +732,9 @@
                 hideWindow();
             }
             // If user uses hard keyboard, IME button should always be shown.
-            if (!onEvaluateInputViewShown()) {
-                mImm.setIMEButtonVisible(mToken, true);
-            }
+            boolean showing = onEvaluateInputViewShown();
+            mImm.setImeWindowStatus(mToken, IME_ACTIVE | (showing ? IME_VISIBLE : 0),
+                    mBackDisposition);
         }
     }
 
@@ -736,6 +764,14 @@
         return mWindow;
     }
     
+    public void setBackDisposition(int disposition) {
+        mBackDisposition = disposition;
+    }
+
+    public int getBackDisposition() {
+        return mBackDisposition;
+    }
+
     /**
      * Return the maximum width, in pixels, available the input method.
      * Input methods are positioned at the bottom of the screen and, unless
@@ -1378,7 +1414,7 @@
 
         if (!wasVisible) {
             if (DEBUG) Log.v(TAG, "showWindow: showing!");
-            mImm.setIMEButtonVisible(mToken, true);
+            mImm.setImeWindowStatus(mToken, IME_ACTIVE, mBackDisposition);
             onWindowShown();
             mWindow.show();
         }
@@ -1394,7 +1430,7 @@
         }
         mInputViewStarted = false;
         mCandidatesViewStarted = false;
-        mImm.setIMEButtonVisible(mToken, false);
+        mImm.setImeWindowStatus(mToken, 0, mBackDisposition);
         if (mWindowVisible) {
             mWindow.hide();
             mWindowVisible = false;
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 7edfd7b..cb67b78 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -531,9 +531,9 @@
     }
 
     /** @hide */
-    public void setIMEButtonVisible(IBinder imeToken, boolean visible) {
+    public void setImeWindowStatus(IBinder imeToken, int vis, int backDisposition) {
         try {
-            mService.setIMEButtonVisible(imeToken, visible);
+            mService.setImeWindowStatus(imeToken, vis, backDisposition);
         } catch (RemoteException e) {
             throw new RuntimeException(e);
         }
diff --git a/core/java/com/android/internal/statusbar/IStatusBar.aidl b/core/java/com/android/internal/statusbar/IStatusBar.aidl
index 1cc068f..5fcd0c2 100644
--- a/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -32,6 +32,6 @@
     void animateCollapse();
     void setLightsOn(boolean on);
     void setMenuKeyVisible(boolean visible);
-    void setIMEButtonVisible(in IBinder token, boolean visible);
+    void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
 }
 
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
index d1ea52e..c62aeb0 100644
--- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -31,7 +31,7 @@
     void setIconVisibility(String slot, boolean visible);
     void removeIcon(String slot);
     void setMenuKeyVisible(boolean visible);
-    void setIMEButtonVisible(in IBinder token, boolean visible);
+    void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
 
     // ---- Methods below are for use by the status bar policy services ----
     // You need the STATUS_BAR_SERVICE permission
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index b2fbd3a7..611d987 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -59,7 +59,7 @@
     void hideMySoftInput(in IBinder token, int flags);
     void showMySoftInput(in IBinder token, int flags);
     void updateStatusIcon(in IBinder token, String packageName, int iconId);
-    void setIMEButtonVisible(in IBinder token, boolean visible);
+    void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
     InputMethodSubtype getCurrentInputMethodSubtype();
     boolean setCurrentInputMethodSubtype(in InputMethodSubtype subtype);
     boolean switchToLastInputMethod(in IBinder token);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index 37939df..76aa793 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -82,7 +82,7 @@
         public void animateCollapse();
         public void setLightsOn(boolean on);
         public void setMenuKeyVisible(boolean visible);
-        public void setIMEButtonVisible(IBinder token, boolean visible);
+        public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
     }
 
     public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
@@ -165,10 +165,11 @@
         }
     }
 
-    public void setIMEButtonVisible(IBinder token, boolean visible) {
+    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
         synchronized (mList) {
             mHandler.removeMessages(MSG_SHOW_IME_BUTTON);
-            mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, visible ? 1 : 0, 0, token).sendToTarget();
+            mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token)
+                    .sendToTarget();
         }
     }
 
@@ -233,7 +234,7 @@
                     mCallbacks.setMenuKeyVisible(msg.arg1 != 0);
                     break;
                 case MSG_SHOW_IME_BUTTON:
-                    mCallbacks.setIMEButtonVisible((IBinder)msg.obj, msg.arg1 != 0);
+                    mCallbacks.setImeWindowStatus((IBinder)msg.obj, msg.arg1, msg.arg2);
                     break;
             }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java
index 8fca759..da8e831 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java
@@ -67,7 +67,7 @@
         mCommandQueue = new CommandQueue(this, iconList);
         mBarService = IStatusBarService.Stub.asInterface(
                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
-        int[] switches = new int[4];
+        int[] switches = new int[5];
         ArrayList<IBinder> binders = new ArrayList<IBinder>();
         try {
             mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications,
@@ -80,7 +80,7 @@
         setLightsOn(switches[1] != 0);
         setMenuKeyVisible(switches[2] != 0);
         // StatusBarManagerService has a back up of IME token and it's restored here.
-        setIMEButtonVisible(binders.get(0), switches[3] != 0);
+        setImeWindowStatus(binders.get(0), switches[3], switches[4]);
 
         // Set up the initial icon state
         int N = iconList.size();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 132433b..9505391 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -1020,7 +1020,7 @@
 
     // Not supported
     public void setMenuKeyVisible(boolean visible) { }
-    public void setIMEButtonVisible(IBinder token, boolean visible) { }
+    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { }
 
     private class Launcher implements View.OnClickListener {
         private PendingIntent mIntent;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
index 28f485c..f131111 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
@@ -53,7 +53,7 @@
     private final int mId;
     private ImageView mIcon;
     private IBinder mToken;
-    private boolean mKeyboardVisible = false;
+    private boolean mShowButton = false;
     private boolean mScreenLocked = false;
     private InputMethodInfo mShortcutInfo;
     private InputMethodSubtype mShortcutSubtype;
@@ -144,7 +144,7 @@
     // * There are no explicitly enabled (by the user) subtypes of the IME, or the IME doesn't have
     // its subtypes at all
     private boolean needsToShowIMEButton() {
-        if (!mKeyboardVisible || mScreenLocked) return false;
+        if (!mShowButton || mScreenLocked) return false;
         List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
         final int size = imis.size();
         final int visibility = loadInputMethodSelectorVisibility();
@@ -194,9 +194,9 @@
         }
     }
 
-    public void setIMEButtonVisible(IBinder token, boolean keyboardVisible) {
+    public void setImeWindowStatus(IBinder token, boolean showButton) {
         mToken = token;
-        mKeyboardVisible = keyboardVisible;
+        mShowButton = showButton;
         refreshStatusIcon();
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
index eaa5cc9..8dc0afb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
@@ -33,6 +33,7 @@
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.inputmethodservice.InputMethodService;
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
@@ -863,17 +864,32 @@
         if (visible) setLightsOn(true);
     }
 
-    public void setIMEButtonVisible(IBinder token, boolean visible) {
-        if (DEBUG) {
-            Slog.d(TAG, (visible?"showing":"hiding") + " the IME button");
-        }
-        mInputMethodSwitchButton.setIMEButtonVisible(token, visible);
+    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
+        mInputMethodSwitchButton.setImeWindowStatus(token,
+                (vis & InputMethodService.IME_ACTIVE) != 0);
         updateNotificationIcons();
         mInputMethodsPanel.setImeToken(token);
-        mBackButton.setImageResource(
-                visible ? R.drawable.ic_sysbar_back_ime : R.drawable.ic_sysbar_back);
+        int res;
+        switch (backDisposition) {
+            case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
+                res = R.drawable.ic_sysbar_back;
+                break;
+            case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
+                res = R.drawable.ic_sysbar_back_ime;
+                break;
+            case InputMethodService.BACK_DISPOSITION_DEFAULT:
+            default:
+                if ((vis & InputMethodService.IME_VISIBLE) != 0) {
+                    res = R.drawable.ic_sysbar_back_ime;
+                } else {
+                    res = R.drawable.ic_sysbar_back;
+                }
+                break;
+        }
+        mBackButton.setImageResource(res);
         if (FAKE_SPACE_BAR) {
-            mFakeSpaceBar.setVisibility(visible ? View.VISIBLE : View.GONE);
+            mFakeSpaceBar.setVisibility(((vis & InputMethodService.IME_VISIBLE) != 0)
+                    ? View.VISIBLE : View.GONE);
         }
     }
 
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index 0147b1a..8d6d3a1 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -49,6 +49,7 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.database.ContentObserver;
+import android.inputmethodservice.InputMethodService;
 import android.os.Binder;
 import android.os.Handler;
 import android.os.IBinder;
@@ -311,6 +312,9 @@
      */
     boolean mScreenOn = true;
 
+    int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
+    int mImeWindowVis;
+
     AlertDialog.Builder mDialogBuilder;
     AlertDialog mSwitchingDialog;
     InputMethodInfo[] mIms;
@@ -430,7 +434,9 @@
                             // Uh oh, current input method is no longer around!
                             // Pick another one...
                             Slog.i(TAG, "Current input method removed: " + curInputMethodId);
-                            mStatusBar.setIMEButtonVisible(mCurToken, false);
+                            mImeWindowVis = 0;
+                            mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis,
+                                    mBackDisposition);
                             if (!chooseNewDefaultIMELocked()) {
                                 changed = true;
                                 curIm = null;
@@ -982,17 +988,19 @@
         }
     }
 
-    public void setIMEButtonVisible(IBinder token, boolean visible) {
+    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
         int uid = Binder.getCallingUid();
         long ident = Binder.clearCallingIdentity();
         try {
             if (token == null || mCurToken != token) {
-                Slog.w(TAG, "Ignoring setIMEButtonVisible of uid " + uid + " token: " + token);
+                Slog.w(TAG, "Ignoring setImeWindowStatus of uid " + uid + " token: " + token);
                 return;
             }
 
             synchronized (mMethodMap) {
-                mStatusBar.setIMEButtonVisible(token, visible);
+                mImeWindowVis = vis;
+                mBackDisposition = backDisposition;
+                mStatusBar.setImeWindowStatus(token, vis, backDisposition);
             }
         } finally {
             Binder.restoreCallingIdentity(ident);
@@ -1045,12 +1053,9 @@
                     }
                     if (mCurMethod != null) {
                         try {
-                            if (mInputShown) {
-                                // If mInputShown is false, there is no IME button on the
-                                // system bar.
-                                // Thus there is no need to make it invisible explicitly.
-                                mStatusBar.setIMEButtonVisible(mCurToken, true);
-                            }
+                            mImeWindowVis = 0;
+                            mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis,
+                                    mBackDisposition);
                             // If subtype is null, try to find the most applicable one from
                             // getCurrentInputMethodSubtype.
                             if (subtype == null) {
@@ -1168,11 +1173,14 @@
                         if (!mIWindowManager.inputMethodClientHasFocus(client)) {
                             if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
                                     + uid + ": " + client);
-                            mStatusBar.setIMEButtonVisible(mCurToken, false);
+                            mImeWindowVis = 0;
+                            mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis,
+                                    mBackDisposition);
                             return false;
                         }
                     } catch (RemoteException e) {
-                        mStatusBar.setIMEButtonVisible(mCurToken, false);
+                        mImeWindowVis = 0;
+                        mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis, mBackDisposition);
                         return false;
                     }
                 }
diff --git a/services/java/com/android/server/StatusBarManagerService.java b/services/java/com/android/server/StatusBarManagerService.java
index bdaa3b0..cdbf237 100644
--- a/services/java/com/android/server/StatusBarManagerService.java
+++ b/services/java/com/android/server/StatusBarManagerService.java
@@ -73,8 +73,9 @@
     // We usually call it lights out mode, but double negatives are annoying
     boolean mLightsOn = true;
     boolean mMenuVisible = false;
-    boolean mIMEButtonVisible = false;
-    IBinder mIMEToken = null;
+    int mImeWindowVis = 0;
+    int mImeBackDisposition;
+    IBinder mImeToken = null;
 
     private class DisableRecord implements IBinder.DeathRecipient {
         String pkg;
@@ -259,22 +260,25 @@
         }
     }
 
-    public void setIMEButtonVisible(final IBinder token, final boolean visible) {
+    public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
         enforceStatusBar();
 
-        if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " IME Button");
+        if (SPEW) {
+            Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
+        }
 
         synchronized(mLock) {
-            // In case of IME change, we need to call up setIMEButtonVisible() regardless of
-            // mIMEButtonVisible because mIMEButtonVisible may not have been set to false when the
+            // In case of IME change, we need to call up setImeWindowStatus() regardless of
+            // mImeWindowVis because mImeWindowVis may not have been set to false when the
             // previous IME was destroyed.
-            mIMEButtonVisible = visible;
-            mIMEToken = token;
+            mImeWindowVis = vis;
+            mImeBackDisposition = backDisposition;
+            mImeToken = token;
             mHandler.post(new Runnable() {
                 public void run() {
                     if (mBar != null) {
                         try {
-                            mBar.setIMEButtonVisible(token, visible);
+                            mBar.setImeWindowStatus(token, vis, backDisposition);
                         } catch (RemoteException ex) {
                         }
                     }
@@ -348,8 +352,9 @@
             switches[0] = gatherDisableActionsLocked();
             switches[1] = mLightsOn ? 1 : 0;
             switches[2] = mMenuVisible ? 1 : 0;
-            switches[3] = mIMEButtonVisible ? 1 : 0;
-            binders.add(mIMEToken);
+            switches[3] = mImeWindowVis;
+            switches[4] = mImeBackDisposition;
+            binders.add(mImeToken);
         }
     }