If an icon add remove get coalesced, don't remove some other icon.

Also adds a test case and turns off the extra logging we added to debug this.

Change-Id: I8640938ae4d1e75c88213177888f363e05ce0fa0
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index f9347b1..4f080d5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -165,8 +165,10 @@
                             break;
                         }
                         case OP_REMOVE_ICON:
-                            mList.removeIcon(index);
-                            mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
+                            if (mList.getIcon(index) != null) {
+                                mList.removeIcon(index);
+                                mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
+                            }
                             break;
                     }
                     break;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java
index fece5ce..ea54656 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java
@@ -82,7 +82,7 @@
 
 public class StatusBarService extends Service implements CommandQueue.Callbacks {
     static final String TAG = "StatusBarService";
-    static final boolean SPEW_ICONS = true;
+    static final boolean SPEW_ICONS = false;
     static final boolean SPEW = false;
 
     public static final String ACTION_STATUSBAR_START
diff --git a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
index 1078701..438a060 100644
--- a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
@@ -60,6 +60,27 @@
     }
 
     private Test[] mTests = new Test[] {
+        new Test("Double Remove") {
+            public void run() {
+                Log.d(TAG, "set 0");
+                mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0);
+                Log.d(TAG, "remove 1");
+                mStatusBarManager.removeIcon("tty");
+
+                SystemClock.sleep(1000);
+
+                Log.d(TAG, "set 1");
+                mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0);
+                if (false) {
+                    Log.d(TAG, "set 2");
+                    mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0);
+                }
+                Log.d(TAG, "remove 2");
+                mStatusBarManager.removeIcon("tty");
+                Log.d(TAG, "set 3");
+                mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0);
+            }
+        },
         new Test("Hide") {
             public void run() {
                 Window win = getWindow();