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 cb64796196ede..338ece5afbc25 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 @@ -30,6 +30,7 @@ import android.os.ServiceManager; import android.util.Slog; import android.util.SparseArray; import android.view.IDisplayWindowInsetsController; +import android.view.IWindowManager; import android.view.InsetsSource; import android.view.InsetsSourceControl; import android.view.InsetsState; @@ -60,20 +61,20 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged private static final int DIRECTION_HIDE = 2; private static final int FLOATING_IME_BOTTOM_INSET = -80; - protected final SystemWindows mSystemWindows; + protected final IWindowManager mWmService; protected final Handler mHandler; - final TransactionPool mTransactionPool; + private final TransactionPool mTransactionPool; + private final DisplayController mDisplayController; + private final SparseArray mImePerDisplay = new SparseArray<>(); + private final ArrayList mPositionProcessors = new ArrayList<>(); - final SparseArray mImePerDisplay = new SparseArray<>(); - - final ArrayList mPositionProcessors = new ArrayList<>(); - - public DisplayImeController(SystemWindows syswin, DisplayController displayController, - Handler handler, TransactionPool transactionPool) { - mHandler = handler; - mSystemWindows = syswin; + public DisplayImeController(IWindowManager wmService, DisplayController displayController, + Handler mainHandler, TransactionPool transactionPool) { + mHandler = mainHandler; + mWmService = wmService; mTransactionPool = transactionPool; - displayController.addDisplayWindowListener(this); + mDisplayController = displayController; + mDisplayController.addDisplayWindowListener(this); } @Override @@ -81,9 +82,9 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged // Add's a system-ui window-manager specifically for ime. This type is special because // WM will defer IME inset handling to it in multi-window scenarious. PerDisplay pd = new PerDisplay(displayId, - mSystemWindows.mDisplayController.getDisplayLayout(displayId).rotation()); + mDisplayController.getDisplayLayout(displayId).rotation()); try { - mSystemWindows.mWmService.setDisplayWindowInsetsController(displayId, pd); + mWmService.setDisplayWindowInsetsController(displayId, pd); } catch (RemoteException e) { Slog.w(TAG, "Unable to set insets controller on display " + displayId); } @@ -96,7 +97,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged if (pd == null) { return; } - if (mSystemWindows.mDisplayController.getDisplayLayout(displayId).rotation() + if (mDisplayController.getDisplayLayout(displayId).rotation() != pd.mRotation && isImeShowing(displayId)) { pd.startAnimation(true, false /* forceRestart */); } @@ -105,7 +106,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged @Override public void onDisplayRemoved(int displayId) { try { - mSystemWindows.mWmService.setDisplayWindowInsetsController(displayId, null); + mWmService.setDisplayWindowInsetsController(displayId, null); } catch (RemoteException e) { Slog.w(TAG, "Unable to remove insets controller on display " + displayId); } @@ -263,7 +264,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged private void setVisibleDirectly(boolean visible) { mInsetsState.getSource(InsetsState.ITYPE_IME).setVisible(visible); try { - mSystemWindows.mWmService.modifyDisplayWindowInsets(mDisplayId, mInsetsState); + mWmService.modifyDisplayWindowInsets(mDisplayId, mInsetsState); } catch (RemoteException e) { } } @@ -282,7 +283,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged // an IME inset). For now, we assume that no non-floating IME will be <= this nav bar // frame height so any reported frame that is <= nav-bar frame height is assumed to // be floating. - return frame.height() <= mSystemWindows.mDisplayController.getDisplayLayout(mDisplayId) + return frame.height() <= mDisplayController.getDisplayLayout(mDisplayId) .navBarFrameHeight(); } @@ -297,8 +298,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged // This is a "floating" or "expanded" IME, so to get animations, just // pretend the ime has some size just below the screen. mImeFrame.set(newFrame); - final int floatingInset = (int) ( - mSystemWindows.mDisplayController.getDisplayLayout(mDisplayId) + final int floatingInset = (int) (mDisplayController.getDisplayLayout(mDisplayId) .density() * FLOATING_IME_BOTTOM_INSET); mImeFrame.bottom -= floatingInset; } else if (newFrame.height() != 0) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java index 34018e8cb3056..8abe9eeb6a9a2 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java @@ -60,11 +60,10 @@ public class SystemWindows { private static final String TAG = "SystemWindows"; private final SparseArray mPerDisplay = new SparseArray<>(); - final HashMap mViewRoots = new HashMap<>(); - public Context mContext; - public IWindowManager mWmService; - IWindowSession mSession; - DisplayController mDisplayController; + private final HashMap mViewRoots = new HashMap<>(); + private final DisplayController mDisplayController; + private final IWindowManager mWmService; + private IWindowSession mSession; private final DisplayController.OnDisplaysChangedListener mDisplayListener = new DisplayController.OnDisplaysChangedListener() { @@ -84,9 +83,7 @@ public class SystemWindows { public void onDisplayRemoved(int displayId) { } }; - public SystemWindows(Context context, DisplayController displayController, - IWindowManager wmService) { - mContext = context; + public SystemWindows(DisplayController displayController, IWindowManager wmService) { mWmService = wmService; mDisplayController = displayController; mDisplayController.addDisplayWindowListener(mDisplayListener); @@ -210,8 +207,8 @@ public class SystemWindows { } final Display display = mDisplayController.getDisplay(mDisplayId); SurfaceControlViewHost viewRoot = - new SurfaceControlViewHost(mContext, display, wwm, - true /* useSfChoreographer */); + new SurfaceControlViewHost( + view.getContext(), display, wwm, true /* useSfChoreographer */); attrs.flags |= FLAG_HARDWARE_ACCELERATED; viewRoot.setView(view, attrs); mViewRoots.put(view, viewRoot); @@ -313,7 +310,7 @@ public class SystemWindows { } } - class ContainerWindow extends IWindow.Stub { + static class ContainerWindow extends IWindow.Stub { ContainerWindow() {} @Override diff --git a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIModule.java b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIModule.java index e5fbbd87a91b5..5134f0071204e 100644 --- a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIModule.java +++ b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIModule.java @@ -132,9 +132,9 @@ public abstract class CarSystemUIModule { @Singleton @Provides - static SystemWindows provideSystemWindows(Context context, DisplayController displayController, + static SystemWindows provideSystemWindows(DisplayController displayController, IWindowManager wmService) { - return new SystemWindows(context, displayController, wmService); + return new SystemWindows(displayController, wmService); } @Singleton diff --git a/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java b/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java index 63f8c72b354a3..5c80202ba592b 100644 --- a/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java +++ b/packages/CarSystemUI/src/com/android/systemui/wm/DisplaySystemBarsController.java @@ -16,12 +16,14 @@ package com.android.systemui.wm; +import android.content.Context; import android.os.Handler; import android.os.RemoteException; import android.util.ArraySet; import android.util.Slog; import android.util.SparseArray; import android.view.IDisplayWindowInsetsController; +import android.view.IWindowManager; import android.view.InsetsController; import android.view.InsetsSourceControl; import android.view.InsetsState; @@ -32,7 +34,6 @@ import androidx.annotation.VisibleForTesting; import com.android.systemui.dagger.qualifiers.Main; import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.DisplayImeController; -import com.android.wm.shell.common.SystemWindows; import com.android.wm.shell.common.TransactionPool; import javax.inject.Inject; @@ -50,29 +51,32 @@ public class DisplaySystemBarsController extends DisplayImeController { private static final String TAG = "DisplaySystemBarsController"; private SparseArray mPerDisplaySparseArray; + private final Context mContext; @Inject public DisplaySystemBarsController( - SystemWindows syswin, + Context context, + IWindowManager wmService, DisplayController displayController, @Main Handler mainHandler, TransactionPool transactionPool) { - super(syswin, displayController, mainHandler, transactionPool); + super(wmService, displayController, mainHandler, transactionPool); + mContext = context; } @Override public void onDisplayAdded(int displayId) { PerDisplay pd = new PerDisplay(displayId); try { - mSystemWindows.mWmService.setDisplayWindowInsetsController(displayId, pd); + mWmService.setDisplayWindowInsetsController(displayId, pd); } catch (RemoteException e) { Slog.w(TAG, "Unable to set insets controller on display " + displayId); } // Lazy loading policy control filters instead of during boot. if (mPerDisplaySparseArray == null) { mPerDisplaySparseArray = new SparseArray<>(); - BarControlPolicy.reloadFromSetting(mSystemWindows.mContext); - BarControlPolicy.registerContentObserver(mSystemWindows.mContext, mHandler, () -> { + BarControlPolicy.reloadFromSetting(mContext); + BarControlPolicy.registerContentObserver(mContext, mHandler, () -> { int size = mPerDisplaySparseArray.size(); for (int i = 0; i < size; i++) { mPerDisplaySparseArray.valueAt(i).modifyDisplayWindowInsets(); @@ -85,7 +89,7 @@ public class DisplaySystemBarsController extends DisplayImeController { @Override public void onDisplayRemoved(int displayId) { try { - mSystemWindows.mWmService.setDisplayWindowInsetsController(displayId, null); + mWmService.setDisplayWindowInsetsController(displayId, null); } catch (RemoteException e) { Slog.w(TAG, "Unable to remove insets controller on display " + displayId); } @@ -155,7 +159,7 @@ public class DisplaySystemBarsController extends DisplayImeController { showInsets(barVisibilities[0], /* fromIme= */ false); hideInsets(barVisibilities[1], /* fromIme= */ false); try { - mSystemWindows.mWmService.modifyDisplayWindowInsets(mDisplayId, mInsetsState); + mWmService.modifyDisplayWindowInsets(mDisplayId, mInsetsState); } catch (RemoteException e) { Slog.w(TAG, "Unable to update window manager service."); } diff --git a/packages/CarSystemUI/tests/src/com/android/systemui/wm/DisplaySystemBarsControllerTest.java b/packages/CarSystemUI/tests/src/com/android/systemui/wm/DisplaySystemBarsControllerTest.java index 0f28d38f78787..391f75e353828 100644 --- a/packages/CarSystemUI/tests/src/com/android/systemui/wm/DisplaySystemBarsControllerTest.java +++ b/packages/CarSystemUI/tests/src/com/android/systemui/wm/DisplaySystemBarsControllerTest.java @@ -34,7 +34,6 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.wm.shell.common.DisplayController; -import com.android.wm.shell.common.SystemWindows; import com.android.wm.shell.common.TransactionPool; import org.junit.Before; @@ -52,8 +51,6 @@ public class DisplaySystemBarsControllerTest extends SysuiTestCase { private static final int DISPLAY_ID = 1; - @Mock - private SystemWindows mSystemWindows; @Mock private IWindowManager mIWindowManager; @Mock @@ -66,11 +63,10 @@ public class DisplaySystemBarsControllerTest extends SysuiTestCase { @Before public void setUp() { MockitoAnnotations.initMocks(this); - mSystemWindows.mContext = mContext; - mSystemWindows.mWmService = mIWindowManager; mController = new DisplaySystemBarsController( - mSystemWindows, + mContext, + mIWindowManager, mDisplayController, mHandler, mTransactionPool diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WindowManagerShellModule.java b/packages/SystemUI/src/com/android/systemui/wmshell/WindowManagerShellModule.java index bba5ff5b54ca8..fbc167683a2ae 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WindowManagerShellModule.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WindowManagerShellModule.java @@ -52,16 +52,16 @@ public class WindowManagerShellModule { @Singleton @Provides - static SystemWindows provideSystemWindows(Context context, DisplayController displayController, + static SystemWindows provideSystemWindows(DisplayController displayController, IWindowManager wmService) { - return new SystemWindows(context, displayController, wmService); + return new SystemWindows(displayController, wmService); } @Singleton @Provides static DisplayImeController provideDisplayImeController( - SystemWindows syswin, DisplayController displayController, + IWindowManager wmService, DisplayController displayController, @Main Handler mainHandler, TransactionPool transactionPool) { - return new DisplayImeController(syswin, displayController, mainHandler, transactionPool); + return new DisplayImeController(wmService, displayController, mainHandler, transactionPool); } }