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
Merged-In: I562e271b7b350f06238f6291ed84c468cfb2d28a
This commit is contained in:
Yuncheol Heo
2023-04-05 17:42:13 -07:00
parent 5a2d1e8f80
commit bbe09689c2
5 changed files with 34 additions and 6 deletions

View File

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

View File

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

View File

@@ -3615,6 +3615,19 @@ public class WindowManagerService extends IWindowManager.Stub
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() {
synchronized (mGlobalLock) {
ProtoLog.i(WM_DEBUG_BOOT, "enableScreenAfterBoot: mDisplayEnabled=%b "

View File

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

View File

@@ -78,6 +78,7 @@ import com.android.server.GestureLauncherService;
import com.android.server.LocalServices;
import com.android.server.input.InputManagerInternal;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.pm.UserManagerInternal;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
@@ -118,6 +119,7 @@ class TestPhoneWindowManager {
@Mock private PowerManager mPowerManager;
@Mock private WindowManagerPolicy.WindowManagerFuncs mWindowManagerFuncsImpl;
@Mock private InputMethodManagerInternal mInputMethodManagerInternal;
@Mock private UserManagerInternal mUserManagerInternal;
@Mock private AudioManagerInternal mAudioManagerInternal;
@Mock private SearchManager mSearchManager;
@@ -186,6 +188,8 @@ class TestPhoneWindowManager {
() -> LocalServices.getService(eq(DisplayManagerInternal.class)));
doReturn(mGestureLauncherService).when(
() -> 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(AutofillManagerInternal.class)));
LocalServices.removeServiceForTest(InputMethodManagerInternal.class);