blob: 85852f90c2815cbbdd08d43dbbcd4dd68c36116d [file] [log] [blame]
Julia Reynoldseb3dca72017-07-11 10:39:58 -04001/*
2 * Copyright (C) 2017 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
17package com.android.server.notification;
18
19import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
20import static android.app.NotificationManager.IMPORTANCE_LOW;
21
Julia Reynoldsbbc469c2017-07-19 13:48:07 -040022import static com.android.server.notification.NotificationIntrusivenessExtractor.HANG_TIME_MS;
23
24import static junit.framework.Assert.assertFalse;
Julia Reynoldseb3dca72017-07-11 10:39:58 -040025import static junit.framework.Assert.assertNotNull;
26import static junit.framework.Assert.assertNull;
27
28import android.app.Notification;
29import android.app.NotificationChannel;
30import android.app.PendingIntent;
31import android.content.Intent;
32import android.os.UserHandle;
33import android.service.notification.StatusBarNotification;
34
35import org.junit.Test;
36
37public class NotificationIntrusivenessExtractorTest extends NotificationTestCase {
38
39 @Test
40 public void testNonIntrusive() {
41 NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
42 final Notification.Builder builder = new Notification.Builder(getContext())
43 .setContentTitle("foo")
44 .setSmallIcon(android.R.drawable.sym_def_app_icon);
45
46 Notification n = builder.build();
47 StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
48 0, n, UserHandle.ALL, null, System.currentTimeMillis());
49 NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
50
51 assertNull(new NotificationIntrusivenessExtractor().process(r));
52 }
53
54 @Test
55 public void testIntrusive_fillScreen() {
56 NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_DEFAULT);
57 final Notification.Builder builder = new Notification.Builder(getContext())
58 .setContentTitle("foo")
59 .setFullScreenIntent(PendingIntent.getActivity(
60 getContext(), 0, new Intent(""), 0), true)
61 .setSmallIcon(android.R.drawable.sym_def_app_icon);
62
63 Notification n = builder.build();
64 StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
Julia Reynoldsbbc469c2017-07-19 13:48:07 -040065 0, n, UserHandle.ALL, null,
66 System.currentTimeMillis());
Julia Reynoldseb3dca72017-07-11 10:39:58 -040067 NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
68
69 assertNotNull(new NotificationIntrusivenessExtractor().process(r));
70 }
Julia Reynoldsbbc469c2017-07-19 13:48:07 -040071
72 @Test
73 public void testOldNotificationsNotIntrusive() {
74 NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_DEFAULT);
75 final Notification.Builder builder = new Notification.Builder(getContext())
76 .setContentTitle("foo")
77 .setFullScreenIntent(PendingIntent.getActivity(
78 getContext(), 0, new Intent(""), 0), true)
79 .setSmallIcon(android.R.drawable.sym_def_app_icon);
80
81 Notification n = builder.build();
82 StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
83 0, n, UserHandle.ALL, null,
84 System.currentTimeMillis() - HANG_TIME_MS);
85
86 NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
87 assertNull(new NotificationIntrusivenessExtractor().process(r));
88 assertFalse(r.isRecentlyIntrusive());
89 }
Julia Reynoldseb3dca72017-07-11 10:39:58 -040090}