diff options
| author | 2024-09-18 03:29:41 +0000 | |
|---|---|---|
| committer | 2024-09-18 03:41:21 +0000 | |
| commit | 6f43ab936024415418349e97f074525b16eeb10d (patch) | |
| tree | 20bd894775fb448c3b317667cee85fa172ce3851 | |
| parent | 1cedcfeabcb37c6d88b32cd4f88f1f6c9e123cf4 (diff) | |
Fix NPE in UiModeManagerServiceTest
Replace enforceValidCallingUser() in UiModeMaangerService with
UserManagerService#enforceCurrentUserIfVisibleBackgroundEnabled().
This fixes the NPE in UiModeManagerServiceTest that was caused by
UserManagerService not being instantiated in unit tests.
Also remove redundant UiModeManagerService#enforceValidCallingUser
method.
Bug: 360925919
Flag: EXEMPT bugfix
Test: atest FrameworksUiServicesTests:com.android.server.UiModeManagerServiceTest
Change-Id: I6c6b23c55835c535dd8d140b21332a8f141eeba1
| -rw-r--r-- | services/core/java/com/android/server/UiModeManagerService.java | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java index 1c13ad5b3ceb..f32031dec43c 100644 --- a/services/core/java/com/android/server/UiModeManagerService.java +++ b/services/core/java/com/android/server/UiModeManagerService.java @@ -32,11 +32,11 @@ import static android.app.UiModeManager.PROJECTION_TYPE_AUTOMOTIVE; import static android.app.UiModeManager.PROJECTION_TYPE_NONE; import static android.os.UserHandle.USER_SYSTEM; import static android.os.UserHandle.getCallingUserId; -import static android.os.UserManager.isVisibleBackgroundUsersEnabled; import static android.provider.Settings.Secure.CONTRAST_LEVEL; import static android.util.TimeUtils.isTimeBetween; import static com.android.internal.util.FunctionalUtils.ignoreRemoteException; +import static com.android.server.pm.UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled; import android.annotation.IntRange; import android.annotation.NonNull; @@ -100,7 +100,6 @@ import com.android.internal.app.DisableCarModeActivity; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.util.DumpUtils; -import com.android.server.pm.UserManagerService; import com.android.server.twilight.TwilightListener; import com.android.server.twilight.TwilightManager; import com.android.server.twilight.TwilightState; @@ -850,7 +849,7 @@ final class UiModeManagerService extends SystemService { } final int user = UserHandle.getCallingUserId(); - enforceValidCallingUser(user); + enforceCurrentUserIfVisibleBackgroundEnabled(user); final long ident = Binder.clearCallingIdentity(); try { @@ -914,7 +913,7 @@ final class UiModeManagerService extends SystemService { @AttentionModeThemeOverlayType int attentionModeThemeOverlayType) { setAttentionModeThemeOverlay_enforcePermission(); - enforceValidCallingUser(UserHandle.getCallingUserId()); + enforceCurrentUserIfVisibleBackgroundEnabled(UserHandle.getCallingUserId()); synchronized (mLock) { if (mAttentionModeThemeOverlay != attentionModeThemeOverlayType) { @@ -1005,7 +1004,7 @@ final class UiModeManagerService extends SystemService { return false; } final int user = Binder.getCallingUserHandle().getIdentifier(); - enforceValidCallingUser(user); + enforceCurrentUserIfVisibleBackgroundEnabled(user); if (user != mCurrentUser && getContext().checkCallingOrSelfPermission( android.Manifest.permission.INTERACT_ACROSS_USERS) @@ -1064,7 +1063,7 @@ final class UiModeManagerService extends SystemService { return; } final int user = UserHandle.getCallingUserId(); - enforceValidCallingUser(user); + enforceCurrentUserIfVisibleBackgroundEnabled(user); final long ident = Binder.clearCallingIdentity(); try { @@ -1094,7 +1093,7 @@ final class UiModeManagerService extends SystemService { return; } final int user = UserHandle.getCallingUserId(); - enforceValidCallingUser(user); + enforceCurrentUserIfVisibleBackgroundEnabled(user); final long ident = Binder.clearCallingIdentity(); try { @@ -1116,7 +1115,7 @@ final class UiModeManagerService extends SystemService { assertLegit(callingPackage); assertSingleProjectionType(projectionType); enforceProjectionTypePermissions(projectionType); - enforceValidCallingUser(getCallingUserId()); + enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); synchronized (mLock) { if (mProjectionHolders == null) { @@ -1162,7 +1161,7 @@ final class UiModeManagerService extends SystemService { assertLegit(callingPackage); assertSingleProjectionType(projectionType); enforceProjectionTypePermissions(projectionType); - enforceValidCallingUser(getCallingUserId()); + enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); return releaseProjectionUnchecked(projectionType, callingPackage); } @@ -1204,7 +1203,7 @@ final class UiModeManagerService extends SystemService { return; } - enforceValidCallingUser(getCallingUserId()); + enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); synchronized (mLock) { if (mProjectionListeners == null) { @@ -1253,32 +1252,6 @@ final class UiModeManagerService extends SystemService { } }; - // This method validates whether calling user is valid in visible background users - // feature. Valid user is the current user or the system or in the same profile group as - // the current user. - private void enforceValidCallingUser(int userId) { - if (!isVisibleBackgroundUsersEnabled()) { - return; - } - if (LOG) { - Slog.d(TAG, "enforceValidCallingUser: userId=" + userId - + " isSystemUser=" + (userId == USER_SYSTEM) + " current user=" + mCurrentUser - + " callingPid=" + Binder.getCallingPid() - + " callingUid=" + mInjector.getCallingUid()); - } - long ident = Binder.clearCallingIdentity(); - try { - if (userId != USER_SYSTEM && userId != mCurrentUser - && !UserManagerService.getInstance().isSameProfileGroup(userId, mCurrentUser)) { - throw new SecurityException( - "Calling user is not valid for level-1 compatibility in MUMD. " - + "callingUserId=" + userId + " currentUserId=" + mCurrentUser); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - private void enforceProjectionTypePermissions(@UiModeManager.ProjectionType int p) { if ((p & PROJECTION_TYPE_AUTOMOTIVE) != 0) { getContext().enforceCallingPermission( |