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