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