Move default pip position to right above the shelf (Pt. Launcher)

SysUI change: ag/3721784, ag/3793664

- Track LauncherState and launcher activity state through callbacks.
- Devise logic to send shelf visibility and height signal to SysUI based
on LauncherState and Launcher activity state.

Bug: 73961893
Test:
- By default, pip shows up right above the shelf.
- Transitioning to all apps moves the pip down as the shelf becomes
invisible.
- Going to any specific app moves pip down. Hitting home moves pip
right above the shelf again.
- Dismissing IME should push PIP down but above the shelf on home
screen, bottom if not.

Change-Id: I1ab6ceb8007a5a7b5d932a456efa0a07f586ea4c
diff --git a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
index 846e803..80d63ae 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
@@ -18,6 +18,7 @@
 
 import static com.android.launcher3.Utilities.getPrefs;
 import static com.android.quickstep.OverviewInteractionState.KEY_SWIPE_UP_ENABLED;
+import static com.android.launcher3.LauncherState.ALL_APPS;
 
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -33,6 +34,7 @@
 import com.android.quickstep.OverviewInteractionState;
 import com.android.quickstep.RecentsModel;
 import com.android.quickstep.views.RecentsView;
+import com.android.systemui.shared.system.WindowManagerWrapper;
 
 public class UiFactory {
 
@@ -93,6 +95,14 @@
         }
     }
 
+    public static void onLauncherStateOrResumeChanged(Launcher launcher) {
+        WindowManagerWrapper.getInstance().setShelfHeight(
+                launcher.getStateManager().getState() != ALL_APPS &&
+                        launcher.isUserActive() &&
+                        !launcher.getDeviceProfile().isVerticalBarLayout(),
+                launcher.getDeviceProfile().hotseatBarSizePx);
+    }
+
     public static void onTrimMemory(Context context, int level) {
         RecentsModel model = RecentsModel.getInstance(context);
         if (model != null) {
diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java
index 02d70c4..cf2d79f 100644
--- a/src/com/android/launcher3/BaseActivity.java
+++ b/src/com/android/launcher3/BaseActivity.java
@@ -39,6 +39,7 @@
     protected SystemUiController mSystemUiController;
 
     private boolean mStarted;
+    private boolean mUserActive;
 
     public DeviceProfile getDeviceProfile() {
         return mDeviceProfile;
@@ -85,6 +86,18 @@
     }
 
     @Override
+    protected void onResume() {
+        mUserActive = true;
+        super.onResume();
+    }
+
+    @Override
+    protected void onUserLeaveHint() {
+        mUserActive = false;
+        super.onUserLeaveHint();
+    }
+
+    @Override
     protected void onStop() {
         mStarted = false;
         super.onStop();
@@ -94,6 +107,10 @@
         return mStarted;
     }
 
+    public boolean isUserActive() {
+        return mUserActive;
+    }
+
     public void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
         mDPChangeListeners.add(listener);
     }
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index ed94aa43..985e096 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -379,6 +379,7 @@
         }
 
         mOldConfig.setTo(newConfig);
+        UiFactory.onLauncherStateOrResumeChanged(this);
         super.onConfigurationChanged(newConfig);
     }
 
@@ -820,6 +821,7 @@
         if (mLauncherCallbacks != null) {
             mLauncherCallbacks.onResume();
         }
+        UiFactory.onLauncherStateOrResumeChanged(this);
 
         TraceHelper.endSection("ON_RESUME");
     }
@@ -839,6 +841,12 @@
     }
 
     @Override
+    protected void onUserLeaveHint() {
+        super.onUserLeaveHint();
+        UiFactory.onLauncherStateOrResumeChanged(this);
+    }
+
+    @Override
     public void onWindowFocusChanged(boolean hasFocus) {
         super.onWindowFocusChanged(hasFocus);
         mStateManager.onWindowFocusChanged();
diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java
index 7d50a52..ef285df 100644
--- a/src/com/android/launcher3/LauncherStateManager.java
+++ b/src/com/android/launcher3/LauncherStateManager.java
@@ -294,6 +294,7 @@
             // Only disable clipping if needed, otherwise leave it as previous value.
             mLauncher.getWorkspace().setClipChildren(false);
         }
+        UiFactory.onLauncherStateOrResumeChanged(mLauncher);
     }
 
     private void onStateTransitionEnd(LauncherState state) {
@@ -312,6 +313,7 @@
         }
 
         UiFactory.onLauncherStateOrFocusChanged(mLauncher);
+        UiFactory.onLauncherStateOrResumeChanged(mLauncher);
     }
 
     public void onWindowFocusChanged() {
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java
index 94abcce..6645e89 100644
--- a/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java
@@ -46,6 +46,8 @@
 
     public static void onStart(Launcher launcher) { }
 
+    public static void onLauncherStateOrResumeChanged(Launcher launcher) { }
+
     public static void onTrimMemory(Launcher launcher, int level) { }
 
     public static View[] getHotseatExtraContent(Hotseat hotseat) {