Loading src/com/android/settings/notification/app/BundleListPreferenceController.java +21 −9 Original line number Diff line number Diff line Loading @@ -91,14 +91,27 @@ public class BundleListPreferenceController extends NotificationPreferenceContro public void updateState(Preference preference) { PreferenceCategory category = (PreferenceCategory) preference; createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)); createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)); createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)); createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)); NotificationChannel promos = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID); if (promos != null) { createOrUpdatePrefForChannel(category, promos); } NotificationChannel recs = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID); if (recs != null) { createOrUpdatePrefForChannel(category, recs); } NotificationChannel social = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID); if (social != null) { createOrUpdatePrefForChannel(category, social); } NotificationChannel news = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID); if (news != null) { createOrUpdatePrefForChannel(category, news); } int preferenceCount = ((PreferenceGroup) preference).getPreferenceCount(); if (preferenceCount == 0) { preference.setVisible(false); } } @NonNull Loading Loading @@ -167,5 +180,4 @@ public class BundleListPreferenceController extends NotificationPreferenceContro icon.setTintList(Utils.getColorAccent(mContext)); return icon; } } tests/robotests/src/com/android/settings/notification/app/BundleListPreferenceControllerTest.java +31 −13 Original line number Diff line number Diff line Loading @@ -89,15 +89,6 @@ public class BundleListPreferenceControllerTest { mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext); mGroupList = new PreferenceCategory(mContext); mPreferenceScreen.addPreference(mGroupList); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)).thenReturn( new NotificationChannel(NEWS_ID, NEWS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)).thenReturn( new NotificationChannel(SOCIAL_MEDIA_ID, SOCIAL_MEDIA_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)).thenReturn( new NotificationChannel(RECS_ID, RECS_ID, 2)); } @Test Loading Loading @@ -132,6 +123,14 @@ public class BundleListPreferenceControllerTest { @Test public void updateState() { when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)).thenReturn( new NotificationChannel(NEWS_ID, NEWS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)).thenReturn( new NotificationChannel(SOCIAL_MEDIA_ID, SOCIAL_MEDIA_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)).thenReturn( new NotificationChannel(RECS_ID, RECS_ID, 2)); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); assertThat(mGroupList.findPreference(PROMOTIONS_ID).getTitle()).isEqualTo(PROMOTIONS_ID); Loading @@ -142,19 +141,38 @@ public class BundleListPreferenceControllerTest { } @Test public void updateState_updateChildren() { public void updateState_noBundles() { mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); assertThat(mGroupList.getPreferenceCount()).isEqualTo(0); assertThat(mGroupList.isVisible()).isFalse(); } @Test public void updateState_onlySomeBundlesUsed() { when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(1); assertThat(mGroupList.findPreference(PROMOTIONS_ID).getTitle()).isEqualTo(PROMOTIONS_ID); } @Test public void updateState_noDuplicateChannelsOnReload() { when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)).thenReturn( new NotificationChannel(NEWS_ID, NEWS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)).thenReturn( new NotificationChannel(SOCIAL_MEDIA_ID, SOCIAL_MEDIA_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)).thenReturn( new NotificationChannel(RECS_ID, RECS_ID, 2)); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); assertThat(((PrimarySwitchPreference) mGroupList.findPreference(NEWS_ID)).isChecked()) .isEqualTo(false); assertThat(((PrimarySwitchPreference) mGroupList.findPreference(NEWS_ID)).isChecked()) .isEqualTo(false); } } Loading
src/com/android/settings/notification/app/BundleListPreferenceController.java +21 −9 Original line number Diff line number Diff line Loading @@ -91,14 +91,27 @@ public class BundleListPreferenceController extends NotificationPreferenceContro public void updateState(Preference preference) { PreferenceCategory category = (PreferenceCategory) preference; createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)); createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)); createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)); createOrUpdatePrefForChannel(category, mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)); NotificationChannel promos = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID); if (promos != null) { createOrUpdatePrefForChannel(category, promos); } NotificationChannel recs = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID); if (recs != null) { createOrUpdatePrefForChannel(category, recs); } NotificationChannel social = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID); if (social != null) { createOrUpdatePrefForChannel(category, social); } NotificationChannel news = mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID); if (news != null) { createOrUpdatePrefForChannel(category, news); } int preferenceCount = ((PreferenceGroup) preference).getPreferenceCount(); if (preferenceCount == 0) { preference.setVisible(false); } } @NonNull Loading Loading @@ -167,5 +180,4 @@ public class BundleListPreferenceController extends NotificationPreferenceContro icon.setTintList(Utils.getColorAccent(mContext)); return icon; } }
tests/robotests/src/com/android/settings/notification/app/BundleListPreferenceControllerTest.java +31 −13 Original line number Diff line number Diff line Loading @@ -89,15 +89,6 @@ public class BundleListPreferenceControllerTest { mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext); mGroupList = new PreferenceCategory(mContext); mPreferenceScreen.addPreference(mGroupList); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)).thenReturn( new NotificationChannel(NEWS_ID, NEWS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)).thenReturn( new NotificationChannel(SOCIAL_MEDIA_ID, SOCIAL_MEDIA_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)).thenReturn( new NotificationChannel(RECS_ID, RECS_ID, 2)); } @Test Loading Loading @@ -132,6 +123,14 @@ public class BundleListPreferenceControllerTest { @Test public void updateState() { when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)).thenReturn( new NotificationChannel(NEWS_ID, NEWS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)).thenReturn( new NotificationChannel(SOCIAL_MEDIA_ID, SOCIAL_MEDIA_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)).thenReturn( new NotificationChannel(RECS_ID, RECS_ID, 2)); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); assertThat(mGroupList.findPreference(PROMOTIONS_ID).getTitle()).isEqualTo(PROMOTIONS_ID); Loading @@ -142,19 +141,38 @@ public class BundleListPreferenceControllerTest { } @Test public void updateState_updateChildren() { public void updateState_noBundles() { mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); assertThat(mGroupList.getPreferenceCount()).isEqualTo(0); assertThat(mGroupList.isVisible()).isFalse(); } @Test public void updateState_onlySomeBundlesUsed() { when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(1); assertThat(mGroupList.findPreference(PROMOTIONS_ID).getTitle()).isEqualTo(PROMOTIONS_ID); } @Test public void updateState_noDuplicateChannelsOnReload() { when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, PROMOTIONS_ID)).thenReturn( new NotificationChannel(PROMOTIONS_ID, PROMOTIONS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, NEWS_ID)).thenReturn( new NotificationChannel(NEWS_ID, NEWS_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, SOCIAL_MEDIA_ID)).thenReturn( new NotificationChannel(SOCIAL_MEDIA_ID, SOCIAL_MEDIA_ID, 2)); when(mBackend.getChannel(mAppRow.pkg, mAppRow.uid, RECS_ID)).thenReturn( new NotificationChannel(RECS_ID, RECS_ID, 2)); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); mController.updateState(mGroupList); assertThat(mGroupList.getPreferenceCount()).isEqualTo(4); assertThat(((PrimarySwitchPreference) mGroupList.findPreference(NEWS_ID)).isChecked()) .isEqualTo(false); assertThat(((PrimarySwitchPreference) mGroupList.findPreference(NEWS_ID)).isChecked()) .isEqualTo(false); } }