Loading libs/WindowManager/Shell/src/com/android/wm/shell/common/DockStateReader.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 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.wm.shell.common; import static android.content.Intent.EXTRA_DOCK_STATE; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import com.android.wm.shell.dagger.WMSingleton; import javax.inject.Inject; /** * Provides information about the docked state of the device. */ @WMSingleton public class DockStateReader { private static final IntentFilter DOCK_INTENT_FILTER = new IntentFilter( Intent.ACTION_DOCK_EVENT); private final Context mContext; @Inject public DockStateReader(Context context) { mContext = context; } /** * @return True if the device is docked and false otherwise. */ public boolean isDocked() { Intent dockStatus = mContext.registerReceiver(/* receiver */ null, DOCK_INTENT_FILTER); if (dockStatus != null) { int dockState = dockStatus.getIntExtra(EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED); return dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED; } return false; } } libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java +7 −2 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayInsetsController.OnInsetsChangedListener; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.compatui.CompatUIWindowManager.CompatUIHintsState; Loading Loading @@ -109,6 +110,7 @@ public class CompatUIController implements OnDisplaysChangedListener, private final SyncTransactionQueue mSyncQueue; private final ShellExecutor mMainExecutor; private final Lazy<Transitions> mTransitionsLazy; private final DockStateReader mDockStateReader; private CompatUICallback mCallback; Loading @@ -127,7 +129,8 @@ public class CompatUIController implements OnDisplaysChangedListener, DisplayImeController imeController, SyncTransactionQueue syncQueue, ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy) { Lazy<Transitions> transitionsLazy, DockStateReader dockStateReader) { mContext = context; mShellController = shellController; mDisplayController = displayController; Loading @@ -138,6 +141,7 @@ public class CompatUIController implements OnDisplaysChangedListener, mTransitionsLazy = transitionsLazy; mCompatUIHintsState = new CompatUIHintsState(); shellInit.addInitCallback(this::onInit, this); mDockStateReader = dockStateReader; } private void onInit() { Loading Loading @@ -315,7 +319,8 @@ public class CompatUIController implements OnDisplaysChangedListener, return new LetterboxEduWindowManager(context, taskInfo, mSyncQueue, taskListener, mDisplayController.getDisplayLayout(taskInfo.displayId), mTransitionsLazy.get(), this::onLetterboxEduDismissed); this::onLetterboxEduDismissed, mDockStateReader); } private void onLetterboxEduDismissed() { Loading libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduWindowManager.java +11 −5 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.wm.shell.R; import com.android.wm.shell.ShellTaskOrganizer; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.compatui.CompatUIWindowManagerAbstract; import com.android.wm.shell.transition.Transitions; Loading Loading @@ -88,19 +89,21 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { */ private final int mDialogVerticalMargin; private final DockStateReader mDockStateReader; public LetterboxEduWindowManager(Context context, TaskInfo taskInfo, SyncTransactionQueue syncQueue, ShellTaskOrganizer.TaskListener taskListener, DisplayLayout displayLayout, Transitions transitions, Runnable onDismissCallback) { Runnable onDismissCallback, DockStateReader dockStateReader) { this(context, taskInfo, syncQueue, taskListener, displayLayout, transitions, onDismissCallback, new LetterboxEduAnimationController(context)); onDismissCallback, new LetterboxEduAnimationController(context), dockStateReader); } @VisibleForTesting LetterboxEduWindowManager(Context context, TaskInfo taskInfo, SyncTransactionQueue syncQueue, ShellTaskOrganizer.TaskListener taskListener, DisplayLayout displayLayout, Transitions transitions, Runnable onDismissCallback, LetterboxEduAnimationController animationController) { LetterboxEduAnimationController animationController, DockStateReader dockStateReader) { super(context, taskInfo, syncQueue, taskListener, displayLayout); mTransitions = transitions; mOnDismissCallback = onDismissCallback; Loading @@ -111,6 +114,7 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { Context.MODE_PRIVATE); mDialogVerticalMargin = (int) mContext.getResources().getDimension( R.dimen.letterbox_education_dialog_margin); mDockStateReader = dockStateReader; } @Override Loading @@ -130,13 +134,15 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { @Override protected boolean eligibleToShowLayout() { // - The letterbox education should not be visible if the device is docked. // - If taskbar education is showing, the letterbox education shouldn't be shown for the // given task until the taskbar education is dismissed and the compat info changes (then // the controller will create a new instance of this class since this one isn't eligible). // - If the layout isn't null then it was previously showing, and we shouldn't check if the // user has seen the letterbox education before. return mEligibleForLetterboxEducation && !isTaskbarEduShowing() && (mLayout != null || !getHasSeenLetterboxEducation()); return mEligibleForLetterboxEducation && !isTaskbarEduShowing() && (mLayout != null || !getHasSeenLetterboxEducation()) && !mDockStateReader.isDocked(); } @Override Loading libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java +5 −2 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; Loading Loading @@ -196,9 +197,11 @@ public abstract class WMShellBaseModule { ShellController shellController, DisplayController displayController, DisplayInsetsController displayInsetsController, DisplayImeController imeController, SyncTransactionQueue syncQueue, @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy) { @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy, DockStateReader dockStateReader) { return new CompatUIController(context, shellInit, shellController, displayController, displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy); displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy, dockStateReader); } @WMSingleton Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayInsetsController.OnInsetsChangedListener; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.compatui.letterboxedu.LetterboxEduWindowManager; Loading Loading @@ -93,6 +94,7 @@ public class CompatUIControllerTest extends ShellTestCase { private @Mock Lazy<Transitions> mMockTransitionsLazy; private @Mock CompatUIWindowManager mMockCompatLayout; private @Mock LetterboxEduWindowManager mMockLetterboxEduLayout; private @Mock DockStateReader mDockStateReader; @Captor ArgumentCaptor<OnInsetsChangedListener> mOnInsetsChangedListenerCaptor; Loading @@ -113,7 +115,7 @@ public class CompatUIControllerTest extends ShellTestCase { mShellInit = spy(new ShellInit(mMockExecutor)); mController = new CompatUIController(mContext, mShellInit, mMockShellController, mMockDisplayController, mMockDisplayInsetsController, mMockImeController, mMockSyncQueue, mMockExecutor, mMockTransitionsLazy) { mMockSyncQueue, mMockExecutor, mMockTransitionsLazy, mDockStateReader) { @Override CompatUIWindowManager createCompatUiWindowManager(Context context, TaskInfo taskInfo, ShellTaskOrganizer.TaskListener taskListener) { Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/common/DockStateReader.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 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.wm.shell.common; import static android.content.Intent.EXTRA_DOCK_STATE; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import com.android.wm.shell.dagger.WMSingleton; import javax.inject.Inject; /** * Provides information about the docked state of the device. */ @WMSingleton public class DockStateReader { private static final IntentFilter DOCK_INTENT_FILTER = new IntentFilter( Intent.ACTION_DOCK_EVENT); private final Context mContext; @Inject public DockStateReader(Context context) { mContext = context; } /** * @return True if the device is docked and false otherwise. */ public boolean isDocked() { Intent dockStatus = mContext.registerReceiver(/* receiver */ null, DOCK_INTENT_FILTER); if (dockStatus != null) { int dockState = dockStatus.getIntExtra(EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED); return dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED; } return false; } }
libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java +7 −2 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayInsetsController.OnInsetsChangedListener; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.compatui.CompatUIWindowManager.CompatUIHintsState; Loading Loading @@ -109,6 +110,7 @@ public class CompatUIController implements OnDisplaysChangedListener, private final SyncTransactionQueue mSyncQueue; private final ShellExecutor mMainExecutor; private final Lazy<Transitions> mTransitionsLazy; private final DockStateReader mDockStateReader; private CompatUICallback mCallback; Loading @@ -127,7 +129,8 @@ public class CompatUIController implements OnDisplaysChangedListener, DisplayImeController imeController, SyncTransactionQueue syncQueue, ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy) { Lazy<Transitions> transitionsLazy, DockStateReader dockStateReader) { mContext = context; mShellController = shellController; mDisplayController = displayController; Loading @@ -138,6 +141,7 @@ public class CompatUIController implements OnDisplaysChangedListener, mTransitionsLazy = transitionsLazy; mCompatUIHintsState = new CompatUIHintsState(); shellInit.addInitCallback(this::onInit, this); mDockStateReader = dockStateReader; } private void onInit() { Loading Loading @@ -315,7 +319,8 @@ public class CompatUIController implements OnDisplaysChangedListener, return new LetterboxEduWindowManager(context, taskInfo, mSyncQueue, taskListener, mDisplayController.getDisplayLayout(taskInfo.displayId), mTransitionsLazy.get(), this::onLetterboxEduDismissed); this::onLetterboxEduDismissed, mDockStateReader); } private void onLetterboxEduDismissed() { Loading
libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduWindowManager.java +11 −5 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.wm.shell.R; import com.android.wm.shell.ShellTaskOrganizer; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.compatui.CompatUIWindowManagerAbstract; import com.android.wm.shell.transition.Transitions; Loading Loading @@ -88,19 +89,21 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { */ private final int mDialogVerticalMargin; private final DockStateReader mDockStateReader; public LetterboxEduWindowManager(Context context, TaskInfo taskInfo, SyncTransactionQueue syncQueue, ShellTaskOrganizer.TaskListener taskListener, DisplayLayout displayLayout, Transitions transitions, Runnable onDismissCallback) { Runnable onDismissCallback, DockStateReader dockStateReader) { this(context, taskInfo, syncQueue, taskListener, displayLayout, transitions, onDismissCallback, new LetterboxEduAnimationController(context)); onDismissCallback, new LetterboxEduAnimationController(context), dockStateReader); } @VisibleForTesting LetterboxEduWindowManager(Context context, TaskInfo taskInfo, SyncTransactionQueue syncQueue, ShellTaskOrganizer.TaskListener taskListener, DisplayLayout displayLayout, Transitions transitions, Runnable onDismissCallback, LetterboxEduAnimationController animationController) { LetterboxEduAnimationController animationController, DockStateReader dockStateReader) { super(context, taskInfo, syncQueue, taskListener, displayLayout); mTransitions = transitions; mOnDismissCallback = onDismissCallback; Loading @@ -111,6 +114,7 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { Context.MODE_PRIVATE); mDialogVerticalMargin = (int) mContext.getResources().getDimension( R.dimen.letterbox_education_dialog_margin); mDockStateReader = dockStateReader; } @Override Loading @@ -130,13 +134,15 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { @Override protected boolean eligibleToShowLayout() { // - The letterbox education should not be visible if the device is docked. // - If taskbar education is showing, the letterbox education shouldn't be shown for the // given task until the taskbar education is dismissed and the compat info changes (then // the controller will create a new instance of this class since this one isn't eligible). // - If the layout isn't null then it was previously showing, and we shouldn't check if the // user has seen the letterbox education before. return mEligibleForLetterboxEducation && !isTaskbarEduShowing() && (mLayout != null || !getHasSeenLetterboxEducation()); return mEligibleForLetterboxEducation && !isTaskbarEduShowing() && (mLayout != null || !getHasSeenLetterboxEducation()) && !mDockStateReader.isDocked(); } @Override Loading
libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java +5 −2 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; Loading Loading @@ -196,9 +197,11 @@ public abstract class WMShellBaseModule { ShellController shellController, DisplayController displayController, DisplayInsetsController displayInsetsController, DisplayImeController imeController, SyncTransactionQueue syncQueue, @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy) { @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy, DockStateReader dockStateReader) { return new CompatUIController(context, shellInit, shellController, displayController, displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy); displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy, dockStateReader); } @WMSingleton Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayInsetsController.OnInsetsChangedListener; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.compatui.letterboxedu.LetterboxEduWindowManager; Loading Loading @@ -93,6 +94,7 @@ public class CompatUIControllerTest extends ShellTestCase { private @Mock Lazy<Transitions> mMockTransitionsLazy; private @Mock CompatUIWindowManager mMockCompatLayout; private @Mock LetterboxEduWindowManager mMockLetterboxEduLayout; private @Mock DockStateReader mDockStateReader; @Captor ArgumentCaptor<OnInsetsChangedListener> mOnInsetsChangedListenerCaptor; Loading @@ -113,7 +115,7 @@ public class CompatUIControllerTest extends ShellTestCase { mShellInit = spy(new ShellInit(mMockExecutor)); mController = new CompatUIController(mContext, mShellInit, mMockShellController, mMockDisplayController, mMockDisplayInsetsController, mMockImeController, mMockSyncQueue, mMockExecutor, mMockTransitionsLazy) { mMockSyncQueue, mMockExecutor, mMockTransitionsLazy, mDockStateReader) { @Override CompatUIWindowManager createCompatUiWindowManager(Context context, TaskInfo taskInfo, ShellTaskOrganizer.TaskListener taskListener) { Loading