Send HOME Intent for the main display of the visibule user, with the visible userId.

Previously CATEGORY_HOME is used for the default display, and
CATEGORY_SECONDARY_HOME is used for all non-default displays with
the current user id. But, in the concurrent multi user enviorment,
we should use CATEGORY_HOME Intent for each user's main display,
CATEGORY_SECONDARY_HOME for the others.

This CL fixes
- to use CATEGORY_HOME for main displays assigned to concurrent users.
- to send HOME Intent with the correct userId.

Bug: 272281432
Test: atest MultiDisplaySystemDecorationTests
Change-Id: I562e271b7b350f06238f6291ed84c468cfb2d28a
This commit is contained in:
Yuncheol Heo
2023-04-05 17:42:13 -07:00
parent 98f21b18f3
commit 9d5f4681e5
5 changed files with 34 additions and 6 deletions

View File

@@ -218,6 +218,7 @@ import com.android.server.UiThread;
import com.android.server.display.BrightnessUtils; import com.android.server.display.BrightnessUtils;
import com.android.server.input.InputManagerInternal; import com.android.server.input.InputManagerInternal;
import com.android.server.inputmethod.InputMethodManagerInternal; import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.pm.UserManagerInternal;
import com.android.server.policy.KeyCombinationManager.TwoKeysCombinationRule; import com.android.server.policy.KeyCombinationManager.TwoKeysCombinationRule;
import com.android.server.policy.keyguard.KeyguardServiceDelegate; import com.android.server.policy.keyguard.KeyguardServiceDelegate;
import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
@@ -415,6 +416,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
SensorPrivacyManager mSensorPrivacyManager; SensorPrivacyManager mSensorPrivacyManager;
DisplayManager mDisplayManager; DisplayManager mDisplayManager;
DisplayManagerInternal mDisplayManagerInternal; DisplayManagerInternal mDisplayManagerInternal;
UserManagerInternal mUserManagerInternal;
private WallpaperManagerInternal mWallpaperManagerInternal; private WallpaperManagerInternal mWallpaperManagerInternal;
@@ -2059,6 +2061,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mSensorPrivacyManager = mContext.getSystemService(SensorPrivacyManager.class); mSensorPrivacyManager = mContext.getSystemService(SensorPrivacyManager.class);
mDisplayManager = mContext.getSystemService(DisplayManager.class); mDisplayManager = mContext.getSystemService(DisplayManager.class);
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
mPackageManager = mContext.getPackageManager(); mPackageManager = mContext.getPackageManager();
mHasFeatureWatch = mPackageManager.hasSystemFeature(FEATURE_WATCH); mHasFeatureWatch = mPackageManager.hasSystemFeature(FEATURE_WATCH);
mHasFeatureLeanback = mPackageManager.hasSystemFeature(FEATURE_LEANBACK); mHasFeatureLeanback = mPackageManager.hasSystemFeature(FEATURE_LEANBACK);
@@ -5781,8 +5784,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Log.d(TAG, "startDockOrHome: startReason= " + startReason); Log.d(TAG, "startDockOrHome: startReason= " + startReason);
} }
int userId = mUserManagerInternal.getUserAssignedToDisplay(displayId);
// Start home. // Start home.
mActivityTaskManagerInternal.startHomeOnDisplay(mCurrentUserId, startReason, mActivityTaskManagerInternal.startHomeOnDisplay(userId, startReason,
displayId, true /* allowInstrumenting */, fromHomeKey); displayId, true /* allowInstrumenting */, fromHomeKey);
} }

View File

@@ -1374,7 +1374,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
void startHomeOnEmptyDisplays(String reason) { void startHomeOnEmptyDisplays(String reason) {
forAllTaskDisplayAreas(taskDisplayArea -> { forAllTaskDisplayAreas(taskDisplayArea -> {
if (taskDisplayArea.topRunningActivity() == null) { if (taskDisplayArea.topRunningActivity() == null) {
startHomeOnTaskDisplayArea(mCurrentUser, reason, taskDisplayArea, int userId = mWmService.getUserAssignedToDisplay(taskDisplayArea.getDisplayId());
startHomeOnTaskDisplayArea(userId, reason, taskDisplayArea,
false /* allowInstrumenting */, false /* fromHomeKey */); false /* allowInstrumenting */, false /* fromHomeKey */);
} }
}); });
@@ -1422,7 +1423,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
Intent homeIntent = null; Intent homeIntent = null;
ActivityInfo aInfo = null; ActivityInfo aInfo = null;
if (taskDisplayArea == getDefaultTaskDisplayArea()) { if (taskDisplayArea == getDefaultTaskDisplayArea()
|| mWmService.shouldPlacePrimaryHomeOnDisplay(
taskDisplayArea.getDisplayId(), userId)) {
homeIntent = mService.getHomeIntent(); homeIntent = mService.getHomeIntent();
aInfo = resolveHomeActivity(userId, homeIntent); aInfo = resolveHomeActivity(userId, homeIntent);
} else if (shouldPlaceSecondaryHomeOnDisplayArea(taskDisplayArea)) { } else if (shouldPlaceSecondaryHomeOnDisplayArea(taskDisplayArea)) {
@@ -1589,7 +1592,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
r.moveFocusableActivityToTop(myReason); r.moveFocusableActivityToTop(myReason);
return resumeFocusedTasksTopActivities(r.getRootTask(), prev, null); return resumeFocusedTasksTopActivities(r.getRootTask(), prev, null);
} }
return startHomeOnTaskDisplayArea(mCurrentUser, myReason, taskDisplayArea, int userId = mWmService.getUserAssignedToDisplay(taskDisplayArea.getDisplayId());
return startHomeOnTaskDisplayArea(userId, myReason, taskDisplayArea,
false /* allowInstrumenting */, false /* fromHomeKey */); false /* allowInstrumenting */, false /* fromHomeKey */);
} }
@@ -1667,8 +1671,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
final int displayId = taskDisplayArea != null ? taskDisplayArea.getDisplayId() final int displayId = taskDisplayArea != null ? taskDisplayArea.getDisplayId()
: INVALID_DISPLAY; : INVALID_DISPLAY;
if (displayId == DEFAULT_DISPLAY || (displayId != INVALID_DISPLAY if (displayId == DEFAULT_DISPLAY || (displayId != INVALID_DISPLAY
&& displayId == mService.mVr2dDisplayId)) { && (displayId == mService.mVr2dDisplayId
// No restrictions to default display or vr 2d display. || mWmService.shouldPlacePrimaryHomeOnDisplay(displayId)))) {
// No restrictions to default display, vr 2d display or main display for visible users.
return true; return true;
} }

View File

@@ -3613,6 +3613,19 @@ public class WindowManagerService extends IWindowManager.Stub
return mUmInternal.isUserVisible(userId); return mUmInternal.isUserVisible(userId);
} }
@UserIdInt int getUserAssignedToDisplay(int displayId) {
return mUmInternal.getUserAssignedToDisplay(displayId);
}
boolean shouldPlacePrimaryHomeOnDisplay(int displayId) {
int userId = mUmInternal.getUserAssignedToDisplay(displayId);
return shouldPlacePrimaryHomeOnDisplay(displayId, userId);
}
boolean shouldPlacePrimaryHomeOnDisplay(int displayId, int userId) {
return mUmInternal.getMainDisplayAssignedToUser(userId) == displayId;
}
public void enableScreenAfterBoot() { public void enableScreenAfterBoot() {
synchronized (mGlobalLock) { synchronized (mGlobalLock) {
ProtoLog.i(WM_DEBUG_BOOT, "enableScreenAfterBoot: mDisplayEnabled=%b " ProtoLog.i(WM_DEBUG_BOOT, "enableScreenAfterBoot: mDisplayEnabled=%b "

View File

@@ -34,6 +34,7 @@ import android.app.ActivityManager;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import com.android.server.pm.UserManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal; import com.android.server.wm.ActivityTaskManagerInternal;
import org.junit.After; import org.junit.After;
@@ -91,5 +92,6 @@ public class PhoneWindowManagerTests {
when(mMockActivityTaskManagerInternal.startHomeOnDisplay( when(mMockActivityTaskManagerInternal.startHomeOnDisplay(
anyInt(), anyString(), anyInt(), anyBoolean(), anyBoolean())).thenReturn(false); anyInt(), anyString(), anyInt(), anyBoolean(), anyBoolean())).thenReturn(false);
mPhoneWindowManager.mActivityTaskManagerInternal = mMockActivityTaskManagerInternal; mPhoneWindowManager.mActivityTaskManagerInternal = mMockActivityTaskManagerInternal;
mPhoneWindowManager.mUserManagerInternal = mock(UserManagerInternal.class);
} }
} }

View File

@@ -82,6 +82,7 @@ import com.android.server.GestureLauncherService;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.input.InputManagerInternal; import com.android.server.input.InputManagerInternal;
import com.android.server.inputmethod.InputMethodManagerInternal; import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.pm.UserManagerInternal;
import com.android.server.policy.keyguard.KeyguardServiceDelegate; import com.android.server.policy.keyguard.KeyguardServiceDelegate;
import com.android.server.statusbar.StatusBarManagerInternal; import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal; import com.android.server.vr.VrManagerInternal;
@@ -125,6 +126,7 @@ class TestPhoneWindowManager {
@Mock private PowerManager mPowerManager; @Mock private PowerManager mPowerManager;
@Mock private WindowManagerPolicy.WindowManagerFuncs mWindowManagerFuncsImpl; @Mock private WindowManagerPolicy.WindowManagerFuncs mWindowManagerFuncsImpl;
@Mock private InputMethodManagerInternal mInputMethodManagerInternal; @Mock private InputMethodManagerInternal mInputMethodManagerInternal;
@Mock private UserManagerInternal mUserManagerInternal;
@Mock private AudioManagerInternal mAudioManagerInternal; @Mock private AudioManagerInternal mAudioManagerInternal;
@Mock private SearchManager mSearchManager; @Mock private SearchManager mSearchManager;
@@ -199,6 +201,8 @@ class TestPhoneWindowManager {
() -> LocalServices.getService(eq(DisplayManagerInternal.class))); () -> LocalServices.getService(eq(DisplayManagerInternal.class)));
doReturn(mGestureLauncherService).when( doReturn(mGestureLauncherService).when(
() -> LocalServices.getService(eq(GestureLauncherService.class))); () -> LocalServices.getService(eq(GestureLauncherService.class)));
doReturn(mUserManagerInternal).when(
() -> LocalServices.getService(eq(UserManagerInternal.class)));
doReturn(null).when(() -> LocalServices.getService(eq(VrManagerInternal.class))); doReturn(null).when(() -> LocalServices.getService(eq(VrManagerInternal.class)));
doReturn(null).when(() -> LocalServices.getService(eq(AutofillManagerInternal.class))); doReturn(null).when(() -> LocalServices.getService(eq(AutofillManagerInternal.class)));
LocalServices.removeServiceForTest(InputMethodManagerInternal.class); LocalServices.removeServiceForTest(InputMethodManagerInternal.class);