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( 719 kNumberedIconResIDs[i], 720 null, System.currentTimeMillis()); 721 n.number = i; 722 n.setLatestEventInfo( 723 NotificationTestList.this, 724 "Persistent #" + i, 725 "Notify me!!!" + i, 726 null); 727 n.flags |= Notification.FLAG_ONGOING_EVENT; 728 mNM.notify((i+1)*10, n); 729 } 730 for (int i = 2; i < 10; i++) { 731 Notification n = new Notification( 732 kNumberedIconResIDs[i], 733 null, System.currentTimeMillis()); 734 n.number = i; 735 n.setLatestEventInfo( 736 NotificationTestList.this, 737 "Persistent #" + i, 738 "Notify me!!!" + i, 739 null); 740 mNM.notify((i+1)*10, n); 741 } 742 } 743 }, 744 745 new Test("Cancel eight notifications") { 746 public void run() { 747 for (int i = 1; i < 9; i++) { 748 mNM.cancel((i+1)*10); 749 } 750 } 751 }, 752 753 new Test("Cancel the other two notifications") { 754 public void run() { 755 mNM.cancel(10); 756 mNM.cancel(100); 757 } 758 }, 759 760 new Test("Persistent with numbers 1") { 761 public void run() { 762 mNM.notify(1, notificationWithNumbers(1)); 763 } 764 }, 765 766 new Test("Persistent with numbers 22") { 767 public void run() { 768 mNM.notify(1, notificationWithNumbers(22)); 769 } 770 }, 771 772 new Test("Persistent with numbers 333") { 773 public void run() { 774 mNM.notify(1, notificationWithNumbers(333)); 775 } 776 }, 777 778 new Test("Persistent with numbers 4444") { 779 public void run() { 780 mNM.notify(1, notificationWithNumbers(4444)); 781 } 782 }, 783 784 new Test("PRIORITY_HIGH") { 785 public void run() { 786 Notification n = new Notification.Builder(NotificationTestList.this) 787 .setSmallIcon(R.drawable.notification5) 788 .setContentTitle("High priority") 789 .setContentText("This should appear before all others") 790 .setPriority(Notification.PRIORITY_HIGH) 791 .getNotification(); 792 793 int[] idOut = new int[1]; 794 try { 795 INotificationManager directLine = mNM.getService(); 796 directLine.enqueueNotificationWithTag( 797 getPackageName(), 798 null, 799 100, 800 n, 801 idOut); 802 } catch (android.os.RemoteException ex) { 803 // oh well 804 } 805 } 806 }, 807 808 new Test("PRIORITY_MAX") { 809 public void run() { 810 Notification n = new Notification.Builder(NotificationTestList.this) 811 .setSmallIcon(R.drawable.notification9) 812 .setContentTitle("MAX priority") 813 .setContentText("This might appear as an intruder alert") 814 .setPriority(Notification.PRIORITY_MAX) 815 .getNotification(); 816 817 int[] idOut = new int[1]; 818 try { 819 INotificationManager directLine = mNM.getService(); 820 directLine.enqueueNotificationWithTag( 821 getPackageName(), 822 null, 823 200, 824 n, 825 idOut); 826 } catch (android.os.RemoteException ex) { 827 // oh well 828 } 829 } 830 }, 831 832 new Test("PRIORITY_MIN") { 833 public void run() { 834 Notification n = new Notification.Builder(NotificationTestList.this) 835 .setSmallIcon(R.drawable.notification0) 836 .setContentTitle("MIN priority") 837 .setContentText("You should not see this") 838 .setPriority(Notification.PRIORITY_MIN) 839 .getNotification(); 840 841 int[] idOut = new int[1]; 842 try { 843 INotificationManager directLine = mNM.getService(); 844 directLine.enqueueNotificationWithTag( 845 getPackageName(), 846 null, 847 1, 848 n, 849 idOut); 850 } catch (android.os.RemoteException ex) { 851 // oh well 852 } 853 } 854 }, 855 856 new Test("Crash") { 857 public void run() 858 { 859 PowerManager.WakeLock wl 860 = ((PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE)) 861 .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher"); 862 wl.acquire(); 863 mHandler.postDelayed(new Runnable() { 864 public void run() { 865 throw new RuntimeException("Die!"); 866 } 867 }, 10000); 868 869 } 870 }, 871 872 }; 873 874 private Notification notificationWithNumbers(int num) { 875 Notification n = new Notification(this, 876 (num >= 0 && num < kNumberedIconResIDs.length) 877 ? kNumberedIconResIDs[num] 878 : kUnnumberedIconResID, 879 null, 880 System.currentTimeMillis(), 881 "Notification", "Number=" + num, 882 null); 883 n.number = num; 884 return n; 885 } 886 887 private PendingIntent makeIntent() { 888 Intent intent = new Intent(Intent.ACTION_MAIN); 889 intent.addCategory(Intent.CATEGORY_HOME); 890 return PendingIntent.getActivity(this, 0, intent, 0); 891 } 892 893 private PendingIntent makeIntent2() { 894 Intent intent = new Intent(this, StatusBarTest.class); 895 return PendingIntent.getActivity(this, 0, intent, 0); 896 } 897 898 899 class StateStress extends Test { 900 StateStress(String name, int pause, int iterations, Runnable[] tasks) { 901 super(name); 902 mPause = pause; 903 mTasks = tasks; 904 mIteration = iterations; 905 } 906 Runnable[] mTasks; 907 int mNext; 908 int mIteration; 909 long mPause; 910 Runnable mRunnable = new Runnable() { 911 public void run() { 912 mTasks[mNext].run(); 913 mNext++; 914 if (mNext >= mTasks.length) { 915 mNext = 0; 916 mIteration--; 917 if (mIteration <= 0) { 918 return; 919 } 920 } 921 mHandler.postDelayed(mRunnable, mPause); 922 } 923 }; 924 public void run() { 925 mNext = 0; 926 mHandler.postDelayed(mRunnable, mPause); 927 } 928 } 929 930 void timeNotification(int n, String label, long time) { 931 mNM.notify(n, new Notification(NotificationTestList.this, 932 R.drawable.ic_statusbar_missedcall, null, 933 time, label, "" + new java.util.Date(time), null)); 934 935 } 936 937 Bitmap loadBitmap(int resId) { 938 BitmapDrawable bd = (BitmapDrawable)getResources().getDrawable(resId); 939 return Bitmap.createBitmap(bd.getBitmap()); 940 } 941} 942 943