Merge "Limit instant app access to clipboard"
diff --git a/core/java/android/app/FragmentHostCallback.java b/core/java/android/app/FragmentHostCallback.java
index 7e415e9..41a885e 100644
--- a/core/java/android/app/FragmentHostCallback.java
+++ b/core/java/android/app/FragmentHostCallback.java
@@ -308,13 +308,11 @@
             mAllLoaderManagers = new ArrayMap<String, LoaderManager>();
         }
         LoaderManagerImpl lm = (LoaderManagerImpl) mAllLoaderManagers.get(who);
-        if (lm == null) {
-            if (create) {
-                lm = new LoaderManagerImpl(who, this, started);
-                mAllLoaderManagers.put(who, lm);
-            }
-        } else {
-            lm.updateHostController(this);
+        if (lm == null && create) {
+            lm = new LoaderManagerImpl(who, this, started);
+            mAllLoaderManagers.put(who, lm);
+        } else if (started && lm != null && !lm.mStarted){
+            lm.doStart();
         }
         return lm;
     }
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 977931a..0672e3b 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -1536,12 +1536,14 @@
             boolean loadersRunning = false;
 
             // Must add them in the proper order. mActive fragments may be out of order
-            final int numAdded = mAdded.size();
-            for (int i = 0; i < numAdded; i++) {
-                Fragment f = mAdded.get(i);
-                moveFragmentToExpectedState(f);
-                if (f.mLoaderManager != null) {
-                    loadersRunning |= f.mLoaderManager.hasRunningLoaders();
+            if (mAdded != null) {
+                final int numAdded = mAdded.size();
+                for (int i = 0; i < numAdded; i++) {
+                    Fragment f = mAdded.get(i);
+                    moveFragmentToExpectedState(f);
+                    if (f.mLoaderManager != null) {
+                        loadersRunning |= f.mLoaderManager.hasRunningLoaders();
+                    }
                 }
             }
 
diff --git a/core/java/android/app/ITaskStackListener.aidl b/core/java/android/app/ITaskStackListener.aidl
index d8d4bb9..5768d1a 100644
--- a/core/java/android/app/ITaskStackListener.aidl
+++ b/core/java/android/app/ITaskStackListener.aidl
@@ -31,11 +31,8 @@
      * Called whenever IActivityManager.startActivity is called on an activity that is already
      * running in the pinned stack and the activity is not actually started, but the task is either
      * brought to the front or a new Intent is delivered to it.
-     *
-     * @param launchedFromPackage the package name of the activity that initiated the restart
-     *                            attempt
      */
-    void onPinnedActivityRestartAttempt(String launchedFromPackage);
+    void onPinnedActivityRestartAttempt();
 
     /**
      * Called whenever the pinned stack is starting animating a resize.
diff --git a/core/java/android/app/LoaderManager.java b/core/java/android/app/LoaderManager.java
index bedf31a..56dfc58 100644
--- a/core/java/android/app/LoaderManager.java
+++ b/core/java/android/app/LoaderManager.java
@@ -852,6 +852,7 @@
             mInactiveLoaders.valueAt(i).destroy();
         }
         mInactiveLoaders.clear();
+        mHost = null;
     }
 
     @Override
diff --git a/core/java/android/app/TaskStackListener.java b/core/java/android/app/TaskStackListener.java
index 7a569fc..a07e11e 100644
--- a/core/java/android/app/TaskStackListener.java
+++ b/core/java/android/app/TaskStackListener.java
@@ -35,7 +35,7 @@
     }
 
     @Override
-    public void onPinnedActivityRestartAttempt(String launchedFromPackage) throws RemoteException {
+    public void onPinnedActivityRestartAttempt() throws RemoteException {
     }
 
     @Override
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 13a495e..a638cd4 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -1057,12 +1057,17 @@
      * allowed to run code through scheduled alarms, receiving broadcasts,
      * etc.  A started user may be either the current foreground user or a
      * background user; the result here does not distinguish between the two.
-     * <p>Requires {@code android.permission.MANAGE_USERS} or
-     * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
-     * must be the calling user or a managed profile associated with it.
+     *
+     * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
+     * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
+     * in order to check other profile's status.
+     * Since Android Nougat MR1 (SDK version >= 25;
+     * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
+     * it'll accept any {@link UserHandle} within the same profile group as the caller.
      *
      * @param user The user to retrieve the running state for.
      */
+    // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
     public boolean isUserRunning(UserHandle user) {
         return isUserRunning(user.getIdentifier());
     }
@@ -1081,12 +1086,17 @@
      * This is like {@link #isUserRunning(UserHandle)}, but will also return
      * true if the user had been running but is in the process of being stopped
      * (but is not yet fully stopped, and still running some code).
-     * <p>Requires {@code android.permission.MANAGE_USERS} or
-     * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
-     * must be the calling user or a managed profile associated with it.
+     *
+     * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
+     * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
+     * in order to check other profile's status.
+     * Since Android Nougat MR1 (SDK version >= 25;
+     * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
+     * it'll accept any {@link UserHandle} within the same profile group as the caller.
      *
      * @param user The user to retrieve the running state for.
      */
+    // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
     public boolean isUserRunningOrStopping(UserHandle user) {
         try {
             // TODO: reconcile stopped vs stopping?
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java
index fcff9a2..756e9a0 100644
--- a/core/java/android/text/TextLine.java
+++ b/core/java/android/text/TextLine.java
@@ -852,6 +852,18 @@
         return runIsRtl ? -ret : ret;
     }
 
+    private int adjustHyphenEdit(int start, int limit, int hyphenEdit) {
+        int result = hyphenEdit;
+        // Only draw hyphens on first or last run in line. Disable them otherwise.
+        if (start > 0) { // not the first run
+            result &= ~Paint.HYPHENEDIT_MASK_START_OF_LINE;
+        }
+        if (limit < mLen) { // not the last run
+            result &= ~Paint.HYPHENEDIT_MASK_END_OF_LINE;
+        }
+        return result;
+    }
+
     /**
      * Utility function for handling a unidirectional run.  The run must not
      * contain tabs but can contain styles.
@@ -893,9 +905,9 @@
         if (mSpanned == null) {
             TextPaint wp = mWorkPaint;
             wp.set(mPaint);
-            final int mlimit = measureLimit;
+            wp.setHyphenEdit(adjustHyphenEdit(start, limit, wp.getHyphenEdit()));
             return handleText(wp, start, limit, start, limit, runIsRtl, c, x, top,
-                    y, bottom, fmi, needWidth || mlimit < measureLimit, mlimit);
+                    y, bottom, fmi, needWidth, measureLimit);
         }
 
         mMetricAffectingSpanSpanSet.init(mSpanned, mStart + start, mStart + limit);
@@ -953,10 +965,8 @@
                     span.updateDrawState(wp);
                 }
 
-                // Only draw hyphen on last run in line
-                if (jnext < mLen) {
-                    wp.setHyphenEdit(0);
-                }
+                wp.setHyphenEdit(adjustHyphenEdit(j, jnext, wp.getHyphenEdit()));
+
                 x += handleText(wp, j, jnext, i, inext, runIsRtl, c, x,
                         top, y, bottom, fmi, needWidth || jnext < measureLimit, offset);
             }
diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml
index a47386c..77a1035 100644
--- a/data/etc/privapp-permissions-platform.xml
+++ b/data/etc/privapp-permissions-platform.xml
@@ -139,6 +139,7 @@
         <permission name="android.permission.CHANGE_CONFIGURATION"/>
         <permission name="android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST"/>
         <permission name="android.permission.CONNECTIVITY_INTERNAL"/>
+        <permission name="android.permission.CONTROL_INCALL_EXPERIENCE"/>
         <permission name="android.permission.DUMP"/>
         <permission name="android.permission.INTERACT_ACROSS_USERS"/>
         <permission name="android.permission.LOCAL_MAC_ADDRESS"/>
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index 4ee0c34..b1d51ec 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -340,6 +340,20 @@
     private static final int CURSOR_OPT_MAX_VALUE = CURSOR_AT;
 
     /**
+     * Mask for hyphen edits that happen at the end of a line. Keep in sync with the definition in
+     * Minikin's Hyphenator.h.
+     * @hide
+     */
+    public static final int HYPHENEDIT_MASK_END_OF_LINE = 0x07;
+
+    /**
+     * Mask for hyphen edits that happen at the start of a line. Keep in sync with the definition in
+     * Minikin's Hyphenator.h.
+     * @hide
+     */
+    public static final int HYPHENEDIT_MASK_START_OF_LINE = 0x03 << 3;
+
+    /**
      * The Style specifies if the primitive being drawn is filled, stroked, or
      * both (in the same color). The default is FILL.
      */
@@ -1540,7 +1554,8 @@
      * Set a hyphen edit on the paint (causes a hyphen to be added to text when
      * measured or drawn).
      *
-     * @param hyphen 0 for no edit, 1 for adding a hyphen (other values in future)
+     * @param hyphen 0 for no edit, 1 for adding a hyphen at the end, etc.
+     *        Definition of various values are in the HyphenEdit class in Minikin's Hyphenator.h.
      *
      * @hide
      */
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk
index 9515b82..ec8d63ec 100644
--- a/libs/hwui/Android.mk
+++ b/libs/hwui/Android.mk
@@ -187,6 +187,7 @@
     external/skia/src/effects \
     external/skia/src/image \
     external/skia/src/utils \
+    external/icu/icu4c/source/common \
     external/harfbuzz_ng/src \
     external/freetype/include
 
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
index e7256d1..714b263 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
@@ -83,27 +83,12 @@
         }
 
         @Override
-        public void onPinnedActivityRestartAttempt(String launchedFromPackage) {
+        public void onPinnedActivityRestartAttempt() {
             if (!checkCurrentUserId(false /* debug */)) {
                 return;
             }
 
-            // Expand the activity back to fullscreen only if it was attempted to be restarted from
-            // another package than the top activity in the stack
-            boolean expandPipToFullscreen = true;
-            if (launchedFromPackage != null) {
-                ComponentName topActivity = PipUtils.getTopPinnedActivity(mContext,
-                        mActivityManager);
-                if (topActivity != null
-                        && topActivity.getPackageName().equals(launchedFromPackage)) {
-                    expandPipToFullscreen = false;
-                }
-            }
-            if (expandPipToFullscreen) {
-                mTouchHandler.getMotionHelper().expandPip();
-            } else {
-                Log.w(TAG, "Can not expand PiP to fullscreen via intent from the same package.");
-            }
+            mTouchHandler.getMotionHelper().expandPip();
         }
     };
 
diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
index 8f7a81c..d506669 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
@@ -704,7 +704,7 @@
         }
 
         @Override
-        public void onPinnedActivityRestartAttempt(String launchedFromPackage) {
+        public void onPinnedActivityRestartAttempt() {
             if (DEBUG) Log.d(TAG, "onPinnedActivityRestartAttempt()");
             if (!checkCurrentUserId(DEBUG)) {
                 return;
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
index 1042356..31f9ba4 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -153,7 +153,7 @@
         public void onTaskStackChanged() { }
         public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) { }
         public void onActivityPinned() { }
-        public void onPinnedActivityRestartAttempt(String launchedFromPackage) { }
+        public void onPinnedActivityRestartAttempt() { }
         public void onPinnedStackAnimationStarted() { }
         public void onPinnedStackAnimationEnded() { }
         public void onActivityForcedResizable(String packageName, int taskId) { }
@@ -199,10 +199,10 @@
         }
 
         @Override
-        public void onPinnedActivityRestartAttempt(String launchedFromPackage)
+        public void onPinnedActivityRestartAttempt()
                 throws RemoteException{
             mHandler.removeMessages(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT);
-            mHandler.obtainMessage(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT, launchedFromPackage)
+            mHandler.obtainMessage(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT)
                     .sendToTarget();
         }
 
@@ -1252,7 +1252,7 @@
                 }
                 case ON_PINNED_ACTIVITY_RESTART_ATTEMPT: {
                     for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
-                        mTaskStackListeners.get(i).onPinnedActivityRestartAttempt((String) msg.obj);
+                        mTaskStackListeners.get(i).onPinnedActivityRestartAttempt();
                     }
                     break;
                 }
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index 6021bdc..c26032ce 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -2462,12 +2462,10 @@
                         operationsToCancel.add(token);
                     }
                 }
-
-                for (Integer token : operationsToCancel) {
-                    handleCancel(token, true /* cancelAll */);
-                }
             }
-
+            for (Integer token : operationsToCancel) {
+                handleCancel(token, true /* cancelAll */);
+            }
             // We don't want the backup jobs to kick in any time soon.
             // Reschedules them to run in the distant future.
             KeyValueBackupJob.schedule(mContext, BUSY_BACKOFF_MIN_MILLIS);
diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java
index b9ae4fd..97c8862 100644
--- a/services/core/java/com/android/server/am/ActivityStarter.java
+++ b/services/core/java/com/android/server/am/ActivityStarter.java
@@ -587,8 +587,7 @@
             // The activity was already running in the pinned stack so it wasn't started, but either
             // brought to the front or the new intent was delivered to it since it was already in
             // front. Notify anyone interested in this piece of information.
-            mService.mTaskChangeNotificationController.notifyPinnedActivityRestartAttempt(
-                    sourceRecord.launchedFromPackage);
+            mService.mTaskChangeNotificationController.notifyPinnedActivityRestartAttempt();
             return;
         }
     }
diff --git a/services/core/java/com/android/server/am/TaskChangeNotificationController.java b/services/core/java/com/android/server/am/TaskChangeNotificationController.java
index 9a98bc6..3cec7e4 100644
--- a/services/core/java/com/android/server/am/TaskChangeNotificationController.java
+++ b/services/core/java/com/android/server/am/TaskChangeNotificationController.java
@@ -98,7 +98,7 @@
     };
 
     private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> {
-        l.onPinnedActivityRestartAttempt((String) m.obj);
+        l.onPinnedActivityRestartAttempt();
     };
 
     private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> {
@@ -275,11 +275,10 @@
      * running in the pinned stack and the activity was not actually started, but the task is
      * either brought to the front or a new Intent is delivered to it.
      */
-    void notifyPinnedActivityRestartAttempt(String launchedFromPackage) {
+    void notifyPinnedActivityRestartAttempt() {
         mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG);
         final Message msg =
-                mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG,
-                        launchedFromPackage);
+                mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG);
         forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg);
         msg.sendToTarget();
     }
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 476eb10..bb0742a 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -387,8 +387,9 @@
                 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);
                 }
             }
diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
index 9b1a9f2..c49be88 100644
--- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
+++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
@@ -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.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 @@
         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 @@
 
     @Override
     protected Test[] tests() {
-        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
-        
         return mTests;
     }
 
@@ -95,20 +108,23 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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 @@
                     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 @@
 
         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 @@
 
         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 @@
 
         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 @@
         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 @@
 
         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 @@
 
         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 @@
 
         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 @@
 
         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 @@
 
         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 @@
                 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 @@
                 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 @@
         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 @@
                 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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
                                         + "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 @@
 
         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 @@
 
         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 @@
 
         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 @@
 
         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 @@
 
         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 @@
                 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 @@
         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 @@
             }
         },
 
-        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 @@
     };
 
     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 @@
     }
 
     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)