Loading core/java/android/provider/Settings.java +1 −0 Original line number Diff line number Diff line Loading @@ -12172,6 +12172,7 @@ public final class Settings { CLONE_TO_MANAGED_PROFILE.add(SHOW_IME_WITH_HARD_KEYBOARD); CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_BOUNCE_KEYS); CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_BUBBLES); CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_HISTORY_ENABLED); } /** @hide */ Loading services/core/java/com/android/server/notification/NotificationHistoryManager.java +6 −7 Original line number Diff line number Diff line Loading @@ -118,6 +118,10 @@ public class NotificationHistoryManager { } } public void onUserAdded(@UserIdInt int userId) { mSettingsObserver.update(null, userId); } public void onUserStopped(@UserIdInt int userId) { synchronized (mLock) { mUserUnlockedStates.put(userId, false); Loading Loading @@ -401,12 +405,10 @@ public class NotificationHistoryManager { false, this, UserHandle.USER_ALL); synchronized (mLock) { for (UserInfo userInfo : mUserManager.getUsers()) { if (!userInfo.isProfile()) { update(null, userInfo.id); } } } } void stopObserving() { ContentResolver resolver = mContext.getContentResolver(); Loading @@ -424,10 +426,7 @@ public class NotificationHistoryManager { boolean historyEnabled = Settings.Secure.getIntForUser(resolver, Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, userId) != 0; int[] profiles = mUserManager.getProfileIds(userId, true); for (int profileId : profiles) { onHistoryEnabledChanged(profileId, historyEnabled); } onHistoryEnabledChanged(userId, historyEnabled); } } } Loading services/core/java/com/android/server/notification/NotificationManagerService.java +15 −7 Original line number Diff line number Diff line Loading @@ -2025,6 +2025,8 @@ public class NotificationManagerService extends SystemService { if (!mUserProfiles.isProfileUser(userId)) { allowDefaultApprovedServices(userId); } mHistoryManager.onUserAdded(userId); mSettingsObserver.update(null, userId); } } else if (action.equals(Intent.ACTION_USER_REMOVED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); Loading Loading @@ -2137,13 +2139,8 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.updateBubblesEnabled(); } if (uri == null || NOTIFICATION_HISTORY_ENABLED.equals(uri)) { final IntArray userIds = mUserProfiles.getCurrentProfileIds(); for (int i = 0; i < userIds.size(); i++) { mArchive.updateHistoryEnabled(userIds.get(i), Settings.Secure.getIntForUser(resolver, Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, userIds.get(i)) == 1); for (UserInfo userInfo : mUm.getUsers()) { update(uri, userInfo.id); } } if (uri == null || NOTIFICATION_SHOW_MEDIA_ON_QUICK_SETTINGS_URI.equals(uri)) { Loading @@ -2164,6 +2161,17 @@ public class NotificationManagerService extends SystemService { } } } public void update(Uri uri, int userId) { ContentResolver resolver = getContext().getContentResolver(); if (uri == null || NOTIFICATION_HISTORY_ENABLED.equals(uri)) { mArchive.updateHistoryEnabled(userId, Settings.Secure.getIntForUser(resolver, Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, userId) == 1); // note: this setting is also handled in NotificationHistoryManager } } } private SettingsObserver mSettingsObserver; Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationHistoryManagerTest.java +35 −0 Original line number Diff line number Diff line Loading @@ -170,6 +170,10 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase { Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, USER_SYSTEM); mHistoryManager.mSettingsObserver.update(null, USER_SYSTEM); // fake cloned settings to profile Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, mProfileId); mHistoryManager.mSettingsObserver.update(null, mProfileId); // unlock user, verify that history is disabled for self and profile mHistoryManager.onUserUnlocked(USER_SYSTEM); Loading @@ -180,6 +184,37 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase { verify(mDb, times(2)).disableHistory(); } @Test public void testAddProfile_historyEnabledInPrimary() { // create a history mHistoryManager.onUserUnlocked(MIN_SECONDARY_USER_ID); assertThat(mHistoryManager.doesHistoryExistForUser(MIN_SECONDARY_USER_ID)).isTrue(); // fake Settings#CLONE_TO_MANAGED_PROFILE int newProfileId = 99; Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1, newProfileId); mUsers = new ArrayList<>(); UserInfo userFullSecondary = new UserInfo(); userFullSecondary.id = MIN_SECONDARY_USER_ID; mUsers.add(userFullSecondary); UserInfo userProfile = new UserInfo(); userProfile.id = newProfileId; mUsers.add(userProfile); when(mUserManager.getUsers()).thenReturn(mUsers); mProfiles = new int[] {MIN_SECONDARY_USER_ID, userProfile.id}; when(mUserManager.getProfileIds(MIN_SECONDARY_USER_ID, true)).thenReturn(mProfiles); when(mUserManager.getProfileIds(userProfile.id, true)) .thenReturn(new int[] {userProfile.id}); when(mUserManager.getProfileParent(userProfile.id)).thenReturn(userFullSecondary); // add profile mHistoryManager.onUserAdded(newProfileId); mHistoryManager.onUserUnlocked(newProfileId); assertThat(mHistoryManager.doesHistoryExistForUser(newProfileId)).isTrue(); } @Test public void testOnUserUnlocked_historyDisabledThenEnabled() { // create a history Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +6 −4 Original line number Diff line number Diff line Loading @@ -958,22 +958,24 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel.setAllowBubbles(channelEnabled); } private void setUpPrefsForHistory(int uid, boolean globalEnabled) throws Exception { private void setUpPrefsForHistory(@UserIdInt int userId, boolean globalEnabled) throws Exception { initNMS(SystemService.PHASE_ACTIVITY_MANAGER_READY); // Sets NOTIFICATION_HISTORY_ENABLED setting for calling process uid Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, globalEnabled ? 1 : 0, uid); Settings.Secure.NOTIFICATION_HISTORY_ENABLED, globalEnabled ? 1 : 0, userId); // Sets NOTIFICATION_HISTORY_ENABLED setting for uid 0 Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, globalEnabled ? 1 : 0); setUsers(new int[] {0, userId}); // Forces an update by calling observe on mSettingsObserver, which picks up the settings // changes above. mService.onBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START, mMainLooper); assertEquals(globalEnabled, Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0 /* =def */, uid) != 0); Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0 /* =def */, userId) != 0); } private StatusBarNotification generateSbn(String pkg, int uid, long postTime, int userId) { Loading Loading @@ -10443,7 +10445,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testHandleOnPackageRemoved_ClearsHistory() throws Exception { // Enables Notification History setting setUpPrefsForHistory(mUid, true /* =enabled */); setUpPrefsForHistory(mUserId, true /* =enabled */); // Posts a notification to the mTestNotificationChannel. final NotificationRecord notif = generateNotificationRecord( Loading Loading
core/java/android/provider/Settings.java +1 −0 Original line number Diff line number Diff line Loading @@ -12172,6 +12172,7 @@ public final class Settings { CLONE_TO_MANAGED_PROFILE.add(SHOW_IME_WITH_HARD_KEYBOARD); CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_BOUNCE_KEYS); CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_BUBBLES); CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_HISTORY_ENABLED); } /** @hide */ Loading
services/core/java/com/android/server/notification/NotificationHistoryManager.java +6 −7 Original line number Diff line number Diff line Loading @@ -118,6 +118,10 @@ public class NotificationHistoryManager { } } public void onUserAdded(@UserIdInt int userId) { mSettingsObserver.update(null, userId); } public void onUserStopped(@UserIdInt int userId) { synchronized (mLock) { mUserUnlockedStates.put(userId, false); Loading Loading @@ -401,12 +405,10 @@ public class NotificationHistoryManager { false, this, UserHandle.USER_ALL); synchronized (mLock) { for (UserInfo userInfo : mUserManager.getUsers()) { if (!userInfo.isProfile()) { update(null, userInfo.id); } } } } void stopObserving() { ContentResolver resolver = mContext.getContentResolver(); Loading @@ -424,10 +426,7 @@ public class NotificationHistoryManager { boolean historyEnabled = Settings.Secure.getIntForUser(resolver, Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, userId) != 0; int[] profiles = mUserManager.getProfileIds(userId, true); for (int profileId : profiles) { onHistoryEnabledChanged(profileId, historyEnabled); } onHistoryEnabledChanged(userId, historyEnabled); } } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +15 −7 Original line number Diff line number Diff line Loading @@ -2025,6 +2025,8 @@ public class NotificationManagerService extends SystemService { if (!mUserProfiles.isProfileUser(userId)) { allowDefaultApprovedServices(userId); } mHistoryManager.onUserAdded(userId); mSettingsObserver.update(null, userId); } } else if (action.equals(Intent.ACTION_USER_REMOVED)) { final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); Loading Loading @@ -2137,13 +2139,8 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.updateBubblesEnabled(); } if (uri == null || NOTIFICATION_HISTORY_ENABLED.equals(uri)) { final IntArray userIds = mUserProfiles.getCurrentProfileIds(); for (int i = 0; i < userIds.size(); i++) { mArchive.updateHistoryEnabled(userIds.get(i), Settings.Secure.getIntForUser(resolver, Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, userIds.get(i)) == 1); for (UserInfo userInfo : mUm.getUsers()) { update(uri, userInfo.id); } } if (uri == null || NOTIFICATION_SHOW_MEDIA_ON_QUICK_SETTINGS_URI.equals(uri)) { Loading @@ -2164,6 +2161,17 @@ public class NotificationManagerService extends SystemService { } } } public void update(Uri uri, int userId) { ContentResolver resolver = getContext().getContentResolver(); if (uri == null || NOTIFICATION_HISTORY_ENABLED.equals(uri)) { mArchive.updateHistoryEnabled(userId, Settings.Secure.getIntForUser(resolver, Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, userId) == 1); // note: this setting is also handled in NotificationHistoryManager } } } private SettingsObserver mSettingsObserver; Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationHistoryManagerTest.java +35 −0 Original line number Diff line number Diff line Loading @@ -170,6 +170,10 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase { Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, USER_SYSTEM); mHistoryManager.mSettingsObserver.update(null, USER_SYSTEM); // fake cloned settings to profile Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, mProfileId); mHistoryManager.mSettingsObserver.update(null, mProfileId); // unlock user, verify that history is disabled for self and profile mHistoryManager.onUserUnlocked(USER_SYSTEM); Loading @@ -180,6 +184,37 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase { verify(mDb, times(2)).disableHistory(); } @Test public void testAddProfile_historyEnabledInPrimary() { // create a history mHistoryManager.onUserUnlocked(MIN_SECONDARY_USER_ID); assertThat(mHistoryManager.doesHistoryExistForUser(MIN_SECONDARY_USER_ID)).isTrue(); // fake Settings#CLONE_TO_MANAGED_PROFILE int newProfileId = 99; Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1, newProfileId); mUsers = new ArrayList<>(); UserInfo userFullSecondary = new UserInfo(); userFullSecondary.id = MIN_SECONDARY_USER_ID; mUsers.add(userFullSecondary); UserInfo userProfile = new UserInfo(); userProfile.id = newProfileId; mUsers.add(userProfile); when(mUserManager.getUsers()).thenReturn(mUsers); mProfiles = new int[] {MIN_SECONDARY_USER_ID, userProfile.id}; when(mUserManager.getProfileIds(MIN_SECONDARY_USER_ID, true)).thenReturn(mProfiles); when(mUserManager.getProfileIds(userProfile.id, true)) .thenReturn(new int[] {userProfile.id}); when(mUserManager.getProfileParent(userProfile.id)).thenReturn(userFullSecondary); // add profile mHistoryManager.onUserAdded(newProfileId); mHistoryManager.onUserUnlocked(newProfileId); assertThat(mHistoryManager.doesHistoryExistForUser(newProfileId)).isTrue(); } @Test public void testOnUserUnlocked_historyDisabledThenEnabled() { // create a history Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +6 −4 Original line number Diff line number Diff line Loading @@ -958,22 +958,24 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel.setAllowBubbles(channelEnabled); } private void setUpPrefsForHistory(int uid, boolean globalEnabled) throws Exception { private void setUpPrefsForHistory(@UserIdInt int userId, boolean globalEnabled) throws Exception { initNMS(SystemService.PHASE_ACTIVITY_MANAGER_READY); // Sets NOTIFICATION_HISTORY_ENABLED setting for calling process uid Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, globalEnabled ? 1 : 0, uid); Settings.Secure.NOTIFICATION_HISTORY_ENABLED, globalEnabled ? 1 : 0, userId); // Sets NOTIFICATION_HISTORY_ENABLED setting for uid 0 Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, globalEnabled ? 1 : 0); setUsers(new int[] {0, userId}); // Forces an update by calling observe on mSettingsObserver, which picks up the settings // changes above. mService.onBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START, mMainLooper); assertEquals(globalEnabled, Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0 /* =def */, uid) != 0); Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0 /* =def */, userId) != 0); } private StatusBarNotification generateSbn(String pkg, int uid, long postTime, int userId) { Loading Loading @@ -10443,7 +10445,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testHandleOnPackageRemoved_ClearsHistory() throws Exception { // Enables Notification History setting setUpPrefsForHistory(mUid, true /* =enabled */); setUpPrefsForHistory(mUserId, true /* =enabled */); // Posts a notification to the mTestNotificationChannel. final NotificationRecord notif = generateNotificationRecord( Loading