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 | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 18 | import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 19 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
| 20 | import static android.app.NotificationManager.IMPORTANCE_HIGH; |
| 21 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 22 | import static android.service.notification.Adjustment.KEY_IMPORTANCE; |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 23 | import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; |
| 24 | import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL; |
| 25 | import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_POSITIVE; |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 26 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 27 | import static junit.framework.Assert.assertEquals; |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 28 | import static junit.framework.Assert.assertFalse; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 29 | import static junit.framework.Assert.assertNotNull; |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 30 | import static junit.framework.Assert.assertNull; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 31 | import static junit.framework.Assert.assertTrue; |
| 32 | |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 33 | import static org.junit.Assert.assertNotEquals; |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 34 | import static org.junit.Assert.fail; |
| 35 | import static org.mockito.ArgumentMatchers.any; |
| 36 | import static org.mockito.ArgumentMatchers.anyInt; |
| 37 | import static org.mockito.ArgumentMatchers.eq; |
| 38 | import static org.mockito.Mockito.mock; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 39 | import static org.mockito.Mockito.when; |
| 40 | |
| 41 | import android.app.ActivityManager; |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 42 | import android.app.IActivityManager; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 43 | import android.app.Notification; |
| 44 | import android.app.Notification.Builder; |
| 45 | import android.app.NotificationChannel; |
| 46 | import android.app.NotificationManager; |
| 47 | import android.content.Context; |
| 48 | import android.content.pm.ApplicationInfo; |
| 49 | import android.content.pm.PackageManager; |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 50 | import android.graphics.Color; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 51 | import android.graphics.drawable.Icon; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 52 | import android.media.AudioAttributes; |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 53 | import android.metrics.LogMaker; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 54 | import android.net.Uri; |
Chris Wren | 6cbf57b | 2019-12-12 15:33:21 -0500 | [diff] [blame] | 55 | import android.os.Build; |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 56 | import android.os.Bundle; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 57 | import android.os.UserHandle; |
| 58 | import android.provider.Settings; |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 59 | import android.service.notification.Adjustment; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 60 | import android.service.notification.StatusBarNotification; |
Chris Wren | 6cbf57b | 2019-12-12 15:33:21 -0500 | [diff] [blame] | 61 | import android.widget.RemoteViews; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 62 | |
| 63 | import androidx.test.filters.SmallTest; |
| 64 | import androidx.test.runner.AndroidJUnit4; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 65 | |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 66 | import com.android.internal.R; |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 67 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 68 | import com.android.server.UiServiceTestCase; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 69 | import com.android.server.uri.UriGrantsManagerInternal; |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 70 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 71 | import org.junit.Before; |
| 72 | import org.junit.Test; |
| 73 | import org.junit.runner.RunWith; |
| 74 | import org.mockito.Mock; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 75 | import org.mockito.MockitoAnnotations; |
| 76 | |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 77 | import java.util.ArrayList; |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 78 | import java.util.Arrays; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 79 | |
| 80 | @SmallTest |
| 81 | @RunWith(AndroidJUnit4.class) |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 82 | public class NotificationRecordTest extends UiServiceTestCase { |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 83 | |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 84 | private final Context mMockContext = mock(Context.class); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 85 | @Mock private PackageManager mPm; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 86 | |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 87 | private final String pkg = PKG_N_MR1; |
Julia Reynolds | 19ad747 | 2016-12-12 08:51:08 -0500 | [diff] [blame] | 88 | private final int uid = 9583; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 89 | private final int id1 = 1; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 90 | private final String tag1 = "tag1"; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 91 | private final String channelId = "channel"; |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 92 | private NotificationChannel channel = |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 93 | new NotificationChannel(channelId, "test", NotificationManager.IMPORTANCE_DEFAULT); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 94 | private final String groupId = "group"; |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 95 | private NotificationChannel defaultChannel = |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 96 | new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "test", |
| 97 | NotificationManager.IMPORTANCE_UNSPECIFIED); |
| 98 | private android.os.UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 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); |
Chris Wren | 6cbf57b | 2019-12-12 15:33:21 -0500 | [diff] [blame] | 119 | ApplicationInfo appInfo = new ApplicationInfo(); |
| 120 | appInfo.targetSdkVersion = Build.VERSION_CODES.O; |
| 121 | when(mMockContext.getApplicationInfo()).thenReturn(appInfo); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 124 | private StatusBarNotification getNotification(String pkg, boolean noisy, boolean defaultSound, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 125 | boolean buzzy, boolean defaultVibration, boolean lights, boolean defaultLights, |
| 126 | String group) { |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 127 | final Builder builder = new Builder(mMockContext) |
| 128 | .setContentTitle("foo") |
| 129 | .setSmallIcon(android.R.drawable.sym_def_app_icon) |
| 130 | .setPriority(Notification.PRIORITY_HIGH); |
| 131 | |
| 132 | int defaults = 0; |
| 133 | if (noisy) { |
| 134 | if (defaultSound) { |
| 135 | defaults |= Notification.DEFAULT_SOUND; |
| 136 | } else { |
| 137 | builder.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 138 | channel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 139 | } |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 140 | } else { |
| 141 | channel.setSound(null, null); |
| 142 | builder.setSound(null, null); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 143 | } |
| 144 | if (buzzy) { |
| 145 | if (defaultVibration) { |
| 146 | defaults |= Notification.DEFAULT_VIBRATE; |
| 147 | } else { |
| 148 | builder.setVibrate(CUSTOM_VIBRATION); |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 149 | channel.setVibrationPattern(CUSTOM_CHANNEL_VIBRATION); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 150 | } |
| 151 | } |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 152 | if (lights) { |
| 153 | if (defaultLights) { |
| 154 | defaults |= Notification.DEFAULT_LIGHTS; |
| 155 | } else { |
| 156 | builder.setLights(CUSTOM_LIGHT.color, CUSTOM_LIGHT.onMs, CUSTOM_LIGHT.offMs); |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 157 | channel.setLightColor(Color.BLUE); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 158 | } |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 159 | channel.enableLights(true); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 160 | } else { |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 161 | channel.enableLights(false); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 164 | builder.setDefaults(defaults); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 165 | builder.setChannelId(channelId); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 166 | |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 167 | if(group != null) { |
| 168 | builder.setGroup(group); |
| 169 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 170 | |
| 171 | Notification n = builder.build(); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 172 | return new StatusBarNotification(pkg, pkg, id1, tag1, uid, uid, n, mUser, null, uid); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Chris Wren | 6cbf57b | 2019-12-12 15:33:21 -0500 | [diff] [blame] | 175 | private StatusBarNotification getStyledNotification(boolean customContent, boolean customBig, |
| 176 | boolean customHeadsUp, Notification.Style style) { |
| 177 | final Builder builder = new Builder(mMockContext) |
| 178 | .setContentTitle("foo") |
| 179 | .setSmallIcon(android.R.drawable.sym_def_app_icon); |
| 180 | if (style != null) { |
| 181 | builder.setStyle(style); |
| 182 | } |
| 183 | if (customContent) { |
| 184 | builder.setCustomContentView(mock(RemoteViews.class)); |
| 185 | } |
| 186 | if (customBig) { |
| 187 | builder.setCustomBigContentView(mock(RemoteViews.class)); |
| 188 | } |
| 189 | if (customHeadsUp) { |
| 190 | builder.setCustomHeadsUpContentView(mock(RemoteViews.class)); |
| 191 | } |
| 192 | |
| 193 | Notification n = builder.build(); |
| 194 | return new StatusBarNotification(pkg, pkg, id1, tag1, uid, uid, n, mUser, null, uid); |
| 195 | } |
| 196 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 197 | // |
| 198 | // Tests |
| 199 | // |
| 200 | |
| 201 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 202 | public void testSound_default_preUpgradeUsesNotification() { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 203 | defaultChannel.setSound(null, null); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 204 | // pre upgrade, default sound. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 205 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 206 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 207 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 208 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 209 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 210 | assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 211 | assertEquals(Notification.AUDIO_ATTRIBUTES_DEFAULT, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 215 | public void testSound_custom_preUpgradeUsesNotification() { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 216 | defaultChannel.setSound(null, null); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 217 | // pre upgrade, custom sound. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 218 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 219 | false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 220 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 221 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 222 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 223 | assertEquals(CUSTOM_SOUND, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 224 | assertEquals(CUSTOM_ATTRIBUTES, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 228 | public void testSound_default_userLocked_preUpgrade() { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 229 | defaultChannel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 230 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_SOUND); |
| 231 | // pre upgrade, default sound. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 232 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 233 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 234 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 235 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 236 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 237 | assertEquals(CUSTOM_SOUND, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 238 | assertEquals(CUSTOM_ATTRIBUTES, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 242 | public void testSound_noSound_preUpgrade() { |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 243 | // pre upgrade, default sound. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 244 | StatusBarNotification sbn = getNotification(PKG_N_MR1, false /* noisy */, |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 245 | false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 246 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 247 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 248 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 249 | assertNull(record.getSound()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 250 | assertEquals(Notification.AUDIO_ATTRIBUTES_DEFAULT, record.getAudioAttributes()); |
| 251 | } |
| 252 | |
| 253 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 254 | public void testSound_default_upgradeUsesChannel() { |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 255 | channel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 256 | // post upgrade, default sound. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 257 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 258 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 259 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 260 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 261 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 262 | assertEquals(CUSTOM_SOUND, record.getSound()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 263 | assertEquals(CUSTOM_ATTRIBUTES, record.getAudioAttributes()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 267 | public void testVibration_default_preUpgradeUsesNotification() { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 268 | defaultChannel.enableVibration(false); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 269 | // pre upgrade, default vibration. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 270 | StatusBarNotification sbn = getNotification(PKG_N_MR1, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 271 | false /* defaultSound */, true /* buzzy */, true /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 272 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 273 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 274 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 275 | assertNotNull(record.getVibration()); |
| 276 | } |
| 277 | |
| 278 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 279 | public void testVibration_custom_preUpgradeUsesNotification() { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 280 | defaultChannel.enableVibration(false); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 281 | // pre upgrade, custom vibration. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 282 | StatusBarNotification sbn = getNotification(PKG_N_MR1, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 283 | false /* defaultSound */, true /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 284 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 285 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 286 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 287 | assertEquals(CUSTOM_VIBRATION, record.getVibration()); |
| 288 | } |
| 289 | |
| 290 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 291 | public void testVibration_custom_userLocked_preUpgrade() { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 292 | defaultChannel.enableVibration(true); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 293 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_VIBRATION); |
| 294 | // pre upgrade, custom vibration. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 295 | StatusBarNotification sbn = getNotification(PKG_N_MR1, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 296 | false /* defaultSound */, true /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 297 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 298 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 299 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 300 | assertTrue(!Arrays.equals(CUSTOM_VIBRATION, record.getVibration())); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 304 | public void testVibration_custom_upgradeUsesChannel() { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 305 | channel.enableVibration(true); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 306 | // post upgrade, custom vibration. |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 307 | StatusBarNotification sbn = getNotification(PKG_O, false /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 308 | false /* defaultSound */, true /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 309 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 310 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 311 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 312 | assertEquals(CUSTOM_CHANNEL_VIBRATION, record.getVibration()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 316 | public void testImportance_preUpgrade() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 317 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 318 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 319 | false /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 320 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 321 | assertEquals(NotificationManager.IMPORTANCE_HIGH, record.getImportance()); |
| 322 | } |
| 323 | |
| 324 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 325 | public void testImportance_locked_preUpgrade() { |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 326 | defaultChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 327 | defaultChannel.lockFields(USER_LOCKED_IMPORTANCE); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 328 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 329 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 330 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 331 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 332 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 333 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 337 | public void testImportance_locked_unspecified_preUpgrade() { |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 338 | defaultChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 339 | defaultChannel.lockFields(USER_LOCKED_IMPORTANCE); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 340 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 341 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 342 | false /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 343 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 344 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 345 | assertEquals(NotificationManager.IMPORTANCE_HIGH, record.getImportance()); |
| 346 | } |
| 347 | |
| 348 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 349 | public void testImportance_upgrade() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 350 | StatusBarNotification sbn = getNotification(PKG_O, 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, channel); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 354 | assertEquals(NotificationManager.IMPORTANCE_DEFAULT, record.getImportance()); |
| 355 | } |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 356 | |
| 357 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 358 | public void testLights_preUpgrade_noLight() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 359 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 360 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 361 | false /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 362 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 363 | assertNull(record.getLight()); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 368 | public void testLights_preUpgrade() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 369 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 370 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 371 | true /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 372 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 373 | assertEquals(CUSTOM_LIGHT, record.getLight()); |
| 374 | } |
| 375 | |
| 376 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 377 | public void testLights_locked_preUpgrade() { |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 378 | defaultChannel.enableLights(true); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 379 | defaultChannel.lockFields(NotificationChannel.USER_LOCKED_LIGHTS); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 380 | StatusBarNotification sbn = getNotification(PKG_N_MR1, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 381 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 382 | true /* lights */, false /* defaultLights */, null /* group */); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 383 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 384 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 385 | assertNotEquals(CUSTOM_LIGHT, record.getLight()); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 389 | public void testLights_upgrade_defaultLights() { |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 390 | int defaultLightColor = mMockContext.getResources().getColor( |
| 391 | com.android.internal.R.color.config_defaultNotificationColor); |
| 392 | int defaultLightOn = mMockContext.getResources().getInteger( |
| 393 | com.android.internal.R.integer.config_defaultNotificationLedOn); |
| 394 | int defaultLightOff = mMockContext.getResources().getInteger( |
| 395 | com.android.internal.R.integer.config_defaultNotificationLedOff); |
| 396 | |
| 397 | NotificationRecord.Light expected = new NotificationRecord.Light( |
| 398 | defaultLightColor, defaultLightOn, defaultLightOff); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 399 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 400 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 401 | true /* lights */, true /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 402 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 403 | assertEquals(expected, record.getLight()); |
| 404 | } |
| 405 | |
| 406 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 407 | public void testLights_upgrade() { |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 408 | int defaultLightOn = mMockContext.getResources().getInteger( |
| 409 | com.android.internal.R.integer.config_defaultNotificationLedOn); |
| 410 | int defaultLightOff = mMockContext.getResources().getInteger( |
| 411 | com.android.internal.R.integer.config_defaultNotificationLedOff); |
| 412 | |
| 413 | NotificationRecord.Light expected = new NotificationRecord.Light( |
| 414 | Color.BLUE, defaultLightOn, defaultLightOff); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 415 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 416 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 417 | true /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 418 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 419 | assertEquals(expected, record.getLight()); |
| 420 | } |
| 421 | |
| 422 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 423 | public void testLights_upgrade_noLight() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 424 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 425 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 426 | false /* lights */, false /* defaultLights */, null /* group */); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 427 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, defaultChannel); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 428 | assertNull(record.getLight()); |
| 429 | } |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 430 | |
| 431 | @Test |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 432 | public void testLogMaker() { |
| 433 | long timestamp = 1000L; |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 434 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 435 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 436 | false /* lights */, false /* defaultLights */, null /* group */); |
| 437 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 438 | final LogMaker logMaker = record.getLogMaker(timestamp); |
| 439 | |
| 440 | assertNull(logMaker.getTaggedData(MetricsEvent.NOTIFICATION_SHADE_INDEX)); |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 441 | assertEquals(channelId, |
| 442 | (String) logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID)); |
| 443 | assertEquals(channel.getImportance(), |
| 444 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE)); |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 445 | assertEquals(record.getLifespanMs(timestamp), |
| 446 | (int) logMaker.getTaggedData(MetricsEvent.NOTIFICATION_SINCE_CREATE_MILLIS)); |
| 447 | assertEquals(record.getFreshnessMs(timestamp), |
| 448 | (int) logMaker.getTaggedData(MetricsEvent.NOTIFICATION_SINCE_UPDATE_MILLIS)); |
| 449 | assertEquals(record.getExposureMs(timestamp), |
| 450 | (int) logMaker.getTaggedData(MetricsEvent.NOTIFICATION_SINCE_VISIBLE_MILLIS)); |
| 451 | assertEquals(record.getInterruptionMs(timestamp), |
| 452 | (int) logMaker.getTaggedData(MetricsEvent.NOTIFICATION_SINCE_INTERRUPTION_MILLIS)); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 453 | // If no importance calculation has been run, no explanation is available. |
| 454 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_EXPLANATION)); |
| 455 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL)); |
| 456 | assertNull(logMaker.getTaggedData( |
| 457 | MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL_EXPLANATION)); |
| 458 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST)); |
| 459 | } |
| 460 | |
| 461 | @Test |
| 462 | public void testLogMakerImportanceApp() { |
| 463 | long timestamp = 1000L; |
| 464 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 465 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 466 | false /* lights */, false /* defaultLights */, null /* group */); |
| 467 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 468 | |
| 469 | record.calculateImportance(); // This importance calculation will yield 'app' |
| 470 | final LogMaker logMaker = record.getLogMaker(timestamp); |
| 471 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_APP, |
| 472 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_EXPLANATION)); |
| 473 | assertEquals(channel.getImportance(), |
| 474 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE)); |
| 475 | // The additional information is only populated if the initial importance is overridden. |
| 476 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL)); |
| 477 | assertNull(logMaker.getTaggedData( |
| 478 | MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL_EXPLANATION)); |
| 479 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST)); |
| 480 | } |
| 481 | |
| 482 | @Test |
| 483 | public void testLogMakerImportanceAsst() { |
| 484 | long timestamp = 1000L; |
| 485 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 486 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 487 | false /* lights */, false /* defaultLights */, null /* group */); |
| 488 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 489 | Bundle signals = new Bundle(); |
| 490 | signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); |
| 491 | record.addAdjustment(new Adjustment(PKG_O, KEY_IMPORTANCE, signals, "", uid)); |
| 492 | record.applyAdjustments(); |
| 493 | record.calculateImportance(); // This importance calculation will yield 'asst' |
| 494 | final LogMaker logMaker = record.getLogMaker(timestamp); |
| 495 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_ASST, |
| 496 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_EXPLANATION)); |
| 497 | // Therefore this is the assistant-set importance |
| 498 | assertEquals(IMPORTANCE_LOW, |
| 499 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE)); |
| 500 | // Initial importance is populated so we know what it was, since it didn't get used. |
| 501 | assertEquals(channel.getImportance(), |
| 502 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL)); |
| 503 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_APP, |
| 504 | logMaker.getTaggedData( |
| 505 | MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL_EXPLANATION)); |
Will Brockman | 605d61b | 2019-03-29 13:08:49 -0400 | [diff] [blame] | 506 | // This field is populated whenever mImportanceExplanationCode is. |
| 507 | assertEquals(IMPORTANCE_LOW, |
| 508 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST)); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | @Test |
| 512 | public void testLogMakerImportanceSystem() { |
| 513 | long timestamp = 1000L; |
| 514 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 515 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 516 | false /* lights */, false /* defaultLights */, null /* group */); |
| 517 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 518 | record.setSystemImportance(IMPORTANCE_HIGH); |
| 519 | record.calculateImportance(); // This importance calculation will yield 'system' |
| 520 | final LogMaker logMaker = record.getLogMaker(timestamp); |
| 521 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_SYSTEM, |
| 522 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_EXPLANATION)); |
| 523 | // Therefore this is the system-set importance |
| 524 | assertEquals(IMPORTANCE_HIGH, |
| 525 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE)); |
| 526 | // Initial importance is populated so we know what it was, since it didn't get used. |
| 527 | assertEquals(channel.getImportance(), |
| 528 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL)); |
| 529 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_APP, |
| 530 | logMaker.getTaggedData( |
| 531 | MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL_EXPLANATION)); |
| 532 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST)); |
| 533 | } |
| 534 | |
| 535 | @Test |
| 536 | public void testLogMakerImportanceUser() { |
| 537 | long timestamp = 1000L; |
| 538 | channel.lockFields(channel.USER_LOCKED_IMPORTANCE); |
| 539 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 540 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 541 | false /* lights */, false /* defaultLights */, null /* group */); |
| 542 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 543 | record.calculateImportance(); // This importance calculation will yield 'user' |
| 544 | final LogMaker logMaker = record.getLogMaker(timestamp); |
| 545 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_USER, |
| 546 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_EXPLANATION)); |
| 547 | // Therefore this is the user-set importance |
| 548 | assertEquals(channel.getImportance(), |
| 549 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE)); |
| 550 | // The additional information is only populated if the initial importance is overridden. |
| 551 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL)); |
| 552 | assertNull(logMaker.getTaggedData( |
| 553 | MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL_EXPLANATION)); |
| 554 | assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST)); |
| 555 | } |
| 556 | |
| 557 | @Test |
| 558 | public void testLogMakerImportanceMulti() { |
| 559 | long timestamp = 1000L; |
| 560 | channel.lockFields(channel.USER_LOCKED_IMPORTANCE); |
| 561 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 562 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 563 | false /* lights */, false /* defaultLights */, null /* group */); |
| 564 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 565 | // Add all 3 ways of overriding the app-set importance of the notification |
| 566 | Bundle signals = new Bundle(); |
| 567 | signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); |
| 568 | record.addAdjustment(new Adjustment(PKG_O, KEY_IMPORTANCE, signals, "", uid)); |
| 569 | record.applyAdjustments(); |
| 570 | record.setSystemImportance(IMPORTANCE_HIGH); |
| 571 | record.calculateImportance(); // This importance calculation will yield 'system' |
| 572 | final LogMaker logMaker = record.getLogMaker(timestamp); |
| 573 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_SYSTEM, |
| 574 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_EXPLANATION)); |
| 575 | // Therefore this is the system-set importance |
| 576 | assertEquals(IMPORTANCE_HIGH, |
| 577 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE)); |
| 578 | // Initial importance is populated so we know what it was, since it didn't get used. |
| 579 | assertEquals(channel.getImportance(), |
| 580 | logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL)); |
| 581 | assertEquals(MetricsEvent.IMPORTANCE_EXPLANATION_USER, logMaker.getTaggedData( |
| 582 | MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL_EXPLANATION)); |
| 583 | // Assistant importance is populated so we know what it was, since it didn't get used. |
| 584 | assertEquals(IMPORTANCE_LOW, logMaker.getTaggedData( |
| 585 | MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST)); |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 586 | } |
| 587 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 588 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 589 | public void testNotificationStats() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 590 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 591 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 592 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 593 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 594 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 595 | assertFalse(record.getStats().hasSeen()); |
| 596 | assertFalse(record.isSeen()); |
| 597 | assertFalse(record.getStats().hasDirectReplied()); |
| 598 | assertFalse(record.getStats().hasExpanded()); |
| 599 | assertFalse(record.getStats().hasInteracted()); |
| 600 | assertFalse(record.getStats().hasViewedSettings()); |
| 601 | assertFalse(record.getStats().hasSnoozed()); |
| 602 | |
| 603 | record.setSeen(); |
| 604 | assertTrue(record.getStats().hasSeen()); |
| 605 | assertTrue(record.isSeen()); |
| 606 | assertFalse(record.getStats().hasDirectReplied()); |
| 607 | assertFalse(record.getStats().hasExpanded()); |
| 608 | assertFalse(record.getStats().hasInteracted()); |
| 609 | assertFalse(record.getStats().hasViewedSettings()); |
| 610 | assertFalse(record.getStats().hasSnoozed()); |
| 611 | |
| 612 | record.recordViewedSettings(); |
| 613 | assertFalse(record.getStats().hasDirectReplied()); |
| 614 | assertFalse(record.getStats().hasExpanded()); |
| 615 | assertTrue(record.getStats().hasViewedSettings()); |
| 616 | assertFalse(record.getStats().hasSnoozed()); |
| 617 | |
| 618 | record.recordSnoozed(); |
| 619 | assertFalse(record.getStats().hasDirectReplied()); |
| 620 | assertFalse(record.getStats().hasExpanded()); |
| 621 | assertTrue(record.getStats().hasSnoozed()); |
| 622 | |
| 623 | record.recordExpanded(); |
| 624 | assertFalse(record.getStats().hasDirectReplied()); |
| 625 | assertTrue(record.getStats().hasExpanded()); |
| 626 | |
| 627 | record.recordDirectReplied(); |
| 628 | assertTrue(record.getStats().hasDirectReplied()); |
| 629 | } |
| 630 | |
| 631 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 632 | public void testUserSentiment() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 633 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 634 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 635 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 636 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 637 | |
| 638 | assertEquals(USER_SENTIMENT_NEUTRAL, record.getUserSentiment()); |
| 639 | |
| 640 | Bundle signals = new Bundle(); |
| 641 | signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE); |
| 642 | record.addAdjustment(new Adjustment(pkg, record.getKey(), signals, null, sbn.getUserId())); |
| 643 | |
| 644 | record.applyAdjustments(); |
| 645 | |
| 646 | assertEquals(USER_SENTIMENT_NEGATIVE, record.getUserSentiment()); |
| 647 | } |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 648 | |
| 649 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 650 | public void testUserSentiment_appImportanceUpdatesSentiment() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 651 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 652 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 653 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 654 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 655 | assertEquals(USER_SENTIMENT_NEUTRAL, record.getUserSentiment()); |
| 656 | |
| 657 | record.setIsAppImportanceLocked(true); |
| 658 | assertEquals(USER_SENTIMENT_POSITIVE, record.getUserSentiment()); |
| 659 | } |
| 660 | |
| 661 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 662 | public void testUserSentiment_appImportanceBlocksNegativeSentimentUpdate() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 663 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 664 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 665 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 666 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 667 | record.setIsAppImportanceLocked(true); |
| 668 | |
| 669 | Bundle signals = new Bundle(); |
| 670 | signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE); |
| 671 | record.addAdjustment(new Adjustment(pkg, record.getKey(), signals, null, sbn.getUserId())); |
| 672 | record.applyAdjustments(); |
| 673 | |
| 674 | assertEquals(USER_SENTIMENT_POSITIVE, record.getUserSentiment()); |
| 675 | } |
| 676 | |
| 677 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 678 | public void testUserSentiment_userLocked() { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 679 | channel.lockFields(USER_LOCKED_IMPORTANCE); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 680 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 681 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 682 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 683 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 684 | |
| 685 | assertEquals(USER_SENTIMENT_POSITIVE, record.getUserSentiment()); |
| 686 | |
| 687 | Bundle signals = new Bundle(); |
| 688 | signals.putInt(Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE); |
| 689 | record.addAdjustment(new Adjustment(pkg, record.getKey(), signals, null, sbn.getUserId())); |
| 690 | |
| 691 | record.applyAdjustments(); |
| 692 | |
| 693 | assertEquals(USER_SENTIMENT_POSITIVE, record.getUserSentiment()); |
| 694 | } |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 695 | |
| 696 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 697 | public void testAppImportance_returnsCorrectly() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 698 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 699 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 700 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 701 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 702 | |
| 703 | record.setIsAppImportanceLocked(true); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 704 | assertTrue(record.getIsAppImportanceLocked()); |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 705 | |
| 706 | record.setIsAppImportanceLocked(false); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 707 | assertFalse(record.getIsAppImportanceLocked()); |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 708 | } |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 709 | |
| 710 | @Test |
| 711 | public void testIsInterruptive_textChanged_notSeen() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 712 | StatusBarNotification sbn = getNotification(PKG_O, false /* noisy */, |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 713 | false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 714 | false /* lights */, false /* defaultLights */, null /* group */); |
| 715 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 716 | |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 717 | assertFalse(record.isInterruptive()); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 718 | |
| 719 | record.setTextChanged(true); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 720 | assertFalse(record.isInterruptive()); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | @Test |
| 724 | public void testIsInterruptive_textChanged_seen() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 725 | StatusBarNotification sbn = getNotification(PKG_O, false /* noisy */, |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 726 | false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 727 | false /* lights */, false /* defaultLights */, null /* group */); |
| 728 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 729 | |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 730 | assertFalse(record.isInterruptive()); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 731 | |
| 732 | record.setTextChanged(true); |
| 733 | record.setSeen(); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 734 | assertTrue(record.isInterruptive()); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | @Test |
| 738 | public void testIsInterruptive_textNotChanged_seen() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 739 | StatusBarNotification sbn = getNotification(PKG_O, false /* noisy */, |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 740 | false /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 741 | false /* lights */, false /* defaultLights */, null /* group */); |
| 742 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 743 | |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 744 | assertFalse(record.isInterruptive()); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 745 | |
| 746 | record.setTextChanged(false); |
| 747 | record.setSeen(); |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 748 | assertFalse(record.isInterruptive()); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 749 | } |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 750 | |
| 751 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 752 | public void testCalculateGrantableUris_PappProvided() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 753 | IActivityManager am = mock(IActivityManager.class); |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 754 | UriGrantsManagerInternal ugm = mock(UriGrantsManagerInternal.class); |
| 755 | when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class), |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 756 | anyInt(), anyInt())).thenThrow(new SecurityException()); |
| 757 | |
| 758 | Notification n = mock(Notification.class); |
| 759 | when(n.getChannelId()).thenReturn(channel.getId()); |
| 760 | StatusBarNotification sbn = |
| 761 | new StatusBarNotification(PKG_P, PKG_P, id1, tag1, uid, uid, n, mUser, null, uid); |
| 762 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 763 | record.mAm = am; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 764 | record.mUgmInternal = ugm; |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 765 | |
| 766 | try { |
| 767 | record.calculateGrantableUris(); |
| 768 | fail("App provided uri for p targeting app should throw exception"); |
| 769 | } catch (SecurityException e) { |
| 770 | // expected |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 775 | public void testCalculateGrantableUris_PuserOverridden() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 776 | IActivityManager am = mock(IActivityManager.class); |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 777 | UriGrantsManagerInternal ugm = mock(UriGrantsManagerInternal.class); |
| 778 | when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class), |
| 779 | anyInt(), anyInt())).thenThrow(new SecurityException()); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 780 | |
| 781 | channel.lockFields(NotificationChannel.USER_LOCKED_SOUND); |
| 782 | Notification n = mock(Notification.class); |
| 783 | when(n.getChannelId()).thenReturn(channel.getId()); |
| 784 | StatusBarNotification sbn = |
| 785 | new StatusBarNotification(PKG_P, PKG_P, id1, tag1, uid, uid, n, mUser, null, uid); |
| 786 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 787 | record.mAm = am; |
| 788 | |
| 789 | record.calculateGrantableUris(); |
| 790 | } |
| 791 | |
| 792 | @Test |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 793 | public void testCalculateGrantableUris_prePappProvided() { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 794 | IActivityManager am = mock(IActivityManager.class); |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 795 | UriGrantsManagerInternal ugm = mock(UriGrantsManagerInternal.class); |
| 796 | when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class), |
| 797 | anyInt(), anyInt())).thenThrow(new SecurityException()); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 798 | |
| 799 | Notification n = mock(Notification.class); |
| 800 | when(n.getChannelId()).thenReturn(channel.getId()); |
| 801 | StatusBarNotification sbn = |
| 802 | new StatusBarNotification(PKG_O, PKG_O, id1, tag1, uid, uid, n, mUser, null, uid); |
| 803 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 804 | record.mAm = am; |
| 805 | |
| 806 | record.calculateGrantableUris(); |
| 807 | // should not throw |
| 808 | } |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 809 | |
| 810 | @Test |
| 811 | public void testSmartActions() { |
| 812 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 813 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 814 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 815 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 816 | assertNull(record.getSystemGeneratedSmartActions()); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 817 | |
| 818 | ArrayList<Notification.Action> smartActions = new ArrayList<>(); |
| 819 | smartActions.add(new Notification.Action.Builder( |
| 820 | Icon.createWithResource(getContext(), R.drawable.btn_default), |
| 821 | "text", null).build()); |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 822 | record.setSystemGeneratedSmartActions(smartActions); |
| 823 | assertEquals(smartActions, record.getSystemGeneratedSmartActions()); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 824 | } |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 825 | |
| 826 | @Test |
| 827 | public void testUpdateNotificationChannel() { |
| 828 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 829 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 830 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 831 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 832 | |
| 833 | assertEquals(channel.getImportance(), record.getImportance()); |
| 834 | |
| 835 | record.updateNotificationChannel( |
| 836 | new NotificationChannel(channelId, "", channel.getImportance() - 1)); |
| 837 | |
| 838 | assertEquals(channel.getImportance() - 1, record.getImportance()); |
| 839 | } |
| 840 | |
| 841 | @Test |
| 842 | public void testCalculateImportance_systemImportance() { |
| 843 | channel.setImportance(IMPORTANCE_HIGH); |
| 844 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 845 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 846 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 847 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 848 | |
| 849 | record.setSystemImportance(IMPORTANCE_LOW); |
| 850 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
| 851 | |
| 852 | record = new NotificationRecord(mMockContext, sbn, channel); |
| 853 | channel.lockFields(USER_LOCKED_IMPORTANCE); |
| 854 | |
| 855 | record.setSystemImportance(IMPORTANCE_LOW); |
| 856 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
| 857 | } |
| 858 | |
| 859 | @Test |
| 860 | public void testCalculateImportance_asstImportance() { |
| 861 | channel.setImportance(IMPORTANCE_HIGH); |
| 862 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 863 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 864 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 865 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 866 | |
| 867 | record.setAssistantImportance(IMPORTANCE_LOW); |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 868 | record.calculateImportance(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 869 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
| 870 | |
| 871 | // assistant ignored if user expressed preference |
| 872 | record = new NotificationRecord(mMockContext, sbn, channel); |
| 873 | channel.lockFields(USER_LOCKED_IMPORTANCE); |
| 874 | |
| 875 | record.setAssistantImportance(IMPORTANCE_LOW); |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 876 | record.calculateImportance(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 877 | assertEquals(channel.getImportance(), record.getImportance()); |
| 878 | } |
| 879 | |
| 880 | @Test |
| 881 | public void testCalculateImportance_asstImportanceChannelUpdate() { |
| 882 | channel.setImportance(IMPORTANCE_HIGH); |
| 883 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 884 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 885 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 886 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 887 | |
| 888 | record.setAssistantImportance(IMPORTANCE_LOW); |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 889 | record.calculateImportance(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 890 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
| 891 | |
| 892 | record.updateNotificationChannel( |
| 893 | new NotificationChannel(channelId, "", IMPORTANCE_DEFAULT)); |
| 894 | |
| 895 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
| 896 | } |
Julia Reynolds | 8a7e4ac | 2018-10-08 09:23:35 -0400 | [diff] [blame] | 897 | |
| 898 | @Test |
| 899 | public void testSetContactAffinity() { |
| 900 | channel.setImportance(IMPORTANCE_LOW); |
| 901 | channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
| 902 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 903 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 904 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 905 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 906 | |
| 907 | record.setContactAffinity(1.0f); |
| 908 | |
| 909 | assertEquals(1.0f, record.getContactAffinity()); |
| 910 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
| 911 | } |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 912 | |
| 913 | @Test |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 914 | public void testSetDidNotAudiblyAlert() { |
| 915 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 916 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 917 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 918 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 919 | |
| 920 | record.setAudiblyAlerted(false); |
| 921 | |
| 922 | assertEquals(-1, record.getLastAudiblyAlertedMs()); |
| 923 | } |
| 924 | |
| 925 | @Test |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 926 | public void testSetAudiblyAlerted() { |
| 927 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 928 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 929 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 930 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 931 | |
| 932 | record.setAudiblyAlerted(true); |
| 933 | |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 934 | assertNotEquals(-1, record.getLastAudiblyAlertedMs()); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 935 | } |
Julia Reynolds | d673007 | 2019-01-04 12:52:52 -0500 | [diff] [blame] | 936 | |
| 937 | @Test |
| 938 | public void testIsNewEnoughForAlerting_new() { |
| 939 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 940 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 941 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 942 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 943 | |
| 944 | assertTrue(record.isNewEnoughForAlerting(record.mUpdateTimeMs)); |
| 945 | } |
| 946 | |
| 947 | @Test |
| 948 | public void testIsNewEnoughForAlerting_old() { |
| 949 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 950 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 951 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 952 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 953 | |
| 954 | assertFalse(record.isNewEnoughForAlerting(record.mUpdateTimeMs + (1000 * 60 * 60))); |
| 955 | } |
Julia Reynolds | 413ba84 | 2019-01-11 10:38:08 -0500 | [diff] [blame] | 956 | |
| 957 | @Test |
| 958 | public void testIgnoreImportanceAdjustmentsForOemLockedChannels() { |
| 959 | NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_DEFAULT); |
| 960 | channel.setImportanceLockedByOEM(true); |
| 961 | |
| 962 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 963 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 964 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 965 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 966 | |
| 967 | assertEquals(IMPORTANCE_DEFAULT, record.getImportance()); |
| 968 | |
| 969 | Bundle bundle = new Bundle(); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 970 | bundle.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); |
Julia Reynolds | 413ba84 | 2019-01-11 10:38:08 -0500 | [diff] [blame] | 971 | Adjustment adjustment = new Adjustment( |
| 972 | PKG_O, record.getKey(), bundle, "", record.getUserId()); |
| 973 | |
| 974 | record.addAdjustment(adjustment); |
| 975 | record.applyAdjustments(); |
| 976 | record.calculateImportance(); |
| 977 | |
| 978 | assertEquals(IMPORTANCE_DEFAULT, record.getImportance()); |
| 979 | } |
| 980 | |
| 981 | @Test |
Julia Reynolds | 0c24500 | 2019-03-27 16:10:11 -0400 | [diff] [blame] | 982 | public void testIgnoreImportanceAdjustmentsForDefaultAppLockedChannels() { |
| 983 | NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_DEFAULT); |
| 984 | channel.setImportanceLockedByCriticalDeviceFunction(true); |
| 985 | |
| 986 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 987 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 988 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 989 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 990 | |
| 991 | assertEquals(IMPORTANCE_DEFAULT, record.getImportance()); |
| 992 | |
| 993 | Bundle bundle = new Bundle(); |
| 994 | bundle.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); |
| 995 | Adjustment adjustment = new Adjustment( |
| 996 | PKG_O, record.getKey(), bundle, "", record.getUserId()); |
| 997 | |
| 998 | record.addAdjustment(adjustment); |
| 999 | record.applyAdjustments(); |
| 1000 | record.calculateImportance(); |
| 1001 | |
| 1002 | assertEquals(IMPORTANCE_DEFAULT, record.getImportance()); |
| 1003 | } |
| 1004 | |
| 1005 | @Test |
| 1006 | public void testApplyImportanceAdjustmentsForNonOemDefaultAppLockedChannels() { |
Julia Reynolds | 413ba84 | 2019-01-11 10:38:08 -0500 | [diff] [blame] | 1007 | NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_DEFAULT); |
| 1008 | channel.setImportanceLockedByOEM(false); |
| 1009 | |
| 1010 | StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, |
| 1011 | true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, |
| 1012 | false /* lights */, false /* defaultLights */, groupId /* group */); |
| 1013 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1014 | |
| 1015 | assertEquals(IMPORTANCE_DEFAULT, record.getImportance()); |
| 1016 | |
| 1017 | Bundle bundle = new Bundle(); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 1018 | bundle.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); |
Julia Reynolds | 413ba84 | 2019-01-11 10:38:08 -0500 | [diff] [blame] | 1019 | Adjustment adjustment = new Adjustment( |
| 1020 | PKG_O, record.getKey(), bundle, "", record.getUserId()); |
| 1021 | |
| 1022 | record.addAdjustment(adjustment); |
| 1023 | record.applyAdjustments(); |
| 1024 | record.calculateImportance(); |
| 1025 | |
| 1026 | assertEquals(IMPORTANCE_LOW, record.getImportance()); |
| 1027 | } |
Chris Wren | 6cbf57b | 2019-12-12 15:33:21 -0500 | [diff] [blame] | 1028 | |
| 1029 | @Test |
| 1030 | public void testHasUndecoratedRemoteViews_NoRemoteViews() { |
| 1031 | StatusBarNotification sbn = getStyledNotification(false, false, false, null); |
| 1032 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1033 | |
| 1034 | assertFalse("false positive detection", record.hasUndecoratedRemoteView()); |
| 1035 | } |
| 1036 | |
| 1037 | @Test |
| 1038 | public void testHasUndecoratedRemoteViews_NoRemoteViewsWithStyle() { |
| 1039 | StatusBarNotification sbn = getStyledNotification(false, false, false, |
| 1040 | new Notification.BigPictureStyle()); |
| 1041 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1042 | |
| 1043 | assertFalse("false positive detection", record.hasUndecoratedRemoteView()); |
| 1044 | } |
| 1045 | |
| 1046 | @Test |
| 1047 | public void testHasUndecoratedRemoteViews_UndecoratedContent() { |
| 1048 | StatusBarNotification sbn = getStyledNotification(true, false, false, null); |
| 1049 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1050 | |
| 1051 | assertTrue("false negative detection", record.hasUndecoratedRemoteView()); |
| 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | @Test |
| 1056 | public void testHasUndecoratedRemoteViews_UndecoratedBig() { |
| 1057 | StatusBarNotification sbn = getStyledNotification(false, true, false, null); |
| 1058 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1059 | |
| 1060 | assertTrue("false negative detection", record.hasUndecoratedRemoteView()); |
| 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | @Test |
| 1065 | public void testHasUndecoratedRemoteViews_UndecoratedHeadsup() { |
| 1066 | StatusBarNotification sbn = getStyledNotification(false, false, true, null); |
| 1067 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1068 | |
| 1069 | assertTrue("false negative detection", record.hasUndecoratedRemoteView()); |
| 1070 | } |
| 1071 | |
| 1072 | @Test |
| 1073 | public void testHasUndecoratedRemoteViews_DecoratedRemoteViews() { |
| 1074 | StatusBarNotification sbn = getStyledNotification(true, true, true, |
| 1075 | new Notification.DecoratedCustomViewStyle()); |
| 1076 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1077 | |
| 1078 | assertFalse("false positive detection", record.hasUndecoratedRemoteView()); |
| 1079 | } |
| 1080 | |
| 1081 | @Test |
| 1082 | public void testHasUndecoratedRemoteViews_DecoratedMediaRemoteViews() { |
| 1083 | StatusBarNotification sbn = getStyledNotification(true, true, true, |
| 1084 | new Notification.DecoratedMediaCustomViewStyle()); |
| 1085 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1086 | |
| 1087 | assertFalse("false positive detection", record.hasUndecoratedRemoteView()); |
| 1088 | } |
| 1089 | |
| 1090 | @Test |
| 1091 | public void testHasUndecoratedRemoteViews_UndecoratedWrongStyle() { |
| 1092 | StatusBarNotification sbn = getStyledNotification(true, true, true, |
| 1093 | new Notification.BigPictureStyle()); |
| 1094 | NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); |
| 1095 | |
| 1096 | assertTrue("false negative detection", record.hasUndecoratedRemoteView()); |
| 1097 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 1098 | } |