Home | History | Annotate | Download | only in statusbartest
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.statusbartest;
     18 
     19 import android.app.Notification;
     20 import android.app.NotificationManager;
     21 import android.app.PendingIntent;
     22 import android.content.Context;
     23 import android.content.ContentResolver;
     24 import android.content.Intent;
     25 import android.graphics.Bitmap;
     26 import android.graphics.drawable.BitmapDrawable;
     27 import android.os.Bundle;
     28 import android.os.Environment;
     29 import android.os.Vibrator;
     30 import android.os.Handler;
     31 import android.os.UserHandle;
     32 import android.util.Log;
     33 import android.net.Uri;
     34 import android.os.SystemClock;
     35 import android.widget.RemoteViews;
     36 import android.os.PowerManager;
     37 
     38 // private NM API
     39 import android.app.INotificationManager;
     40 
     41 public class NotificationTestList extends TestActivity
     42 {
     43     private final static String TAG = "NotificationTestList";
     44 
     45     NotificationManager mNM;
     46     Vibrator mVibrator;
     47     Handler mHandler = new Handler();
     48 
     49     long mActivityCreateTime;
     50     long mChronometerBase = 0;
     51 
     52     boolean mProgressDone = true;
     53 
     54     final int[] kNumberedIconResIDs = {
     55         R.drawable.notification0,
     56         R.drawable.notification1,
     57         R.drawable.notification2,
     58         R.drawable.notification3,
     59         R.drawable.notification4,
     60         R.drawable.notification5,
     61         R.drawable.notification6,
     62         R.drawable.notification7,
     63         R.drawable.notification8,
     64         R.drawable.notification9
     65     };
     66     final int kUnnumberedIconResID = R.drawable.notificationx;
     67 
     68     @Override
     69     public void onCreate(Bundle icicle) {
     70         super.onCreate(icicle);
     71         mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
     72         mActivityCreateTime = System.currentTimeMillis();
     73     }
     74 
     75     @Override
     76     protected String tag() {
     77         return TAG;
     78     }
     79 
     80     @Override
     81     protected Test[] tests() {
     82         mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
     83 
     84         return mTests;
     85     }
     86 
     87     private Test[] mTests = new Test[] {
     88         new Test("Off and sound") {
     89             public void run() {
     90                 PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE);
     91                 PowerManager.WakeLock wl =
     92                             pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sound");
     93                 wl.acquire();
     94 
     95                 pm.goToSleep(SystemClock.uptimeMillis());
     96 
     97                 Notification n = new Notification();
     98                 n.sound = Uri.parse("file://" + Environment.getExternalStorageDirectory() +
     99                         "/virtual-void.mp3");
    100                 Log.d(TAG, "n.sound=" + n.sound);
    101 
    102                 mNM.notify(1, n);
    103 
    104                 Log.d(TAG, "releasing wake lock");
    105                 wl.release();
    106                 Log.d(TAG, "released wake lock");
    107             }
    108         },
    109 
    110         new Test("Cancel #1") {
    111             public void run()
    112             {
    113                 mNM.cancel(1);
    114             }
    115         },
    116 
    117         new Test("Button") {
    118             public void run() {
    119                 Notification n = new Notification(R.drawable.icon1, null,
    120                         mActivityCreateTime);
    121                 n.contentView = new RemoteViews(getPackageName(), R.layout.button_notification);
    122                 n.flags |= Notification.FLAG_ONGOING_EVENT;
    123                 n.contentIntent = makeIntent();
    124                 n.contentView.setOnClickPendingIntent(R.id.button, makeIntent2());
    125 
    126                 mNM.notify(1, n);
    127             }
    128         },
    129 
    130         new Test("custom intent on text view") {
    131             public void run() {
    132                 Notification n = new Notification(R.drawable.icon1, null,
    133                         mActivityCreateTime);
    134                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    135                             "This is a notification!!!", null);
    136                 n.contentView.setOnClickPendingIntent(com.android.internal.R.id.text,
    137                         makeIntent2());
    138                 mNM.notify(1, n);
    139             }
    140         },
    141 
    142         new Test("Ticker 1 line") {
    143             public void run() {
    144                 Notification n = new Notification(R.drawable.icon1, "tick tick tick",
    145                         mActivityCreateTime);
    146                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    147                             "This is a notification!!!", makeIntent());
    148                 mNM.notify(1, n);
    149             }
    150         },
    151 
    152         new Test("No view") {
    153             public void run() {
    154                 Notification n = new Notification(R.drawable.icon1, "No view",
    155                         System.currentTimeMillis());
    156                 mNM.notify(1, n);
    157             }
    158         },
    159 
    160         new Test("No intent") {
    161             public void run() {
    162                 Notification n = new Notification(R.drawable.icon1, "No intent",
    163                         System.currentTimeMillis());
    164                 n.setLatestEventInfo(NotificationTestList.this, "No intent",
    165                             "No intent", null);
    166                 mNM.notify(1, n);
    167             }
    168         },
    169 
    170         new Test("Layout") {
    171             public void run()
    172             {
    173                 Notification n;
    174 
    175                 n = new Notification(NotificationTestList.this,
    176                             R.drawable.ic_statusbar_missedcall,
    177                             null, System.currentTimeMillis()-(1000*60*60*24),
    178                             "(453) 123-2328",
    179                             "", null);
    180                 n.flags |= Notification.FLAG_ONGOING_EVENT;
    181 
    182                 mNM.notify(1, n);
    183 
    184                 mNM.notify(2, new Notification(NotificationTestList.this,
    185                             R.drawable.ic_statusbar_email,
    186                             null, System.currentTimeMillis(),
    187                             "Mark Willem, Me (2)",
    188                             "Re: Didn't you get the memo?", null));
    189 
    190                 mNM.notify(3, new Notification(NotificationTestList.this,
    191                             R.drawable.ic_statusbar_chat,
    192                             null, System.currentTimeMillis()+(1000*60*60*24),
    193                             "Sophia Winterlanden",
    194                             "Lorem ipsum dolor sit amet.", null));
    195             }
    196         },
    197 
    198         new Test("Bad Icon #1 (when=create)") {
    199             public void run() {
    200                 Notification n = new Notification(R.layout.chrono_notification /* not an icon */,
    201                         null, mActivityCreateTime);
    202                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    203                             "This is the same notification!!!", makeIntent());
    204                 mNM.notify(1, n);
    205             }
    206         },
    207 
    208         new Test("Bad Icon #1 (when=now)") {
    209             public void run() {
    210                 Notification n = new Notification(R.layout.chrono_notification /* not an icon */,
    211                         null, System.currentTimeMillis());
    212                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    213                             "This is the same notification!!!", makeIntent());
    214                 mNM.notify(1, n);
    215             }
    216         },
    217 
    218         new Test("Null Icon #1 (when=now)") {
    219             public void run() {
    220                 Notification n = new Notification(0, null, System.currentTimeMillis());
    221                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    222                             "This is the same notification!!!", makeIntent());
    223                 mNM.notify(1, n);
    224             }
    225         },
    226 
    227         new Test("Bad resource #1 (when=create)") {
    228             public void run() {
    229                 Notification n = new Notification(R.drawable.icon2,
    230                         null, mActivityCreateTime);
    231                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    232                             "This is the same notification!!!", makeIntent());
    233                 n.contentView.setInt(1 /*bogus*/, "bogus method", 666);
    234                 mNM.notify(1, n);
    235             }
    236         },
    237 
    238         new Test("Bad resource #1 (when=now)") {
    239             public void run() {
    240                 Notification n = new Notification(R.drawable.icon2,
    241                         null, System.currentTimeMillis());
    242                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    243                             "This is the same notification!!!", makeIntent());
    244                 n.contentView.setInt(1 /*bogus*/, "bogus method", 666);
    245                 mNM.notify(1, n);
    246             }
    247         },
    248 
    249 
    250         new Test("Bad resource #3") {
    251             public void run()
    252             {
    253                 Notification n = new Notification(NotificationTestList.this,
    254                             R.drawable.ic_statusbar_missedcall,
    255                             null, System.currentTimeMillis()-(1000*60*60*24),
    256                             "(453) 123-2328",
    257                             "", null);
    258                 n.contentView.setInt(1 /*bogus*/, "bogus method", 666);
    259                 mNM.notify(3, n);
    260             }
    261         },
    262 
    263         new Test("Times") {
    264             public void run()
    265             {
    266                 long now = System.currentTimeMillis();
    267 
    268                 timeNotification(7, "24 hours from now", now+(1000*60*60*24));
    269                 timeNotification(6, "12:01:00 from now", now+(1000*60*60*12)+(60*1000));
    270                 timeNotification(5, "12 hours from now", now+(1000*60*60*12));
    271                 timeNotification(4, "now", now);
    272                 timeNotification(3, "11:59:00 ago", now-((1000*60*60*12)-(60*1000)));
    273                 timeNotification(2, "12 hours ago", now-(1000*60*60*12));
    274                 timeNotification(1, "24 hours ago", now-(1000*60*60*24));
    275             }
    276         },
    277         new StateStress("Stress - Ongoing / Latest", 100, 100, new Runnable[] {
    278                 new Runnable() {
    279                     public void run() {
    280                         Log.d(TAG, "Stress - Ongoing/Latest 0");
    281                         Notification n = new Notification(NotificationTestList.this,
    282                                 R.drawable.icon3,
    283                                 null, System.currentTimeMillis(), "Stress - Ongoing",
    284                                 "Notify me!!!", null);
    285                         n.flags |= Notification.FLAG_ONGOING_EVENT;
    286                         mNM.notify(1, n);
    287                     }
    288                 },
    289                 new Runnable() {
    290                     public void run() {
    291                         Log.d(TAG, "Stress - Ongoing/Latest 1");
    292                         Notification n = new Notification(NotificationTestList.this,
    293                                 R.drawable.icon4,
    294                                 null, System.currentTimeMillis(), "Stress - Latest",
    295                                 "Notify me!!!", null);
    296                         //n.flags |= Notification.FLAG_ONGOING_EVENT;
    297                         mNM.notify(1, n);
    298                     }
    299                 }
    300             }),
    301 
    302         new Test("Long") {
    303             public void run()
    304             {
    305                 Notification n = new Notification();
    306                 n.defaults |= Notification.DEFAULT_SOUND ;
    307                 n.vibrate = new long[] {
    308                         300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
    309                         300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
    310                         300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 };
    311                 mNM.notify(1, n);
    312             }
    313         },
    314 
    315         new Test("Progress #1") {
    316             public void run() {
    317                 final boolean PROGRESS_UPDATES_WHEN = true;
    318                 if (!mProgressDone) return;
    319                 mProgressDone = false;
    320                 Thread t = new Thread() {
    321                     public void run() {
    322                         int x = 0;
    323                         while (!mProgressDone) {
    324                             Notification n = new Notification(R.drawable.icon1, null,
    325                                     PROGRESS_UPDATES_WHEN
    326                                     ? System.currentTimeMillis()
    327                                     : mActivityCreateTime);
    328                             RemoteViews v = new RemoteViews(getPackageName(),
    329                                     R.layout.progress_notification);
    330 
    331                             v.setProgressBar(R.id.progress_bar, 100, x, false);
    332                             v.setTextViewText(R.id.status_text, "Progress: " + x + "%");
    333 
    334                             n.contentView = v;
    335                             n.flags |= Notification.FLAG_ONGOING_EVENT;
    336 
    337                             mNM.notify(500, n);
    338                             x = (x + 7) % 100;
    339 
    340                             try {
    341                                 Thread.sleep(1000);
    342                             } catch (InterruptedException e) {
    343                                 break;
    344                             }
    345                         }
    346                     }
    347                 };
    348                 t.start();
    349             }
    350         },
    351 
    352         new Test("Stop Progress") {
    353             public void run() {
    354                 mProgressDone = true;
    355                 mNM.cancel(500);
    356             }
    357         },
    358 
    359         new Test("Blue Lights") {
    360             public void run()
    361             {
    362                 Notification n = new Notification();
    363                 n.flags |= Notification.FLAG_SHOW_LIGHTS;
    364                 n.ledARGB = 0xff0000ff;
    365                 n.ledOnMS = 1;
    366                 n.ledOffMS = 0;
    367                 mNM.notify(1, n);
    368             }
    369         },
    370 
    371         new Test("Red Lights") {
    372             public void run()
    373             {
    374                 Notification n = new Notification();
    375                 n.flags |= Notification.FLAG_SHOW_LIGHTS;
    376                 n.ledARGB = 0xffff0000;
    377                 n.ledOnMS = 1;
    378                 n.ledOffMS = 0;
    379                 mNM.notify(1, n);
    380             }
    381         },
    382 
    383         new Test("Yellow Lights") {
    384             public void run()
    385             {
    386                 Notification n = new Notification();
    387                 n.flags |= Notification.FLAG_SHOW_LIGHTS;
    388                 n.ledARGB = 0xffffff00;
    389                 n.ledOnMS = 1;
    390                 n.ledOffMS = 0;
    391                 mNM.notify(1, n);
    392             }
    393         },
    394 
    395         new Test("Lights off") {
    396             public void run()
    397             {
    398                 Notification n = new Notification();
    399                 n.flags |= Notification.FLAG_SHOW_LIGHTS;
    400                 n.ledARGB = 0x00000000;
    401                 n.ledOnMS = 0;
    402                 n.ledOffMS = 0;
    403                 mNM.notify(1, n);
    404             }
    405         },
    406 
    407         new Test("Blue Blinking Slow") {
    408             public void run()
    409             {
    410                 Notification n = new Notification();
    411                 n.flags |= Notification.FLAG_SHOW_LIGHTS;
    412                 n.ledARGB = 0xff0000ff;
    413                 n.ledOnMS = 1300;
    414                 n.ledOffMS = 1300;
    415                 mNM.notify(1, n);
    416             }
    417         },
    418 
    419         new Test("Blue Blinking Fast") {
    420             public void run()
    421             {
    422                 Notification n = new Notification();
    423                 n.flags |= Notification.FLAG_SHOW_LIGHTS;
    424                 n.ledARGB = 0xff0000ff;
    425                 n.ledOnMS = 300;
    426                 n.ledOffMS = 300;
    427                 mNM.notify(1, n);
    428             }
    429         },
    430 
    431         new Test("Default All") {
    432             public void run()
    433             {
    434                 Notification n = new Notification();
    435                 n.defaults |= Notification.DEFAULT_ALL;
    436                 mNM.notify(1, n);
    437             }
    438         },
    439 
    440         new Test("Default All, once") {
    441             public void run()
    442             {
    443                 Notification n = new Notification();
    444                 n.defaults |= Notification.DEFAULT_ALL;
    445                 n.flags |= Notification.FLAG_ONLY_ALERT_ONCE ;
    446                 mNM.notify(1, n);
    447             }
    448         },
    449 
    450         new Test("Content Sound") {
    451             public void run()
    452             {
    453                 Notification n = new Notification();
    454                 n.sound = Uri.parse(
    455                         "content://media/internal/audio/media/7");
    456 
    457                 mNM.notify(1, n);
    458             }
    459         },
    460 
    461         new Test("Resource Sound") {
    462             public void run()
    463             {
    464                 Notification n = new Notification();
    465                 n.sound = Uri.parse(
    466                         ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
    467                         getPackageName() + "/raw/ringer");
    468                 Log.d(TAG, "n.sound=" + n.sound);
    469 
    470                 mNM.notify(1, n);
    471             }
    472         },
    473 
    474         new Test("Sound and Cancel") {
    475             public void run()
    476             {
    477                 Notification n = new Notification();
    478                 n.sound = Uri.parse(
    479                             "content://media/internal/audio/media/7");
    480 
    481                 mNM.notify(1, n);
    482                 SystemClock.sleep(200);
    483                 mNM.cancel(1);
    484             }
    485         },
    486 
    487         new Test("Vibrate") {
    488             public void run()
    489             {
    490                 Notification n = new Notification();
    491                     n.vibrate = new long[] { 0, 700, 500, 1000 };
    492 
    493                 mNM.notify(1, n);
    494             }
    495         },
    496 
    497         new Test("Vibrate and cancel") {
    498             public void run()
    499             {
    500                 Notification n = new Notification();
    501                     n.vibrate = new long[] { 0, 700, 500, 1000 };
    502 
    503                 mNM.notify(1, n);
    504                 SystemClock.sleep(500);
    505                 mNM.cancel(1);
    506             }
    507         },
    508 
    509         new Test("Vibrate pattern") {
    510             public void run()
    511             {
    512                 mVibrator.vibrate(new long[] { 250, 1000, 500, 2000 }, -1);
    513             }
    514         },
    515 
    516         new Test("Vibrate pattern repeating") {
    517             public void run()
    518             {
    519                 mVibrator.vibrate(new long[] { 250, 1000, 500 }, 1);
    520             }
    521         },
    522 
    523         new Test("Vibrate 3s") {
    524             public void run()
    525             {
    526                 mVibrator.vibrate(3000);
    527             }
    528         },
    529 
    530         new Test("Vibrate 100s") {
    531             public void run()
    532             {
    533                 mVibrator.vibrate(100000);
    534             }
    535         },
    536 
    537         new Test("Vibrate off") {
    538             public void run()
    539             {
    540                 mVibrator.cancel();
    541             }
    542         },
    543 
    544         new Test("Cancel #1") {
    545             public void run() {
    546                 mNM.cancel(1);
    547             }
    548         },
    549 
    550         new Test("Cancel #1 in 3 sec") {
    551             public void run() {
    552                 mHandler.postDelayed(new Runnable() {
    553                             public void run() {
    554                                 Log.d(TAG, "Cancelling now...");
    555                                 mNM.cancel(1);
    556                             }
    557                         }, 3000);
    558             }
    559         },
    560 
    561         new Test("Cancel #2") {
    562             public void run() {
    563                 mNM.cancel(2);
    564             }
    565         },
    566 
    567         new Test("Persistent #1") {
    568             public void run() {
    569                 Notification n = new Notification(R.drawable.icon1, "tick tick tick",
    570                         mActivityCreateTime);
    571                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    572                             "This is a notification!!!", makeIntent());
    573                 mNM.notify(1, n);
    574             }
    575         },
    576 
    577         new Test("Persistent #1 in 3 sec") {
    578             public void run() {
    579                 mHandler.postDelayed(new Runnable() {
    580                             public void run() {
    581                                 Notification n = new Notification(R.drawable.icon1,
    582                                         "            "
    583                                         + "tick tock tick tock\n\nSometimes notifications can "
    584                                         + "be really long and wrap to more than one line.\n"
    585                                         + "Sometimes."
    586                                         + "Ohandwhathappensifwehaveonereallylongstringarewesure"
    587                                         + "thatwesegmentitcorrectly?\n",
    588                                         System.currentTimeMillis());
    589                                 n.setLatestEventInfo(NotificationTestList.this,
    590                                         "Still Persistent #1",
    591                                         "This is still a notification!!!",
    592                                         makeIntent());
    593                                 mNM.notify(1, n);
    594                             }
    595                         }, 3000);
    596             }
    597         },
    598 
    599         new Test("Persistent #2") {
    600             public void run() {
    601                 Notification n = new Notification(R.drawable.icon2, "tock tock tock",
    602                         System.currentTimeMillis());
    603                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #2",
    604                             "Notify me!!!", makeIntent());
    605                 mNM.notify(2, n);
    606             }
    607         },
    608 
    609         new Test("Persistent #3") {
    610             public void run() {
    611                 Notification n = new Notification(R.drawable.icon2, "tock tock tock\nmooooo",
    612                         System.currentTimeMillis());
    613                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #3",
    614                             "Notify me!!!", makeIntent());
    615                 mNM.notify(3, n);
    616             }
    617         },
    618 
    619         new Test("Persistent #2 Vibrate") {
    620             public void run() {
    621                 Notification n = new Notification(R.drawable.icon2, "tock tock tock",
    622                         System.currentTimeMillis());
    623                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #2",
    624                             "Notify me!!!", makeIntent());
    625                 n.defaults = Notification.DEFAULT_VIBRATE;
    626                 mNM.notify(2, n);
    627             }
    628         },
    629 
    630         new Test("Persistent #1 - different icon") {
    631             public void run() {
    632                 Notification n = new Notification(R.drawable.icon2, null,
    633                         mActivityCreateTime);
    634                 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
    635                             "This is the same notification!!!", makeIntent());
    636                 mNM.notify(1, n);
    637             }
    638         },
    639 
    640         new Test("Chronometer Start") {
    641             public void run() {
    642                 Notification n = new Notification(R.drawable.icon2, "me me me me",
    643                                                     System.currentTimeMillis());
    644                 n.contentView = new RemoteViews(getPackageName(), R.layout.chrono_notification);
    645                 mChronometerBase = SystemClock.elapsedRealtime();
    646                 n.contentView.setChronometer(R.id.time, mChronometerBase, "Yay! (%s)", true);
    647                 n.flags |= Notification.FLAG_ONGOING_EVENT;
    648                 n.contentIntent = makeIntent();
    649                 mNM.notify(2, n);
    650             }
    651         },
    652 
    653         new Test("Chronometer Stop") {
    654             public void run() {
    655                 mHandler.postDelayed(new Runnable() {
    656                         public void run() {
    657                             Log.d(TAG, "Chronometer Stop");
    658                             Notification n = new Notification();
    659                             n.icon = R.drawable.icon1;
    660                             n.contentView = new RemoteViews(getPackageName(),
    661                                                              R.layout.chrono_notification);
    662                             n.contentView.setChronometer(R.id.time, mChronometerBase, null, false);
    663                             n.contentIntent = makeIntent();
    664                             mNM.notify(2, n);
    665                         }
    666                     }, 3000);
    667             }
    668         },
    669 
    670         new Test("Sequential Persistent") {
    671             public void run() {
    672                 mNM.notify(1, notificationWithNumbers(1));
    673                 mNM.notify(2, notificationWithNumbers(2));
    674             }
    675         },
    676 
    677         new Test("Replace Persistent") {
    678             public void run() {
    679                 mNM.notify(1, notificationWithNumbers(1));
    680                 mNM.notify(1, notificationWithNumbers(1));
    681             }
    682         },
    683 
    684         new Test("Run and Cancel (n=1)") {
    685             public void run() {
    686                 mNM.notify(1, notificationWithNumbers(1));
    687                 mNM.cancel(1);
    688             }
    689         },
    690 
    691         new Test("Run an Cancel (n=2)") {
    692             public void run() {
    693                 mNM.notify(1, notificationWithNumbers(1));
    694                 mNM.notify(2, notificationWithNumbers(2));
    695                 mNM.cancel(2);
    696             }
    697         },
    698 
    699         // Repeatedly notify and cancel -- triggers bug #670627
    700         new Test("Bug 670627") {
    701             public void run() {
    702                 for (int i = 0; i < 10; i++) {
    703                   Log.d(TAG, "Add two notifications");
    704                   mNM.notify(1, notificationWithNumbers(1));
    705                   mNM.notify(2, notificationWithNumbers(2));
    706                   Log.d(TAG, "Cancel two notifications");
    707                   mNM.cancel(1);
    708                   mNM.cancel(2);
    709                 }
    710             }
    711         },
    712 
    713         new Test("Ten Notifications") {
    714             public void run() {
    715                 for (int i = 0; i < 2; i++) {
    716                     Notification n = new Notification(
    717                             kNumberedIconResIDs[i],
    718                             null, System.currentTimeMillis());
    719                     n.number = i;
    720                     n.setLatestEventInfo(
    721                             NotificationTestList.this,
    722                             "Persistent #" + i,
    723                             "Notify me!!!" + i,
    724                             null);
    725                     n.flags |= Notification.FLAG_ONGOING_EVENT;
    726                     mNM.notify((i+1)*10, n);
    727                 }
    728                 for (int i = 2; i < 10; i++) {
    729                     Notification n = new Notification(
    730                             kNumberedIconResIDs[i],
    731                             null, System.currentTimeMillis());
    732                     n.number = i;
    733                     n.setLatestEventInfo(
    734                             NotificationTestList.this,
    735                             "Persistent #" + i,
    736                             "Notify me!!!" + i,
    737                             null);
    738                     mNM.notify((i+1)*10, n);
    739                 }
    740             }
    741         },
    742 
    743         new Test("Cancel eight notifications") {
    744             public void run() {
    745                 for (int i = 1; i < 9; i++) {
    746                     mNM.cancel((i+1)*10);
    747                 }
    748             }
    749         },
    750 
    751         new Test("Cancel the other two notifications") {
    752             public void run() {
    753                 mNM.cancel(10);
    754                 mNM.cancel(100);
    755             }
    756         },
    757 
    758         new Test("Persistent with numbers 1") {
    759             public void run() {
    760                 mNM.notify(1, notificationWithNumbers(1));
    761             }
    762         },
    763 
    764         new Test("Persistent with numbers 22") {
    765             public void run() {
    766                 mNM.notify(1, notificationWithNumbers(22));
    767             }
    768         },
    769 
    770         new Test("Persistent with numbers 333") {
    771             public void run() {
    772                 mNM.notify(1, notificationWithNumbers(333));
    773             }
    774         },
    775 
    776         new Test("Persistent with numbers 4444") {
    777             public void run() {
    778                 mNM.notify(1, notificationWithNumbers(4444));
    779             }
    780         },
    781 
    782         new Test("PRIORITY_HIGH") {
    783             public void run() {
    784                 Notification n = new Notification.Builder(NotificationTestList.this)
    785                     .setSmallIcon(R.drawable.notification5)
    786                     .setContentTitle("High priority")
    787                     .setContentText("This should appear before all others")
    788                     .setPriority(Notification.PRIORITY_HIGH)
    789                     .getNotification();
    790 
    791                 int[] idOut = new int[1];
    792                 try {
    793                     INotificationManager directLine = mNM.getService();
    794                     directLine.enqueueNotificationWithTag(
    795                             getPackageName(),
    796                             getPackageName(),
    797                             null,
    798                             100,
    799                             n,
    800                             idOut,
    801                             UserHandle.myUserId());
    802                 } catch (android.os.RemoteException ex) {
    803                     // oh well
    804                 }
    805             }
    806         },
    807 
    808         new Test("PRIORITY_MAX") {
    809             public void run() {
    810                 Notification n = new Notification.Builder(NotificationTestList.this)
    811                     .setSmallIcon(R.drawable.notification9)
    812                     .setContentTitle("MAX priority")
    813                     .setContentText("This might appear as an intruder alert")
    814                     .setPriority(Notification.PRIORITY_MAX)
    815                     .getNotification();
    816 
    817                 int[] idOut = new int[1];
    818                 try {
    819                     INotificationManager directLine = mNM.getService();
    820                     directLine.enqueueNotificationWithTag(
    821                             getPackageName(),
    822                             getPackageName(),
    823                             null,
    824                             200,
    825                             n,
    826                             idOut,
    827                             UserHandle.myUserId());
    828                 } catch (android.os.RemoteException ex) {
    829                     // oh well
    830                 }
    831             }
    832         },
    833 
    834         new Test("PRIORITY_MIN") {
    835             public void run() {
    836                 Notification n = new Notification.Builder(NotificationTestList.this)
    837                     .setSmallIcon(R.drawable.notification0)
    838                     .setContentTitle("MIN priority")
    839                     .setContentText("You should not see this")
    840                     .setPriority(Notification.PRIORITY_MIN)
    841                     .getNotification();
    842 
    843                 int[] idOut = new int[1];
    844                 try {
    845                     INotificationManager directLine = mNM.getService();
    846                     directLine.enqueueNotificationWithTag(
    847                             getPackageName(),
    848                             getPackageName(),
    849                             null,
    850                             1,
    851                             n,
    852                             idOut,
    853                             UserHandle.myUserId());
    854                 } catch (android.os.RemoteException ex) {
    855                     // oh well
    856                 }
    857             }
    858         },
    859 
    860         new Test("Crash") {
    861             public void run()
    862             {
    863                 PowerManager.WakeLock wl
    864                         = ((PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE))
    865                             .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher");
    866                 wl.acquire();
    867                 mHandler.postDelayed(new Runnable() {
    868                             public void run() {
    869                                 throw new RuntimeException("Die!");
    870                             }
    871                         }, 10000);
    872 
    873             }
    874         },
    875 
    876     };
    877 
    878     private Notification notificationWithNumbers(int num) {
    879         Notification n = new Notification(this,
    880                 (num >= 0 && num < kNumberedIconResIDs.length)
    881                     ? kNumberedIconResIDs[num]
    882                     : kUnnumberedIconResID,
    883                 null,
    884                 System.currentTimeMillis(),
    885                 "Notification", "Number=" + num,
    886                 null);
    887         n.number = num;
    888         return n;
    889     }
    890 
    891     private PendingIntent makeIntent() {
    892         Intent intent = new Intent(Intent.ACTION_MAIN);
    893         intent.addCategory(Intent.CATEGORY_HOME);
    894         return PendingIntent.getActivity(this, 0, intent, 0);
    895     }
    896 
    897     private PendingIntent makeIntent2() {
    898         Intent intent = new Intent(this, StatusBarTest.class);
    899         return PendingIntent.getActivity(this, 0, intent, 0);
    900     }
    901 
    902 
    903     class StateStress extends Test {
    904         StateStress(String name, int pause, int iterations, Runnable[] tasks) {
    905             super(name);
    906             mPause = pause;
    907             mTasks = tasks;
    908             mIteration = iterations;
    909         }
    910         Runnable[] mTasks;
    911         int mNext;
    912         int mIteration;
    913         long mPause;
    914         Runnable mRunnable = new Runnable() {
    915             public void run() {
    916                 mTasks[mNext].run();
    917                 mNext++;
    918                 if (mNext >= mTasks.length) {
    919                     mNext = 0;
    920                     mIteration--;
    921                     if (mIteration <= 0) {
    922                         return;
    923                     }
    924                 }
    925                 mHandler.postDelayed(mRunnable, mPause);
    926             }
    927         };
    928         public void run() {
    929             mNext = 0;
    930             mHandler.postDelayed(mRunnable, mPause);
    931         }
    932     }
    933 
    934     void timeNotification(int n, String label, long time) {
    935         mNM.notify(n, new Notification(NotificationTestList.this,
    936                     R.drawable.ic_statusbar_missedcall, null,
    937                     time, label, "" + new java.util.Date(time), null));
    938 
    939     }
    940 
    941     Bitmap loadBitmap(int resId) {
    942         BitmapDrawable bd = (BitmapDrawable)getResources().getDrawable(resId);
    943         return Bitmap.createBitmap(bd.getBitmap());
    944     }
    945 }
    946 
    947