Merge "Fix WindowManagerServiceTests touch tests" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c0a3c23ac0
@@ -67,7 +67,6 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.hardware.display.VirtualDisplay;
|
import android.hardware.display.VirtualDisplay;
|
||||||
@@ -515,12 +514,8 @@ public class WindowManagerServiceTests extends WindowTestsBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInTouchMode_instrumentedProcessGetPermissionToSwitchTouchMode() {
|
public void testSetInTouchMode_instrumentedProcessGetPermissionToSwitchTouchMode() {
|
||||||
// Disable global touch mode (config_perDisplayFocusEnabled set to true)
|
// Enable global touch mode
|
||||||
Resources mockResources = mock(Resources.class);
|
mWm.mPerDisplayFocusEnabled = true;
|
||||||
spyOn(mContext);
|
|
||||||
when(mContext.getResources()).thenReturn(mockResources);
|
|
||||||
doReturn(true).when(mockResources).getBoolean(
|
|
||||||
com.android.internal.R.bool.config_perDisplayFocusEnabled);
|
|
||||||
|
|
||||||
// Get current touch mode state and setup WMS to run setInTouchMode
|
// Get current touch mode state and setup WMS to run setInTouchMode
|
||||||
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
||||||
@@ -539,12 +534,8 @@ public class WindowManagerServiceTests extends WindowTestsBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInTouchMode_nonInstrumentedProcessDontGetPermissionToSwitchTouchMode() {
|
public void testSetInTouchMode_nonInstrumentedProcessDontGetPermissionToSwitchTouchMode() {
|
||||||
// Disable global touch mode (config_perDisplayFocusEnabled set to true)
|
// Enable global touch mode
|
||||||
Resources mockResources = mock(Resources.class);
|
mWm.mPerDisplayFocusEnabled = true;
|
||||||
spyOn(mContext);
|
|
||||||
when(mContext.getResources()).thenReturn(mockResources);
|
|
||||||
doReturn(true).when(mockResources).getBoolean(
|
|
||||||
com.android.internal.R.bool.config_perDisplayFocusEnabled);
|
|
||||||
|
|
||||||
// Get current touch mode state and setup WMS to run setInTouchMode
|
// Get current touch mode state and setup WMS to run setInTouchMode
|
||||||
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
||||||
@@ -563,6 +554,9 @@ public class WindowManagerServiceTests extends WindowTestsBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInTouchMode_multiDisplay_globalTouchModeUpdate() {
|
public void testSetInTouchMode_multiDisplay_globalTouchModeUpdate() {
|
||||||
|
// Disable global touch mode
|
||||||
|
mWm.mPerDisplayFocusEnabled = false;
|
||||||
|
|
||||||
// Create one extra display
|
// Create one extra display
|
||||||
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ false);
|
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ false);
|
||||||
final VirtualDisplay virtualDisplayOwnTouchMode =
|
final VirtualDisplay virtualDisplayOwnTouchMode =
|
||||||
@@ -570,17 +564,10 @@ public class WindowManagerServiceTests extends WindowTestsBase {
|
|||||||
final int numberOfDisplays = mWm.mRoot.mChildren.size();
|
final int numberOfDisplays = mWm.mRoot.mChildren.size();
|
||||||
assertThat(numberOfDisplays).isAtLeast(3);
|
assertThat(numberOfDisplays).isAtLeast(3);
|
||||||
final int numberOfGlobalTouchModeDisplays = (int) mWm.mRoot.mChildren.stream()
|
final int numberOfGlobalTouchModeDisplays = (int) mWm.mRoot.mChildren.stream()
|
||||||
.filter(d -> (d.getDisplay().getFlags() & FLAG_OWN_FOCUS) == 0)
|
.filter(d -> (d.getDisplay().getFlags() & FLAG_OWN_FOCUS) == 0)
|
||||||
.count();
|
.count();
|
||||||
assertThat(numberOfGlobalTouchModeDisplays).isAtLeast(2);
|
assertThat(numberOfGlobalTouchModeDisplays).isAtLeast(2);
|
||||||
|
|
||||||
// Enable global touch mode (config_perDisplayFocusEnabled set to false)
|
|
||||||
Resources mockResources = mock(Resources.class);
|
|
||||||
spyOn(mContext);
|
|
||||||
when(mContext.getResources()).thenReturn(mockResources);
|
|
||||||
doReturn(false).when(mockResources).getBoolean(
|
|
||||||
com.android.internal.R.bool.config_perDisplayFocusEnabled);
|
|
||||||
|
|
||||||
// Get current touch mode state and setup WMS to run setInTouchMode
|
// Get current touch mode state and setup WMS to run setInTouchMode
|
||||||
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
||||||
int callingPid = Binder.getCallingPid();
|
int callingPid = Binder.getCallingPid();
|
||||||
@@ -598,18 +585,14 @@ public class WindowManagerServiceTests extends WindowTestsBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInTouchMode_multiDisplay_perDisplayFocus_singleDisplayTouchModeUpdate() {
|
public void testSetInTouchMode_multiDisplay_perDisplayFocus_singleDisplayTouchModeUpdate() {
|
||||||
|
// Enable global touch mode
|
||||||
|
mWm.mPerDisplayFocusEnabled = true;
|
||||||
|
|
||||||
// Create one extra display
|
// Create one extra display
|
||||||
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ false);
|
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ false);
|
||||||
final int numberOfDisplays = mWm.mRoot.mChildren.size();
|
final int numberOfDisplays = mWm.mRoot.mChildren.size();
|
||||||
assertThat(numberOfDisplays).isAtLeast(2);
|
assertThat(numberOfDisplays).isAtLeast(2);
|
||||||
|
|
||||||
// Disable global touch mode (config_perDisplayFocusEnabled set to true)
|
|
||||||
Resources mockResources = mock(Resources.class);
|
|
||||||
spyOn(mContext);
|
|
||||||
when(mContext.getResources()).thenReturn(mockResources);
|
|
||||||
doReturn(true).when(mockResources).getBoolean(
|
|
||||||
com.android.internal.R.bool.config_perDisplayFocusEnabled);
|
|
||||||
|
|
||||||
// Get current touch mode state and setup WMS to run setInTouchMode
|
// Get current touch mode state and setup WMS to run setInTouchMode
|
||||||
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
||||||
int callingPid = Binder.getCallingPid();
|
int callingPid = Binder.getCallingPid();
|
||||||
@@ -628,18 +611,14 @@ public class WindowManagerServiceTests extends WindowTestsBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInTouchMode_multiDisplay_ownTouchMode_singleDisplayTouchModeUpdate() {
|
public void testSetInTouchMode_multiDisplay_ownTouchMode_singleDisplayTouchModeUpdate() {
|
||||||
|
// Disable global touch mode
|
||||||
|
mWm.mPerDisplayFocusEnabled = false;
|
||||||
|
|
||||||
// Create one extra display
|
// Create one extra display
|
||||||
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ true);
|
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ true);
|
||||||
final int numberOfDisplays = mWm.mRoot.mChildren.size();
|
final int numberOfDisplays = mWm.mRoot.mChildren.size();
|
||||||
assertThat(numberOfDisplays).isAtLeast(2);
|
assertThat(numberOfDisplays).isAtLeast(2);
|
||||||
|
|
||||||
// Enable global touch mode (config_perDisplayFocusEnabled set to false)
|
|
||||||
Resources mockResources = mock(Resources.class);
|
|
||||||
spyOn(mContext);
|
|
||||||
when(mContext.getResources()).thenReturn(mockResources);
|
|
||||||
doReturn(false).when(mockResources).getBoolean(
|
|
||||||
com.android.internal.R.bool.config_perDisplayFocusEnabled);
|
|
||||||
|
|
||||||
// Get current touch mode state and setup WMS to run setInTouchMode
|
// Get current touch mode state and setup WMS to run setInTouchMode
|
||||||
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
boolean currentTouchMode = mWm.isInTouchMode(DEFAULT_DISPLAY);
|
||||||
int callingPid = Binder.getCallingPid();
|
int callingPid = Binder.getCallingPid();
|
||||||
@@ -667,19 +646,14 @@ public class WindowManagerServiceTests extends WindowTestsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testSetInTouchModeOnAllDisplays(boolean perDisplayFocusEnabled) {
|
private void testSetInTouchModeOnAllDisplays(boolean perDisplayFocusEnabled) {
|
||||||
|
// Set global touch mode with the value passed as argument.
|
||||||
|
mWm.mPerDisplayFocusEnabled = perDisplayFocusEnabled;
|
||||||
|
|
||||||
// Create a couple of extra displays.
|
// Create a couple of extra displays.
|
||||||
// setInTouchModeOnAllDisplays should ignore the ownFocus setting.
|
// setInTouchModeOnAllDisplays should ignore the ownFocus setting.
|
||||||
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ false);
|
final VirtualDisplay virtualDisplay = createVirtualDisplay(/* ownFocus= */ false);
|
||||||
final VirtualDisplay virtualDisplayOwnFocus = createVirtualDisplay(/* ownFocus= */ true);
|
final VirtualDisplay virtualDisplayOwnFocus = createVirtualDisplay(/* ownFocus= */ true);
|
||||||
|
|
||||||
// Enable or disable global touch mode (config_perDisplayFocusEnabled setting).
|
|
||||||
// setInTouchModeOnAllDisplays should ignore this value.
|
|
||||||
Resources mockResources = mock(Resources.class);
|
|
||||||
spyOn(mContext);
|
|
||||||
when(mContext.getResources()).thenReturn(mockResources);
|
|
||||||
doReturn(perDisplayFocusEnabled).when(mockResources).getBoolean(
|
|
||||||
com.android.internal.R.bool.config_perDisplayFocusEnabled);
|
|
||||||
|
|
||||||
int callingPid = Binder.getCallingPid();
|
int callingPid = Binder.getCallingPid();
|
||||||
int callingUid = Binder.getCallingUid();
|
int callingUid = Binder.getCallingUid();
|
||||||
doReturn(false).when(mWm).checkCallingPermission(anyString(), anyString(), anyBoolean());
|
doReturn(false).when(mWm).checkCallingPermission(anyString(), anyString(), anyBoolean());
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
|||||||
*/
|
*/
|
||||||
private static boolean sOverridesCheckedTestDisplay;
|
private static boolean sOverridesCheckedTestDisplay;
|
||||||
|
|
||||||
|
private boolean mOriginalPerDisplayFocusEnabled;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpOnceBase() {
|
public static void setUpOnceBase() {
|
||||||
AttributeCache.init(getInstrumentation().getTargetContext());
|
AttributeCache.init(getInstrumentation().getTargetContext());
|
||||||
@@ -208,6 +210,7 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
|||||||
mSupervisor = mAtm.mTaskSupervisor;
|
mSupervisor = mAtm.mTaskSupervisor;
|
||||||
mRootWindowContainer = mAtm.mRootWindowContainer;
|
mRootWindowContainer = mAtm.mRootWindowContainer;
|
||||||
mWm = mSystemServicesTestRule.getWindowManagerService();
|
mWm = mSystemServicesTestRule.getWindowManagerService();
|
||||||
|
mOriginalPerDisplayFocusEnabled = mWm.mPerDisplayFocusEnabled;
|
||||||
SystemServicesTestRule.checkHoldsLock(mWm.mGlobalLock);
|
SystemServicesTestRule.checkHoldsLock(mWm.mGlobalLock);
|
||||||
|
|
||||||
mDefaultDisplay = mWm.mRoot.getDefaultDisplay();
|
mDefaultDisplay = mWm.mRoot.getDefaultDisplay();
|
||||||
@@ -279,6 +282,7 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
|||||||
if (mUseFakeSettingsProvider) {
|
if (mUseFakeSettingsProvider) {
|
||||||
FakeSettingsProvider.clearSettingsProvider();
|
FakeSettingsProvider.clearSettingsProvider();
|
||||||
}
|
}
|
||||||
|
mWm.mPerDisplayFocusEnabled = mOriginalPerDisplayFocusEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user