Change group ranking.

Rank notification groups where the highest child ranks

Change-Id: Ia45455a34fc10ece75e11a7b58c60a6b2e59a7c3
Fixes: 34844490
Test: notificationtestlist
This commit is contained in:
Julia Reynolds
2017-02-28 16:06:55 -05:00
parent e096df0063
commit 3fb989b1b6
2 changed files with 170 additions and 330 deletions

View File

@@ -387,8 +387,9 @@ public class RankingHelper implements RankingConfig {
final NotificationRecord record = notificationList.get(i);
record.setAuthoritativeRank(i);
final String groupKey = record.getGroupKey();
boolean isGroupSummary = record.getNotification().isGroupSummary();
if (isGroupSummary || !mProxyByGroupTmp.containsKey(groupKey)) {
NotificationRecord existingProxy = mProxyByGroupTmp.get(groupKey);
if (existingProxy == null
|| record.getImportance() > existingProxy.getImportance()) {
mProxyByGroupTmp.put(groupKey, record);
}
}

View File

@@ -16,7 +16,13 @@
package com.android.statusbartest;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
@@ -24,7 +30,9 @@ import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Icon;
import android.media.AudioAttributes;
import android.os.Bundle;
import android.os.Vibrator;
@@ -72,6 +80,13 @@ public class NotificationTestList extends TestActivity
super.onCreate(icicle);
mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
mActivityCreateTime = System.currentTimeMillis();
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNM.createNotificationChannel(new NotificationChannel("min", "Min", IMPORTANCE_MIN));
mNM.createNotificationChannel(new NotificationChannel("low", "Low", IMPORTANCE_LOW));
mNM.createNotificationChannel(
new NotificationChannel("default", "Default", IMPORTANCE_DEFAULT));
mNM.createNotificationChannel(new NotificationChannel("high", "High", IMPORTANCE_HIGH));
}
@Override
@@ -81,8 +96,6 @@ public class NotificationTestList extends TestActivity
@Override
protected Test[] tests() {
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
return mTests;
}
@@ -95,20 +108,23 @@ public class NotificationTestList extends TestActivity
new Test("Phone call") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon2)
.setContentTitle("phone call")
.setLights(0xff0000ff, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
NotificationChannel phoneCall =
new NotificationChannel("phone call", "Phone Call", IMPORTANCE_HIGH);
phoneCall.setVibrationPattern(new long[] {
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 });
phoneCall.enableVibration(true);
phoneCall.setLightColor(0xff0000ff);
phoneCall.enableLights(true);
phoneCall.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"),
new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build())
.setPriority(Notification.PRIORITY_MAX)
.setVibrate(new long[] {
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 })
new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());
Notification n = new Notification.Builder(NotificationTestList.this,
"phone call")
.setSmallIcon(R.drawable.icon2)
.setChannel(phoneCall.getId())
.setFullScreenIntent(makeIntent2(), true)
.build();
mNM.notify(7001, n);
@@ -117,35 +133,29 @@ public class NotificationTestList extends TestActivity
new Test("Post a group") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "min")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Min priority group 1")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_MIN)
.setGroup("group1")
.build();
mNM.notify(6000, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("low priority group 1")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_LOW)
.setGroup("group1")
.build();
mNM.notify(6001, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("default priority group 1")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_DEFAULT)
.setGroup("group1")
.setOngoing(true)
.setColorized(true)
.build();
mNM.notify(6002, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("summary group 1")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_MIN)
.setGroup("group1")
.setGroupSummary(true)
.build();
@@ -155,27 +165,21 @@ public class NotificationTestList extends TestActivity
new Test("Post a group (2) w/o summary") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "min")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Min priority group 2")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_MIN)
.setGroup("group2")
.build();
mNM.notify(6100, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("low priority group 2")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_LOW)
.setGroup("group2")
.build();
mNM.notify(6101, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("default priority group 2")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_DEFAULT)
.setGroup("group2")
.build();
mNM.notify(6102, n);
@@ -184,11 +188,9 @@ public class NotificationTestList extends TestActivity
new Test("Summary for group 2") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "min")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("summary group 2")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_MIN)
.setGroup("group2")
.setGroupSummary(true)
.build();
@@ -198,54 +200,44 @@ public class NotificationTestList extends TestActivity
new Test("Group up public-secret") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("public notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setGroup("public-secret")
.build();
mNM.notify("public", 7009, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("private only notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setGroup("public-secret")
.build();
mNM.notify("no public", 7010, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("private version of notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setGroup("public-secret")
.setPublicVersion(new Notification.Builder(NotificationTestList.this)
.setPublicVersion(new Notification.Builder(
NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("public notification of private notification")
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.build())
.build();
mNM.notify("priv with pub", 7011, n);
n = new Notification.Builder(NotificationTestList.this)
n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("secret notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_SECRET)
.setGroup("public-secret")
.build();
mNM.notify("secret", 7012, n);
Notification s = new Notification.Builder(NotificationTestList.this)
Notification s = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("summary group public-secret")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_MIN)
.setGroup("public-secret")
.setGroupSummary(true)
.build();
@@ -266,40 +258,19 @@ public class NotificationTestList extends TestActivity
new Test("Min priority") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "min")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Min priority")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_MIN)
.build();
mNM.notify("min", 7000, n);
}
},
new Test("Min priority, high pri flag") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Min priority, high pri flag")
.setLights(0xff0000ff, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"))
.setPriority(Notification.PRIORITY_MIN)
.setFullScreenIntent(makeIntent2(), true)
.build();
mNM.notify(7001, n);
}
},
new Test("Low priority") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Low priority")
.setTimeout(60000)
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_LOW)
.build();
mNM.notify("low", 7002, n);
}
@@ -307,11 +278,9 @@ public class NotificationTestList extends TestActivity
new Test("Default priority") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Default priority")
.setLights(0xff0000ff, 1, 0)
.setPriority(Notification.PRIORITY_DEFAULT)
.build();
mNM.notify("default", 7004, n);
}
@@ -319,49 +288,23 @@ public class NotificationTestList extends TestActivity
new Test("High priority") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "high")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("High priority")
.setLights(0xff0000ff, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"))
.setPriority(Notification.PRIORITY_HIGH)
.build();
mNM.notify("high", 7006, n);
}
},
new Test("Max priority") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Max priority")
.setLights(0xff0000ff, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"))
.setPriority(Notification.PRIORITY_MAX)
.setFullScreenIntent(makeIntent2(), false)
.build();
mNM.notify("max", 7007, n);
}
},
new Test("Max priority with delay") {
new Test("high priority with delay") {
public void run()
{
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "high")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("Max priority")
.setLights(0xff0000ff, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"))
.setPriority(Notification.PRIORITY_MAX)
.setContentTitle("High priority")
.setFullScreenIntent(makeIntent2(), false)
.build();
mNM.notify(7008, n);
@@ -370,11 +313,9 @@ public class NotificationTestList extends TestActivity
new Test("public notification") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("public notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.build();
mNM.notify("public", 7009, n);
@@ -383,11 +324,9 @@ public class NotificationTestList extends TestActivity
new Test("private notification, no public") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("private only notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.build();
mNM.notify("no public", 7010, n);
@@ -396,16 +335,14 @@ public class NotificationTestList extends TestActivity
new Test("private notification, has public") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("private version of notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setPublicVersion(new Notification.Builder(NotificationTestList.this)
.setPublicVersion(new Notification.Builder(
NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("public notification of private notification")
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.build())
.build();
@@ -415,11 +352,9 @@ public class NotificationTestList extends TestActivity
new Test("secret notification") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("secret notification")
.setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT)
.setVisibility(Notification.VISIBILITY_SECRET)
.build();
mNM.notify("secret", 7012, n);
@@ -428,7 +363,7 @@ public class NotificationTestList extends TestActivity
new Test("1 minute timeout") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("timeout in a minute")
.setTimeout(System.currentTimeMillis() + (1000 * 60))
@@ -436,20 +371,34 @@ public class NotificationTestList extends TestActivity
mNM.notify("timeout_min", 7013, n);
}
},
new Test("Colorized") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle("RED IS BEST")
.setContentText("or is blue?")
.setTimeout(System.currentTimeMillis() + (1000 * 60))
.setColor(Color.RED)
.setFlag(Notification.FLAG_ONGOING_EVENT, true)
.setColorized(true)
.build();
mNM.notify("timeout_min", 7013, n);
}
},
new Test("Off") {
public void run() {
PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE);
PowerManager pm = (PowerManager) NotificationTestList.this.getSystemService(
Context.POWER_SERVICE);
PowerManager.WakeLock wl =
pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sound");
wl.acquire();
pm.goToSleep(SystemClock.uptimeMillis());
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.stat_sys_phone)
.setContentTitle(name)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"))
.build();
Log.d(TAG, "n.sound=" + n.sound);
@@ -470,14 +419,15 @@ public class NotificationTestList extends TestActivity
new Test("Custom Button") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
RemoteViews view = new RemoteViews(getPackageName(), R.layout.button_notification);
view.setOnClickPendingIntent(R.id.button, makeIntent2());
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon1)
.setWhen(mActivityCreateTime)
.setContentTitle(name)
.setOngoing(true)
.setCustomContentView(view)
.build();
n.contentView = new RemoteViews(getPackageName(), R.layout.button_notification);
n.contentView.setOnClickPendingIntent(R.id.button, makeIntent2());
mNM.notify(1, n);
}
@@ -485,12 +435,16 @@ public class NotificationTestList extends TestActivity
new Test("Action Button") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon1)
.setWhen(mActivityCreateTime)
.setContentTitle(name)
.setOngoing(true)
.addAction(R.drawable.ic_statusbar_chat, "Button", makeIntent2())
.addAction(new Notification.Action.Builder(
Icon.createWithResource(NotificationTestList.this,
R.drawable.ic_statusbar_chat),
"Button", makeIntent2())
.build())
.build();
mNM.notify(1, n);
@@ -499,7 +453,7 @@ public class NotificationTestList extends TestActivity
new Test("with intent") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon1)
.setWhen(mActivityCreateTime)
.setContentTitle("Persistent #1")
@@ -531,7 +485,8 @@ public class NotificationTestList extends TestActivity
new Test("Whens") {
public void run()
{
Notification.Builder n = new Notification.Builder(NotificationTestList.this)
Notification.Builder n = new Notification.Builder(
NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon1)
.setContentTitle(name)
.setOngoing(true);
@@ -552,7 +507,7 @@ public class NotificationTestList extends TestActivity
new Test("Bad Icon #1 (when=create)") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.layout.chrono_notification /* not an icon */)
.setWhen(mActivityCreateTime)
.setContentTitle("Persistent #1")
@@ -565,7 +520,7 @@ public class NotificationTestList extends TestActivity
new Test("Bad Icon #1 (when=now)") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.layout.chrono_notification /* not an icon */)
.setWhen(System.currentTimeMillis())
.setContentTitle("Persistent #1")
@@ -578,7 +533,7 @@ public class NotificationTestList extends TestActivity
new Test("Null Icon #1 (when=now)") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(0)
.setWhen(System.currentTimeMillis())
.setContentTitle("Persistent #1")
@@ -591,7 +546,7 @@ public class NotificationTestList extends TestActivity
new Test("Bad resource #1 (when=create)") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setWhen(mActivityCreateTime)
.setContentTitle("Persistent #1")
@@ -605,7 +560,7 @@ public class NotificationTestList extends TestActivity
new Test("Bad resource #1 (when=now)") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setWhen(System.currentTimeMillis())
.setContentTitle("Persistent #1")
@@ -635,7 +590,7 @@ public class NotificationTestList extends TestActivity
new Runnable() {
public void run() {
Log.d(TAG, "Stress - Ongoing/Latest 0");
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon3)
.setWhen(System.currentTimeMillis())
.setContentTitle("Stress - Ongoing")
@@ -648,7 +603,7 @@ public class NotificationTestList extends TestActivity
new Runnable() {
public void run() {
Log.d(TAG, "Stress - Ongoing/Latest 1");
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon4)
.setWhen(System.currentTimeMillis())
.setContentTitle("Stress - Latest")
@@ -662,14 +617,18 @@ public class NotificationTestList extends TestActivity
new Test("Long") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
NotificationChannel channel = new NotificationChannel("v. noisy",
"channel for sound and a custom vibration", IMPORTANCE_DEFAULT);
channel.enableVibration(true);
channel.setVibrationPattern(new long[] {
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 });
mNM.createNotificationChannel(channel);
Notification n = new Notification.Builder(NotificationTestList.this, "v. noisy")
.setSmallIcon(R.drawable.icon1)
.setContentTitle(name)
.setDefaults(Notification.DEFAULT_SOUND)
.setVibrate(new long[] {
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 })
.build();
mNM.notify(1, n);
}
@@ -683,7 +642,8 @@ public class NotificationTestList extends TestActivity
Thread t = new Thread() {
public void run() {
int x = 0;
final Notification.Builder n = new Notification.Builder(NotificationTestList.this)
final Notification.Builder n = new Notification.Builder(
NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon1)
.setContentTitle(name)
.setOngoing(true);
@@ -720,11 +680,15 @@ public class NotificationTestList extends TestActivity
new Test("Blue Lights") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
NotificationChannel channel = new NotificationChannel("blue",
"blue", IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(0xff0000ff);
mNM.createNotificationChannel(channel);
Notification n = new Notification.Builder(NotificationTestList.this, "blue")
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setLights(0xff0000ff, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS)
.build();
mNM.notify(1, n);
}
@@ -733,24 +697,15 @@ public class NotificationTestList extends TestActivity
new Test("Red Lights") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setLights(0xffff0000, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS)
.build();
mNM.notify(1, n);
}
},
NotificationChannel channel = new NotificationChannel("red",
"red", IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(0xffff0000);
mNM.createNotificationChannel(channel);
new Test("Yellow Lights") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "red")
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setLights(0xffffff00, 1, 0)
.setDefaults(Notification.DEFAULT_LIGHTS)
.build();
mNM.notify(1, n);
}
@@ -759,62 +714,21 @@ public class NotificationTestList extends TestActivity
new Test("Lights off") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "default")
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setLights(0x00000000, 0, 0)
.setDefaults(Notification.DEFAULT_LIGHTS)
.build();
mNM.notify(1, n);
}
},
new Test("Blue Blinking Slow") {
new Test("Alert once") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setLights(0xff0000ff, 1300, 1300)
.setDefaults(Notification.DEFAULT_LIGHTS)
.build();
mNM.notify(1, n);
}
},
new Test("Blue Blinking Fast") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setLights(0xff0000ff, 300, 300)
.setDefaults(Notification.DEFAULT_LIGHTS)
.build();
mNM.notify(1, n);
}
},
new Test("Default All") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setDefaults(Notification.DEFAULT_ALL)
.build();
mNM.notify(1, n);
}
},
new Test("Default All, once") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "high")
.setSmallIcon(R.drawable.icon2)
.setContentTitle(name)
.setOnlyAlertOnce(true)
.setDefaults(Notification.DEFAULT_ALL)
.build();
mNM.notify(1, n);
}
@@ -823,11 +737,15 @@ public class NotificationTestList extends TestActivity
new Test("Resource Sound") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
NotificationChannel channel = new NotificationChannel("res_sound",
"resource sound", IMPORTANCE_DEFAULT);
channel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"), Notification.AUDIO_ATTRIBUTES_DEFAULT);
mNM.createNotificationChannel(channel);
Notification n = new Notification.Builder(NotificationTestList.this, "res_sound")
.setSmallIcon(R.drawable.stat_sys_phone)
.setContentTitle(name)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"))
.build();
Log.d(TAG, "n.sound=" + n.sound);
@@ -838,40 +756,37 @@ public class NotificationTestList extends TestActivity
new Test("Sound and Cancel") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
NotificationChannel channel = new NotificationChannel("res_sound",
"resource sound", IMPORTANCE_DEFAULT);
channel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"), Notification.AUDIO_ATTRIBUTES_DEFAULT);
mNM.createNotificationChannel(channel);
Notification n = new Notification.Builder(NotificationTestList.this, "res_sound")
.setSmallIcon(R.drawable.stat_sys_phone)
.setContentTitle(name)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/ringer"))
.build();
Log.d(TAG, "n.sound=" + n.sound);
mNM.notify(1, n);
SystemClock.sleep(200);
SystemClock.sleep(600);
mNM.cancel(1);
}
},
new Test("Vibrate") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.stat_sys_phone)
.setContentTitle(name)
.setVibrate(new long[]{0, 700, 500, 1000})
.build();
mNM.notify(1, n);
}
},
new Test("Vibrate and cancel") {
public void run()
{
Notification n = new Notification.Builder(NotificationTestList.this)
NotificationChannel channel = new NotificationChannel("vibrate",
"vibrate", IMPORTANCE_DEFAULT);
channel.enableVibration(true);
channel.setVibrationPattern(new long[] {0, 700, 500, 1000, 0, 700, 500, 1000,
0, 700, 500, 1000, 0, 700, 500, 1000, 0, 700, 500, 1000, 0, 700, 500, 1000,
0, 700, 500, 1000, 0, 700, 500, 1000});
mNM.createNotificationChannel(channel);
Notification n = new Notification.Builder(NotificationTestList.this, "vibrate")
.setSmallIcon(R.drawable.stat_sys_phone)
.setContentTitle(name)
.setVibrate(new long[]{0, 700, 500, 1000})
.build();
mNM.notify(1, n);
@@ -961,7 +876,8 @@ public class NotificationTestList extends TestActivity
+ "Sometimes."
+ "Ohandwhathappensifwehaveonereallylongstringarewesure"
+ "thatwesegmentitcorrectly?\n";
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(
NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon1)
.setContentTitle(name)
.setContentText("This is still a notification!!!")
@@ -976,7 +892,7 @@ public class NotificationTestList extends TestActivity
new Test("Persistent #2") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon1)
.setWhen(mActivityCreateTime)
.setContentTitle(name)
@@ -989,7 +905,7 @@ public class NotificationTestList extends TestActivity
new Test("Persistent #3") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon1)
.setWhen(mActivityCreateTime)
.setContentTitle(name)
@@ -1002,7 +918,7 @@ public class NotificationTestList extends TestActivity
new Test("Persistent #2 Vibrate") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon1)
.setWhen(mActivityCreateTime)
.setContentTitle(name)
@@ -1016,7 +932,7 @@ public class NotificationTestList extends TestActivity
new Test("Persistent #1 - different icon") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon2)
.setWhen(mActivityCreateTime)
.setContentTitle(name)
@@ -1029,7 +945,7 @@ public class NotificationTestList extends TestActivity
new Test("Chronometer Start") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon1)
.setWhen(System.currentTimeMillis())
.setContentTitle(name)
@@ -1046,7 +962,8 @@ public class NotificationTestList extends TestActivity
mHandler.postDelayed(new Runnable() {
public void run() {
Log.d(TAG, "Chronometer Stop");
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(
NotificationTestList.this, "low")
.setSmallIcon(R.drawable.icon1)
.setWhen(System.currentTimeMillis())
.setContentTitle(name)
@@ -1104,7 +1021,7 @@ public class NotificationTestList extends TestActivity
new Test("Ten Notifications") {
public void run() {
for (int i = 0; i < 10; i++) {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(kNumberedIconResIDs[i])
.setContentTitle("Persistent #" + i)
.setContentText("Notify me!!!" + i)
@@ -1155,90 +1072,12 @@ public class NotificationTestList extends TestActivity
}
},
new Test("PRIORITY_HIGH") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.notification5)
.setContentTitle("High priority")
.setContentText("This should appear before all others")
.setPriority(Notification.PRIORITY_HIGH)
.build();
int[] idOut = new int[1];
try {
INotificationManager directLine = mNM.getService();
directLine.enqueueNotificationWithTag(
getPackageName(),
getPackageName(),
null,
100,
n,
idOut,
UserHandle.myUserId());
} catch (android.os.RemoteException ex) {
// oh well
}
}
},
new Test("PRIORITY_MAX") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.notification9)
.setContentTitle("MAX priority")
.setContentText("This might appear as an intruder alert")
.setPriority(Notification.PRIORITY_MAX)
.build();
int[] idOut = new int[1];
try {
INotificationManager directLine = mNM.getService();
directLine.enqueueNotificationWithTag(
getPackageName(),
getPackageName(),
null,
200,
n,
idOut,
UserHandle.myUserId());
} catch (android.os.RemoteException ex) {
// oh well
}
}
},
new Test("PRIORITY_MIN") {
public void run() {
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.notification0)
.setContentTitle("MIN priority")
.setContentText("You should not see this")
.setPriority(Notification.PRIORITY_MIN)
.build();
int[] idOut = new int[1];
try {
INotificationManager directLine = mNM.getService();
directLine.enqueueNotificationWithTag(
getPackageName(),
getPackageName(),
null,
1,
n,
idOut,
UserHandle.myUserId());
} catch (android.os.RemoteException ex) {
// oh well
}
}
},
new Test("Crash") {
public void run()
{
PowerManager.WakeLock wl
= ((PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher");
PowerManager.WakeLock wl =
((PowerManager) NotificationTestList.this.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher");
wl.acquire();
mHandler.postDelayed(new Runnable() {
public void run() {
@@ -1252,7 +1091,7 @@ public class NotificationTestList extends TestActivity
};
private Notification notificationWithNumbers(String name, int num) {
Notification n = new Notification.Builder(NotificationTestList.this)
Notification n = new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon((num >= 0 && num < kNumberedIconResIDs.length)
? kNumberedIconResIDs[num]
: kUnnumberedIconResID)
@@ -1307,7 +1146,7 @@ public class NotificationTestList extends TestActivity
}
void timeNotification(int n, String label, long time) {
mNM.notify(n, new Notification.Builder(NotificationTestList.this)
mNM.notify(n, new Notification.Builder(NotificationTestList.this, "low")
.setSmallIcon(R.drawable.ic_statusbar_missedcall)
.setWhen(time)
.setContentTitle(label)