The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.statusbartest; |
| 18 | |
| 19 | import android.app.ListActivity; |
| 20 | import android.app.PendingIntent; |
| 21 | import android.widget.ArrayAdapter; |
| 22 | import android.view.View; |
| 23 | import android.widget.ListView; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 24 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.Intent; |
| 26 | import android.app.Notification; |
| 27 | import android.app.NotificationManager; |
| 28 | import android.os.Vibrator; |
| 29 | import android.os.Bundle; |
| 30 | import android.os.Handler; |
| 31 | import android.util.Log; |
| 32 | import android.net.Uri; |
| 33 | import android.os.SystemClock; |
| 34 | import android.widget.RemoteViews; |
| 35 | import android.widget.TextView; |
| 36 | import android.os.PowerManager; |
| 37 | |
| 38 | public class NotificationTestList extends TestActivity |
| 39 | { |
| 40 | private final static String TAG = "NotificationTestList"; |
| 41 | |
| 42 | NotificationManager mNM; |
| 43 | Vibrator mVibrator = new Vibrator(); |
| 44 | Handler mHandler = new Handler(); |
| 45 | |
| 46 | long mChronometerBase = 0; |
| 47 | |
| 48 | @Override |
| 49 | protected String tag() { |
| 50 | return TAG; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | protected Test[] tests() { |
| 55 | mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); |
| 56 | |
| 57 | return mTests; |
| 58 | } |
| 59 | |
| 60 | private Test[] mTests = new Test[] { |
Joe Onorato | e71d9e4 | 2009-11-05 17:12:18 -0500 | [diff] [blame] | 61 | new Test("Off and sound") { |
| 62 | public void run() { |
| 63 | PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService("power"); |
| 64 | PowerManager.WakeLock wl = |
| 65 | pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sound"); |
| 66 | wl.acquire(); |
| 67 | |
| 68 | pm.goToSleep(SystemClock.uptimeMillis()); |
| 69 | |
| 70 | Notification n = new Notification(); |
| 71 | n.sound = Uri.parse("file:///sdcard/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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | new Test("No view") { |
| 83 | public void run() { |
| 84 | Notification n = new Notification(R.drawable.icon1, "No view", |
| 85 | System.currentTimeMillis()); |
| 86 | mNM.notify(1, n); |
| 87 | } |
| 88 | }, |
| 89 | |
| 90 | new Test("No intent") { |
| 91 | public void run() { |
| 92 | Notification n = new Notification(R.drawable.icon1, "No intent", |
| 93 | System.currentTimeMillis()); |
| 94 | n.setLatestEventInfo(NotificationTestList.this, "No intent", |
| 95 | "No intent", null); |
| 96 | mNM.notify(1, n); |
| 97 | } |
| 98 | }, |
| 99 | |
| 100 | new Test("Layout") { |
| 101 | public void run() |
| 102 | { |
| 103 | |
| 104 | mNM.notify(1, new Notification(NotificationTestList.this, |
| 105 | R.drawable.ic_statusbar_missedcall, |
| 106 | null, System.currentTimeMillis()-(1000*60*60*24), |
| 107 | "(453) 123-2328", |
| 108 | "", null)); |
| 109 | |
| 110 | mNM.notify(2, new Notification(NotificationTestList.this, |
| 111 | R.drawable.ic_statusbar_email, |
| 112 | null, System.currentTimeMillis(), |
| 113 | "Mark Willem, Me (2)", |
| 114 | "Re: Didn't you get the memo?", null)); |
| 115 | |
| 116 | mNM.notify(3, new Notification(NotificationTestList.this, |
| 117 | R.drawable.ic_statusbar_chat, |
| 118 | null, System.currentTimeMillis()+(1000*60*60*24), |
| 119 | "Sophia Winterlanden", |
| 120 | "Lorem ipsum dolor sit amet.", null)); |
| 121 | } |
| 122 | }, |
| 123 | |
| 124 | new StateStress("Stress - Ongoing / Latest", 100, 100, new Runnable[] { |
| 125 | new Runnable() { |
| 126 | public void run() { |
| 127 | Log.d(TAG, "Stress - Ongoing/Latest 0"); |
| 128 | Notification n = new Notification(NotificationTestList.this, |
| 129 | R.drawable.icon3, |
| 130 | null, System.currentTimeMillis(), "Stress - Ongoing", |
| 131 | "Notify me!!!", null); |
| 132 | n.flags |= Notification.FLAG_ONGOING_EVENT; |
| 133 | mNM.notify(1, n); |
| 134 | } |
| 135 | }, |
| 136 | new Runnable() { |
| 137 | public void run() { |
| 138 | Log.d(TAG, "Stress - Ongoing/Latest 1"); |
| 139 | Notification n = new Notification(NotificationTestList.this, |
| 140 | R.drawable.icon4, |
| 141 | null, System.currentTimeMillis(), "Stress - Latest", |
| 142 | "Notify me!!!", null); |
| 143 | n.flags |= Notification.FLAG_ONGOING_EVENT; |
| 144 | mNM.notify(1, n); |
| 145 | } |
| 146 | } |
| 147 | }), |
| 148 | |
| 149 | new Test("Long") { |
| 150 | public void run() |
| 151 | { |
| 152 | Notification n = new Notification(); |
| 153 | n.defaults |= Notification.DEFAULT_SOUND ; |
| 154 | n.vibrate = new long[] { |
| 155 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 156 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 157 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }; |
| 158 | mNM.notify(1, n); |
| 159 | } |
| 160 | }, |
| 161 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 162 | new Test("Blue Lights") { |
| 163 | public void run() |
| 164 | { |
| 165 | Notification n = new Notification(); |
| 166 | n.flags |= Notification.FLAG_SHOW_LIGHTS; |
| 167 | n.ledARGB = 0xff0000ff; |
Mattias Östergren | b0fbe29 | 2010-03-05 09:44:15 +0100 | [diff] [blame^] | 168 | n.ledOnMS = 1; |
| 169 | n.ledOffMS = 0; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 170 | mNM.notify(1, n); |
| 171 | } |
| 172 | }, |
| 173 | |
| 174 | new Test("Red Lights") { |
| 175 | public void run() |
| 176 | { |
| 177 | Notification n = new Notification(); |
| 178 | n.flags |= Notification.FLAG_SHOW_LIGHTS; |
| 179 | n.ledARGB = 0xffff0000; |
Mattias Östergren | b0fbe29 | 2010-03-05 09:44:15 +0100 | [diff] [blame^] | 180 | n.ledOnMS = 1; |
| 181 | n.ledOffMS = 0; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 182 | mNM.notify(1, n); |
| 183 | } |
| 184 | }, |
| 185 | |
| 186 | new Test("Yellow Lights") { |
| 187 | public void run() |
| 188 | { |
| 189 | Notification n = new Notification(); |
| 190 | n.flags |= Notification.FLAG_SHOW_LIGHTS; |
| 191 | n.ledARGB = 0xffffff00; |
Mattias Östergren | b0fbe29 | 2010-03-05 09:44:15 +0100 | [diff] [blame^] | 192 | n.ledOnMS = 1; |
| 193 | n.ledOffMS = 0; |
| 194 | mNM.notify(1, n); |
| 195 | } |
| 196 | }, |
| 197 | |
| 198 | new Test("Lights off") { |
| 199 | public void run() |
| 200 | { |
| 201 | Notification n = new Notification(); |
| 202 | n.flags |= Notification.FLAG_SHOW_LIGHTS; |
| 203 | n.ledARGB = 0x00000000; |
| 204 | n.ledOnMS = 0; |
| 205 | n.ledOffMS = 0; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 206 | mNM.notify(1, n); |
| 207 | } |
| 208 | }, |
| 209 | |
| 210 | new Test("Blue Blinking Slow") { |
| 211 | public void run() |
| 212 | { |
| 213 | Notification n = new Notification(); |
| 214 | n.flags |= Notification.FLAG_SHOW_LIGHTS; |
Mattias Östergren | b0fbe29 | 2010-03-05 09:44:15 +0100 | [diff] [blame^] | 215 | n.ledARGB = 0xff0000ff; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 216 | n.ledOnMS = 1300; |
| 217 | n.ledOffMS = 1300; |
| 218 | mNM.notify(1, n); |
| 219 | } |
| 220 | }, |
| 221 | |
| 222 | new Test("Blue Blinking Fast") { |
| 223 | public void run() |
| 224 | { |
| 225 | Notification n = new Notification(); |
| 226 | n.flags |= Notification.FLAG_SHOW_LIGHTS; |
Mattias Östergren | b0fbe29 | 2010-03-05 09:44:15 +0100 | [diff] [blame^] | 227 | n.ledARGB = 0xff0000ff; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 228 | n.ledOnMS = 300; |
| 229 | n.ledOffMS = 300; |
| 230 | mNM.notify(1, n); |
| 231 | } |
| 232 | }, |
| 233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | new Test("Default All") { |
| 235 | public void run() |
| 236 | { |
| 237 | Notification n = new Notification(); |
| 238 | n.defaults |= Notification.DEFAULT_ALL; |
| 239 | mNM.notify(1, n); |
| 240 | } |
| 241 | }, |
| 242 | |
| 243 | new Test("Default All, once") { |
| 244 | public void run() |
| 245 | { |
| 246 | Notification n = new Notification(); |
| 247 | n.defaults |= Notification.DEFAULT_ALL; |
| 248 | n.flags |= Notification.FLAG_ONLY_ALERT_ONCE ; |
| 249 | mNM.notify(1, n); |
| 250 | } |
| 251 | }, |
| 252 | |
| 253 | new Test("Content Sound") { |
| 254 | public void run() |
| 255 | { |
| 256 | Notification n = new Notification(); |
| 257 | n.sound = Uri.parse( |
| 258 | "content://media/internal/audio/media/7"); |
| 259 | |
| 260 | mNM.notify(1, n); |
| 261 | } |
| 262 | }, |
| 263 | |
| 264 | new Test("Resource Sound") { |
| 265 | public void run() |
| 266 | { |
| 267 | Notification n = new Notification(); |
| 268 | n.sound = Uri.parse( |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 269 | ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 270 | getPackageName() + "/raw/ringer"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | Log.d(TAG, "n.sound=" + n.sound); |
| 272 | |
| 273 | mNM.notify(1, n); |
| 274 | } |
| 275 | }, |
| 276 | |
| 277 | new Test("Sound and Cancel") { |
| 278 | public void run() |
| 279 | { |
| 280 | Notification n = new Notification(); |
| 281 | n.sound = Uri.parse( |
| 282 | "content://media/internal/audio/media/7"); |
| 283 | |
| 284 | mNM.notify(1, n); |
| 285 | SystemClock.sleep(200); |
| 286 | mNM.cancel(1); |
| 287 | } |
| 288 | }, |
| 289 | |
| 290 | new Test("Vibrate") { |
| 291 | public void run() |
| 292 | { |
| 293 | Notification n = new Notification(); |
| 294 | n.vibrate = new long[] { 0, 700, 500, 1000 }; |
| 295 | |
| 296 | mNM.notify(1, n); |
| 297 | } |
| 298 | }, |
| 299 | |
| 300 | new Test("Vibrate and cancel") { |
| 301 | public void run() |
| 302 | { |
| 303 | Notification n = new Notification(); |
| 304 | n.vibrate = new long[] { 0, 700, 500, 1000 }; |
| 305 | |
| 306 | mNM.notify(1, n); |
| 307 | SystemClock.sleep(500); |
| 308 | mNM.cancel(1); |
| 309 | } |
| 310 | }, |
| 311 | |
| 312 | new Test("Vibrate pattern") { |
| 313 | public void run() |
| 314 | { |
| 315 | mVibrator.vibrate(new long[] { 250, 1000, 500, 2000 }, -1); |
| 316 | } |
| 317 | }, |
| 318 | |
| 319 | new Test("Vibrate pattern repeating") { |
| 320 | public void run() |
| 321 | { |
| 322 | mVibrator.vibrate(new long[] { 250, 1000, 500 }, 1); |
| 323 | } |
| 324 | }, |
| 325 | |
| 326 | new Test("Vibrate 3s") { |
| 327 | public void run() |
| 328 | { |
| 329 | mVibrator.vibrate(3000); |
| 330 | } |
| 331 | }, |
| 332 | |
| 333 | new Test("Vibrate 100s") { |
| 334 | public void run() |
| 335 | { |
| 336 | mVibrator.vibrate(100000); |
| 337 | } |
| 338 | }, |
| 339 | |
| 340 | new Test("Vibrate off") { |
| 341 | public void run() |
| 342 | { |
| 343 | mVibrator.cancel(); |
| 344 | } |
| 345 | }, |
| 346 | |
| 347 | new Test("Cancel #1") { |
| 348 | public void run() { |
| 349 | mNM.cancel(1); |
| 350 | } |
| 351 | }, |
| 352 | |
| 353 | new Test("Cancel #1 in 3 sec") { |
| 354 | public void run() { |
| 355 | mHandler.postDelayed(new Runnable() { |
| 356 | public void run() { |
| 357 | Log.d(TAG, "Cancelling now..."); |
| 358 | mNM.cancel(1); |
| 359 | } |
| 360 | }, 3000); |
| 361 | } |
| 362 | }, |
| 363 | |
| 364 | new Test("Cancel #2") { |
| 365 | public void run() { |
| 366 | mNM.cancel(2); |
| 367 | } |
| 368 | }, |
| 369 | |
| 370 | new Test("Persistent #1") { |
| 371 | public void run() { |
| 372 | Notification n = new Notification(R.drawable.icon1, "tick tick tick", |
| 373 | System.currentTimeMillis()); |
| 374 | n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", |
| 375 | "This is a notification!!!", makeIntent()); |
| 376 | mNM.notify(1, n); |
| 377 | } |
| 378 | }, |
| 379 | |
| 380 | new Test("Persistent #1 in 3 sec") { |
| 381 | public void run() { |
| 382 | mHandler.postDelayed(new Runnable() { |
| 383 | public void run() { |
| 384 | Notification n = new Notification(R.drawable.icon1, |
| 385 | " " |
| 386 | + "tick tock tick tock\n\nSometimes notifications can " |
| 387 | + "be really long and wrap to more than one line.\n" |
| 388 | + "Sometimes." |
| 389 | + "Ohandwhathappensifwehaveonereallylongstringarewesure" |
| 390 | + "thatwesegmentitcorrectly?\n", |
| 391 | System.currentTimeMillis()); |
| 392 | n.setLatestEventInfo(NotificationTestList.this, |
| 393 | "Still Persistent #1", |
| 394 | "This is still a notification!!!", |
| 395 | makeIntent()); |
| 396 | mNM.notify(1, n); |
| 397 | } |
| 398 | }, 3000); |
| 399 | } |
| 400 | }, |
| 401 | |
| 402 | new Test("Persistent #2") { |
| 403 | public void run() { |
| 404 | Notification n = new Notification(R.drawable.icon2, "tock tock tock", |
| 405 | System.currentTimeMillis()); |
| 406 | n.setLatestEventInfo(NotificationTestList.this, "Persistent #2", |
| 407 | "Notify me!!!", makeIntent()); |
| 408 | mNM.notify(2, n); |
| 409 | } |
| 410 | }, |
| 411 | |
| 412 | new Test("Persistent #2 Vibrate") { |
| 413 | public void run() { |
| 414 | Notification n = new Notification(R.drawable.icon2, "tock tock tock", |
| 415 | System.currentTimeMillis()); |
| 416 | n.setLatestEventInfo(NotificationTestList.this, "Persistent #2", |
| 417 | "Notify me!!!", makeIntent()); |
| 418 | n.defaults = Notification.DEFAULT_VIBRATE; |
| 419 | mNM.notify(2, n); |
| 420 | } |
| 421 | }, |
| 422 | |
| 423 | new Test("Chronometer Start") { |
| 424 | public void run() { |
| 425 | Notification n = new Notification(R.drawable.icon2, "me me me me", |
| 426 | System.currentTimeMillis()); |
| 427 | n.contentView = new RemoteViews(getPackageName(), R.layout.chrono_notification); |
| 428 | mChronometerBase = SystemClock.elapsedRealtime(); |
| 429 | n.contentView.setChronometer(R.id.time, mChronometerBase, "Yay! (%s)", true); |
| 430 | n.flags |= Notification.FLAG_ONGOING_EVENT; |
| 431 | n.contentIntent = makeIntent(); |
| 432 | mNM.notify(2, n); |
| 433 | } |
| 434 | }, |
| 435 | |
| 436 | new Test("Chronometer Stop") { |
| 437 | public void run() { |
| 438 | mHandler.postDelayed(new Runnable() { |
| 439 | public void run() { |
| 440 | Log.d(TAG, "Chronometer Stop"); |
| 441 | Notification n = new Notification(); |
| 442 | n.icon = R.drawable.icon1; |
| 443 | n.contentView = new RemoteViews(getPackageName(), |
| 444 | R.layout.chrono_notification); |
| 445 | n.contentView.setChronometer(R.id.time, mChronometerBase, null, false); |
| 446 | n.contentIntent = makeIntent(); |
| 447 | mNM.notify(2, n); |
| 448 | } |
| 449 | }, 3000); |
| 450 | } |
| 451 | }, |
| 452 | |
| 453 | new Test("Sequential Persistent") { |
| 454 | public void run() { |
| 455 | mNM.notify(1, notificationWithNumbers(1)); |
| 456 | mNM.notify(2, notificationWithNumbers(2)); |
| 457 | } |
| 458 | }, |
| 459 | |
| 460 | new Test("Replace Persistent") { |
| 461 | public void run() { |
| 462 | mNM.notify(1, notificationWithNumbers(1)); |
| 463 | mNM.notify(1, notificationWithNumbers(1)); |
| 464 | } |
| 465 | }, |
| 466 | |
| 467 | new Test("Run and Cancel (n=1)") { |
| 468 | public void run() { |
| 469 | mNM.notify(1, notificationWithNumbers(1)); |
| 470 | mNM.cancel(1); |
| 471 | } |
| 472 | }, |
| 473 | |
| 474 | new Test("Run an Cancel (n=2)") { |
| 475 | public void run() { |
| 476 | mNM.notify(1, notificationWithNumbers(1)); |
| 477 | mNM.notify(2, notificationWithNumbers(2)); |
| 478 | mNM.cancel(2); |
| 479 | } |
| 480 | }, |
| 481 | |
| 482 | // Repeatedly notify and cancel -- triggers bug #670627 |
| 483 | new Test("Bug 670627") { |
| 484 | public void run() { |
| 485 | for (int i = 0; i < 10; i++) { |
| 486 | Log.d(TAG, "Add two notifications"); |
| 487 | mNM.notify(1, notificationWithNumbers(1)); |
| 488 | mNM.notify(2, notificationWithNumbers(2)); |
| 489 | Log.d(TAG, "Cancel two notifications"); |
| 490 | mNM.cancel(1); |
| 491 | mNM.cancel(2); |
| 492 | } |
| 493 | } |
| 494 | }, |
| 495 | |
| 496 | new Test("Ten Notifications") { |
| 497 | public void run() { |
| 498 | for (int i = 0; i < 2; i++) { |
| 499 | Notification n = new Notification(NotificationTestList.this, R.drawable.icon2, |
| 500 | null, System.currentTimeMillis(), "Persistent #" + i, |
| 501 | "Notify me!!!" + i, null); |
| 502 | n.flags |= Notification.FLAG_ONGOING_EVENT; |
| 503 | n.number = i; |
| 504 | mNM.notify((i+1)*10, n); |
| 505 | } |
| 506 | for (int i = 2; i < 10; i++) { |
| 507 | Notification n = new Notification(NotificationTestList.this, R.drawable.icon2, |
| 508 | null, System.currentTimeMillis(), "Persistent #" + i, |
| 509 | "Notify me!!!" + i, null); |
| 510 | n.number = i; |
| 511 | mNM.notify((i+1)*10, n); |
| 512 | } |
| 513 | } |
| 514 | }, |
| 515 | |
| 516 | new Test("Cancel eight notifications") { |
| 517 | public void run() { |
| 518 | for (int i = 1; i < 9; i++) { |
| 519 | mNM.cancel((i+1)*10); |
| 520 | } |
| 521 | } |
| 522 | }, |
| 523 | |
| 524 | new Test("Persistent with numbers 1") { |
| 525 | public void run() { |
| 526 | mNM.notify(1, notificationWithNumbers(1)); |
| 527 | } |
| 528 | }, |
| 529 | |
| 530 | new Test("Persistent with numbers 222") { |
| 531 | public void run() { |
| 532 | mNM.notify(1, notificationWithNumbers(22)); |
| 533 | } |
| 534 | }, |
| 535 | |
| 536 | new Test("Persistent with numbers 333") { |
| 537 | public void run() { |
| 538 | mNM.notify(1, notificationWithNumbers(333)); |
| 539 | } |
| 540 | }, |
| 541 | |
| 542 | new Test("Persistent with numbers 4444") { |
| 543 | public void run() { |
| 544 | mNM.notify(1, notificationWithNumbers(4444)); |
| 545 | } |
| 546 | }, |
| 547 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 548 | new Test("Crash") { |
| 549 | public void run() |
| 550 | { |
| 551 | PowerManager.WakeLock wl |
| 552 | = ((PowerManager)NotificationTestList.this.getSystemService("power")) |
| 553 | .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher"); |
| 554 | wl.acquire(); |
| 555 | mHandler.postDelayed(new Runnable() { |
| 556 | public void run() { |
| 557 | throw new RuntimeException("Die!"); |
| 558 | } |
| 559 | }, 10000); |
| 560 | |
| 561 | } |
| 562 | }, |
| 563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | }; |
| 565 | |
| 566 | private Notification notificationWithNumbers(int num) { |
| 567 | Notification n = new Notification(this, R.drawable.icon2, null, System.currentTimeMillis(), |
| 568 | "Persistent #2", "Notify me!!!", null); |
| 569 | n.number = num; |
| 570 | return n; |
| 571 | } |
| 572 | |
| 573 | private PendingIntent makeIntent() { |
| 574 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 575 | intent.setComponent(new android.content.ComponentName( |
| 576 | "com.android.contacts", |
| 577 | "com.android.contacts.ContactsActivity")); |
| 578 | return PendingIntent.getActivity(this, 0, intent, 0); |
| 579 | } |
| 580 | |
| 581 | class StateStress extends Test { |
| 582 | StateStress(String name, int pause, int iterations, Runnable[] tasks) { |
| 583 | super(name); |
| 584 | mPause = pause; |
| 585 | mTasks = tasks; |
| 586 | mIteration = iterations; |
| 587 | } |
| 588 | Runnable[] mTasks; |
| 589 | int mNext; |
| 590 | int mIteration; |
| 591 | long mPause; |
| 592 | Runnable mRunnable = new Runnable() { |
| 593 | public void run() { |
| 594 | mTasks[mNext].run(); |
| 595 | mNext++; |
| 596 | if (mNext >= mTasks.length) { |
| 597 | mNext = 0; |
| 598 | mIteration--; |
| 599 | if (mIteration <= 0) { |
| 600 | return; |
| 601 | } |
| 602 | } |
| 603 | mHandler.postDelayed(mRunnable, mPause); |
| 604 | } |
| 605 | }; |
| 606 | public void run() { |
| 607 | mNext = 0; |
| 608 | mHandler.postDelayed(mRunnable, mPause); |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |