Clearing binder identity before getting the current User
Otherwise it checks for Interact user permission which is not required for the locale change.
Flag: EXEMPT minor fix
Bug: 322229751
Test: atest --user-type secondary_user_on_secondary_display CtsCarTestCases:android.car.cts.LocaleManagerTest
Test: atest CtsCarTestCases:android.car.cts.LocaleManagerTest
Change-Id: I7a5b18a6caf49a5dc91043a59015d2360ad4e766
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 25fb729..5517ff3 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -16957,16 +16957,24 @@
int userId = UserHandle.getCallingUserId();
- if (UserManager.isVisibleBackgroundUsersEnabled() && userId != getCurrentUserId()) {
- // The check is added mainly for auto devices. On auto devices, it is possible that
- // multiple users are visible simultaneously using visible background users.
- // In such cases, it is desired that only the current user (not the visible background
- // user) can change the locale and other persistent settings of the device.
- Slog.w(TAG, "Only current user is allowed to update persistent configuration if "
- + "visible background users are enabled. Current User" + getCurrentUserId()
- + ". Calling User: " + userId);
- throw new SecurityException("Only current user is allowed to update persistent "
- + "configuration.");
+ if (UserManager.isVisibleBackgroundUsersEnabled()) {
+ final long origId = Binder.clearCallingIdentity();
+ try {
+ if (userId != getCurrentUserId()) {
+ // The check is added mainly for auto devices. On auto devices, it is
+ // possible that multiple users are visible simultaneously using visible
+ // background users. In such cases, it is desired that only the current user
+ // (not the visible background user) can change the locale and other persistent
+ // settings of the device.
+ Slog.w(TAG, "Only current user is allowed to update persistent configuration "
+ + "if visible background users are enabled. Current User"
+ + getCurrentUserId() + ". Calling User: " + userId);
+ throw new SecurityException("Only current user is allowed to update persistent "
+ + "configuration.");
+ }
+ } finally {
+ Binder.restoreCallingIdentity(origId);
+ }
}
mActivityTaskManager.updatePersistentConfiguration(values, userId);