Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 18 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 21 | import static org.junit.Assert.assertFalse; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 22 | import static org.mockito.ArgumentMatchers.any; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 23 | import static org.mockito.ArgumentMatchers.anyFloat; |
| 24 | import static org.mockito.Mockito.doNothing; |
| 25 | import static org.mockito.Mockito.doReturn; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 26 | import static org.mockito.Mockito.mock; |
| 27 | import static org.mockito.Mockito.never; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 28 | import static org.mockito.Mockito.spy; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 29 | import static org.mockito.Mockito.times; |
| 30 | import static org.mockito.Mockito.verify; |
| 31 | import static org.mockito.Mockito.when; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 32 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 33 | import android.app.AppOpsManager; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 34 | import android.app.Notification; |
| 35 | import android.app.PendingIntent; |
| 36 | import android.app.RemoteInput; |
| 37 | import android.content.Intent; |
| 38 | import android.graphics.drawable.Icon; |
| 39 | import android.service.notification.StatusBarNotification; |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 40 | import android.support.test.annotation.UiThreadTest; |
| 41 | import android.support.test.filters.SmallTest; |
| 42 | import android.support.test.runner.AndroidJUnit4; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 43 | import android.util.ArraySet; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 44 | import android.util.Pair; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 45 | import android.view.NotificationHeaderView; |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 46 | import android.view.View; |
| 47 | |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 48 | import com.android.systemui.R; |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 49 | import com.android.systemui.SysuiTestCase; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.SmartReplyConstants; |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 52 | |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 53 | import org.junit.Before; |
| 54 | import org.junit.Test; |
| 55 | import org.junit.runner.RunWith; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 56 | import org.mockito.Mock; |
| 57 | import org.mockito.MockitoAnnotations; |
| 58 | |
| 59 | import java.util.ArrayList; |
| 60 | import java.util.List; |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 61 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 62 | @SmallTest |
| 63 | @RunWith(AndroidJUnit4.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 64 | public class NotificationContentViewTest extends SysuiTestCase { |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 65 | |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 66 | private static final String TEST_ACTION = "com.android.SMART_REPLY_VIEW_ACTION"; |
| 67 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 68 | NotificationContentView mView; |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 69 | |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 70 | @Mock |
| 71 | SmartReplyConstants mSmartReplyConstants; |
| 72 | @Mock |
| 73 | StatusBarNotification mStatusBarNotification; |
| 74 | @Mock |
| 75 | Notification mNotification; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 76 | NotificationEntry mEntry; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 77 | @Mock |
| 78 | RemoteInput mRemoteInput; |
| 79 | @Mock |
| 80 | RemoteInput mFreeFormRemoteInput; |
| 81 | |
| 82 | private Icon mActionIcon; |
| 83 | |
| 84 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 85 | @Before |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 86 | @UiThreadTest |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 87 | public void setup() { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 88 | MockitoAnnotations.initMocks(this); |
| 89 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 90 | mView = new NotificationContentView(mContext, null); |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 91 | ExpandableNotificationRow row = new ExpandableNotificationRow(mContext, null); |
| 92 | ExpandableNotificationRow mockRow = spy(row); |
| 93 | doNothing().when(mockRow).updateBackgroundAlpha(anyFloat()); |
| 94 | doReturn(10).when(mockRow).getIntrinsicHeight(); |
| 95 | |
| 96 | mView.setContainingNotification(mockRow); |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 97 | mView.setHeights(10, 20, 30, 40); |
| 98 | |
| 99 | mView.setContractedChild(createViewWithHeight(10)); |
| 100 | mView.setExpandedChild(createViewWithHeight(20)); |
| 101 | mView.setHeadsUpChild(createViewWithHeight(30)); |
| 102 | mView.setAmbientChild(createViewWithHeight(40)); |
| 103 | |
| 104 | mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); |
| 105 | mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 106 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 107 | // Smart replies and actions |
| 108 | when(mNotification.getAllowSystemGeneratedContextualActions()).thenReturn(true); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 109 | when(mStatusBarNotification.getNotification()).thenReturn(mNotification); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 110 | mEntry = new NotificationEntry(mStatusBarNotification); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 111 | when(mSmartReplyConstants.isEnabled()).thenReturn(true); |
| 112 | mActionIcon = Icon.createWithResource(mContext, R.drawable.ic_person); |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | private View createViewWithHeight(int height) { |
| 116 | View view = new View(mContext, null); |
| 117 | view.setMinimumHeight(height); |
| 118 | return view; |
| 119 | } |
| 120 | |
| 121 | @Test |
| 122 | @UiThreadTest |
| 123 | public void animationStartType_getsClearedAfterUpdatingVisibilitiesWithoutAnimation() { |
| 124 | mView.setHeadsUp(true); |
| 125 | mView.setDark(true, false, 0); |
| 126 | mView.setDark(false, true, 0); |
| 127 | mView.setHeadsUpAnimatingAway(true); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 128 | assertFalse(mView.isAnimatingVisibleType()); |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 129 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 130 | |
| 131 | @Test |
| 132 | @UiThreadTest |
| 133 | public void testShowAppOpsIcons() { |
| 134 | NotificationHeaderView mockContracted = mock(NotificationHeaderView.class); |
| 135 | when(mockContracted.findViewById(com.android.internal.R.id.notification_header)) |
| 136 | .thenReturn(mockContracted); |
| 137 | NotificationHeaderView mockExpanded = mock(NotificationHeaderView.class); |
| 138 | when(mockExpanded.findViewById(com.android.internal.R.id.notification_header)) |
| 139 | .thenReturn(mockExpanded); |
| 140 | NotificationHeaderView mockHeadsUp = mock(NotificationHeaderView.class); |
| 141 | when(mockHeadsUp.findViewById(com.android.internal.R.id.notification_header)) |
| 142 | .thenReturn(mockHeadsUp); |
| 143 | NotificationHeaderView mockAmbient = mock(NotificationHeaderView.class); |
| 144 | when(mockAmbient.findViewById(com.android.internal.R.id.notification_header)) |
| 145 | .thenReturn(mockAmbient); |
| 146 | |
| 147 | mView.setContractedChild(mockContracted); |
| 148 | mView.setExpandedChild(mockExpanded); |
| 149 | mView.setHeadsUpChild(mockHeadsUp); |
| 150 | mView.setAmbientChild(mockAmbient); |
| 151 | |
| 152 | ArraySet<Integer> ops = new ArraySet<>(); |
| 153 | ops.add(AppOpsManager.OP_ANSWER_PHONE_CALLS); |
| 154 | mView.showAppOpsIcons(ops); |
| 155 | |
| 156 | verify(mockContracted, times(1)).showAppOpsIcons(ops); |
| 157 | verify(mockExpanded, times(1)).showAppOpsIcons(ops); |
| 158 | verify(mockAmbient, never()).showAppOpsIcons(ops); |
| 159 | verify(mockHeadsUp, times(1)).showAppOpsIcons(any()); |
| 160 | } |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 161 | |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 162 | private void setupAppGeneratedReplies(CharSequence[] smartReplies) { |
| 163 | setupAppGeneratedReplies(smartReplies, true /* allowSystemGeneratedReplies */); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | private void setupAppGeneratedReplies( |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 167 | CharSequence[] smartReplies, boolean allowSystemGeneratedReplies) { |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 168 | PendingIntent pendingIntent = |
| 169 | PendingIntent.getBroadcast(mContext, 0, new Intent(TEST_ACTION), 0); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 170 | Notification.Action action = |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 171 | new Notification.Action.Builder(null, "Test Action", pendingIntent).build(); |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 172 | when(mRemoteInput.getChoices()).thenReturn(smartReplies); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 173 | Pair<RemoteInput, Notification.Action> remoteInputActionPair = |
| 174 | Pair.create(mRemoteInput, action); |
| 175 | when(mNotification.findRemoteInputActionPair(false)).thenReturn(remoteInputActionPair); |
| 176 | |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 177 | Notification.Action freeFormRemoteInputAction = |
| 178 | createActionBuilder("Freeform Test Action") |
| 179 | .setAllowGeneratedReplies(allowSystemGeneratedReplies) |
| 180 | .build(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 181 | Pair<RemoteInput, Notification.Action> freeFormRemoteInputActionPair = |
| 182 | Pair.create(mFreeFormRemoteInput, freeFormRemoteInputAction); |
| 183 | when(mNotification.findRemoteInputActionPair(true)).thenReturn( |
| 184 | freeFormRemoteInputActionPair); |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 185 | |
| 186 | when(mSmartReplyConstants.requiresTargetingP()).thenReturn(false); |
| 187 | } |
| 188 | |
| 189 | private void setupAppGeneratedSuggestions( |
| 190 | CharSequence[] smartReplies, List<Notification.Action> smartActions) { |
| 191 | setupAppGeneratedReplies(smartReplies); |
| 192 | when(mNotification.getContextualActions()).thenReturn(smartActions); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | @Test |
Gustav Sennton | 1ee9c9d | 2019-01-29 17:13:36 +0000 | [diff] [blame] | 196 | public void chooseSmartRepliesAndActions_smartRepliesOff_noAppGeneratedSmartSuggestions() { |
| 197 | CharSequence[] smartReplies = new String[] {"Reply1", "Reply2"}; |
| 198 | List<Notification.Action> smartActions = |
| 199 | createActions(new String[] {"Test Action 1", "Test Action 2"}); |
| 200 | setupAppGeneratedSuggestions(smartReplies, smartActions); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 201 | when(mSmartReplyConstants.isEnabled()).thenReturn(false); |
| 202 | |
| 203 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 204 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 205 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 206 | assertThat(repliesAndActions.smartReplies).isNull(); |
Gustav Sennton | 1ee9c9d | 2019-01-29 17:13:36 +0000 | [diff] [blame] | 207 | assertThat(repliesAndActions.smartActions).isNull(); |
| 208 | } |
| 209 | |
| 210 | @Test |
| 211 | public void chooseSmartRepliesAndActions_smartRepliesOff_noSystemGeneratedSmartSuggestions() { |
Gustav Sennton | e255f90 | 2019-01-31 13:28:02 +0000 | [diff] [blame] | 212 | mEntry.systemGeneratedSmartReplies = |
| 213 | new String[] {"Sys Smart Reply 1", "Sys Smart Reply 2"}; |
Gustav Sennton | 1ee9c9d | 2019-01-29 17:13:36 +0000 | [diff] [blame] | 214 | mEntry.systemGeneratedSmartActions = |
| 215 | createActions(new String[] {"Sys Smart Action 1", "Sys Smart Action 2"}); |
| 216 | when(mSmartReplyConstants.isEnabled()).thenReturn(false); |
| 217 | |
| 218 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 219 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 220 | |
| 221 | assertThat(repliesAndActions.smartReplies).isNull(); |
| 222 | assertThat(repliesAndActions.smartActions).isNull(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | @Test |
| 226 | public void chooseSmartRepliesAndActions_appGeneratedSmartReplies() { |
| 227 | CharSequence[] smartReplies = new String[] {"Reply1", "Reply2"}; |
| 228 | setupAppGeneratedReplies(smartReplies); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 229 | |
| 230 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 231 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 232 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 233 | assertThat(repliesAndActions.smartReplies.choices).isEqualTo(smartReplies); |
| 234 | assertThat(repliesAndActions.smartReplies.fromAssistant).isFalse(); |
| 235 | assertThat(repliesAndActions.smartActions).isNull(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Test |
| 239 | public void chooseSmartRepliesAndActions_appGeneratedSmartRepliesAndActions() { |
| 240 | CharSequence[] smartReplies = new String[] {"Reply1", "Reply2"}; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 241 | List<Notification.Action> smartActions = |
| 242 | createActions(new String[] {"Test Action 1", "Test Action 2"}); |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 243 | setupAppGeneratedSuggestions(smartReplies, smartActions); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 244 | |
| 245 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 246 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 247 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 248 | assertThat(repliesAndActions.smartReplies.choices).isEqualTo(smartReplies); |
| 249 | assertThat(repliesAndActions.smartReplies.fromAssistant).isFalse(); |
| 250 | assertThat(repliesAndActions.smartActions.actions).isEqualTo(smartActions); |
| 251 | assertThat(repliesAndActions.smartActions.fromAssistant).isFalse(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Test |
| 255 | public void chooseSmartRepliesAndActions_sysGeneratedSmartReplies() { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 256 | // Pass a null-array as app-generated smart replies, so that we use NAS-generated smart |
| 257 | // replies. |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 258 | setupAppGeneratedReplies(null /* smartReplies */); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 259 | |
Gustav Sennton | e255f90 | 2019-01-31 13:28:02 +0000 | [diff] [blame] | 260 | mEntry.systemGeneratedSmartReplies = |
| 261 | new String[] {"Sys Smart Reply 1", "Sys Smart Reply 2"}; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 262 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 263 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 264 | |
Gustav Sennton | e255f90 | 2019-01-31 13:28:02 +0000 | [diff] [blame] | 265 | assertThat(repliesAndActions.smartReplies.choices).isEqualTo( |
| 266 | mEntry.systemGeneratedSmartReplies); |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 267 | assertThat(repliesAndActions.smartReplies.fromAssistant).isTrue(); |
| 268 | assertThat(repliesAndActions.smartActions).isNull(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Test |
| 272 | public void chooseSmartRepliesAndActions_noSysGeneratedSmartRepliesIfNotAllowed() { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 273 | // Pass a null-array as app-generated smart replies, so that we use NAS-generated smart |
| 274 | // replies. |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 275 | setupAppGeneratedReplies(null /* smartReplies */, false /* allowSystemGeneratedReplies */); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 276 | |
Gustav Sennton | e255f90 | 2019-01-31 13:28:02 +0000 | [diff] [blame] | 277 | mEntry.systemGeneratedSmartReplies = |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 278 | new String[] {"Sys Smart Reply 1", "Sys Smart Reply 2"}; |
| 279 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 280 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 281 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 282 | assertThat(repliesAndActions.smartReplies).isNull(); |
| 283 | assertThat(repliesAndActions.smartActions).isNull(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Test |
| 287 | public void chooseSmartRepliesAndActions_sysGeneratedSmartActions() { |
| 288 | // Pass a null-array as app-generated smart replies, so that we use NAS-generated smart |
| 289 | // actions. |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 290 | setupAppGeneratedReplies(null /* smartReplies */); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 291 | |
| 292 | mEntry.systemGeneratedSmartActions = |
| 293 | createActions(new String[] {"Sys Smart Action 1", "Sys Smart Action 2"}); |
| 294 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 295 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 296 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 297 | assertThat(repliesAndActions.smartReplies).isNull(); |
| 298 | assertThat(repliesAndActions.smartActions.actions) |
| 299 | .isEqualTo(mEntry.systemGeneratedSmartActions); |
| 300 | assertThat(repliesAndActions.smartActions.fromAssistant).isTrue(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | @Test |
| 304 | public void chooseSmartRepliesAndActions_appGenPreferredOverSysGen() { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 305 | CharSequence[] appGenSmartReplies = new String[] {"Reply1", "Reply2"}; |
| 306 | // Pass a null-array as app-generated smart replies, so that we use NAS-generated smart |
| 307 | // replies. |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 308 | List<Notification.Action> appGenSmartActions = |
| 309 | createActions(new String[] {"Test Action 1", "Test Action 2"}); |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 310 | setupAppGeneratedSuggestions(appGenSmartReplies, appGenSmartActions); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 311 | |
Gustav Sennton | e255f90 | 2019-01-31 13:28:02 +0000 | [diff] [blame] | 312 | mEntry.systemGeneratedSmartReplies = |
| 313 | new String[] {"Sys Smart Reply 1", "Sys Smart Reply 2"}; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 314 | mEntry.systemGeneratedSmartActions = |
| 315 | createActions(new String[] {"Sys Smart Action 1", "Sys Smart Action 2"}); |
| 316 | |
| 317 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 318 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 319 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 320 | assertThat(repliesAndActions.smartReplies.choices).isEqualTo(appGenSmartReplies); |
| 321 | assertThat(repliesAndActions.smartReplies.fromAssistant).isFalse(); |
| 322 | assertThat(repliesAndActions.smartActions.actions).isEqualTo(appGenSmartActions); |
| 323 | assertThat(repliesAndActions.smartActions.fromAssistant).isFalse(); |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 326 | @Test |
| 327 | public void chooseSmartRepliesAndActions_disallowSysGenSmartActions() { |
| 328 | // Pass a null-array as app-generated smart replies, so that we use NAS-generated smart |
| 329 | // actions. |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 330 | setupAppGeneratedReplies(null /* smartReplies */, false /* allowSystemGeneratedReplies */); |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 331 | when(mNotification.getAllowSystemGeneratedContextualActions()).thenReturn(false); |
Gustav Sennton | e255f90 | 2019-01-31 13:28:02 +0000 | [diff] [blame] | 332 | mEntry.systemGeneratedSmartReplies = |
| 333 | new String[] {"Sys Smart Reply 1", "Sys Smart Reply 2"}; |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 334 | mEntry.systemGeneratedSmartActions = |
| 335 | createActions(new String[] {"Sys Smart Action 1", "Sys Smart Action 2"}); |
Gustav Sennton | 79d22ae | 2018-12-17 16:45:46 +0000 | [diff] [blame] | 336 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 337 | NotificationContentView.SmartRepliesAndActions repliesAndActions = |
| 338 | NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry); |
| 339 | |
Tony Mak | 2999670 | 2018-11-26 16:23:34 +0000 | [diff] [blame] | 340 | assertThat(repliesAndActions.smartActions).isNull(); |
| 341 | assertThat(repliesAndActions.smartReplies).isNull(); |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 344 | private Notification.Action.Builder createActionBuilder(String actionTitle) { |
| 345 | PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, |
| 346 | new Intent(TEST_ACTION), 0); |
| 347 | return new Notification.Action.Builder(mActionIcon, actionTitle, pendingIntent); |
| 348 | } |
| 349 | |
| 350 | private Notification.Action createAction(String actionTitle) { |
| 351 | return createActionBuilder(actionTitle).build(); |
| 352 | } |
| 353 | |
| 354 | private List<Notification.Action> createActions(String[] actionTitles) { |
| 355 | List<Notification.Action> actions = new ArrayList<>(); |
| 356 | for (String title : actionTitles) { |
| 357 | actions.add(createAction(title)); |
| 358 | } |
| 359 | return actions; |
| 360 | } |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 361 | } |