summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author junseok01.lee <junseok01.lee@lge.com> 2025-02-20 08:49:20 -0800
committer BK Choi <bkchoi@google.com> 2025-02-20 08:54:39 -0800
commit46e10f86bbeb39ac4adae8b58e98b5e8aed4d9a8 (patch)
tree5d16e6db2f7f19b00453206d3a0ed9260914869f
parent7c87f8e65bb8fa7eec6d037f2d761337c507d63e (diff)
fix UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled
secondary_user_on_secondary_display is for background users that have access to UI on assigned displays (a.k.a. visible background users) on devices that have config_multiuserVisibleBackgroundUsers enabled. The main use case is Automotive's multi-display Whole Cabin experience where passengers (modeled as visible background users) can interact with the display in front of them concurrently with the driver (modeled as the the current user) interacting with driver's display. A11yMS replaces the current user ID of A11yMS with the ID of the visible background user through the workaround code A11yMS.changeCurrentUserForTestAutomationIfNeededLocked when the visible background user is utilizing the service. If this value is provided as an input parameter to UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled, it may lead to malfunctions, as this value does not correspond to the actual current user ID. The structure of accepting the current user ID as an input parameter in UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled can result in such errors; therefore, it would be better to utilize ActivityManager.getCurrentUser within the function to obtain the current user ID. Fixes include - Removed the input parameter for UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled that accepts the current user ID. - Ensured that UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled retrieves the current user ID using ActivityManager.getCurrentUser within its implementation Bug: 395311248 Flag: EXEMPT bugfix Test: atest CtsUiAutomationTestCases atest CtsUiAutomationTestCases --user-type secondary_user atest CtsUiAutomationTestCases --user-type secondary_user_on_secondary_display atest CtsAppTestCases:android.app.cts.UiModeManagerTest atest CtsAppTestCases:android.app.cts.UiModeManagerTest --user-type secondary_user atest CtsAppTestCases:android.app.cts.UiModeManagerTest --user-type secondary_user_on_secondary_display atest FrameworksServicesTests:com.android.server.accessibility.AccessibilityManagerServiceTest atest FrameworksUiServicesTests:com.android.server.UiModeManagerServiceTest (cherry picked from https://partner-android-review.googlesource.com/q/commit:7e327fdc350126b63af06e913faabe208bb081c0) Change-Id: Icbf357ecd348eb4bf6421334dc5263ee12ebcc66
-rw-r--r--services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java10
-rw-r--r--services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java26
-rw-r--r--services/core/java/com/android/server/UiModeManagerService.java16
-rw-r--r--services/core/java/com/android/server/pm/UserManagerService.java18
4 files changed, 25 insertions, 45 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
index 4b042489f3eb..47aa8f5736bf 100644
--- a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
+++ b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
@@ -1115,14 +1115,12 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
if (svcConnTracingEnabled()) {
logTraceSvcConn("performGlobalAction", "action=" + action);
}
- int currentUserId;
synchronized (mLock) {
if (!hasRightsToCurrentUserLocked()) {
return false;
}
- currentUserId = mSystemSupport.getCurrentUserIdLocked();
}
- enforceCurrentUserIfVisibleBackgroundEnabled(currentUserId);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
final long identity = Binder.clearCallingIdentity();
try {
return mSystemActionPerformer.performSystemAction(action);
@@ -2791,11 +2789,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
@RequiresNoPermission
@Override
public void setAnimationScale(float scale) {
- int currentUserId;
- synchronized (mLock) {
- currentUserId = mSystemSupport.getCurrentUserIdLocked();
- }
- enforceCurrentUserIfVisibleBackgroundEnabled(currentUserId);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
final long identity = Binder.clearCallingIdentity();
try {
Settings.Global.putFloat(
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index 9eb8442be783..1c951848bc0a 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -1402,11 +1402,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
@EnforcePermission(MANAGE_ACCESSIBILITY)
public void registerSystemAction(RemoteAction action, int actionId) {
registerSystemAction_enforcePermission();
- int currentUserId;
- synchronized (mLock) {
- currentUserId = mCurrentUserId;
- }
- enforceCurrentUserIfVisibleBackgroundEnabled(currentUserId);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
if (mTraceManager.isA11yTracingEnabledForTypes(FLAGS_ACCESSIBILITY_MANAGER)) {
mTraceManager.logTrace(LOG_TAG + ".registerSystemAction",
FLAGS_ACCESSIBILITY_MANAGER, "action=" + action + ";actionId=" + actionId);
@@ -1423,11 +1419,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
@EnforcePermission(MANAGE_ACCESSIBILITY)
public void unregisterSystemAction(int actionId) {
unregisterSystemAction_enforcePermission();
- int currentUserId;
- synchronized (mLock) {
- currentUserId = mCurrentUserId;
- }
- enforceCurrentUserIfVisibleBackgroundEnabled(currentUserId);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
if (mTraceManager.isA11yTracingEnabledForTypes(FLAGS_ACCESSIBILITY_MANAGER)) {
mTraceManager.logTrace(LOG_TAG + ".unregisterSystemAction",
FLAGS_ACCESSIBILITY_MANAGER, "actionId=" + actionId);
@@ -1759,7 +1751,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
synchronized (mLock) {
currentUserId = mCurrentUserId;
}
- enforceCurrentUserIfVisibleBackgroundEnabled(currentUserId);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
if (mTraceManager.isA11yTracingEnabledForTypes(FLAGS_ACCESSIBILITY_MANAGER)) {
mTraceManager.logTrace(LOG_TAG + ".notifyAccessibilityButtonClicked",
FLAGS_ACCESSIBILITY_MANAGER,
@@ -1807,11 +1799,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
@EnforcePermission(STATUS_BAR_SERVICE)
public void notifyAccessibilityButtonVisibilityChanged(boolean shown) {
notifyAccessibilityButtonVisibilityChanged_enforcePermission();
- int currentUserId;
- synchronized (mLock) {
- currentUserId = mCurrentUserId;
- }
- enforceCurrentUserIfVisibleBackgroundEnabled(currentUserId);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
if (mTraceManager.isA11yTracingEnabledForTypes(FLAGS_ACCESSIBILITY_MANAGER)) {
mTraceManager.logTrace(LOG_TAG + ".notifyAccessibilityButtonVisibilityChanged",
FLAGS_ACCESSIBILITY_MANAGER, "shown=" + shown);
@@ -5002,11 +4990,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
throws RemoteException {
registerProxyForDisplay_enforcePermission();
mSecurityPolicy.checkForAccessibilityPermissionOrRole();
- int currentUserId;
- synchronized (mLock) {
- currentUserId = mCurrentUserId;
- }
- enforceCurrentUserIfVisibleBackgroundEnabled(currentUserId);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
if (client == null) {
return false;
}
diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java
index 8eda17698b9b..296f7cfe93ba 100644
--- a/services/core/java/com/android/server/UiModeManagerService.java
+++ b/services/core/java/com/android/server/UiModeManagerService.java
@@ -907,7 +907,7 @@ final class UiModeManagerService extends SystemService {
throw new IllegalArgumentException("Unknown mode: " + mode);
}
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
final int user = UserHandle.getCallingUserId();
final long ident = Binder.clearCallingIdentity();
@@ -970,7 +970,7 @@ final class UiModeManagerService extends SystemService {
@AttentionModeThemeOverlayType int attentionModeThemeOverlayType) {
setAttentionModeThemeOverlay_enforcePermission();
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
synchronized (mLock) {
if (mAttentionModeThemeOverlay != attentionModeThemeOverlayType) {
@@ -1070,7 +1070,7 @@ final class UiModeManagerService extends SystemService {
return false;
}
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
// Store the last requested bedtime night mode state so that we don't need to notify
// anyone if the user decides to switch to the night mode to bedtime.
@@ -1124,7 +1124,7 @@ final class UiModeManagerService extends SystemService {
return;
}
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
final int user = UserHandle.getCallingUserId();
final long ident = Binder.clearCallingIdentity();
@@ -1155,7 +1155,7 @@ final class UiModeManagerService extends SystemService {
return;
}
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
final int user = UserHandle.getCallingUserId();
final long ident = Binder.clearCallingIdentity();
@@ -1178,7 +1178,7 @@ final class UiModeManagerService extends SystemService {
assertLegit(callingPackage);
assertSingleProjectionType(projectionType);
enforceProjectionTypePermissions(projectionType);
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
synchronized (mLock) {
if (mProjectionHolders == null) {
@@ -1224,7 +1224,7 @@ final class UiModeManagerService extends SystemService {
assertLegit(callingPackage);
assertSingleProjectionType(projectionType);
enforceProjectionTypePermissions(projectionType);
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
return releaseProjectionUnchecked(projectionType, callingPackage);
}
@@ -1266,7 +1266,7 @@ final class UiModeManagerService extends SystemService {
return;
}
- enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser);
+ enforceCurrentUserIfVisibleBackgroundEnabled();
synchronized (mLock) {
if (mProjectionListeners == null) {
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index c7737e9f8bbd..c660e57983cc 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -2621,20 +2621,22 @@ public class UserManagerService extends IUserManager.Stub {
* Valid user is the current user or the system or in the same profile group as the current
* user. Visible background users are not valid calling users.
*/
- public static void enforceCurrentUserIfVisibleBackgroundEnabled(@UserIdInt int currentUserId) {
+ public static void enforceCurrentUserIfVisibleBackgroundEnabled() {
if (!UserManager.isVisibleBackgroundUsersEnabled()) {
return;
}
final int callingUserId = UserHandle.getCallingUserId();
- if (DBG) {
- Slog.d(LOG_TAG, "enforceValidCallingUser: callingUserId=" + callingUserId
- + " isSystemUser=" + (callingUserId == USER_SYSTEM)
- + " currentUserId=" + currentUserId
- + " callingPid=" + Binder.getCallingPid()
- + " callingUid=" + Binder.getCallingUid());
- }
final long ident = Binder.clearCallingIdentity();
try {
+ final int currentUserId = ActivityManager.getCurrentUser();
+ if (DBG) {
+ Slog.d(LOG_TAG, "enforceCurrentUserIfVisibleBackgroundEnabled:"
+ + " callingUserId=" + callingUserId
+ + " isSystemUser=" + (callingUserId == USER_SYSTEM)
+ + " currentUserId=" + currentUserId
+ + " callingPid=" + Binder.getCallingPid()
+ + " callingUid=" + Binder.getCallingUid());
+ }
if (callingUserId != USER_SYSTEM && callingUserId != currentUserId
&& !UserManagerService.getInstance()
.isSameProfileGroup(callingUserId, currentUserId)) {