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