diff --git a/quickstep/src/com/android/launcher3/HomeTransitionController.java b/quickstep/src/com/android/launcher3/HomeTransitionController.java deleted file mode 100644 index c4a2e9e17e..0000000000 --- a/quickstep/src/com/android/launcher3/HomeTransitionController.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.launcher3; - -import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; - -import androidx.annotation.Nullable; - -import com.android.launcher3.uioverrides.QuickstepLauncher; -import com.android.quickstep.SystemUiProxy; -import com.android.wm.shell.shared.IHomeTransitionListener; - -/** - * Controls launcher response to home activity visibility changing. - */ -public class HomeTransitionController { - - @Nullable private QuickstepLauncher mLauncher; - @Nullable private IHomeTransitionListener mHomeTransitionListener; - - public void registerHomeTransitionListener(QuickstepLauncher launcher) { - mLauncher = launcher; - mHomeTransitionListener = new IHomeTransitionListener.Stub() { - @Override - public void onHomeVisibilityChanged(boolean isVisible) { - MAIN_EXECUTOR.execute(() -> { - if (mLauncher != null && mLauncher.getTaskbarUIController() != null) { - mLauncher.getTaskbarUIController().onLauncherVisibilityChanged(isVisible); - } - }); - } - }; - - SystemUiProxy.INSTANCE.get(mLauncher).setHomeTransitionListener(mHomeTransitionListener); - } - - public void unregisterHomeTransitionListener() { - SystemUiProxy.INSTANCE.get(mLauncher).setHomeTransitionListener(null); - mHomeTransitionListener = null; - mLauncher = null; - } -} diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java index a59aeada5f..def6287d2b 100644 --- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java @@ -35,6 +35,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.DeviceProfile; +import com.android.launcher3.Flags; import com.android.launcher3.LauncherState; import com.android.launcher3.QuickstepTransitionManager; import com.android.launcher3.R; @@ -49,8 +50,10 @@ import com.android.launcher3.uioverrides.QuickstepLauncher; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.MultiPropertyFactory; import com.android.launcher3.util.OnboardingPrefs; +import com.android.quickstep.HomeVisibilityState; import com.android.quickstep.LauncherActivityInterface; import com.android.quickstep.RecentsAnimationCallbacks; +import com.android.quickstep.SystemUiProxy; import com.android.quickstep.util.GroupTask; import com.android.quickstep.util.TISBindHelper; import com.android.quickstep.views.RecentsView; @@ -79,6 +82,7 @@ public class LauncherTaskbarUIController extends TaskbarUIController { AnimatedFloat.VALUE, DISPLAY_PROGRESS_COUNT, Float::max); private final QuickstepLauncher mLauncher; + private final HomeVisibilityState mHomeState; private final DeviceProfile.OnDeviceProfileChangeListener mOnDeviceProfileChangeListener = dp -> { @@ -87,6 +91,8 @@ public class LauncherTaskbarUIController extends TaskbarUIController { mControllers.taskbarViewController.onRotationChanged(dp); } }; + private final HomeVisibilityState.VisibilityChangeListener mVisibilityChangeListener = + this::onLauncherVisibilityChanged; // Initialized in init. private final TaskbarLauncherStateController @@ -94,6 +100,7 @@ public class LauncherTaskbarUIController extends TaskbarUIController { public LauncherTaskbarUIController(QuickstepLauncher launcher) { mLauncher = launcher; + mHomeState = SystemUiProxy.INSTANCE.get(mLauncher).getHomeVisibilityState(); } @Override @@ -104,8 +111,11 @@ public class LauncherTaskbarUIController extends TaskbarUIController { mControllers.getSharedState().sysuiStateFlags); mLauncher.setTaskbarUIController(this); - - onLauncherVisibilityChanged(mLauncher.hasBeenResumed(), true /* fromInit */); + mHomeState.addListener(mVisibilityChangeListener); + onLauncherVisibilityChanged( + Flags.useActivityOverlay() + ? mHomeState.isHomeVisible() : mLauncher.hasBeenResumed(), + true /* fromInit */); onStashedInAppChanged(mLauncher.getDeviceProfile()); mLauncher.addOnDeviceProfileChangeListener(mOnDeviceProfileChangeListener); @@ -129,6 +139,7 @@ public class LauncherTaskbarUIController extends TaskbarUIController { mLauncher.setTaskbarUIController(null); mLauncher.removeOnDeviceProfileChangeListener(mOnDeviceProfileChangeListener); + mHomeState.removeListener(mVisibilityChangeListener); updateTaskTransitionSpec(true); } @@ -234,7 +245,8 @@ public class LauncherTaskbarUIController extends TaskbarUIController { @Override public void refreshResumedState() { - onLauncherVisibilityChanged(mLauncher.hasBeenResumed()); + onLauncherVisibilityChanged(Flags.useActivityOverlay() + ? mHomeState.isHomeVisible() : mLauncher.hasBeenResumed()); } @Override diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java index 8d481543c8..1a120da8b2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java @@ -656,7 +656,8 @@ public class TaskbarLauncherStateController { * Returns if the current Launcher state has hotseat on top of other elemnets. */ public boolean isInHotseatOnTopStates() { - return mLauncherState != LauncherState.ALL_APPS; + return mLauncherState != LauncherState.ALL_APPS + && !mLauncher.getWorkspace().isOverlayShown(); } boolean isInOverview() { diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index b49c7525ea..8b923ada30 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -62,8 +62,8 @@ import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MOD import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.quickstep.util.AnimUtils.completeRunnableListCallback; import static com.android.quickstep.util.SplitAnimationTimings.TABLET_HOME_TO_SPLIT; -import static com.android.window.flags.Flags.enableDesktopWindowingMode; import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY; +import static com.android.window.flags.Flags.enableDesktopWindowingMode; import static com.android.wm.shell.common.split.SplitScreenConstants.SNAP_TO_50_50; import android.animation.Animator; @@ -105,7 +105,6 @@ import com.android.app.viewcapture.SettingsAwareViewCapture; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Flags; -import com.android.launcher3.HomeTransitionController; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherSettings.Favorites; @@ -245,8 +244,6 @@ public class QuickstepLauncher extends Launcher { private boolean mIsPredictiveBackToHomeInProgress; - private HomeTransitionController mHomeTransitionController; - @Override protected void setupViews() { super.setupViews(); @@ -277,11 +274,6 @@ public class QuickstepLauncher extends Launcher { mAppTransitionManager.registerRemoteAnimations(); mAppTransitionManager.registerRemoteTransitions(); - if (FeatureFlags.enableHomeTransitionListener()) { - mHomeTransitionController = new HomeTransitionController(); - mHomeTransitionController.registerHomeTransitionListener(this); - } - mTISBindHelper = new TISBindHelper(this, this::onTISConnected); mDepthController = new DepthController(this); mDesktopVisibilityController = new DesktopVisibilityController(this); @@ -523,10 +515,6 @@ public class QuickstepLauncher extends Launcher { mLauncherUnfoldAnimationController.onDestroy(); } - if (mHomeTransitionController != null) { - mHomeTransitionController.unregisterHomeTransitionListener(); - } - if (mDesktopVisibilityController != null) { mDesktopVisibilityController.unregisterSystemUiListener(); } diff --git a/quickstep/src/com/android/quickstep/HomeVisibilityState.kt b/quickstep/src/com/android/quickstep/HomeVisibilityState.kt new file mode 100644 index 0000000000..241e16d111 --- /dev/null +++ b/quickstep/src/com/android/quickstep/HomeVisibilityState.kt @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.quickstep + +import android.os.RemoteException +import android.util.Log +import com.android.launcher3.config.FeatureFlags +import com.android.launcher3.util.Executors +import com.android.wm.shell.shared.IHomeTransitionListener.Stub +import com.android.wm.shell.shared.IShellTransitions + +/** Class to track visibility state of Launcher */ +class HomeVisibilityState { + + var isHomeVisible = true + private set + + private var listeners = mutableSetOf() + + fun addListener(l: VisibilityChangeListener) = listeners.add(l) + + fun removeListener(l: VisibilityChangeListener) = listeners.remove(l) + + fun init(transitions: IShellTransitions?) { + if (!FeatureFlags.enableHomeTransitionListener()) return + try { + transitions?.setHomeTransitionListener( + object : Stub() { + override fun onHomeVisibilityChanged(isVisible: Boolean) { + Executors.MAIN_EXECUTOR.execute { + isHomeVisible = isVisible + listeners.forEach { it.onHomeVisibilityChanged(isVisible) } + } + } + } + ) + } catch (e: RemoteException) { + Log.w(TAG, "Failed call setHomeTransitionListener", e) + } + } + + interface VisibilityChangeListener { + fun onHomeVisibilityChanged(isVisible: Boolean) + } + + override fun toString() = "{HomeVisibilityState isHomeVisible=$isHomeVisible}" + + companion object { + + private const val TAG = "HomeVisibilityState" + } +} diff --git a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java index 97c48e6327..7c17e4ee7a 100644 --- a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java +++ b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java @@ -35,6 +35,7 @@ import androidx.annotation.Nullable; import androidx.annotation.UiThread; import com.android.launcher3.DeviceProfile; +import com.android.launcher3.Flags; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAnimUtils; import com.android.launcher3.LauncherInitListener; @@ -206,8 +207,17 @@ public final class LauncherActivityInterface extends @UiThread private Launcher getVisibleLauncher() { Launcher launcher = getCreatedActivity(); - return (launcher != null) && launcher.isStarted() - && (isInLiveTileMode() || launcher.hasBeenResumed()) ? launcher : null; + if (launcher == null) { + return null; + } + if (launcher.isStarted() && (isInLiveTileMode() || launcher.hasBeenResumed())) { + return launcher; + } + if (Flags.useActivityOverlay() + && SystemUiProxy.INSTANCE.get(launcher).getHomeVisibilityState().isHomeVisible()) { + return launcher; + } + return null; } @Override diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java index b6272dad87..1521b02b7a 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.java +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java @@ -63,7 +63,6 @@ import androidx.annotation.WorkerThread; import com.android.internal.logging.InstanceId; import com.android.internal.util.ScreenshotRequest; import com.android.internal.view.AppearanceRegion; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.Preconditions; import com.android.quickstep.util.ActiveGestureLog; @@ -91,7 +90,6 @@ import com.android.wm.shell.draganddrop.IDragAndDrop; import com.android.wm.shell.onehanded.IOneHanded; import com.android.wm.shell.recents.IRecentTasks; import com.android.wm.shell.recents.IRecentTasksListener; -import com.android.wm.shell.shared.IHomeTransitionListener; import com.android.wm.shell.shared.IShellTransitions; import com.android.wm.shell.splitscreen.ISplitScreen; import com.android.wm.shell.splitscreen.ISplitScreenListener; @@ -157,7 +155,7 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle { private IOnBackInvokedCallback mBackToLauncherCallback; private IRemoteAnimationRunner mBackToLauncherRunner; private IDragAndDrop mDragAndDrop; - private IHomeTransitionListener mHomeTransitionListener; + private final HomeVisibilityState mHomeVisibilityState = new HomeVisibilityState(); // Used to dedupe calls to SystemUI private int mLastShelfHeight; @@ -269,7 +267,7 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle { setBubblesListener(mBubblesListener); registerSplitScreenListener(mSplitScreenListener); registerSplitSelectListener(mSplitSelectListener); - setHomeTransitionListener(mHomeTransitionListener); + mHomeVisibilityState.init(mShellTransitions); setStartingWindowListener(mStartingWindowListener); setLauncherUnlockAnimationController( mLauncherActivityClass, mLauncherUnlockAnimationController); @@ -1102,22 +1100,8 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle { mRemoteTransitions.remove(remoteTransition); } - public void setHomeTransitionListener(IHomeTransitionListener listener) { - if (!FeatureFlags.enableHomeTransitionListener()) { - return; - } - - mHomeTransitionListener = listener; - - if (mShellTransitions != null) { - try { - mShellTransitions.setHomeTransitionListener(listener); - } catch (RemoteException e) { - Log.w(TAG, "Failed call setHomeTransitionListener", e); - } - } else { - Log.w(TAG, "Unable to call setHomeTransitionListener because ShellTransitions is null"); - } + public HomeVisibilityState getHomeVisibilityState() { + return mHomeVisibilityState; } /** @@ -1558,7 +1542,7 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle { pw.println("\tmSplitSelectListener=" + mSplitSelectListener); pw.println("\tmOneHanded=" + mOneHanded); pw.println("\tmShellTransitions=" + mShellTransitions); - pw.println("\tmHomeTransitionListener=" + mHomeTransitionListener); + pw.println("\tmHomeVisibilityState=" + mHomeVisibilityState); pw.println("\tmStartingWindow=" + mStartingWindow); pw.println("\tmStartingWindowListener=" + mStartingWindowListener); pw.println("\tmSysuiUnlockAnimationController=" + mSysuiUnlockAnimationController);