diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-14 07:27:09 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-14 07:27:09 +0000 |
commit | 498634c1b82f27bfdaf74f8967acd0fb6f32562e (patch) | |
tree | 83d4738603f84e443dbb92ca64d3406dc41cce64 | |
parent | 897fd99ea1cbafcfd4806988aa2c2812e8637a09 (diff) | |
parent | cfcc06f07c2e4c17cd435ea8d29e9b7fa9c15010 (diff) | |
download | platform_testing-498634c1b82f27bfdaf74f8967acd0fb6f32562e.tar.gz |
release-request-f0fc1aa1-730c-4deb-b1ff-e8ebeeccc4b5-for-git_oc-mr1-release-4335659 snap-temp-L85900000102427279
Change-Id: I21a9a3fefb65d997d17efc6a8c5d7b6a0cf40bda
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) |