Loading core/java/android/app/Instrumentation.java +38 −0 Original line number Diff line number Diff line Loading @@ -43,8 +43,10 @@ import android.os.ServiceManager; import android.os.SystemClock; import android.os.TestLooperManager; import android.os.UserHandle; import android.os.UserManager; import android.util.AndroidRuntimeException; import android.util.Log; import android.view.Display; import android.view.IWindowManager; import android.view.InputDevice; import android.view.KeyCharacterMap; Loading Loading @@ -93,6 +95,8 @@ public class Instrumentation { private static final long CONNECT_TIMEOUT_MILLIS = 5000; private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); /** * @hide */ Loading Loading @@ -1124,10 +1128,44 @@ public class Instrumentation { newEvent.setTime(downTime, eventTime); newEvent.setSource(source); newEvent.setFlags(event.getFlags() | KeyEvent.FLAG_FROM_SYSTEM); setDisplayIfNeeded(newEvent); InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); } private void setDisplayIfNeeded(KeyEvent event) { if (!UserManager.isVisibleBackgroundUsersEnabled()) { return; } // In devices that support visible background users visible, the display id must be set to // reflect the display the user was started visible on, otherwise the event would be sent to // the main display (which would most likely fail the test). int eventDisplayId = event.getDisplayId(); if (eventDisplayId != Display.INVALID_DISPLAY) { if (VERBOSE) { Log.v(TAG, "setDisplayIfNeeded(" + event + "): not changing display id as it's " + "explicitly set to " + eventDisplayId); } return; } UserManager userManager = mInstrContext.getSystemService(UserManager.class); int userDisplayId = userManager.getDisplayIdAssignedToUser(); if (VERBOSE) { Log.v(TAG, "setDisplayIfNeeded(" + event + "): eventDisplayId=" + eventDisplayId + ", user=" + mInstrContext.getUser() + ", userDisplayId=" + userDisplayId); } if (userDisplayId == Display.INVALID_DISPLAY) { Log.e(TAG, "setDisplayIfNeeded(" + event + "): UserManager returned INVALID_DISPLAY as " + "display assigned to user " + mInstrContext.getUser()); return; } event.setDisplayId(userDisplayId); } /** * Sends up and down key events with the given key code to the currently focused window, and * waits for it to be processed. Loading core/java/android/os/IUserManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ interface IUserManager { boolean isUserForeground(int userId); boolean isUserVisible(int userId); int[] getVisibleUsers(); int getDisplayIdAssignedToUser(); boolean isUserNameSet(int userId); boolean hasRestrictedProfiles(int userId); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target, int flags); Loading core/java/android/os/UserManager.java +13 −0 Original line number Diff line number Diff line Loading @@ -3051,6 +3051,19 @@ public class UserManager { return result; } /** * See {@link com.android.server.pm.UserManagerInternal#getDisplayAssignedToUser(int)}. * * @hide */ public int getDisplayIdAssignedToUser() { try { return mService.getDisplayIdAssignedToUser(); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } /** * Return whether the context user is running in an "unlocked" state. * <p> Loading services/core/java/com/android/server/pm/UserManagerService.java +8 −0 Original line number Diff line number Diff line Loading @@ -1961,6 +1961,14 @@ public class UserManagerService extends IUserManager.Stub { } } @Override public int getDisplayIdAssignedToUser() { // Not checking for any permission as it returns info about calling user int userId = UserHandle.getUserId(Binder.getCallingUid()); int displayId = mUserVisibilityMediator.getDisplayAssignedToUser(userId); return displayId; } @Override public @NonNull String getUserName() { final int callingUid = Binder.getCallingUid(); Loading Loading
core/java/android/app/Instrumentation.java +38 −0 Original line number Diff line number Diff line Loading @@ -43,8 +43,10 @@ import android.os.ServiceManager; import android.os.SystemClock; import android.os.TestLooperManager; import android.os.UserHandle; import android.os.UserManager; import android.util.AndroidRuntimeException; import android.util.Log; import android.view.Display; import android.view.IWindowManager; import android.view.InputDevice; import android.view.KeyCharacterMap; Loading Loading @@ -93,6 +95,8 @@ public class Instrumentation { private static final long CONNECT_TIMEOUT_MILLIS = 5000; private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); /** * @hide */ Loading Loading @@ -1124,10 +1128,44 @@ public class Instrumentation { newEvent.setTime(downTime, eventTime); newEvent.setSource(source); newEvent.setFlags(event.getFlags() | KeyEvent.FLAG_FROM_SYSTEM); setDisplayIfNeeded(newEvent); InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); } private void setDisplayIfNeeded(KeyEvent event) { if (!UserManager.isVisibleBackgroundUsersEnabled()) { return; } // In devices that support visible background users visible, the display id must be set to // reflect the display the user was started visible on, otherwise the event would be sent to // the main display (which would most likely fail the test). int eventDisplayId = event.getDisplayId(); if (eventDisplayId != Display.INVALID_DISPLAY) { if (VERBOSE) { Log.v(TAG, "setDisplayIfNeeded(" + event + "): not changing display id as it's " + "explicitly set to " + eventDisplayId); } return; } UserManager userManager = mInstrContext.getSystemService(UserManager.class); int userDisplayId = userManager.getDisplayIdAssignedToUser(); if (VERBOSE) { Log.v(TAG, "setDisplayIfNeeded(" + event + "): eventDisplayId=" + eventDisplayId + ", user=" + mInstrContext.getUser() + ", userDisplayId=" + userDisplayId); } if (userDisplayId == Display.INVALID_DISPLAY) { Log.e(TAG, "setDisplayIfNeeded(" + event + "): UserManager returned INVALID_DISPLAY as " + "display assigned to user " + mInstrContext.getUser()); return; } event.setDisplayId(userDisplayId); } /** * Sends up and down key events with the given key code to the currently focused window, and * waits for it to be processed. Loading
core/java/android/os/IUserManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ interface IUserManager { boolean isUserForeground(int userId); boolean isUserVisible(int userId); int[] getVisibleUsers(); int getDisplayIdAssignedToUser(); boolean isUserNameSet(int userId); boolean hasRestrictedProfiles(int userId); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target, int flags); Loading
core/java/android/os/UserManager.java +13 −0 Original line number Diff line number Diff line Loading @@ -3051,6 +3051,19 @@ public class UserManager { return result; } /** * See {@link com.android.server.pm.UserManagerInternal#getDisplayAssignedToUser(int)}. * * @hide */ public int getDisplayIdAssignedToUser() { try { return mService.getDisplayIdAssignedToUser(); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } /** * Return whether the context user is running in an "unlocked" state. * <p> Loading
services/core/java/com/android/server/pm/UserManagerService.java +8 −0 Original line number Diff line number Diff line Loading @@ -1961,6 +1961,14 @@ public class UserManagerService extends IUserManager.Stub { } } @Override public int getDisplayIdAssignedToUser() { // Not checking for any permission as it returns info about calling user int userId = UserHandle.getUserId(Binder.getCallingUid()); int displayId = mUserVisibilityMediator.getDisplayAssignedToUser(userId); return displayId; } @Override public @NonNull String getUserName() { final int callingUid = Binder.getCallingUid(); Loading