diff options
| author | 2018-10-09 13:50:25 +0000 | |
|---|---|---|
| committer | 2018-10-09 13:50:25 +0000 | |
| commit | 99ecc121bca092afb2ace650f879f437c9d3ff9b (patch) | |
| tree | 13b2fccd3df0d0d79942cd213a3ad4972934a7dd | |
| parent | 512ebfe3f612a50cb727fb505d125fe6b1ba8620 (diff) | |
| parent | 8a7e4ac7d73be57095e01607c1e73171bcda6f6f (diff) | |
Merge "Remove side effects of contact affinity."
| -rw-r--r-- | services/core/java/com/android/server/notification/NotificationRecord.java | 4 | ||||
| -rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java | 125 |
2 files changed, 68 insertions, 61 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index fbb42ea160da..65ec5808a0dd 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -662,10 +662,6 @@ public final class NotificationRecord { public void setContactAffinity(float contactAffinity) { mContactAffinity = contactAffinity; - if (mImportance < IMPORTANCE_DEFAULT && - mContactAffinity > ValidateNotificationPeople.VALID_CONTACT) { - setSystemImportance(IMPORTANCE_DEFAULT); - } } public float getContactAffinity() { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java index 11b086ca441c..1b59e75cb30e 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java @@ -32,6 +32,7 @@ import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -54,7 +55,6 @@ import android.media.AudioAttributes; import android.metrics.LogMaker; import android.net.Uri; import android.os.Bundle; -import android.os.RemoteException; import android.os.UserHandle; import android.provider.Settings; import android.service.notification.Adjustment; @@ -74,35 +74,31 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.ArrayList; -import java.util.Objects; +import java.util.Arrays; @SmallTest @RunWith(AndroidJUnit4.class) public class NotificationRecordTest extends UiServiceTestCase { private final Context mMockContext = mock(Context.class); - @Mock PackageManager mPm; + @Mock private PackageManager mPm; private final String pkg = PKG_N_MR1; private final int uid = 9583; - private final String pkg2 = PKG_O; - private final int uid2 = 1111111; private final int id1 = 1; - private final int id2 = 2; private final String tag1 = "tag1"; - private final String tag2 = "tag2"; private final String channelId = "channel"; - NotificationChannel channel = + private NotificationChannel channel = new NotificationChannel(channelId, "test", NotificationManager.IMPORTANCE_DEFAULT); private final String channelIdLong = "give_a_developer_a_string_argument_and_who_knows_what_they_will_pass_in_there"; - final String groupId = "group"; - final String groupIdOverride = "other_group"; + private final String groupId = "group"; + private final String groupIdOverride = "other_group"; private final String groupIdLong = "0|com.foo.bar|g:content://com.foo.bar.ui/account%3A-0000000/account/"; - NotificationChannel channelLongId = + private NotificationChannel channelLongId = new NotificationChannel(channelIdLong, "long", NotificationManager.IMPORTANCE_DEFAULT); - NotificationChannel defaultChannel = + private NotificationChannel defaultChannel = new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "test", NotificationManager.IMPORTANCE_UNSPECIFIED); private android.os.UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser()); @@ -185,7 +181,7 @@ public class NotificationRecordTest extends UiServiceTestCase { // @Test - public void testSound_default_preUpgradeUsesNotification() throws Exception { + public void testSound_default_preUpgradeUsesNotification() { defaultChannel.setSound(null, null); // pre upgrade, default sound. StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, @@ -198,7 +194,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testSound_custom_preUpgradeUsesNotification() throws Exception { + public void testSound_custom_preUpgradeUsesNotification() { defaultChannel.setSound(null, null); // pre upgrade, custom sound. StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, @@ -211,7 +207,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testSound_default_userLocked_preUpgrade() throws Exception { + public void testSound_default_userLocked_preUpgrade() { defaultChannel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); defaultChannel.lockFields(NotificationChannel.USER_LOCKED_SOUND); // pre upgrade, default sound. @@ -225,19 +221,19 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testSound_noSound_preUpgrade() throws Exception { + public void testSound_noSound_preUpgrade() { // pre upgrade, default sound. StatusBarNotification sbn = getNotification(PKG_N_MR1, false /* noisy */, false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, null /* group */); NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); - assertEquals(null, record.getSound()); + assertNull(record.getSound()); assertEquals(Notification.AUDIO_ATTRIBUTES_DEFAULT, record.getAudioAttributes()); } @Test - public void testSound_default_upgradeUsesChannel() throws Exception { + public void testSound_default_upgradeUsesChannel() { channel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); // post upgrade, default sound. StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, @@ -250,7 +246,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testVibration_default_preUpgradeUsesNotification() throws Exception { + public void testVibration_default_preUpgradeUsesNotification() { defaultChannel.enableVibration(false); // pre upgrade, default vibration. StatusBarNotification sbn = getNotification(PKG_N_MR1, false /* noisy */, @@ -262,7 +258,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testVibration_custom_preUpgradeUsesNotification() throws Exception { + public void testVibration_custom_preUpgradeUsesNotification() { defaultChannel.enableVibration(false); // pre upgrade, custom vibration. StatusBarNotification sbn = getNotification(PKG_N_MR1, false /* noisy */, @@ -274,7 +270,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testVibration_custom_userLocked_preUpgrade() throws Exception { + public void testVibration_custom_userLocked_preUpgrade() { defaultChannel.enableVibration(true); defaultChannel.lockFields(NotificationChannel.USER_LOCKED_VIBRATION); // pre upgrade, custom vibration. @@ -283,11 +279,11 @@ public class NotificationRecordTest extends UiServiceTestCase { false /* lights */, false /* defaultLights */, null /* group */); NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); - assertTrue(!Objects.equals(CUSTOM_VIBRATION, record.getVibration())); + assertTrue(!Arrays.equals(CUSTOM_VIBRATION, record.getVibration())); } @Test - public void testVibration_custom_upgradeUsesChannel() throws Exception { + public void testVibration_custom_upgradeUsesChannel() { channel.enableVibration(true); // post upgrade, custom vibration. StatusBarNotification sbn = getNotification(PKG_O, false /* noisy */, @@ -299,7 +295,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testImportance_preUpgrade() throws Exception { + public void testImportance_preUpgrade() { StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, null /* group */); @@ -308,7 +304,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testImportance_locked_preUpgrade() throws Exception { + public void testImportance_locked_preUpgrade() { defaultChannel.setImportance(IMPORTANCE_LOW); defaultChannel.lockFields(USER_LOCKED_IMPORTANCE); StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, @@ -320,7 +316,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testImportance_locked_unspecified_preUpgrade() throws Exception { + public void testImportance_locked_unspecified_preUpgrade() { defaultChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED); defaultChannel.lockFields(USER_LOCKED_IMPORTANCE); StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, @@ -332,7 +328,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testImportance_upgrade() throws Exception { + public void testImportance_upgrade() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, null /* group */); @@ -341,7 +337,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLights_preUpgrade_noLight() throws Exception { + public void testLights_preUpgrade_noLight() { StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, null /* group */); @@ -351,7 +347,7 @@ public class NotificationRecordTest extends UiServiceTestCase { @Test - public void testLights_preUpgrade() throws Exception { + public void testLights_preUpgrade() { StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, true /* lights */, false /* defaultLights */, null /* group */); @@ -360,7 +356,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLights_locked_preUpgrade() throws Exception { + public void testLights_locked_preUpgrade() { defaultChannel.enableLights(true); defaultChannel.lockFields(NotificationChannel.USER_LOCKED_LIGHTS); StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, @@ -368,11 +364,11 @@ public class NotificationRecordTest extends UiServiceTestCase { true /* lights */, false /* defaultLights */, null /* group */); NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); - assertFalse(CUSTOM_LIGHT.equals(record.getLight())); + assertNotEquals(CUSTOM_LIGHT, record.getLight()); } @Test - public void testLights_upgrade_defaultLights() throws Exception { + public void testLights_upgrade_defaultLights() { int defaultLightColor = mMockContext.getResources().getColor( com.android.internal.R.color.config_defaultNotificationColor); int defaultLightOn = mMockContext.getResources().getInteger( @@ -390,7 +386,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLights_upgrade() throws Exception { + public void testLights_upgrade() { int defaultLightOn = mMockContext.getResources().getInteger( com.android.internal.R.integer.config_defaultNotificationLedOn); int defaultLightOff = mMockContext.getResources().getInteger( @@ -406,7 +402,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLights_upgrade_noLight() throws Exception { + public void testLights_upgrade_noLight() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, null /* group */); @@ -415,7 +411,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLogmakerShortChannel() throws Exception { + public void testLogmakerShortChannel() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, null /* group */); @@ -428,7 +424,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLogmakerLongChannel() throws Exception { + public void testLogmakerLongChannel() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /*defaultLights */, null /* group */); @@ -439,7 +435,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLogmakerNoGroup() throws Exception { + public void testLogmakerNoGroup() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /*defaultLights */, null /* group */); @@ -448,7 +444,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLogmakerShortGroup() throws Exception { + public void testLogmakerShortGroup() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupId /* group */); @@ -458,7 +454,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLogmakerLongGroup() throws Exception { + public void testLogmakerLongGroup() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupIdLong /* group */); @@ -469,7 +465,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testLogmakerOverrideGroup() throws Exception { + public void testLogmakerOverrideGroup() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupId /* group */); @@ -485,7 +481,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testNotificationStats() throws Exception { + public void testNotificationStats() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupId /* group */); @@ -528,7 +524,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testUserSentiment() throws Exception { + public void testUserSentiment() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupId /* group */); @@ -546,7 +542,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testUserSentiment_appImportanceUpdatesSentiment() throws Exception { + public void testUserSentiment_appImportanceUpdatesSentiment() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupId /* group */); @@ -558,7 +554,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testUserSentiment_appImportanceBlocksNegativeSentimentUpdate() throws Exception { + public void testUserSentiment_appImportanceBlocksNegativeSentimentUpdate() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupId /* group */); @@ -574,7 +570,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testUserSentiment_userLocked() throws Exception { + public void testUserSentiment_userLocked() { channel.lockFields(USER_LOCKED_IMPORTANCE); StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, @@ -593,17 +589,17 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testAppImportance_returnsCorrectly() throws Exception { + public void testAppImportance_returnsCorrectly() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, false /* lights */, false /* defaultLights */, groupId /* group */); NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); record.setIsAppImportanceLocked(true); - assertEquals(true, record.getIsAppImportanceLocked()); + assertTrue(record.getIsAppImportanceLocked()); record.setIsAppImportanceLocked(false); - assertEquals(false, record.getIsAppImportanceLocked()); + assertFalse(record.getIsAppImportanceLocked()); } @Test @@ -613,10 +609,10 @@ public class NotificationRecordTest extends UiServiceTestCase { false /* lights */, false /* defaultLights */, null /* group */); NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); - assertEquals(false, record.isInterruptive()); + assertFalse(record.isInterruptive()); record.setTextChanged(true); - assertEquals(false, record.isInterruptive()); + assertFalse(record.isInterruptive()); } @Test @@ -626,11 +622,11 @@ public class NotificationRecordTest extends UiServiceTestCase { false /* lights */, false /* defaultLights */, null /* group */); NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); - assertEquals(false, record.isInterruptive()); + assertFalse(record.isInterruptive()); record.setTextChanged(true); record.setSeen(); - assertEquals(true, record.isInterruptive()); + assertTrue(record.isInterruptive()); } @Test @@ -640,15 +636,15 @@ public class NotificationRecordTest extends UiServiceTestCase { false /* lights */, false /* defaultLights */, null /* group */); NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); - assertEquals(false, record.isInterruptive()); + assertFalse(record.isInterruptive()); record.setTextChanged(false); record.setSeen(); - assertEquals(false, record.isInterruptive()); + assertFalse(record.isInterruptive()); } @Test - public void testCalculateGrantableUris_PappProvided() throws RemoteException { + public void testCalculateGrantableUris_PappProvided() { IActivityManager am = mock(IActivityManager.class); UriGrantsManagerInternal ugm = mock(UriGrantsManagerInternal.class); when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class), @@ -671,7 +667,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testCalculateGrantableUris_PuserOverridden() throws RemoteException { + public void testCalculateGrantableUris_PuserOverridden() { IActivityManager am = mock(IActivityManager.class); UriGrantsManagerInternal ugm = mock(UriGrantsManagerInternal.class); when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class), @@ -689,7 +685,7 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test - public void testCalculateGrantableUris_prePappProvided() throws RemoteException { + public void testCalculateGrantableUris_prePappProvided() { IActivityManager am = mock(IActivityManager.class); UriGrantsManagerInternal ugm = mock(UriGrantsManagerInternal.class); when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class), @@ -790,4 +786,19 @@ public class NotificationRecordTest extends UiServiceTestCase { assertEquals(IMPORTANCE_LOW, record.getImportance()); } + + @Test + public void testSetContactAffinity() { + channel.setImportance(IMPORTANCE_LOW); + channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); + StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, + true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, + false /* lights */, false /* defaultLights */, groupId /* group */); + NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); + + record.setContactAffinity(1.0f); + + assertEquals(1.0f, record.getContactAffinity()); + assertEquals(IMPORTANCE_LOW, record.getImportance()); + } } |