summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wren <cwren@google.com>2017-09-12 11:30:25 -0400
committerChris Wren <cwren@google.com>2017-09-12 11:45:32 -0400
commitda53f65c961e255f11dc23ca37926414383c63d3 (patch)
tree8d704549743c6d1404efadabcfcd4be09318e887
parent0f6107f456186f0948a9eb4e25529ce5df0e82fb (diff)
downloadplatform_testing-da53f65c961e255f11dc23ca37926414383c63d3.tar.gz
add channels to the notification functional tests
Bug: 65552160 Test: mmma -j20 platform_testing/tests/functional/notificationtests && adb install -r -g /mnt/fastroid/oc-mr1-dev/out/target/product/sailfish/data/app/NotificationFunctionalTests/NotificationFunctionalTests.apk && adb shell am instrument -w -e iterations 1 -e class com.android.notification.functional.NotificationInteractionTests com.android.notification.functional/android.support.test.runner.AndroidJUnitRunner Change-Id: Ibf8ca0567772574964c45a130f69d0ac3aa6922c
-rw-r--r--tests/functional/notificationtests/src/com/android/notification/functional/NotificationHelper.java36
-rw-r--r--tests/functional/notificationtests/src/com/android/notification/functional/NotificationInteractionTests.java2
2 files changed, 32 insertions, 6 deletions
diff --git a/tests/functional/notificationtests/src/com/android/notification/functional/NotificationHelper.java b/tests/functional/notificationtests/src/com/android/notification/functional/NotificationHelper.java
index c236bc497..12d346822 100644
--- a/tests/functional/notificationtests/src/com/android/notification/functional/NotificationHelper.java
+++ b/tests/functional/notificationtests/src/com/android/notification/functional/NotificationHelper.java
@@ -16,6 +16,9 @@
package com.android.notification.functional;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+
import android.app.Instrumentation;
import android.app.IntentService;
import android.app.KeyguardManager;
@@ -27,7 +30,6 @@ import android.app.RemoteInput;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
-import android.net.Uri;
import android.os.Handler;
import android.os.RemoteException;
import android.provider.Settings;
@@ -65,6 +67,10 @@ public class NotificationHelper {
public static final String FIRST_ACTION = "FIRST ACTION";
public static final String SECOND_ACTION = "SECOND ACTION";
public static final String CONTENT_TITLE = "THIS IS A NOTIFICATION";
+ private static final String BUZZY_CHANNEL_ID = "com.android.notification.functional.buzzy";
+ private static final String QUIET_CHANNEL_ID = "com.android.notification.functional.quiet";
+ private NotificationChannel mBuzzyChannel;
+ private NotificationChannel mQuietChannel;
private UiDevice mDevice;
private Instrumentation mInst;
@@ -76,6 +82,9 @@ public class NotificationHelper {
mInst = inst;
mNotificationManager = nm;
mContext = inst.getContext();
+ // create the channels we need
+ mBuzzyChannel = getChannel(true);
+ mQuietChannel = getChannel(false);
}
public void sleepAndWakeUpDevice() throws RemoteException, InterruptedException {
@@ -186,7 +195,7 @@ public class NotificationHelper {
.setContentText(subtitle)
.setContentIntent(pendingIntent)
.setVisibility(visibility)
- .setPriority(Notification.PRIORITY_HIGH)
+ .setChannelId(buzz ? BUZZY_CHANNEL_ID : QUIET_CHANNEL_ID)
.addAction(new Notification.Action.Builder(R.drawable.stat_notify_email,
FIRST_ACTION, emptyIntent)
.build())
@@ -194,9 +203,6 @@ public class NotificationHelper {
SECOND_ACTION, emptyIntent)
.build())
.setAutoCancel(false);
- if (buzz) {
- notification.setDefaults(Notification.DEFAULT_VIBRATE);
- }
mNotificationManager.notify(id, notification.build());
Thread.sleep(LONG_TIMEOUT);
}
@@ -361,6 +367,26 @@ public class NotificationHelper {
return mNotificationManager.getNotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID);
}
+ public NotificationChannel getChannel(boolean buzz) {
+ String id = (buzz ? BUZZY_CHANNEL_ID : QUIET_CHANNEL_ID);
+ String name = (buzz ? "This channel is buzzy" : "This channel is quiet");
+ int importance = (buzz ? IMPORTANCE_DEFAULT : IMPORTANCE_LOW);
+
+ NotificationChannel channel = (buzz ? mBuzzyChannel : mQuietChannel);
+ if (channel == null) {
+ channel = mNotificationManager.getNotificationChannel(id);
+ }
+ if (channel == null){
+ channel = new NotificationChannel(id, name, importance);
+ if (buzz) {
+ channel.enableVibration(true);
+ channel.setSound(null, null);
+ }
+ mNotificationManager.createNotificationChannel(channel);
+ }
+ return channel;
+ }
+
public static class ToastService extends IntentService {
private static final String TAG = "ToastService";
private static final String ACTION_TOAST = "toast";
diff --git a/tests/functional/notificationtests/src/com/android/notification/functional/NotificationInteractionTests.java b/tests/functional/notificationtests/src/com/android/notification/functional/NotificationInteractionTests.java
index 53b9c6963..d5b4f58cd 100644
--- a/tests/functional/notificationtests/src/com/android/notification/functional/NotificationInteractionTests.java
+++ b/tests/functional/notificationtests/src/com/android/notification/functional/NotificationInteractionTests.java
@@ -237,7 +237,7 @@ public class NotificationInteractionTests extends InstrumentationTestCase {
new LogMaker(MetricsEvent.NOTIFICATION_ALERT)
.setType(MetricsEvent.TYPE_OPEN)
.addTaggedData(MetricsEvent.NOTIFICATION_ID, id)
- .setSubtype(1) // 1: BUZZ, nop BEEP, nop BLINK
+ .setSubtype(MetricsEvent.ALERT_BUZZ) // no BEEP or BLINK
.setPackageName(mContext.getPackageName()));
MetricsAsserts.assertHasLog("missing notification action 0 click log", mMetricsReader,
new LogMaker(MetricsEvent.NOTIFICATION_ITEM_ACTION)