Add spinner for smart replies.
Add a spinner to MessagingGroup that is enabled
when the user has clicked on a smart reply.
Bug: 73607490
Test: atest SystemUiTests
Change-Id: I4d892c19b5df2b443761819929a83f016967e217
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index 5fce0a6..7d19784 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -21,6 +21,7 @@
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Process;
+import android.os.ServiceManager;
import android.util.ArrayMap;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
@@ -28,6 +29,7 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.MetricsLogger;
+import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.Preconditions;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.systemui.assist.AssistManager;
@@ -320,6 +322,9 @@
mProviders.put(VibratorHelper.class, () -> new VibratorHelper(mContext));
+ mProviders.put(IStatusBarService.class, () -> IStatusBarService.Stub.asInterface(
+ ServiceManager.getService(Context.STATUS_BAR_SERVICE)));
+
// Put all dependencies above here so the factory can override them if it wants.
SystemUIFactory.getInstance().injectDependencies(mProviders, mContext);
}
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
index ac4da73..721890f 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
@@ -20,7 +20,6 @@
import android.content.Context;
import android.util.ArrayMap;
import android.util.Log;
-import android.view.View;
import android.view.ViewGroup;
import com.android.internal.logging.MetricsLogger;
@@ -43,12 +42,11 @@
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationViewHierarchyManager;
import com.android.systemui.statusbar.ScrimView;
-import com.android.systemui.statusbar.SmartReplyLogger;
+import com.android.systemui.statusbar.SmartReplyController;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.KeyguardBouncer;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
-import com.android.systemui.statusbar.phone.LightBarController;
import com.android.systemui.statusbar.phone.LockIcon;
import com.android.systemui.statusbar.phone.LockscreenWallpaper;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
@@ -58,7 +56,6 @@
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
-import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.SmartReplyConstants;
import java.util.function.Consumer;
@@ -150,6 +147,6 @@
() -> new NotificationViewHierarchyManager(context));
providers.put(NotificationEntryManager.class, () -> new NotificationEntryManager(context));
providers.put(KeyguardDismissUtil.class, KeyguardDismissUtil::new);
- providers.put(SmartReplyLogger.class, () -> new SmartReplyLogger(context));
+ providers.put(SmartReplyController.class, () -> new SmartReplyController());
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
index e527be1..5477468 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
@@ -81,7 +81,7 @@
private SmartReplyConstants mSmartReplyConstants;
private SmartReplyView mExpandedSmartReplyView;
- private SmartReplyLogger mSmartReplyLogger;
+ private SmartReplyController mSmartReplyController;
private NotificationViewWrapper mContractedWrapper;
private NotificationViewWrapper mExpandedWrapper;
@@ -154,7 +154,7 @@
super(context, attrs);
mHybridGroupManager = new HybridGroupManager(getContext(), this);
mSmartReplyConstants = Dependency.get(SmartReplyConstants.class);
- mSmartReplyLogger = Dependency.get(SmartReplyLogger.class);
+ mSmartReplyController = Dependency.get(SmartReplyController.class);
initView();
}
@@ -1359,7 +1359,7 @@
applySmartReplyView(mExpandedChild, remoteInput, pendingIntent, entry);
if (mExpandedSmartReplyView != null && remoteInput != null
&& remoteInput.getChoices() != null && remoteInput.getChoices().length > 0) {
- mSmartReplyLogger.smartRepliesAdded(entry, remoteInput.getChoices().length);
+ mSmartReplyController.smartRepliesAdded(entry, remoteInput.getChoices().length);
}
}
}
@@ -1377,6 +1377,13 @@
smartReplyContainer.setVisibility(View.GONE);
return null;
}
+ // If we are showing the spinner we don't want to add the buttons.
+ boolean showingSpinner = entry.notification.getNotification()
+ .extras.getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false);
+ if (showingSpinner) {
+ smartReplyContainer.setVisibility(View.GONE);
+ return null;
+ }
SmartReplyView smartReplyView = null;
if (smartReplyContainer.getChildCount() == 0) {
smartReplyView = SmartReplyView.inflate(mContext, smartReplyContainer);
@@ -1389,7 +1396,7 @@
}
if (smartReplyView != null) {
smartReplyView.setRepliesFromRemoteInput(remoteInput, pendingIntent,
- mSmartReplyLogger, entry);
+ mSmartReplyController, entry, smartReplyContainer);
smartReplyContainer.setVisibility(View.VISIBLE);
}
return smartReplyView;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java
index 3a79e70..7681530 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java
@@ -474,37 +474,12 @@
if (FORCE_REMOTE_INPUT_HISTORY
&& shouldKeepForRemoteInput(entry)
&& entry.row != null && !entry.row.isDismissed()) {
- StatusBarNotification sbn = entry.notification;
-
- Notification.Builder b = Notification.Builder
- .recoverBuilder(mContext, sbn.getNotification().clone());
- CharSequence[] oldHistory = sbn.getNotification().extras
- .getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY);
- CharSequence[] newHistory;
- if (oldHistory == null) {
- newHistory = new CharSequence[1];
- } else {
- newHistory = new CharSequence[oldHistory.length + 1];
- System.arraycopy(oldHistory, 0, newHistory, 1, oldHistory.length);
- }
CharSequence remoteInputText = entry.remoteInputText;
if (TextUtils.isEmpty(remoteInputText)) {
remoteInputText = entry.remoteInputTextWhenReset;
}
- newHistory[0] = String.valueOf(remoteInputText);
- b.setRemoteInputHistory(newHistory);
-
- Notification newNotification = b.build();
-
- // Undo any compatibility view inflation
- newNotification.contentView = sbn.getNotification().contentView;
- newNotification.bigContentView = sbn.getNotification().bigContentView;
- newNotification.headsUpContentView = sbn.getNotification().headsUpContentView;
-
- StatusBarNotification newSbn = new StatusBarNotification(sbn.getPackageName(),
- sbn.getOpPkg(),
- sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
- newNotification, sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime());
+ StatusBarNotification newSbn = rebuildNotificationWithRemoteInput(entry,
+ remoteInputText, false /* showSpinner */);
boolean updated = false;
entry.onRemoteInputInserted();
try {
@@ -554,6 +529,39 @@
mCallback.onNotificationRemoved(key, old);
}
+ public StatusBarNotification rebuildNotificationWithRemoteInput(NotificationData.Entry entry,
+ CharSequence remoteInputText, boolean showSpinner) {
+ StatusBarNotification sbn = entry.notification;
+
+ Notification.Builder b = Notification.Builder
+ .recoverBuilder(mContext, sbn.getNotification().clone());
+ CharSequence[] oldHistory = sbn.getNotification().extras
+ .getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY);
+ CharSequence[] newHistory;
+ if (oldHistory == null) {
+ newHistory = new CharSequence[1];
+ } else {
+ newHistory = new CharSequence[oldHistory.length + 1];
+ System.arraycopy(oldHistory, 0, newHistory, 1, oldHistory.length);
+ }
+ newHistory[0] = String.valueOf(remoteInputText);
+ b.setRemoteInputHistory(newHistory);
+ b.setShowRemoteInputSpinner(showSpinner);
+
+ Notification newNotification = b.build();
+
+ // Undo any compatibility view inflation
+ newNotification.contentView = sbn.getNotification().contentView;
+ newNotification.bigContentView = sbn.getNotification().bigContentView;
+ newNotification.headsUpContentView = sbn.getNotification().headsUpContentView;
+
+ StatusBarNotification newSbn = new StatusBarNotification(sbn.getPackageName(),
+ sbn.getOpPkg(),
+ sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
+ newNotification, sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime());
+ return newSbn;
+ }
+
private boolean shouldKeepForRemoteInput(NotificationData.Entry entry) {
if (entry == null) {
return false;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyLogger.java b/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java
similarity index 64%
rename from packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyLogger.java
rename to packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java
index 75dd77d..67da68c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyLogger.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java
@@ -15,24 +15,32 @@
*/
package com.android.systemui.statusbar;
-import android.content.Context;
import android.os.RemoteException;
-import android.os.ServiceManager;
+import android.service.notification.StatusBarNotification;
+
import com.android.internal.statusbar.IStatusBarService;
+import com.android.systemui.Dependency;
+
/**
- * Handles reporting when smart replies are added to a notification
+ * Handles when smart replies are added to a notification
* and clicked upon.
*/
-public class SmartReplyLogger {
- protected IStatusBarService mBarService;
+public class SmartReplyController {
+ private IStatusBarService mBarService;
+ private NotificationEntryManager mNotificationEntryManager;
- public SmartReplyLogger(Context context) {
- mBarService = IStatusBarService.Stub.asInterface(
- ServiceManager.getService(Context.STATUS_BAR_SERVICE));
+ public SmartReplyController() {
+ mBarService = Dependency.get(IStatusBarService.class);
+ mNotificationEntryManager = Dependency.get(NotificationEntryManager.class);
}
- public void smartReplySent(NotificationData.Entry entry, int replyIndex) {
+ public void smartReplySent(NotificationData.Entry entry, int replyIndex, CharSequence reply) {
+ StatusBarNotification newSbn =
+ mNotificationEntryManager.rebuildNotificationWithRemoteInput(entry, reply,
+ true /* showSpinner */);
+ mNotificationEntryManager.updateNotification(newSbn, null /* ranking */);
+
try {
mBarService.onNotificationSmartReplySent(entry.notification.getKey(),
replyIndex);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
index 1431682..b4fa2e8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
@@ -26,7 +26,7 @@
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.NotificationData;
-import com.android.systemui.statusbar.SmartReplyLogger;
+import com.android.systemui.statusbar.SmartReplyController;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
@@ -73,6 +73,8 @@
private PriorityQueue<Button> mCandidateButtonQueueForSqueezing;
+ private View mSmartReplyContainer;
+
public SmartReplyView(Context context, AttributeSet attrs) {
super(context, attrs);
mConstants = Dependency.get(SmartReplyConstants.class);
@@ -133,7 +135,9 @@
}
public void setRepliesFromRemoteInput(RemoteInput remoteInput, PendingIntent pendingIntent,
- SmartReplyLogger smartReplyLogger, NotificationData.Entry entry) {
+ SmartReplyController smartReplyController, NotificationData.Entry entry,
+ View smartReplyContainer) {
+ mSmartReplyContainer = smartReplyContainer;
removeAllViews();
if (remoteInput != null && pendingIntent != null) {
CharSequence[] choices = remoteInput.getChoices();
@@ -141,7 +145,7 @@
for (int i = 0; i < choices.length; ++i) {
Button replyButton = inflateReplyButton(
getContext(), this, i, choices[i], remoteInput, pendingIntent,
- smartReplyLogger, entry);
+ smartReplyController, entry);
addView(replyButton);
}
}
@@ -157,7 +161,7 @@
@VisibleForTesting
Button inflateReplyButton(Context context, ViewGroup root, int replyIndex,
CharSequence choice, RemoteInput remoteInput, PendingIntent pendingIntent,
- SmartReplyLogger smartReplyLogger, NotificationData.Entry entry) {
+ SmartReplyController smartReplyController, NotificationData.Entry entry) {
Button b = (Button) LayoutInflater.from(context).inflate(
R.layout.smart_reply_button, root, false);
b.setText(choice);
@@ -173,7 +177,8 @@
} catch (PendingIntent.CanceledException e) {
Log.w(TAG, "Unable to send smart reply", e);
}
- smartReplyLogger.smartReplySent(entry, replyIndex);
+ smartReplyController.smartReplySent(entry, replyIndex, b.getText());
+ mSmartReplyContainer.setVisibility(View.GONE);
return false; // do not defer
};
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java
index 7cfd7a3..8172626 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java
@@ -367,4 +367,44 @@
mEntryManager.tagForeground(mEntry.notification);
Assert.assertEquals(0, mEntry.mActiveAppOps.size());
}
+
+ @Test
+ public void testRebuildWithRemoteInput_noExistingInputNoSpinner() {
+ StatusBarNotification newSbn =
+ mEntryManager.rebuildNotificationWithRemoteInput(mEntry, "A Reply", false);
+ CharSequence[] messages = newSbn.getNotification().extras
+ .getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY);
+ Assert.assertEquals(1, messages.length);
+ Assert.assertEquals("A Reply", messages[0]);
+ Assert.assertFalse(newSbn.getNotification().extras
+ .getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false));
+ }
+
+ @Test
+ public void testRebuildWithRemoteInput_noExistingInputWithSpinner() {
+ StatusBarNotification newSbn =
+ mEntryManager.rebuildNotificationWithRemoteInput(mEntry, "A Reply", true);
+ CharSequence[] messages = newSbn.getNotification().extras
+ .getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY);
+ Assert.assertEquals(1, messages.length);
+ Assert.assertEquals("A Reply", messages[0]);
+ Assert.assertTrue(newSbn.getNotification().extras
+ .getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false));
+ }
+
+ @Test
+ public void testRebuildWithRemoteInput_withExistingInput() {
+ // Setup a notification entry with 1 remote input.
+ StatusBarNotification newSbn =
+ mEntryManager.rebuildNotificationWithRemoteInput(mEntry, "A Reply", false);
+ NotificationData.Entry entry = new NotificationData.Entry(newSbn);
+
+ // Try rebuilding to add another reply.
+ newSbn = mEntryManager.rebuildNotificationWithRemoteInput(entry, "Reply 2", true);
+ CharSequence[] messages = newSbn.getNotification().extras
+ .getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY);
+ Assert.assertEquals(2, messages.length);
+ Assert.assertEquals("Reply 2", messages[0]);
+ Assert.assertEquals("A Reply", messages[1]);
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java
new file mode 100644
index 0000000..84dceae
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.android.systemui.statusbar;
+
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Notification;
+import android.os.RemoteException;
+import android.service.notification.StatusBarNotification;
+import android.support.test.filters.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+
+import com.android.internal.statusbar.IStatusBarService;
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+@SmallTest
+public class SmartReplyControllerTest extends SysuiTestCase {
+ private static final String TEST_NOTIFICATION_KEY = "akey";
+ private static final String TEST_CHOICE_TEXT = "A Reply";
+ private static final int TEST_CHOICE_INDEX = 2;
+ private static final int TEST_CHOICE_COUNT = 4;
+
+ private Notification mNotification;
+ private NotificationData.Entry mEntry;
+
+ @Mock
+ private NotificationEntryManager mNotificationEntryManager;
+ @Mock
+ private IStatusBarService mIStatusBarService;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mDependency.injectTestDependency(NotificationEntryManager.class,
+ mNotificationEntryManager);
+ mDependency.injectTestDependency(IStatusBarService.class, mIStatusBarService);
+
+ mNotification = new Notification.Builder(mContext, "")
+ .setSmallIcon(R.drawable.ic_person)
+ .setContentTitle("Title")
+ .setContentText("Text").build();
+ StatusBarNotification sbn = mock(StatusBarNotification.class);
+ when(sbn.getNotification()).thenReturn(mNotification);
+ when(sbn.getKey()).thenReturn(TEST_NOTIFICATION_KEY);
+ mEntry = new NotificationData.Entry(sbn);
+ }
+
+ @Test
+ public void testSendSmartReply_updatesRemoteInput() throws RemoteException {
+ StatusBarNotification sbn = mock(StatusBarNotification.class);
+ when(sbn.getKey()).thenReturn(TEST_NOTIFICATION_KEY);
+ when(mNotificationEntryManager.rebuildNotificationWithRemoteInput(
+ argThat(entry -> entry.notification.getKey().equals(TEST_NOTIFICATION_KEY)),
+ eq(TEST_CHOICE_TEXT), eq(true))).thenReturn(sbn);
+
+ SmartReplyController controller = new SmartReplyController();
+ controller.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT);
+
+ // Sending smart reply should make calls to NotificationEntryManager
+ // to update the notification with reply and spinner.
+ verify(mNotificationEntryManager).rebuildNotificationWithRemoteInput(
+ argThat(entry -> entry.notification.getKey().equals(TEST_NOTIFICATION_KEY)),
+ eq(TEST_CHOICE_TEXT), eq(true));
+ verify(mNotificationEntryManager).updateNotification(
+ argThat(sbn2 -> sbn2.getKey().equals(TEST_NOTIFICATION_KEY)), isNull());
+ }
+
+ @Test
+ public void testSendSmartReply_logsToStatusBar() throws RemoteException {
+ StatusBarNotification sbn = mock(StatusBarNotification.class);
+ when(sbn.getKey()).thenReturn(TEST_NOTIFICATION_KEY);
+ when(mNotificationEntryManager.rebuildNotificationWithRemoteInput(
+ argThat(entry -> entry.notification.getKey().equals(TEST_NOTIFICATION_KEY)),
+ eq(TEST_CHOICE_TEXT), eq(true))).thenReturn(sbn);
+
+ SmartReplyController controller = new SmartReplyController();
+ controller.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT);
+
+ // Check we log the result to the status bar service.
+ verify(mIStatusBarService).onNotificationSmartReplySent(TEST_NOTIFICATION_KEY,
+ TEST_CHOICE_INDEX);
+ }
+
+ @Test
+ public void testShowSmartReply_logsToStatusBar() throws RemoteException {
+ SmartReplyController controller = new SmartReplyController();
+ controller.smartRepliesAdded(mEntry, TEST_CHOICE_COUNT);
+
+ // Check we log the result to the status bar service.
+ verify(mIStatusBarService).onNotificationSmartRepliesAdded(TEST_NOTIFICATION_KEY,
+ TEST_CHOICE_COUNT);
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
index 2bb8106..99c06e6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
@@ -23,9 +23,10 @@
import static junit.framework.Assert.fail;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
import android.content.Intent;
@@ -44,7 +45,7 @@
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.NotificationData;
-import com.android.systemui.statusbar.SmartReplyLogger;
+import com.android.systemui.statusbar.SmartReplyController;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
import java.util.concurrent.atomic.AtomicReference;
@@ -64,19 +65,22 @@
private static final String TEST_ACTION = "com.android.SMART_REPLY_VIEW_ACTION";
private static final String[] TEST_CHOICES = new String[]{"Hello", "What's up?", "I'm here"};
+ private static final String TEST_NOTIFICATION_KEY = "akey";
private static final int WIDTH_SPEC = MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY);
private static final int HEIGHT_SPEC = MeasureSpec.makeMeasureSpec(400, MeasureSpec.AT_MOST);
private BlockingQueueIntentReceiver mReceiver;
private SmartReplyView mView;
+ private View mContainer;
private int mSingleLinePaddingHorizontal;
private int mDoubleLinePaddingHorizontal;
private int mSpacing;
- @Mock private SmartReplyLogger mLogger;
+ @Mock private SmartReplyController mLogger;
private NotificationData.Entry mEntry;
+ private Notification mNotification;
@Before
public void setUp() {
@@ -86,6 +90,7 @@
mDependency.get(KeyguardDismissUtil.class).setDismissHandler(
(action, cancelAction, afterKeyguardGone) -> action.onDismiss());
+ mContainer = new View(mContext, null);
mView = SmartReplyView.inflate(mContext, null);
@@ -96,9 +101,14 @@
R.dimen.smart_reply_button_padding_horizontal_double_line);
mSpacing = res.getDimensionPixelSize(R.dimen.smart_reply_button_spacing);
- StatusBarNotification notification = mock(StatusBarNotification.class);
- when(notification.getKey()).thenReturn("akey");
- mEntry = new NotificationData.Entry(notification);
+ mNotification = new Notification.Builder(mContext, "")
+ .setSmallIcon(R.drawable.ic_person)
+ .setContentTitle("Title")
+ .setContentText("Text").build();
+ StatusBarNotification sbn = mock(StatusBarNotification.class);
+ when(sbn.getNotification()).thenReturn(mNotification);
+ when(sbn.getKey()).thenReturn(TEST_NOTIFICATION_KEY);
+ mEntry = new NotificationData.Entry(sbn);
}
@After
@@ -155,10 +165,18 @@
}
@Test
- public void testSendSmartReply_LoggerCall() {
+ public void testSendSmartReply_controllerCalled() {
setRepliesFromRemoteInput(TEST_CHOICES);
mView.getChildAt(2).performClick();
- verify(mLogger).smartReplySent(mEntry, 2);
+ verify(mLogger).smartReplySent(mEntry, 2, TEST_CHOICES[2]);
+ }
+
+ @Test
+ public void testSendSmartReply_hidesContainer() {
+ mContainer.setVisibility(View.VISIBLE);
+ setRepliesFromRemoteInput(TEST_CHOICES);
+ mView.getChildAt(0).performClick();
+ assertEquals(View.GONE, mContainer.getVisibility());
}
@Test
@@ -340,7 +358,7 @@
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0,
new Intent(TEST_ACTION), 0);
RemoteInput input = new RemoteInput.Builder(TEST_RESULT_KEY).setChoices(choices).build();
- mView.setRepliesFromRemoteInput(input, pendingIntent, mLogger, mEntry);
+ mView.setRepliesFromRemoteInput(input, pendingIntent, mLogger, mEntry, mContainer);
}
/** Builds a {@link ViewGroup} whose measures and layout mirror a {@link SmartReplyView}. */