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