Fixing regression in dismissing Recents.

- Restoring app info functionality when developer options are enabled and you long-press on the app icon.

Change-Id: I8a20ff5f595eefa20db5528c0d5b1a1f0b110834
diff --git a/packages/SystemUI/src/com/android/systemui/RecentsComponent.java b/packages/SystemUI/src/com/android/systemui/RecentsComponent.java
index 105f70e..7c85712 100644
--- a/packages/SystemUI/src/com/android/systemui/RecentsComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/RecentsComponent.java
@@ -21,7 +21,7 @@
 
 public interface RecentsComponent {
     void showRecents(boolean triggeredFromAltTab, View statusBarView);
-    void hideRecents();
+    void hideRecents(boolean triggeredFromAltTab);
     void toggleRecents(Display display, int layoutDirection, View statusBarView);
     void preloadRecents();
     void cancelPreloadingRecents();
diff --git a/packages/SystemUI/src/com/android/systemui/recent/Recents.java b/packages/SystemUI/src/com/android/systemui/recent/Recents.java
index 00c43e8..0cc09c8 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/Recents.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/Recents.java
@@ -72,9 +72,9 @@
     }
 
     @Override
-    public void hideRecents() {
+    public void hideRecents(boolean triggeredFromAltTab) {
         if (mUseAlternateRecents) {
-            mAlternateRecents.onHideRecents();
+            mAlternateRecents.onHideRecents(triggeredFromAltTab);
         } else {
             Intent intent = new Intent(RecentsActivity.CLOSE_RECENTS_INTENT);
             intent.setPackage("com.android.systemui");
diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
index ec50bfa..6df2a19 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
@@ -185,13 +185,13 @@
     }
 
     /** Hides the recents */
-    public void onHideRecents() {
+    public void onHideRecents(boolean triggeredFromAltTab) {
         Console.log(Constants.Log.App.RecentsComponent, "[RecentsComponent|hideRecents]");
         if (mServiceIsBound) {
             // Notify recents to close it
             try {
                 Bundle data = new Bundle();
-                Message msg = Message.obtain(null, MSG_HIDE_RECENTS, 0, 0);
+                Message msg = Message.obtain(null, MSG_HIDE_RECENTS, triggeredFromAltTab ? 1 : 0, 0);
                 msg.setData(data);
                 mService.send(msg);
             } catch (RemoteException re) {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Constants.java b/packages/SystemUI/src/com/android/systemui/recents/Constants.java
index 9390b0d..79545b3 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Constants.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Constants.java
@@ -31,8 +31,10 @@
             public static final boolean EnableTaskStackClipping = false;
             // Enables the use of theme colors as the task bar background
             public static final boolean EnableTaskBarThemeColors = true;
-            // Enables the info pane on long-press
+            // Enables the info pane on long-pressing the task
             public static final boolean EnableInfoPane = false;
+            // Enables app-info pane on long-pressing the icon
+            public static final boolean EnableDevAppInfoOnLongPress = true;
             // Enables the search bar layout
             public static final boolean EnableSearchLayout = true;
             // Enables the dynamic shadows behind each task
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index 325e4b0..591b175 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -83,8 +83,13 @@
             Console.log(Constants.Log.App.SystemUIHandshake,
                     "[RecentsActivity|serviceBroadcast]", action, Console.AnsiRed);
             if (action.equals(RecentsService.ACTION_HIDE_RECENTS_ACTIVITY)) {
-                // Dismiss recents, launching the focused task
-                dismissRecentsIfVisible();
+                if (intent.getBooleanExtra(RecentsService.EXTRA_TRIGGERED_FROM_ALT_TAB, false)) {
+                    // Dismiss recents, launching the focused task
+                    dismissRecentsIfVisible();
+                } else {
+                    // Otherwise, just finish the activity without launching any other activities
+                    finish();
+                }
             } else if (action.equals(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY)) {
                 // Try and unfilter and filtered stacks
                 if (!mRecentsView.unfilterFilteredStacks()) {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java
index 601b382..1c04cb1 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java
@@ -110,6 +110,9 @@
             // Send a broadcast to hide recents
             Intent intent = new Intent(RecentsService.ACTION_HIDE_RECENTS_ACTIVITY);
             intent.setPackage(context.getPackageName());
+            if (msg.arg1 != 0) {
+                intent.putExtra(RecentsService.EXTRA_TRIGGERED_FROM_ALT_TAB, true);
+            }
             context.sendBroadcast(intent);
         } else if (msg.what == AlternateRecentsComponent.MSG_TOGGLE_RECENTS) {
             // Send a broadcast to toggle recents
@@ -130,6 +133,7 @@
 public class RecentsService extends Service {
     final static String ACTION_HIDE_RECENTS_ACTIVITY = "action_hide_recents_activity";
     final static String ACTION_TOGGLE_RECENTS_ACTIVITY = "action_toggle_recents_activity";
+    final static String EXTRA_TRIGGERED_FROM_ALT_TAB = "extra_triggered_from_alt_tab";
 
     Messenger mSystemUIMessenger = new Messenger(new SystemUIMessageHandler(this));
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
index ffcb82b..46af4c1 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
@@ -18,7 +18,7 @@
 
 import android.animation.TimeInterpolator;
 import android.animation.ValueAnimator;
-import android.annotation.Nullable;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Outline;
@@ -26,6 +26,7 @@
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.graphics.RectF;
+import android.provider.Settings;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
@@ -38,8 +39,8 @@
 
 
 /* A task view */
-public class TaskView extends FrameLayout implements View.OnClickListener,
-        Task.TaskCallbacks {
+public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.OnClickListener,
+        View.OnLongClickListener {
     /** The TaskView callbacks */
     interface TaskViewCallbacks {
         public void onTaskIconClicked(TaskView tv);
@@ -415,7 +416,17 @@
             // Rebind any listeners
             mBarView.mApplicationIcon.setOnClickListener(this);
             mBarView.mDismissButton.setOnClickListener(this);
-            mInfoView.mAppInfoButton.setOnClickListener(this);
+            if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) {
+                ContentResolver cr = getContext().getContentResolver();
+                boolean devOptsEnabled = Settings.Global.getInt(cr,
+                        Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+                if (devOptsEnabled) {
+                    mBarView.mApplicationIcon.setOnLongClickListener(this);
+                }
+            }
+            if (Constants.DebugFlags.App.EnableInfoPane) {
+                mInfoView.mAppInfoButton.setOnClickListener(this);
+            }
         }
         mTaskDataLoaded = true;
     }
@@ -429,7 +440,13 @@
             mBarView.unbindFromTask();
             // Unbind any listeners
             mBarView.mApplicationIcon.setOnClickListener(null);
-            mInfoView.mAppInfoButton.setOnClickListener(null);
+            mBarView.mDismissButton.setOnClickListener(null);
+            if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) {
+                mBarView.mApplicationIcon.setOnLongClickListener(null);
+            }
+            if (Constants.DebugFlags.App.EnableInfoPane) {
+                mInfoView.mAppInfoButton.setOnClickListener(null);
+            }
         }
         mTaskDataLoaded = false;
     }
@@ -453,4 +470,13 @@
             mCb.onTaskAppInfoClicked(this);
         }
     }
+
+    @Override
+    public boolean onLongClick(View v) {
+        if (v == mBarView.mApplicationIcon) {
+            mCb.onTaskAppInfoClicked(this);
+            return true;
+        }
+        return false;
+    }
 }
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index 7918dec..eb4e77a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -504,10 +504,10 @@
     }
 
     @Override
-    public void hideRecentApps() {
+    public void hideRecentApps(boolean triggeredFromAltTab) {
         int msg = MSG_HIDE_RECENT_APPS;
         mHandler.removeMessages(msg);
-        mHandler.sendEmptyMessage(msg);
+        mHandler.obtainMessage(msg, triggeredFromAltTab ? 1 : 0, 0).sendToTarget();
     }
 
     @Override
@@ -617,10 +617,10 @@
         }
     }
 
-    protected void hideRecents() {
+    protected void hideRecents(boolean triggeredFromAltTab) {
         if (mRecents != null) {
             sendCloseSystemWindows(mContext, SYSTEM_DIALOG_REASON_RECENT_APPS);
-            mRecents.hideRecents();
+            mRecents.hideRecents(triggeredFromAltTab);
         }
     }
 
@@ -684,7 +684,7 @@
                  showRecents(m.arg1 > 0);
                  break;
              case MSG_HIDE_RECENT_APPS:
-                 hideRecents();
+                 hideRecents(m.arg1 > 0);
                  break;
              case MSG_TOGGLE_RECENTS_APPS:
                  toggleRecents();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index ebab7fb..b4a347b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -99,7 +99,7 @@
                 boolean showImeSwitcher);
         public void setHardKeyboardStatus(boolean available, boolean enabled);
         public void showRecentApps(boolean triggeredFromAltTab);
-        public void hideRecentApps();
+        public void hideRecentApps(boolean triggeredFromAltTab);
         public void toggleRecentApps();
         public void preloadRecentApps();
         public void cancelPreloadRecentApps();
@@ -223,10 +223,11 @@
         }
     }
 
-    public void hideRecentApps() {
+    public void hideRecentApps(boolean triggeredFromAltTab) {
         synchronized (mList) {
             mHandler.removeMessages(MSG_HIDE_RECENT_APPS);
-            mHandler.obtainMessage(MSG_HIDE_RECENT_APPS, 0, 0, null).sendToTarget();
+            mHandler.obtainMessage(MSG_HIDE_RECENT_APPS,
+                    triggeredFromAltTab ? 1 : 0, 0, null).sendToTarget();
         }
     }
 
@@ -332,7 +333,7 @@
                     mCallbacks.showRecentApps(msg.arg1 != 0);
                     break;
                 case MSG_HIDE_RECENT_APPS:
-                    mCallbacks.hideRecentApps();
+                    mCallbacks.hideRecentApps(msg.arg1 != 0);
                     break;
                 case MSG_TOGGLE_RECENT_APPS:
                     mCallbacks.toggleRecentApps();