Loading services/core/java/com/android/server/UiModeManagerService.java +20 −13 Original line number Original line Diff line number Diff line Loading @@ -443,6 +443,11 @@ final class UiModeManagerService extends SystemService { mDreamsDisabledByAmbientModeSuppression = disabledByAmbientModeSuppression; mDreamsDisabledByAmbientModeSuppression = disabledByAmbientModeSuppression; } } @VisibleForTesting void setCurrentUser(int currentUserId) { mCurrentUser = currentUserId; } @Override @Override public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) { public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) { mCurrentUser = to.getUserIdentifier(); mCurrentUser = to.getUserIdentifier(); Loading Loading @@ -864,9 +869,9 @@ final class UiModeManagerService extends SystemService { throw new IllegalArgumentException("Unknown mode: " + mode); throw new IllegalArgumentException("Unknown mode: " + mode); } } final int user = UserHandle.getCallingUserId(); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); enforceCurrentUserIfVisibleBackgroundEnabled(user); final int user = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); try { try { synchronized (mLock) { synchronized (mLock) { Loading Loading @@ -929,7 +934,7 @@ final class UiModeManagerService extends SystemService { @AttentionModeThemeOverlayType int attentionModeThemeOverlayType) { @AttentionModeThemeOverlayType int attentionModeThemeOverlayType) { setAttentionModeThemeOverlay_enforcePermission(); setAttentionModeThemeOverlay_enforcePermission(); enforceCurrentUserIfVisibleBackgroundEnabled(UserHandle.getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); synchronized (mLock) { synchronized (mLock) { if (mAttentionModeThemeOverlay != attentionModeThemeOverlayType) { if (mAttentionModeThemeOverlay != attentionModeThemeOverlayType) { Loading Loading @@ -1020,16 +1025,16 @@ final class UiModeManagerService extends SystemService { return false; return false; } } final int user = Binder.getCallingUserHandle().getIdentifier(); final int user = Binder.getCallingUserHandle().getIdentifier(); enforceCurrentUserIfVisibleBackgroundEnabled(user); if (user != mCurrentUser && getContext().checkCallingOrSelfPermission( if (user != mCurrentUser && getContext().checkCallingOrSelfPermission( android.Manifest.permission.INTERACT_ACROSS_USERS) android.Manifest.permission.INTERACT_ACROSS_USERS) != PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) { Slog.e(TAG, "Target user is not current user," Slog.e(TAG, "Target user is not current user," + " INTERACT_ACROSS_USERS permission is required"); + " INTERACT_ACROSS_USERS permission is required"); return false; return false; } } enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); // Store the last requested bedtime night mode state so that we don't need to notify // 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. // anyone if the user decides to switch to the night mode to bedtime. if (modeCustomType == MODE_NIGHT_CUSTOM_TYPE_BEDTIME) { if (modeCustomType == MODE_NIGHT_CUSTOM_TYPE_BEDTIME) { Loading Loading @@ -1078,9 +1083,10 @@ final class UiModeManagerService extends SystemService { Slog.e(TAG, "Set custom time start, requires MODIFY_DAY_NIGHT_MODE permission"); Slog.e(TAG, "Set custom time start, requires MODIFY_DAY_NIGHT_MODE permission"); return; return; } } final int user = UserHandle.getCallingUserId(); enforceCurrentUserIfVisibleBackgroundEnabled(user); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); final int user = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); try { try { LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); Loading Loading @@ -1108,9 +1114,10 @@ final class UiModeManagerService extends SystemService { Slog.e(TAG, "Set custom time end, requires MODIFY_DAY_NIGHT_MODE permission"); Slog.e(TAG, "Set custom time end, requires MODIFY_DAY_NIGHT_MODE permission"); return; return; } } final int user = UserHandle.getCallingUserId(); enforceCurrentUserIfVisibleBackgroundEnabled(user); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); final int user = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); try { try { LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); Loading @@ -1131,7 +1138,7 @@ final class UiModeManagerService extends SystemService { assertLegit(callingPackage); assertLegit(callingPackage); assertSingleProjectionType(projectionType); assertSingleProjectionType(projectionType); enforceProjectionTypePermissions(projectionType); enforceProjectionTypePermissions(projectionType); enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); synchronized (mLock) { synchronized (mLock) { if (mProjectionHolders == null) { if (mProjectionHolders == null) { Loading Loading @@ -1177,7 +1184,7 @@ final class UiModeManagerService extends SystemService { assertLegit(callingPackage); assertLegit(callingPackage); assertSingleProjectionType(projectionType); assertSingleProjectionType(projectionType); enforceProjectionTypePermissions(projectionType); enforceProjectionTypePermissions(projectionType); enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); return releaseProjectionUnchecked(projectionType, callingPackage); return releaseProjectionUnchecked(projectionType, callingPackage); } } Loading Loading @@ -1219,7 +1226,7 @@ final class UiModeManagerService extends SystemService { return; return; } } enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); synchronized (mLock) { synchronized (mLock) { if (mProjectionListeners == null) { if (mProjectionListeners == null) { Loading services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -68,6 +68,7 @@ import static org.testng.Assert.assertThrows; import android.Manifest; import android.Manifest; import android.app.Activity; import android.app.Activity; import android.app.ActivityManager; import android.app.AlarmManager; import android.app.AlarmManager; import android.app.Flags; import android.app.Flags; import android.app.IOnProjectionStateChangedListener; import android.app.IOnProjectionStateChangedListener; Loading Loading @@ -247,6 +248,8 @@ public class UiModeManagerServiceTest extends UiServiceTestCase { mInjector = spy(new TestInjector()); mInjector = spy(new TestInjector()); mUiManagerService = new UiModeManagerService(mContext, /* setupWizardComplete= */ true, mUiManagerService = new UiModeManagerService(mContext, /* setupWizardComplete= */ true, mTwilightManager, mInjector); mTwilightManager, mInjector); // Initialize the current user. mUiManagerService.setCurrentUser(ActivityManager.getCurrentUser()); try { try { mUiManagerService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); mUiManagerService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); } catch (SecurityException e) {/* ignore for permission denial */} } catch (SecurityException e) {/* ignore for permission denial */} Loading Loading
services/core/java/com/android/server/UiModeManagerService.java +20 −13 Original line number Original line Diff line number Diff line Loading @@ -443,6 +443,11 @@ final class UiModeManagerService extends SystemService { mDreamsDisabledByAmbientModeSuppression = disabledByAmbientModeSuppression; mDreamsDisabledByAmbientModeSuppression = disabledByAmbientModeSuppression; } } @VisibleForTesting void setCurrentUser(int currentUserId) { mCurrentUser = currentUserId; } @Override @Override public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) { public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) { mCurrentUser = to.getUserIdentifier(); mCurrentUser = to.getUserIdentifier(); Loading Loading @@ -864,9 +869,9 @@ final class UiModeManagerService extends SystemService { throw new IllegalArgumentException("Unknown mode: " + mode); throw new IllegalArgumentException("Unknown mode: " + mode); } } final int user = UserHandle.getCallingUserId(); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); enforceCurrentUserIfVisibleBackgroundEnabled(user); final int user = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); try { try { synchronized (mLock) { synchronized (mLock) { Loading Loading @@ -929,7 +934,7 @@ final class UiModeManagerService extends SystemService { @AttentionModeThemeOverlayType int attentionModeThemeOverlayType) { @AttentionModeThemeOverlayType int attentionModeThemeOverlayType) { setAttentionModeThemeOverlay_enforcePermission(); setAttentionModeThemeOverlay_enforcePermission(); enforceCurrentUserIfVisibleBackgroundEnabled(UserHandle.getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); synchronized (mLock) { synchronized (mLock) { if (mAttentionModeThemeOverlay != attentionModeThemeOverlayType) { if (mAttentionModeThemeOverlay != attentionModeThemeOverlayType) { Loading Loading @@ -1020,16 +1025,16 @@ final class UiModeManagerService extends SystemService { return false; return false; } } final int user = Binder.getCallingUserHandle().getIdentifier(); final int user = Binder.getCallingUserHandle().getIdentifier(); enforceCurrentUserIfVisibleBackgroundEnabled(user); if (user != mCurrentUser && getContext().checkCallingOrSelfPermission( if (user != mCurrentUser && getContext().checkCallingOrSelfPermission( android.Manifest.permission.INTERACT_ACROSS_USERS) android.Manifest.permission.INTERACT_ACROSS_USERS) != PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) { Slog.e(TAG, "Target user is not current user," Slog.e(TAG, "Target user is not current user," + " INTERACT_ACROSS_USERS permission is required"); + " INTERACT_ACROSS_USERS permission is required"); return false; return false; } } enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); // Store the last requested bedtime night mode state so that we don't need to notify // 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. // anyone if the user decides to switch to the night mode to bedtime. if (modeCustomType == MODE_NIGHT_CUSTOM_TYPE_BEDTIME) { if (modeCustomType == MODE_NIGHT_CUSTOM_TYPE_BEDTIME) { Loading Loading @@ -1078,9 +1083,10 @@ final class UiModeManagerService extends SystemService { Slog.e(TAG, "Set custom time start, requires MODIFY_DAY_NIGHT_MODE permission"); Slog.e(TAG, "Set custom time start, requires MODIFY_DAY_NIGHT_MODE permission"); return; return; } } final int user = UserHandle.getCallingUserId(); enforceCurrentUserIfVisibleBackgroundEnabled(user); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); final int user = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); try { try { LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); Loading Loading @@ -1108,9 +1114,10 @@ final class UiModeManagerService extends SystemService { Slog.e(TAG, "Set custom time end, requires MODIFY_DAY_NIGHT_MODE permission"); Slog.e(TAG, "Set custom time end, requires MODIFY_DAY_NIGHT_MODE permission"); return; return; } } final int user = UserHandle.getCallingUserId(); enforceCurrentUserIfVisibleBackgroundEnabled(user); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); final int user = UserHandle.getCallingUserId(); final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); try { try { LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); LocalTime newTime = LocalTime.ofNanoOfDay(time * 1000); Loading @@ -1131,7 +1138,7 @@ final class UiModeManagerService extends SystemService { assertLegit(callingPackage); assertLegit(callingPackage); assertSingleProjectionType(projectionType); assertSingleProjectionType(projectionType); enforceProjectionTypePermissions(projectionType); enforceProjectionTypePermissions(projectionType); enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); synchronized (mLock) { synchronized (mLock) { if (mProjectionHolders == null) { if (mProjectionHolders == null) { Loading Loading @@ -1177,7 +1184,7 @@ final class UiModeManagerService extends SystemService { assertLegit(callingPackage); assertLegit(callingPackage); assertSingleProjectionType(projectionType); assertSingleProjectionType(projectionType); enforceProjectionTypePermissions(projectionType); enforceProjectionTypePermissions(projectionType); enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); return releaseProjectionUnchecked(projectionType, callingPackage); return releaseProjectionUnchecked(projectionType, callingPackage); } } Loading Loading @@ -1219,7 +1226,7 @@ final class UiModeManagerService extends SystemService { return; return; } } enforceCurrentUserIfVisibleBackgroundEnabled(getCallingUserId()); enforceCurrentUserIfVisibleBackgroundEnabled(mCurrentUser); synchronized (mLock) { synchronized (mLock) { if (mProjectionListeners == null) { if (mProjectionListeners == null) { Loading
services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -68,6 +68,7 @@ import static org.testng.Assert.assertThrows; import android.Manifest; import android.Manifest; import android.app.Activity; import android.app.Activity; import android.app.ActivityManager; import android.app.AlarmManager; import android.app.AlarmManager; import android.app.Flags; import android.app.Flags; import android.app.IOnProjectionStateChangedListener; import android.app.IOnProjectionStateChangedListener; Loading Loading @@ -247,6 +248,8 @@ public class UiModeManagerServiceTest extends UiServiceTestCase { mInjector = spy(new TestInjector()); mInjector = spy(new TestInjector()); mUiManagerService = new UiModeManagerService(mContext, /* setupWizardComplete= */ true, mUiManagerService = new UiModeManagerService(mContext, /* setupWizardComplete= */ true, mTwilightManager, mInjector); mTwilightManager, mInjector); // Initialize the current user. mUiManagerService.setCurrentUser(ActivityManager.getCurrentUser()); try { try { mUiManagerService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); mUiManagerService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); } catch (SecurityException e) {/* ignore for permission denial */} } catch (SecurityException e) {/* ignore for permission denial */} Loading