Decouple OverViewProxyService from DividerView

Add registerBoundsChangeListener API to let others register split screen
bounds chagne listener to decouple OverViewProxyService from DividerView.

Bug: 161116823
Test: atest SystemUITests
Test: manual check splitscreen and recents behavior
Change-Id: I25d0bfaa8c044a91266c35d977bcfba76e8d1c24
This commit is contained in:
Jerry Chang
2020-08-25 19:09:00 +08:00
parent 4c2e287219
commit eb0d1b6e34
4 changed files with 40 additions and 8 deletions

View File

@@ -98,6 +98,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import javax.inject.Inject;
@@ -592,6 +593,8 @@ public class OverviewProxyService extends CurrentUserTracker implements
};
private final StatusBarWindowCallback mStatusBarWindowCallback = this::onStatusBarStateChanged;
private final BiConsumer<Rect, Rect> mSplitScreenBoundsChangeListener =
this::notifySplitScreenBoundsChanged;
// This is the death handler for the binder from the launcher service
private final IBinder.DeathRecipient mOverviewServiceDeathRcpt
@@ -613,7 +616,6 @@ public class OverviewProxyService extends CurrentUserTracker implements
mNavBarControllerLazy = navBarControllerLazy;
mStatusBarWinController = statusBarWinController;
mConnectionBackoffAttempts = 0;
mSplitScreenOptional = splitScreenOptional;
mRecentsComponentName = ComponentName.unflattenFromString(context.getString(
com.android.internal.R.string.config_recentsComponentName));
mQuickStepIntent = new Intent(ACTION_QUICKSTEP)
@@ -653,6 +655,10 @@ public class OverviewProxyService extends CurrentUserTracker implements
});
mCommandQueue = commandQueue;
splitScreenOptional.ifPresent(splitScreen ->
splitScreen.registerBoundsChangeListener(mSplitScreenBoundsChangeListener));
mSplitScreenOptional = splitScreenOptional;
// Listen for user setup
startTracking();

View File

@@ -62,10 +62,8 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.policy.DividerSnapAlgorithm;
import com.android.internal.policy.DividerSnapAlgorithm.SnapTarget;
import com.android.internal.policy.DockedDividerUtils;
import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.statusbar.FlingAnimationUtils;
import java.util.function.Consumer;
@@ -138,6 +136,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
private final Rect mOtherInsetRect = new Rect();
private final Rect mLastResizeRect = new Rect();
private final Rect mTmpRect = new Rect();
private SplitScreenController mSplitScreenController;
private WindowManagerProxy mWindowManagerProxy;
private DividerWindowManager mWindowManager;
private VelocityTracker mVelocityTracker;
@@ -353,9 +352,11 @@ public class DividerView extends FrameLayout implements OnTouchListener,
}
}
public void injectDependencies(DividerWindowManager windowManager, DividerState dividerState,
void injectDependencies(SplitScreenController splitScreenController,
DividerWindowManager windowManager, DividerState dividerState,
DividerCallbacks callback, SplitScreenTaskOrganizer tiles, SplitDisplayLayout sdl,
DividerImeController imeController, WindowManagerProxy wmProxy) {
mSplitScreenController = splitScreenController;
mWindowManager = windowManager;
mState = dividerState;
mCallback = callback;
@@ -697,8 +698,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
mTmpRect.top = 0;
break;
}
Dependency.get(OverviewProxyService.class)
.notifySplitScreenBoundsChanged(mOtherTaskRect, mTmpRect);
mSplitScreenController.notifyBoundsChanged(mOtherTaskRect, mTmpRect);
}
private void cancelFlingAnimation() {

View File

@@ -16,9 +16,11 @@
package com.android.systemui.stackdivider;
import android.graphics.Rect;
import android.window.WindowContainerToken;
import java.io.PrintWriter;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
@@ -81,6 +83,9 @@ public interface SplitScreen {
/** Registers listener that gets called whenever the existence of the divider changes. */
void registerInSplitScreenListener(Consumer<Boolean> listener);
/** Registers listener that gets called whenever the split screen bounds changes. */
void registerBoundsChangeListener(BiConsumer<Rect, Rect> listener);
/** @return the container token for the secondary split root task. */
WindowContainerToken getSecondaryRoot();
}

View File

@@ -46,6 +46,7 @@ import com.android.wm.shell.common.TransactionPool;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
@@ -73,6 +74,8 @@ public class SplitScreenController implements SplitScreen,
private final ArrayList<WeakReference<Consumer<Boolean>>> mDockedStackExistsListeners =
new ArrayList<>();
private final ArrayList<WeakReference<BiConsumer<Rect, Rect>>> mBoundsChangedListeners =
new ArrayList<>();
private DividerWindowManager mWindowManager;
@@ -257,8 +260,8 @@ public class SplitScreenController implements SplitScreen,
mView = (DividerView)
LayoutInflater.from(dctx).inflate(R.layout.docked_stack_divider, null);
DisplayLayout displayLayout = mDisplayController.getDisplayLayout(mContext.getDisplayId());
mView.injectDependencies(mWindowManager, mDividerState, mForcedResizableController, mSplits,
mSplitLayout, mImePositionProcessor, mWindowManagerProxy);
mView.injectDependencies(this, mWindowManager, mDividerState, mForcedResizableController,
mSplits, mSplitLayout, mImePositionProcessor, mWindowManagerProxy);
mView.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE);
mView.setMinimizedDockStack(mMinimized, mHomeStackResizable, null /* transaction */);
final int size = dctx.getResources().getDimensionPixelSize(
@@ -466,6 +469,24 @@ public class SplitScreenController implements SplitScreen,
}
}
@Override
public void registerBoundsChangeListener(BiConsumer<Rect, Rect> listener) {
synchronized (mBoundsChangedListeners) {
mBoundsChangedListeners.add(new WeakReference<>(listener));
}
}
/** Notifies the bounds of split screen changed. */
void notifyBoundsChanged(Rect secondaryWindowBounds, Rect secondaryWindowInsets) {
synchronized (mBoundsChangedListeners) {
mBoundsChangedListeners.removeIf(wf -> {
BiConsumer<Rect, Rect> l = wf.get();
if (l != null) l.accept(secondaryWindowBounds, secondaryWindowInsets);
return l == null;
});
}
}
void startEnterSplit() {
update(mDisplayController.getDisplayContext(
mContext.getDisplayId()).getResources().getConfiguration());