Two panel home empty page removing logic change

- Don't remove a single page if it's empty, only if both pages are empty.
- Add back empty pages after they were removed while the phone
  was on single panel home.
- On two panel home don't add new workspace items onto the second screen

Test: manual
Bug: 196376162
Change-Id: I4c54ffa3b359a236deb3ab67adb54111e77ec896
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 4d5cc5e..6ea7b17 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2186,6 +2186,24 @@
     }
 
     private void bindAddScreens(IntArray orderedScreenIds) {
+        if (mDeviceProfile.isTwoPanels) {
+            // Some empty pages might have been removed while the phone was in a single panel
+            // mode, so we want to add those empty pages back.
+            IntSet screenIds = IntSet.wrap(orderedScreenIds);
+            for (int i = 0; i < orderedScreenIds.size(); i++) {
+                int screenId = orderedScreenIds.get(i);
+                // Don't add the page pair if the page is the last one and if the pair is on the
+                // right, because that would cause a bug when adding new pages.
+                // TODO: (b/196376162) remove this when the new screen id logic is fixed for two
+                //  panel in Workspace::commitExtraEmptyScreen
+                if (i == orderedScreenIds.size() - 1 && screenId % 2 == 0) {
+                    continue;
+                }
+                screenIds.add(mWorkspace.getPagePair(screenId));
+            }
+            orderedScreenIds = screenIds.getArray();
+        }
+
         int count = orderedScreenIds.size();
         for (int i = 0; i < count; i++) {
             int screenId = orderedScreenIds.get(i);
@@ -2193,7 +2211,6 @@
                 // No need to bind the first screen, as its always bound.
                 continue;
             }
-
             mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
         }
     }