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