Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.server.notification; |
| 17 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 18 | import static android.service.notification.NotificationListenerService.Ranking |
| 19 | .USER_SENTIMENT_NEGATIVE; |
| 20 | import static android.service.notification.NotificationListenerService.Ranking |
| 21 | .USER_SENTIMENT_NEUTRAL; |
| 22 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 23 | import static junit.framework.Assert.assertEquals; |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 24 | import static junit.framework.Assert.assertFalse; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 25 | import static junit.framework.Assert.assertNotNull; |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 26 | import static junit.framework.Assert.assertNull; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 27 | import static junit.framework.Assert.assertTrue; |
| 28 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 29 | import static org.mockito.Matchers.anyInt; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 30 | import static org.mockito.Matchers.eq; |
| 31 | import static org.mockito.Mockito.when; |
| 32 | |
| 33 | import android.app.ActivityManager; |
| 34 | import android.app.Notification; |
| 35 | import android.app.Notification.Builder; |
| 36 | import android.app.NotificationChannel; |
| 37 | import android.app.NotificationManager; |
| 38 | import android.content.Context; |
| 39 | import android.content.pm.ApplicationInfo; |
| 40 | import android.content.pm.PackageManager; |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 41 | import android.graphics.Color; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 42 | import android.media.AudioAttributes; |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 43 | import android.metrics.LogMaker; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 44 | import android.net.Uri; |
| 45 | import android.os.Build; |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 46 | import android.os.Bundle; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 47 | import android.os.UserHandle; |
| 48 | import android.provider.Settings; |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 49 | import android.service.notification.Adjustment; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 50 | import android.service.notification.StatusBarNotification; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 51 | import android.support.test.runner.AndroidJUnit4; |
| 52 | import android.test.suitebuilder.annotation.SmallTest; |
| 53 | |
| 54 | |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 55 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 56 | import com.android.server.UiServiceTestCase; |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 57 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 58 | import org.junit.Before; |
| 59 | import org.junit.Test; |
| 60 | import org.junit.runner.RunWith; |
| 61 | import org.mockito.Mock; |
| 62 | import org.mockito.Mockito; |
| 63 | import org.mockito.MockitoAnnotations; |
| 64 | |
| 65 | import java.util.Objects; |
| 66 | |
| 67 | @SmallTest |
| 68 | @RunWith(AndroidJUnit4.class) |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 69 | public class NotificationRecordTest extends UiServiceTestCase { |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 70 | |
| 71 | private final Context mMockContext = Mockito.mock(Context.class); |
| 72 | @Mock PackageManager mPm; |
| 73 | |
| 74 | private final String pkg = "com.android.server.notification"; |
Julia Reynolds | 19ad747 | 2016-12-12 08:51:08 -0500 | [diff] [blame] | 75 | private final int uid = 9583; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 76 | private final String pkg2 = "pkg2"; |
| 77 | private final int uid2 = 1111111; |
| 78 | private final int id1 = 1; |
| 79 | private final int id2 = 2; |
| 80 | private final String tag1 = "tag1"; |
| 81 | private final String tag2 = "tag2"; |
| 82 | private final String channelId = "channel"; |
| 83 | NotificationChannel channel = |
| 84 | new NotificationChannel(channelId, "test", NotificationManager.IMPORTANCE_DEFAULT); |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 85 | private final String channelIdLong = |
| 86 | "give_a_developer_a_string_argument_and_who_knows_what_they_will_pass_in_there"; |
| 87 | final String groupId = "group"; |
| 88 | final String groupIdOverride = "other_group"; |
| 89 | private final String groupIdLong = |
| 90 | "0|com.foo.bar|g:content://com.foo.bar.ui/account%3A-0000000/account/"; |
| 91 | NotificationChannel channelLongId = |
| 92 | new NotificationChannel(channelIdLong, "long", NotificationManager.IMPORTANCE_DEFAULT); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 93 | NotificationChannel defaultChannel = |
| 94 | new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "test", |
| 95 | NotificationManager.IMPORTANCE_UNSPECIFIED); |
| 96 | private android.os.UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser()); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 97 | final ApplicationInfo legacy = new ApplicationInfo(); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 98 | final ApplicationInfo upgrade = new ApplicationInfo(); |
| 99 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 100 | private static final long[] CUSTOM_VIBRATION = new long[] { |
| 101 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 102 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 103 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }; |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 104 | private static final long[] CUSTOM_CHANNEL_VIBRATION = new long[] {300, 400, 300, 400 }; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 105 | private static final Uri CUSTOM_SOUND = Settings.System.DEFAULT_ALARM_ALERT_URI; |
| 106 | private static final AudioAttributes CUSTOM_ATTRIBUTES = new AudioAttributes.Builder() |
| 107 | .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) |
| 108 | .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) |
| 109 | .build(); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 110 | private static final NotificationRecord.Light CUSTOM_LIGHT = |
| 111 | new NotificationRecord.Light(1, 2, 3); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 112 | |
| 113 | @Before |
| 114 | public void setUp() { |
| 115 | MockitoAnnotations.initMocks(this); |
| 116 | |
Chris Wren | 89aa226 | 2017-05-05 18:05:56 -0400 | [diff] [blame] | 117 | when(mMockContext.getResources()).thenReturn(getContext().getResources()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 118 | when(mMockContext.getPackageManager()).thenReturn(mPm); |
| 119 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 120 | legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1; |
Dan Sandler | e103b78 | 2017-05-17 16:07:56 -0700 | [diff] [blame] | 121 | upgrade.targetSdkVersion = Build.VERSION_CODES.O; |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 122 | try { |
| 123 | when(mPm.getApplicationInfoAsUser(eq(pkg), anyInt(), anyInt())).thenReturn(legacy); |
| 124 | when(mPm.getApplicationInfoAsUser(eq(pkg2), anyInt(), anyInt())).thenReturn(upgrade); |
| 125 | } catch (PackageManager.NameNotFoundException e) {} |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 128 | private StatusBarNotification getNotification(boolean preO, boolean noisy, boolean defaultSound, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 129 | boolean buzzy, boolean defaultVibration, boolean lights, boolean defaultLights, |
| 130 | String group) { |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 131 | when(mMockContext.getApplicationInfo()).thenReturn(preO ? legacy : upgrade); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 132 | final Builder builder = new Builder(mMockContext) |
| 133 | .setContentTitle("foo") |
| 134 | .setSmallIcon(android.R.drawable.sym_def_app_icon) |
| 135 | .setPriority(Notification.PRIORITY_HIGH); |
| 136 | |
| 137 | int defaults = 0; |
| 138 | if (noisy) { |
| 139 | if (defaultSound) { |
| 140 | defaults |= Notification.DEFAULT_SOUND; |
| 141 | } else { |
| 142 | builder.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 143 | channel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 144 | } |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 145 | } else { |
| 146 | channel.setSound(null, null); |
| 147 | builder.setSound(null, null); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 148 | } |
| 149 | if (buzzy) { |
| 150 | if (defaultVibration) { |
| 151 | defaults |= Notification.DEFAULT_VIBRATE; |
| 152 | } else { |
| 153 | builder.setVibrate(CUSTOM_VIBRATION); |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 154 | channel.setVibrationPattern(CUSTOM_CHANNEL_VIBRATION); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 155 | } |
| 156 | } |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 157 | if (lights) { |
| 158 | if (defaultLights) { |
| 159 | defaults |= Notification.DEFAULT_LIGHTS; |
| 160 | } else { |
| 161 | builder.setLights(CUSTOM_LIGHT.color, CUSTOM_LIGHT.onMs, CUSTOM_LIGHT.offMs); |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 162 | channel.setLightColor(Color.BLUE); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 163 | } |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 164 | channel.enableLights(true); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 165 | } else { |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 166 | channel.enableLights(false); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 167 | } |
| 168 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 169 | builder.setDefaults(defaults); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 170 | if (!preO) { |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 171 | builder.setChannelId(channelId); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 174 | if(group != null) { |
| 175 | builder.setGroup(group); |
| 176 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 177 | |
| 178 | Notification n = builder.build(); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 179 | if (preO) { |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 180 | return new StatusBarNotification(pkg, pkg, id1, tag1, uid, uid, n, |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 181 | mUser, null, uid); |
| 182 | } else { |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 183 | return new StatusBarNotification(pkg2, pkg2, id2, tag2, uid2, uid2, n, |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 184 | mUser, null, uid2); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // |
| 189 | // Tests |
| 190 | // |
| 191 | |
| 192 | @Test |
| 193 | public void testSound_default_preUpgradeUsesNotification() throws Exception { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 194 | defaultChannel.setSound(null, null); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 195 | // pre upgrade, default sound. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 196 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 197 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 198 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 199 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 200 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 201 | assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 202 | assertEquals(Notification.AUDIO_ATTRIBUTES_DEFAULT, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | @Test |
| 206 | public void testSound_custom_preUpgradeUsesNotification() throws Exception { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 207 | defaultChannel.setSound(null, null); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 208 | // pre upgrade, custom sound. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 209 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 210 | false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 211 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 212 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 213 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 214 | assertEquals(CUSTOM_SOUND, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 215 | assertEquals(CUSTOM_ATTRIBUTES, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | @Test |
| 219 | public void testSound_default_userLocked_preUpgrade() throws Exception { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 220 | defaultChannel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 221 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_SOUND); |
| 222 | // pre upgrade, default sound. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 223 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 224 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 225 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 226 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 227 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 228 | assertEquals(CUSTOM_SOUND, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 229 | assertEquals(CUSTOM_ATTRIBUTES, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Test |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 233 | public void testSound_noSound_preUpgrade() throws Exception { |
| 234 | // pre upgrade, default sound. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 235 | StatusBarNotification sbn = getNotification(true /*preO */, false /* noisy */, |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 236 | false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 237 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 238 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 239 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 240 | assertEquals(null, record.getSound()); |
| 241 | assertEquals(Notification.AUDIO_ATTRIBUTES_DEFAULT, record.getAudioAttributes()); |
| 242 | } |
| 243 | |
| 244 | @Test |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 245 | public void testSound_default_upgradeUsesChannel() throws Exception { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 246 | channel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 247 | // post upgrade, default sound. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 248 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 249 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 250 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 251 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 252 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 253 | assertEquals(CUSTOM_SOUND, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 254 | assertEquals(CUSTOM_ATTRIBUTES, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | @Test |
| 258 | public void testVibration_default_preUpgradeUsesNotification() throws Exception { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 259 | defaultChannel.enableVibration(false); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 260 | // pre upgrade, default vibration. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 261 | StatusBarNotification sbn = getNotification(true /*preO */, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 262 | false /* defaultSound */, true /* buzzy */, true /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 263 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 264 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 265 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 266 | assertNotNull(record.getVibration()); |
| 267 | } |
| 268 | |
| 269 | @Test |
| 270 | public void testVibration_custom_preUpgradeUsesNotification() throws Exception { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 271 | defaultChannel.enableVibration(false); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 272 | // pre upgrade, custom vibration. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 273 | StatusBarNotification sbn = getNotification(true /*preO */, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 274 | false /* defaultSound */, true /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 275 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 276 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 277 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 278 | assertEquals(CUSTOM_VIBRATION, record.getVibration()); |
| 279 | } |
| 280 | |
| 281 | @Test |
| 282 | public void testVibration_custom_userLocked_preUpgrade() throws Exception { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 283 | defaultChannel.enableVibration(true); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 284 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_VIBRATION); |
| 285 | // pre upgrade, custom vibration. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 286 | StatusBarNotification sbn = getNotification(true /*preO */, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 287 | false /* defaultSound */, true /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 288 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 289 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 290 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 291 | assertTrue(!Objects.equals(CUSTOM_VIBRATION, record.getVibration())); |
| 292 | } |
| 293 | |
| 294 | @Test |
| 295 | public void testVibration_custom_upgradeUsesChannel() throws Exception { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 296 | channel.enableVibration(true); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 297 | // post upgrade, custom vibration. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 298 | StatusBarNotification sbn = getNotification(false /*preO */, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 299 | false /* defaultSound */, true /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 300 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 301 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 302 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 303 | assertEquals(CUSTOM_CHANNEL_VIBRATION, record.getVibration()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | @Test |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 307 | public void testImportance_preUpgrade() throws Exception { |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 308 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 309 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 310 | false /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 311 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 312 | assertEquals(NotificationManager.IMPORTANCE_HIGH, record.getImportance()); |
| 313 | } |
| 314 | |
| 315 | @Test |
| 316 | public void testImportance_locked_preUpgrade() throws Exception { |
| 317 | defaultChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 318 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 319 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 320 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 321 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 322 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 323 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 324 | assertEquals(NotificationManager.IMPORTANCE_LOW, record.getImportance()); |
| 325 | } |
| 326 | |
| 327 | @Test |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 328 | public void testImportance_locked_unspecified_preUpgrade() throws Exception { |
| 329 | defaultChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED); |
| 330 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 331 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 332 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 333 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 334 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 335 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 336 | assertEquals(NotificationManager.IMPORTANCE_HIGH, record.getImportance()); |
| 337 | } |
| 338 | |
| 339 | @Test |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 340 | public void testImportance_upgrade() throws Exception { |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 341 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 342 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 343 | false /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 344 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 345 | assertEquals(NotificationManager.IMPORTANCE_DEFAULT, record.getImportance()); |
| 346 | } |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 347 | |
| 348 | @Test |
| 349 | public void testLights_preUpgrade_noLight() throws Exception { |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 350 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 351 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 352 | false /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 353 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 354 | assertNull(record.getLight()); |
| 355 | } |
| 356 | |
| 357 | |
| 358 | @Test |
| 359 | public void testLights_preUpgrade() throws Exception { |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 360 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 361 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 362 | true /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 363 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 364 | assertEquals(CUSTOM_LIGHT, record.getLight()); |
| 365 | } |
| 366 | |
| 367 | @Test |
| 368 | public void testLights_locked_preUpgrade() throws Exception { |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 369 | defaultChannel.enableLights(true); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 370 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_LIGHTS); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 371 | StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 372 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 373 | true /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 374 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 375 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 376 | assertFalse(CUSTOM_LIGHT.equals(record.getLight())); |
| 377 | } |
| 378 | |
| 379 | @Test |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 380 | public void testLights_upgrade_defaultLights() throws Exception { |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 381 | int defaultLightColor = mMockContext.getResources().getColor( |
| 382 | com.android.internal.R.color.config_defaultNotificationColor); |
| 383 | int defaultLightOn = mMockContext.getResources().getInteger( |
| 384 | com.android.internal.R.integer.config_defaultNotificationLedOn); |
| 385 | int defaultLightOff = mMockContext.getResources().getInteger( |
| 386 | com.android.internal.R.integer.config_defaultNotificationLedOff); |
| 387 | |
| 388 | NotificationRecord.Light expected = new NotificationRecord.Light( |
| 389 | defaultLightColor, defaultLightOn, defaultLightOff); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 390 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 391 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 392 | true /* lights */, true /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 393 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 394 | assertEquals(expected, record.getLight()); |
| 395 | } |
| 396 | |
| 397 | @Test |
| 398 | public void testLights_upgrade() throws Exception { |
| 399 | int defaultLightOn = mMockContext.getResources().getInteger( |
| 400 | com.android.internal.R.integer.config_defaultNotificationLedOn); |
| 401 | int defaultLightOff = mMockContext.getResources().getInteger( |
| 402 | com.android.internal.R.integer.config_defaultNotificationLedOff); |
| 403 | |
| 404 | NotificationRecord.Light expected = new NotificationRecord.Light( |
| 405 | Color.BLUE, defaultLightOn, defaultLightOff); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 406 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 407 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 408 | true /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 409 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 410 | assertEquals(expected, record.getLight()); |
| 411 | } |
| 412 | |
| 413 | @Test |
| 414 | public void testLights_upgrade_noLight() throws Exception { |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 415 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 416 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 417 | false /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 418 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 419 | assertNull(record.getLight()); |
| 420 | } |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 421 | |
| 422 | @Test |
| 423 | public void testLogmakerShortChannel() throws Exception { |
| 424 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
| 425 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 426 | false /* lights */, false /* defaultLights */, null /* group */); |
| 427 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 428 | final LogMaker logMaker = record.getLogMaker(); |
| 429 | assertEquals(channelId, |
| 430 | (String) logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID)); |
| 431 | assertEquals(channel.getImportance(), |
| 432 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE)); |
| 433 | } |
| 434 | |
| 435 | @Test |
| 436 | public void testLogmakerLongChannel() throws Exception { |
| 437 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
| 438 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 439 | false /* lights */, false /*defaultLights */, null /* group */); |
| 440 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channelLongId); |
| 441 | final String loggedId = (String) |
| 442 | record.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID); |
| 443 | assertEquals(channelIdLong.substring(0,10), loggedId.substring(0, 10)); |
| 444 | } |
| 445 | |
| 446 | @Test |
| 447 | public void testLogmakerNoGroup() throws Exception { |
| 448 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
| 449 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 450 | false /* lights */, false /*defaultLights */, null /* group */); |
| 451 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 452 | assertNull(record.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID)); |
| 453 | } |
| 454 | |
| 455 | @Test |
| 456 | public void testLogmakerShortGroup() throws Exception { |
| 457 | StatusBarNotification sbn = getNotification(false /*reO */, true /* noisy */, |
| 458 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 459 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 460 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 461 | assertEquals(groupId, |
| 462 | record.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID)); |
| 463 | } |
| 464 | |
| 465 | @Test |
| 466 | public void testLogmakerLongGroup() throws Exception { |
| 467 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
| 468 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 469 | false /* lights */, false /* defaultLights */, groupIdLong /* group */); |
| 470 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 471 | final String loggedId = (String) |
| 472 | record.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID); |
| 473 | assertEquals(groupIdLong.substring(0,10), loggedId.substring(0, 10)); |
| 474 | } |
| 475 | |
| 476 | @Test |
| 477 | public void testLogmakerOverrideGroup() throws Exception { |
| 478 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
| 479 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 480 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 481 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 482 | assertEquals(groupId, |
| 483 | record.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID)); |
| 484 | record.setOverrideGroupKey(groupIdOverride); |
| 485 | assertEquals(groupIdOverride, |
| 486 | record.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID)); |
| 487 | record.setOverrideGroupKey(null); |
| 488 | assertEquals(groupId, |
| 489 | record.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID)); |
| 490 | } |
| 491 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 492 | @Test |
| 493 | public void testNotificationStats() throws Exception { |
| 494 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
| 495 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 496 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 497 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 498 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 499 | assertFalse(record.getStats().hasSeen()); |
| 500 | assertFalse(record.isSeen()); |
| 501 | assertFalse(record.getStats().hasDirectReplied()); |
| 502 | assertFalse(record.getStats().hasExpanded()); |
| 503 | assertFalse(record.getStats().hasInteracted()); |
| 504 | assertFalse(record.getStats().hasViewedSettings()); |
| 505 | assertFalse(record.getStats().hasSnoozed()); |
| 506 | |
| 507 | record.setSeen(); |
| 508 | assertTrue(record.getStats().hasSeen()); |
| 509 | assertTrue(record.isSeen()); |
| 510 | assertFalse(record.getStats().hasDirectReplied()); |
| 511 | assertFalse(record.getStats().hasExpanded()); |
| 512 | assertFalse(record.getStats().hasInteracted()); |
| 513 | assertFalse(record.getStats().hasViewedSettings()); |
| 514 | assertFalse(record.getStats().hasSnoozed()); |
| 515 | |
| 516 | record.recordViewedSettings(); |
| 517 | assertFalse(record.getStats().hasDirectReplied()); |
| 518 | assertFalse(record.getStats().hasExpanded()); |
| 519 | assertTrue(record.getStats().hasViewedSettings()); |
| 520 | assertFalse(record.getStats().hasSnoozed()); |
| 521 | |
| 522 | record.recordSnoozed(); |
| 523 | assertFalse(record.getStats().hasDirectReplied()); |
| 524 | assertFalse(record.getStats().hasExpanded()); |
| 525 | assertTrue(record.getStats().hasSnoozed()); |
| 526 | |
| 527 | record.recordExpanded(); |
| 528 | assertFalse(record.getStats().hasDirectReplied()); |
| 529 | assertTrue(record.getStats().hasExpanded()); |
| 530 | |
| 531 | record.recordDirectReplied(); |
| 532 | assertTrue(record.getStats().hasDirectReplied()); |
| 533 | } |
| 534 | |
| 535 | @Test |
| 536 | public void testUserSentiment() throws Exception { |
| 537 | StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */, |
| 538 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 539 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 540 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 541 | |
| 542 | assertEquals(USER_SENTIMENT_NEUTRAL, record.getUserSentiment()); |
| 543 | |
| 544 | Bundle signals = new Bundle(); |
| 545 | signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE); |
| 546 | record.addAdjustment(new Adjustment(pkg, record.getKey(), signals, null, sbn.getUserId())); |
| 547 | |
| 548 | record.applyAdjustments(); |
| 549 | |
| 550 | assertEquals(USER_SENTIMENT_NEGATIVE, record.getUserSentiment()); |
| 551 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 552 | } |