From bfdfe0ec428e30027cddd3391543f53d85ae509a Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Thu, 24 Sep 2020 14:22:11 +0200 Subject: [PATCH] DisplayImeController: Refactor for testability Bug: 162875596 Test: atest WMShellUnitTests Change-Id: I3118310a391592fcc72ea6ef8b4b8adccce2f14f --- .../wm/shell/common/DisplayImeController.java | 19 +++++++++++++------ .../wm/DisplaySystemBarsController.java | 4 +++- .../systemui/wmshell/TvWMShellModule.java | 7 +++++-- .../systemui/wmshell/WMShellModule.java | 6 ++++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java index c18e9ce761539..1471d1cbc74cd 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java @@ -43,6 +43,7 @@ import android.view.animation.PathInterpolator; import com.android.internal.view.IInputMethodManager; import java.util.ArrayList; +import java.util.concurrent.Executor; /** * Manages IME control at the display-level. This occurs when IME comes up in multi-window mode. @@ -62,15 +63,21 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged private static final int FLOATING_IME_BOTTOM_INSET = -80; protected final IWindowManager mWmService; - protected final Handler mHandler; + protected final Executor mExecutor; private final TransactionPool mTransactionPool; private final DisplayController mDisplayController; private final SparseArray mImePerDisplay = new SparseArray<>(); private final ArrayList mPositionProcessors = new ArrayList<>(); + @Deprecated public DisplayImeController(IWindowManager wmService, DisplayController displayController, Handler mainHandler, TransactionPool transactionPool) { - mHandler = mainHandler; + this(wmService, displayController, mainHandler::post, transactionPool); + } + + public DisplayImeController(IWindowManager wmService, DisplayController displayController, + Executor mainExecutor, TransactionPool transactionPool) { + mExecutor = mainExecutor; mWmService = wmService; mTransactionPool = transactionPool; mDisplayController = displayController; @@ -197,7 +204,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged @Override public void insetsChanged(InsetsState insetsState) { - mHandler.post(() -> { + mExecutor.execute(() -> { if (mInsetsState.equals(insetsState)) { return; } @@ -224,7 +231,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged continue; } if (activeControl.getType() == InsetsState.ITYPE_IME) { - mHandler.post(() -> { + mExecutor.execute(() -> { final Point lastSurfacePosition = mImeSourceControl != null ? mImeSourceControl.getSurfacePosition() : null; mImeSourceControl = activeControl; @@ -246,7 +253,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged return; } if (DEBUG) Slog.d(TAG, "Got showInsets for ime"); - mHandler.post(() -> startAnimation(true /* show */, false /* forceRestart */)); + mExecutor.execute(() -> startAnimation(true /* show */, false /* forceRestart */)); } @Override @@ -255,7 +262,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged return; } if (DEBUG) Slog.d(TAG, "Got hideInsets for ime"); - mHandler.post(() -> startAnimation(false /* show */, false /* forceRestart */)); + mExecutor.execute(() -> startAnimation(false /* show */, false /* forceRestart */)); } @Override diff --git a/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java b/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java index b113d29f00e66..f2ca4956be07f 100644 --- a/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java +++ b/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java @@ -50,6 +50,7 @@ public class DisplaySystemBarsController extends DisplayImeController { private final Context mContext; private final DisplayController mDisplayController; + private final Handler mHandler; private SparseArray mPerDisplaySparseArray; public DisplaySystemBarsController( @@ -58,9 +59,10 @@ public class DisplaySystemBarsController extends DisplayImeController { DisplayController displayController, @Main Handler mainHandler, TransactionPool transactionPool) { - super(wmService, displayController, mainHandler, transactionPool); + super(wmService, displayController, (r) -> mainHandler.post(r), transactionPool); mContext = context; mDisplayController = displayController; + mHandler = mainHandler; } @Override diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/TvWMShellModule.java b/packages/SystemUI/src/com/android/systemui/wmshell/TvWMShellModule.java index 524eca389cebc..ddfd88c3e6283 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/TvWMShellModule.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/TvWMShellModule.java @@ -31,6 +31,8 @@ import com.android.wm.shell.common.TransactionPool; import com.android.wm.shell.splitscreen.SplitScreen; import com.android.wm.shell.splitscreen.SplitScreenController; +import java.util.concurrent.Executor; + import dagger.Module; import dagger.Provides; @@ -44,9 +46,10 @@ public class TvWMShellModule { @SysUISingleton @Provides static DisplayImeController provideDisplayImeController(IWindowManager wmService, - DisplayController displayController, @Main Handler mainHandler, + DisplayController displayController, @Main Executor mainExecutor, TransactionPool transactionPool) { - return new DisplayImeController(wmService, displayController, mainHandler, transactionPool); + return new DisplayImeController(wmService, displayController, mainExecutor, + transactionPool); } @SysUISingleton diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java index 16fb2cacc9508..14c744cb60bc9 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java @@ -44,6 +44,7 @@ import com.android.wm.shell.splitscreen.SplitScreen; import com.android.wm.shell.splitscreen.SplitScreenController; import java.util.Optional; +import java.util.concurrent.Executor; import dagger.Module; import dagger.Provides; @@ -58,9 +59,10 @@ public class WMShellModule { @SysUISingleton @Provides static DisplayImeController provideDisplayImeController(IWindowManager wmService, - DisplayController displayController, @Main Handler mainHandler, + DisplayController displayController, @Main Executor mainExecutor, TransactionPool transactionPool) { - return new DisplayImeController(wmService, displayController, mainHandler, transactionPool); + return new DisplayImeController(wmService, displayController, mainExecutor, + transactionPool); } @SysUISingleton