CTS Verifier test for notif filters for NLSes
Test: this
Bug: 173052211
Change-Id: Ief73574cc01a74f465d3097b413dbfe3a5070d55
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index fc95601..d697f29 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -3028,6 +3028,8 @@
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
+ <meta-data android:name="android.service.notification.default_filter_types"
+ android:value="1,2,4" />
</service>
<service android:name=".notifications.MockAssistant"
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 1149611..798d32a 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -2304,6 +2304,10 @@
<string name="nls_snooze_one_time">Check that service can snooze a notification for a given time.</string>
<string name="nls_get_snoozed">Check that service can retrieve snoozed notifications.</string>
<string name="nls_unsnooze_one">Check that service can unsnooze a notification.</string>
+ <string name="nls_change_type_filter">Click this button to launch the settings page for this app\'s notification listener in settings. Note what types were allowed before you make and changes. Change the filter types to allow everything except silent notifications, and then return to this screen</string>
+ <string name="nls_original_filter_verification">Were all types except ongoing notifications allowed? Are all types except silent notifications allowed now?</string>
+ <string name="nls_filter_test">Checking that an alerting notification is received and a silent one is not</string>
+ <string name="nls_reset_type_filter">Go to settings and allow all notification types, and then return here.</string>
<string name="nas_note_missed_enqueued">Check that notification was not enqueued.</string>
<string name="cp_test">Condition Provider test</string>
<string name="cp_service_name">Condition Provider for CTS Verifier</string>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/NotificationListenerVerifierActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/NotificationListenerVerifierActivity.java
index 0dba921..44abb28 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/NotificationListenerVerifierActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/NotificationListenerVerifierActivity.java
@@ -79,7 +79,7 @@
implements Runnable {
static final String TAG = "NoListenerVerifier";
private static final String NOTIFICATION_CHANNEL_ID = TAG;
- private static final String NOISY_NOTIFICATION_CHANNEL_ID = TAG + "Noisy";
+ private static final String NOISY_NOTIFICATION_CHANNEL_ID = TAG + "noisy";
protected static final String PREFS = "listener_prefs";
final int NUM_NOTIFICATIONS_SENT = 3; // # notifications sent by sendNotifications()
@@ -121,6 +121,10 @@
tests.add(new IsEnabledTest());
tests.add(new ServiceStartedTest());
tests.add(new NotificationReceivedTest());
+ tests.add(new SendUserToChangeFilter());
+ tests.add(new AskIfFilterChanged());
+ tests.add(new NotificationTypeFilterTest());
+ tests.add(new ResetChangeFilter());
tests.add(new LongMessageTest());
tests.add(new DataIntactTest());
tests.add(new AudiblyAlertedTest());
@@ -171,11 +175,11 @@
@SuppressLint("NewApi")
private void sendNotifications() {
mTag1 = UUID.randomUUID().toString();
- Log.d(TAG, "Sending " + mTag1);
+ Log.d(TAG, "Sending #1: " + mTag1);
mTag2 = UUID.randomUUID().toString();
- Log.d(TAG, "Sending " + mTag2);
+ Log.d(TAG, "Sending #2: " + mTag2);
mTag3 = UUID.randomUUID().toString();
- Log.d(TAG, "Sending " + mTag3);
+ Log.d(TAG, "Sending #3: " + mTag3);
mWhen1 = System.currentTimeMillis() + 1;
mWhen2 = System.currentTimeMillis() + 2;
@@ -191,7 +195,7 @@
mPackageString = "com.android.cts.verifier";
- Notification n1 = new Notification.Builder(mContext, NOTIFICATION_CHANNEL_ID)
+ Notification n1 = new Notification.Builder(mContext, NOISY_NOTIFICATION_CHANNEL_ID)
.setContentTitle("ClearTest 1")
.setContentText(mTag1)
.setSmallIcon(mIcon1)
@@ -1807,4 +1811,116 @@
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
}
+
+ /**
+ * Sends the user to settings filter out silent notifications for this notification listener.
+ * Sends silent and not silent notifs and makes sure only the non silent is received
+ */
+ private class NotificationTypeFilterTest extends InteractiveTestCase {
+ int mRetries = 3;
+ @Override
+ protected View inflate(ViewGroup parent) {
+ return createAutoItem(parent, R.string.nls_filter_test);
+
+ }
+
+ @Override
+ protected void setUp() {
+ createChannels();
+ sendNotifications();
+ status = READY;
+ }
+
+ @Override
+ protected void tearDown() {
+ mNm.cancelAll();
+ MockListener.getInstance().resetData();
+ deleteChannels();
+ }
+
+ @Override
+ protected void test() {
+ if (MockListener.getInstance().getPosted(mTag1) == null) {
+ Log.d(TAG, "Could not find " + mTag1);
+ if (--mRetries > 0) {
+ sleep(100);
+ status = RETEST;
+ } else {
+ status = FAIL;
+ }
+ } else if (MockListener.getInstance().getPosted(mTag2) != null) {
+ logFail("Found" + mTag2);
+ status = FAIL;
+ } else {
+ status = PASS;
+ }
+ }
+ }
+
+ protected class SendUserToChangeFilter extends InteractiveTestCase {
+ @Override
+ protected View inflate(ViewGroup parent) {
+ return createUserItem(
+ parent, R.string.cp_start_settings, R.string.nls_change_type_filter);
+ }
+
+ @Override
+ boolean autoStart() {
+ return true;
+ }
+
+ @Override
+ protected void test() {
+ if (getIntent().resolveActivity(mPackageManager) == null) {
+ logFail("no settings activity");
+ status = FAIL;
+ } else {
+ if (buttonPressed) {
+ status = PASS;
+ } else {
+ status = RETEST_AFTER_LONG_DELAY;
+ }
+ next();
+ }
+ }
+
+ protected void tearDown() {
+ // wait for the service to start
+ delay();
+ }
+
+ @Override
+ protected Intent getIntent() {
+ Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_DETAIL_SETTINGS);
+ intent.putExtra(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME,
+ MockListener.COMPONENT_NAME.flattenToString());
+ return intent;
+ }
+ }
+
+ protected class ResetChangeFilter extends SendUserToChangeFilter {
+ @Override
+ protected View inflate(ViewGroup parent) {
+ return createUserItem(
+ parent, R.string.cp_start_settings, R.string.nls_reset_type_filter);
+ }
+ }
+
+ protected class AskIfFilterChanged extends InteractiveTestCase {
+ @Override
+ protected View inflate(ViewGroup parent) {
+ return createPassFailItem(parent, R.string.nls_original_filter_verification);
+ }
+
+ @Override
+ boolean autoStart() {
+ return true;
+ }
+
+ @Override
+ protected void test() {
+ status = WAIT_FOR_USER;
+ next();
+ }
+ }
}