Merge "Synchronize WCT for TaskView with SurfaceControl.Transaction." into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-06-08 18:21:32 +00:00
committed by Android (Google) Code Review
10 changed files with 76 additions and 29 deletions

View File

@@ -1554,12 +1554,21 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
* @hide
*/
public void setResizeBackgroundColor(int bgColor) {
setResizeBackgroundColor(mTmpTransaction, bgColor);
mTmpTransaction.apply();
}
/**
* Version of {@link #setResizeBackgroundColor(int)} that allows you to provide
* {@link SurfaceControl.Transaction}.
* @hide
*/
public void setResizeBackgroundColor(@NonNull SurfaceControl.Transaction t, int bgColor) {
if (mBackgroundControl == null) {
return;
}
mBackgroundColor = bgColor;
updateBackgroundColor(mTmpTransaction).apply();
updateBackgroundColor(t);
}
@UnsupportedAppUsage

View File

@@ -40,6 +40,8 @@ import android.view.ViewTreeObserver;
import android.window.WindowContainerToken;
import android.window.WindowContainerTransaction;
import com.android.wm.shell.common.SyncTransactionQueue;
import java.io.PrintWriter;
import java.util.concurrent.Executor;
@@ -74,6 +76,7 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
private final ShellTaskOrganizer mTaskOrganizer;
private final Executor mShellExecutor;
private final SyncTransactionQueue mSyncQueue;
private ActivityManager.RunningTaskInfo mTaskInfo;
private WindowContainerToken mTaskToken;
@@ -89,11 +92,12 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
private final Rect mTmpRootRect = new Rect();
private final int[] mTmpLocation = new int[2];
public TaskView(Context context, ShellTaskOrganizer organizer) {
public TaskView(Context context, ShellTaskOrganizer organizer, SyncTransactionQueue syncQueue) {
super(context, null, 0, 0, true /* disableBackgroundLayer */);
mTaskOrganizer = organizer;
mShellExecutor = organizer.getExecutor();
mSyncQueue = syncQueue;
setUseAlpha();
getHolder().addCallback(this);
mGuard.open("release");
@@ -189,8 +193,7 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
WindowContainerTransaction wct = new WindowContainerTransaction();
wct.setBounds(mTaskToken, mTmpRect);
// TODO(b/151449487): Enable synchronization
mTaskOrganizer.applyTransaction(wct);
mSyncQueue.queue(wct);
}
/**
@@ -236,14 +239,16 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
private void updateTaskVisibility() {
WindowContainerTransaction wct = new WindowContainerTransaction();
wct.setHidden(mTaskToken, !mSurfaceCreated /* hidden */);
mTaskOrganizer.applyTransaction(wct);
// TODO(b/151449487): Only call callback once we enable synchronization
if (mListener != null) {
final int taskId = mTaskInfo.taskId;
mSyncQueue.queue(wct);
if (mListener == null) {
return;
}
int taskId = mTaskInfo.taskId;
mSyncQueue.runInSync((t) -> {
mListenerExecutor.execute(() -> {
mListener.onTaskVisibilityChanged(taskId, mSurfaceCreated);
});
}
});
}
@Override
@@ -264,10 +269,12 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
updateTaskVisibility();
}
mTaskOrganizer.setInterceptBackPressedOnTaskRoot(mTaskToken, true);
// TODO: Synchronize show with the resize
onLocationChanged();
if (taskInfo.taskDescription != null) {
setResizeBackgroundColor(taskInfo.taskDescription.getBackgroundColor());
int backgroundColor = taskInfo.taskDescription.getBackgroundColor();
mSyncQueue.runInSync((t) -> {
setResizeBackgroundColor(t, backgroundColor);
});
}
if (mListener != null) {

View File

@@ -20,8 +20,8 @@ import android.annotation.UiContext;
import android.content.Context;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.annotations.ExternalThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
@@ -30,12 +30,14 @@ import java.util.function.Consumer;
public class TaskViewFactoryController {
private final ShellTaskOrganizer mTaskOrganizer;
private final ShellExecutor mShellExecutor;
private final SyncTransactionQueue mSyncQueue;
private final TaskViewFactory mImpl = new TaskViewFactoryImpl();
public TaskViewFactoryController(ShellTaskOrganizer taskOrganizer,
ShellExecutor shellExecutor) {
ShellExecutor shellExecutor, SyncTransactionQueue syncQueue) {
mTaskOrganizer = taskOrganizer;
mShellExecutor = shellExecutor;
mSyncQueue = syncQueue;
}
public TaskViewFactory asTaskViewFactory() {
@@ -44,7 +46,7 @@ public class TaskViewFactoryController {
/** Creates an {@link TaskView} */
public void create(@UiContext Context context, Executor executor, Consumer<TaskView> onCreate) {
TaskView taskView = new TaskView(context, mTaskOrganizer);
TaskView taskView = new TaskView(context, mTaskOrganizer, mSyncQueue);
executor.execute(() -> {
onCreate.accept(taskView);
});

View File

@@ -85,6 +85,7 @@ import com.android.wm.shell.common.DisplayChangeController;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.TaskStackListenerCallback;
import com.android.wm.shell.common.TaskStackListenerImpl;
import com.android.wm.shell.pip.PinnedStackListenerForwarder;
@@ -136,6 +137,7 @@ public class BubbleController {
private final TaskStackListenerImpl mTaskStackListener;
private final ShellTaskOrganizer mTaskOrganizer;
private final DisplayController mDisplayController;
private final SyncTransactionQueue mSyncQueue;
// Used to post to main UI thread
private final ShellExecutor mMainExecutor;
@@ -208,7 +210,8 @@ public class BubbleController {
ShellTaskOrganizer organizer,
DisplayController displayController,
ShellExecutor mainExecutor,
Handler mainHandler) {
Handler mainHandler,
SyncTransactionQueue syncQueue) {
BubbleLogger logger = new BubbleLogger(uiEventLogger);
BubblePositioner positioner = new BubblePositioner(context, windowManager);
BubbleData data = new BubbleData(context, logger, positioner, mainExecutor);
@@ -216,7 +219,7 @@ public class BubbleController {
new BubbleDataRepository(context, launcherApps, mainExecutor),
statusBarService, windowManager, windowManagerShellWrapper, launcherApps,
logger, taskStackListener, organizer, positioner, displayController, mainExecutor,
mainHandler);
mainHandler, syncQueue);
}
/**
@@ -238,7 +241,8 @@ public class BubbleController {
BubblePositioner positioner,
DisplayController displayController,
ShellExecutor mainExecutor,
Handler mainHandler) {
Handler mainHandler,
SyncTransactionQueue syncQueue) {
mContext = context;
mLauncherApps = launcherApps;
mBarService = statusBarService == null
@@ -261,6 +265,7 @@ public class BubbleController {
mSavedBubbleKeysPerUser = new SparseSetArray<>();
mBubbleIconFactory = new BubbleIconFactory(context);
mDisplayController = displayController;
mSyncQueue = syncQueue;
}
public void initialize() {
@@ -544,6 +549,10 @@ public class BubbleController {
return mTaskOrganizer;
}
SyncTransactionQueue getSyncTransactionQueue() {
return mSyncQueue;
}
/** Contains information to help position things on the screen. */
BubblePositioner getPositioner() {
return mBubblePositioner;

View File

@@ -338,7 +338,8 @@ public class BubbleExpandedView extends LinearLayout {
bringChildToFront(mOverflowView);
mManageButton.setVisibility(GONE);
} else {
mTaskView = new TaskView(mContext, mController.getTaskOrganizer());
mTaskView = new TaskView(mContext, mController.getTaskOrganizer(),
mController.getSyncTransactionQueue());
mTaskView.setListener(mController.getMainExecutor(), mTaskViewListener);
mExpandedViewContainer.addView(mTaskView);
bringChildToFront(mTaskView);

View File

@@ -47,6 +47,8 @@ import android.window.WindowContainerToken;
import androidx.test.filters.SmallTest;
import com.android.wm.shell.common.HandlerExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.SyncTransactionQueue.TransactionRunnable;
import org.junit.After;
import org.junit.Before;
@@ -71,6 +73,8 @@ public class TaskViewTest extends ShellTestCase {
ShellTaskOrganizer mOrganizer;
@Mock
HandlerExecutor mExecutor;
@Mock
SyncTransactionQueue mSyncQueue;
SurfaceSession mSession;
SurfaceControl mLeash;
@@ -99,7 +103,14 @@ public class TaskViewTest extends ShellTestCase {
}).when(mExecutor).execute(any());
when(mOrganizer.getExecutor()).thenReturn(mExecutor);
mTaskView = new TaskView(mContext, mOrganizer);
doAnswer((InvocationOnMock invocationOnMock) -> {
final TransactionRunnable r = invocationOnMock.getArgument(0);
r.runWithTransaction(new SurfaceControl.Transaction());
return null;
}).when(mSyncQueue).runInSync(any());
mTaskView = new TaskView(mContext, mOrganizer, mSyncQueue);
mTaskView.setListener(mExecutor, mViewListener);
}
@@ -112,7 +123,7 @@ public class TaskViewTest extends ShellTestCase {
@Test
public void testSetPendingListener_throwsException() {
TaskView taskView = new TaskView(mContext, mOrganizer);
TaskView taskView = new TaskView(mContext, mOrganizer, mSyncQueue);
taskView.setListener(mExecutor, mViewListener);
try {
taskView.setListener(mExecutor, mViewListener);

View File

@@ -194,11 +194,12 @@ public abstract class WMShellBaseModule {
ShellTaskOrganizer organizer,
DisplayController displayController,
@ShellMainThread ShellExecutor mainExecutor,
@ShellMainThread Handler mainHandler) {
@ShellMainThread Handler mainHandler,
SyncTransactionQueue syncQueue) {
return Optional.of(BubbleController.create(context, null /* synchronizer */,
floatingContentCoordinator, statusBarService, windowManager,
windowManagerShellWrapper, launcherApps, taskStackListener,
uiEventLogger, organizer, displayController, mainExecutor, mainHandler));
uiEventLogger, organizer, displayController, mainExecutor, mainHandler, syncQueue));
}
//
@@ -424,8 +425,9 @@ public abstract class WMShellBaseModule {
@Provides
static TaskViewFactoryController provideTaskViewFactoryController(
ShellTaskOrganizer shellTaskOrganizer,
@ShellMainThread ShellExecutor mainExecutor) {
return new TaskViewFactoryController(shellTaskOrganizer, mainExecutor);
@ShellMainThread ShellExecutor mainExecutor,
SyncTransactionQueue syncQueue) {
return new TaskViewFactoryController(shellTaskOrganizer, mainExecutor, syncQueue);
}
//

View File

@@ -115,6 +115,7 @@ import com.android.wm.shell.bubbles.Bubbles;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.TaskStackListenerImpl;
import com.google.common.collect.ImmutableList;
@@ -318,7 +319,8 @@ public class BubblesTest extends SysuiTestCase {
mPositioner,
mock(DisplayController.class),
syncExecutor,
mock(Handler.class));
mock(Handler.class),
mock(SyncTransactionQueue.class));
mBubbleController.setExpandListener(mBubbleExpandListener);
mBubblesManager = new BubblesManager(

View File

@@ -95,6 +95,7 @@ import com.android.wm.shell.bubbles.Bubbles;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.TaskStackListenerImpl;
import org.junit.Before;
@@ -262,7 +263,8 @@ public class NewNotifPipelineBubblesTest extends SysuiTestCase {
mPositioner,
mock(DisplayController.class),
syncExecutor,
mock(Handler.class));
mock(Handler.class),
mock(SyncTransactionQueue.class));
mBubbleController.setExpandListener(mBubbleExpandListener);
mBubblesManager = new BubblesManager(

View File

@@ -32,6 +32,7 @@ import com.android.wm.shell.bubbles.BubblePositioner;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.TaskStackListenerImpl;
/**
@@ -54,11 +55,12 @@ public class TestableBubbleController extends BubbleController {
BubblePositioner positioner,
DisplayController displayController,
ShellExecutor shellMainExecutor,
Handler shellMainHandler) {
Handler shellMainHandler,
SyncTransactionQueue syncQueue) {
super(context, data, Runnable::run, floatingContentCoordinator, dataRepository,
statusBarService, windowManager, windowManagerShellWrapper, launcherApps,
bubbleLogger, taskStackListener, shellTaskOrganizer, positioner, displayController,
shellMainExecutor, shellMainHandler);
shellMainExecutor, shellMainHandler, syncQueue);
setInflateSynchronously(true);
initialize();
}