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 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 19 | import android.app.Notification; |
| 20 | import android.app.NotificationManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.app.PendingIntent; |
Christian Mehlmauer | ef36752 | 2010-05-31 23:08:30 +0200 | [diff] [blame] | 22 | import android.content.Context; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 23 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 26 | import android.graphics.BitmapFactory; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 27 | import android.graphics.drawable.BitmapDrawable; |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 28 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.Vibrator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.Handler; |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 31 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.util.Log; |
| 33 | import android.net.Uri; |
| 34 | import android.os.SystemClock; |
| 35 | import android.widget.RemoteViews; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.PowerManager; |
| 37 | |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 38 | // private NM API |
| 39 | import android.app.INotificationManager; |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 40 | import android.widget.Toast; |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 41 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | public class NotificationTestList extends TestActivity |
| 43 | { |
| 44 | private final static String TAG = "NotificationTestList"; |
| 45 | |
| 46 | NotificationManager mNM; |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 47 | Vibrator mVibrator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | Handler mHandler = new Handler(); |
| 49 | |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 50 | long mActivityCreateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | long mChronometerBase = 0; |
| 52 | |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 53 | boolean mProgressDone = true; |
| 54 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 55 | final int[] kNumberedIconResIDs = { |
| 56 | R.drawable.notification0, |
| 57 | R.drawable.notification1, |
| 58 | R.drawable.notification2, |
| 59 | R.drawable.notification3, |
| 60 | R.drawable.notification4, |
| 61 | R.drawable.notification5, |
| 62 | R.drawable.notification6, |
| 63 | R.drawable.notification7, |
| 64 | R.drawable.notification8, |
| 65 | R.drawable.notification9 |
| 66 | }; |
| 67 | final int kUnnumberedIconResID = R.drawable.notificationx; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | @Override |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 70 | public void onCreate(Bundle icicle) { |
| 71 | super.onCreate(icicle); |
| 72 | mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE); |
| 73 | mActivityCreateTime = System.currentTimeMillis(); |
| 74 | } |
| 75 | |
| 76 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | protected String tag() { |
| 78 | return TAG; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | protected Test[] tests() { |
| 83 | mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); |
| 84 | |
| 85 | return mTests; |
| 86 | } |
| 87 | |
| 88 | private Test[] mTests = new Test[] { |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 89 | new Test("Min priority") { |
| 90 | public void run() |
| 91 | { |
| 92 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 93 | .setSmallIcon(R.drawable.icon2) |
| 94 | .setContentTitle("Min priority") |
| 95 | .setLights(0xff0000ff, 1, 0) |
| 96 | .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) |
| 97 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 98 | getPackageName() + "/raw/ringer")) |
| 99 | .setPriority(Notification.PRIORITY_MIN) |
| 100 | .setFullScreenIntent(makeIntent2(), false) |
| 101 | .build(); |
| 102 | mNM.notify(7000, n); |
| 103 | } |
| 104 | }, |
| 105 | new Test("Min priority, high pri flag") { |
| 106 | public void run() |
| 107 | { |
| 108 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 109 | .setSmallIcon(R.drawable.icon2) |
| 110 | .setContentTitle("Min priority, high pri flag") |
| 111 | .setLights(0xff0000ff, 1, 0) |
| 112 | .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) |
| 113 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 114 | getPackageName() + "/raw/ringer")) |
| 115 | .setPriority(Notification.PRIORITY_MIN) |
| 116 | .setFullScreenIntent(makeIntent2(), true) |
| 117 | .build(); |
| 118 | mNM.notify(7001, n); |
| 119 | } |
| 120 | }, |
| 121 | new Test("Low priority") { |
| 122 | public void run() |
| 123 | { |
| 124 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 125 | .setSmallIcon(R.drawable.icon2) |
| 126 | .setContentTitle("Low priority") |
| 127 | .setLights(0xff0000ff, 1, 0) |
| 128 | .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) |
| 129 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 130 | getPackageName() + "/raw/ringer")) |
| 131 | .setPriority(Notification.PRIORITY_LOW) |
| 132 | .setFullScreenIntent(makeIntent2(), false) |
| 133 | .build(); |
| 134 | mNM.notify(7002, n); |
| 135 | } |
| 136 | }, |
| 137 | new Test("Default priority") { |
| 138 | public void run() |
| 139 | { |
| 140 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 141 | .setSmallIcon(R.drawable.icon2) |
| 142 | .setContentTitle("Default priority") |
| 143 | .setLights(0xff0000ff, 1, 0) |
| 144 | .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) |
| 145 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 146 | getPackageName() + "/raw/ringer")) |
| 147 | .setPriority(Notification.PRIORITY_DEFAULT) |
| 148 | .setFullScreenIntent(makeIntent2(), false) |
| 149 | .build(); |
| 150 | mNM.notify(7004, n); |
| 151 | } |
| 152 | }, |
| 153 | new Test("High priority") { |
| 154 | public void run() |
| 155 | { |
| 156 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 157 | .setSmallIcon(R.drawable.icon2) |
| 158 | .setContentTitle("High priority") |
| 159 | .setLights(0xff0000ff, 1, 0) |
| 160 | .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) |
| 161 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 162 | getPackageName() + "/raw/ringer")) |
| 163 | .setPriority(Notification.PRIORITY_HIGH) |
| 164 | .setFullScreenIntent(makeIntent2(), false) |
| 165 | .build(); |
| 166 | mNM.notify(7006, n); |
| 167 | } |
| 168 | }, |
| 169 | new Test("Max priority") { |
| 170 | public void run() |
| 171 | { |
| 172 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 173 | .setSmallIcon(R.drawable.icon2) |
| 174 | .setContentTitle("Max priority") |
| 175 | .setLights(0xff0000ff, 1, 0) |
| 176 | .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) |
| 177 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 178 | getPackageName() + "/raw/ringer")) |
| 179 | .setPriority(Notification.PRIORITY_MAX) |
| 180 | .setFullScreenIntent(makeIntent2(), false) |
| 181 | .build(); |
| 182 | mNM.notify(7008, n); |
| 183 | } |
| 184 | }, |
| 185 | new Test("Max priority with delay") { |
| 186 | public void run() |
| 187 | { |
| 188 | try { |
| 189 | Thread.sleep(5000); |
| 190 | } catch (InterruptedException e) { |
| 191 | } |
| 192 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 193 | .setSmallIcon(R.drawable.icon2) |
| 194 | .setContentTitle("Max priority") |
| 195 | .setLights(0xff0000ff, 1, 0) |
| 196 | .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) |
| 197 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 198 | getPackageName() + "/raw/ringer")) |
| 199 | .setPriority(Notification.PRIORITY_MAX) |
| 200 | .setFullScreenIntent(makeIntent2(), false) |
| 201 | .build(); |
| 202 | mNM.notify(7008, n); |
| 203 | } |
| 204 | }, |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 205 | new Test("Off") { |
Joe Onorato | e71d9e4 | 2009-11-05 17:12:18 -0500 | [diff] [blame] | 206 | public void run() { |
Christian Mehlmauer | ef36752 | 2010-05-31 23:08:30 +0200 | [diff] [blame] | 207 | PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE); |
Joe Onorato | e71d9e4 | 2009-11-05 17:12:18 -0500 | [diff] [blame] | 208 | PowerManager.WakeLock wl = |
| 209 | pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sound"); |
| 210 | wl.acquire(); |
| 211 | |
| 212 | pm.goToSleep(SystemClock.uptimeMillis()); |
| 213 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 214 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 215 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 216 | .setContentTitle(name) |
| 217 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 218 | getPackageName() + "/raw/ringer")) |
| 219 | .build(); |
Joe Onorato | e71d9e4 | 2009-11-05 17:12:18 -0500 | [diff] [blame] | 220 | Log.d(TAG, "n.sound=" + n.sound); |
| 221 | |
| 222 | mNM.notify(1, n); |
| 223 | |
| 224 | Log.d(TAG, "releasing wake lock"); |
| 225 | wl.release(); |
| 226 | Log.d(TAG, "released wake lock"); |
| 227 | } |
| 228 | }, |
| 229 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 230 | new Test("Cancel #1") { |
| 231 | public void run() |
| 232 | { |
| 233 | mNM.cancel(1); |
| 234 | } |
| 235 | }, |
| 236 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 237 | new Test("Custom Button") { |
Joe Onorato | 4058ba0 | 2010-10-31 11:38:04 -0700 | [diff] [blame] | 238 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 239 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 240 | .setSmallIcon(R.drawable.icon1) |
| 241 | .setWhen(mActivityCreateTime) |
| 242 | .setContentTitle(name) |
| 243 | .setOngoing(true) |
| 244 | .build(); |
Joe Onorato | 4058ba0 | 2010-10-31 11:38:04 -0700 | [diff] [blame] | 245 | n.contentView = new RemoteViews(getPackageName(), R.layout.button_notification); |
Joe Onorato | 4058ba0 | 2010-10-31 11:38:04 -0700 | [diff] [blame] | 246 | n.contentView.setOnClickPendingIntent(R.id.button, makeIntent2()); |
| 247 | |
| 248 | mNM.notify(1, n); |
| 249 | } |
| 250 | }, |
| 251 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 252 | new Test("Action Button") { |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 253 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 254 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 255 | .setSmallIcon(R.drawable.icon1) |
| 256 | .setWhen(mActivityCreateTime) |
| 257 | .setContentTitle(name) |
| 258 | .setOngoing(true) |
| 259 | .addAction(R.drawable.ic_statusbar_chat, "Button", makeIntent2()) |
| 260 | .build(); |
| 261 | |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 262 | mNM.notify(1, n); |
| 263 | } |
| 264 | }, |
| 265 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 266 | new Test("with intent") { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 267 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 268 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 269 | .setSmallIcon(R.drawable.icon1) |
| 270 | .setWhen(mActivityCreateTime) |
| 271 | .setContentTitle("Persistent #1") |
| 272 | .setContentText("This is a notification!!!") |
| 273 | .setContentIntent(makeIntent2()) |
| 274 | .setOngoing(true) |
| 275 | .build(); |
| 276 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 277 | mNM.notify(1, n); |
| 278 | } |
| 279 | }, |
| 280 | |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 281 | new Test("Is blocked?") { |
| 282 | public void run() { |
| 283 | Toast.makeText(NotificationTestList.this, |
| 284 | "package enabled? " + mNM.areNotificationsEnabled(), |
| 285 | Toast.LENGTH_LONG).show(); |
| 286 | } |
| 287 | }, |
| 288 | |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 289 | new Test("importance?") { |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 290 | public void run() { |
| 291 | Toast.makeText(NotificationTestList.this, |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 292 | "importance? " + mNM.getImportance(), |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 293 | Toast.LENGTH_LONG).show(); |
| 294 | } |
| 295 | }, |
| 296 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 297 | new Test("Whens") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | public void run() |
| 299 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 300 | Notification.Builder n = new Notification.Builder(NotificationTestList.this) |
| 301 | .setSmallIcon(R.drawable.icon1) |
| 302 | .setContentTitle(name) |
| 303 | .setOngoing(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 305 | mNM.notify(1, n.setContentTitle("(453) 123-2328") |
| 306 | .setWhen(System.currentTimeMillis()-(1000*60*60*24)) |
| 307 | .build()); |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 308 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 309 | mNM.notify(1, n.setContentTitle("Mark Willem, Me (2)") |
| 310 | .setWhen(System.currentTimeMillis()) |
| 311 | .build()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 313 | mNM.notify(1, n.setContentTitle("Sophia Winterlanden") |
| 314 | .setWhen(System.currentTimeMillis() + (1000 * 60 * 60 * 24)) |
| 315 | .build()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | } |
| 317 | }, |
| 318 | |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 319 | new Test("Bad Icon #1 (when=create)") { |
Joe Onorato | 871bdb9 | 2010-05-24 18:36:53 -0400 | [diff] [blame] | 320 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 321 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 322 | .setSmallIcon(R.layout.chrono_notification /* not an icon */) |
| 323 | .setWhen(mActivityCreateTime) |
| 324 | .setContentTitle("Persistent #1") |
| 325 | .setContentText("This is the same notification!!") |
| 326 | .setContentIntent(makeIntent()) |
| 327 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 328 | mNM.notify(1, n); |
Joe Onorato | 871bdb9 | 2010-05-24 18:36:53 -0400 | [diff] [blame] | 329 | } |
| 330 | }, |
| 331 | |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 332 | new Test("Bad Icon #1 (when=now)") { |
| 333 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 334 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 335 | .setSmallIcon(R.layout.chrono_notification /* not an icon */) |
| 336 | .setWhen(System.currentTimeMillis()) |
| 337 | .setContentTitle("Persistent #1") |
| 338 | .setContentText("This is the same notification!!") |
| 339 | .setContentIntent(makeIntent()) |
| 340 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 341 | mNM.notify(1, n); |
Joe Onorato | 68065e0 | 2010-02-03 20:21:41 -0800 | [diff] [blame] | 342 | } |
| 343 | }, |
| 344 | |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 345 | new Test("Null Icon #1 (when=now)") { |
| 346 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 347 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 348 | .setSmallIcon(0) |
| 349 | .setWhen(System.currentTimeMillis()) |
| 350 | .setContentTitle("Persistent #1") |
| 351 | .setContentText("This is the same notification!!") |
| 352 | .setContentIntent(makeIntent()) |
| 353 | .build(); |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 354 | mNM.notify(1, n); |
| 355 | } |
| 356 | }, |
| 357 | |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 358 | new Test("Bad resource #1 (when=create)") { |
| 359 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 360 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 361 | .setSmallIcon(R.drawable.icon2) |
| 362 | .setWhen(mActivityCreateTime) |
| 363 | .setContentTitle("Persistent #1") |
| 364 | .setContentText("This is the same notification!!") |
| 365 | .setContentIntent(makeIntent()) |
| 366 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 367 | n.contentView.setInt(1 /*bogus*/, "bogus method", 666); |
| 368 | mNM.notify(1, n); |
| 369 | } |
| 370 | }, |
| 371 | |
| 372 | new Test("Bad resource #1 (when=now)") { |
| 373 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 374 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 375 | .setSmallIcon(R.drawable.icon2) |
| 376 | .setWhen(System.currentTimeMillis()) |
| 377 | .setContentTitle("Persistent #1") |
| 378 | .setContentText("This is the same notification!!") |
| 379 | .setContentIntent(makeIntent()) |
| 380 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 381 | n.contentView.setInt(1 /*bogus*/, "bogus method", 666); |
| 382 | mNM.notify(1, n); |
| 383 | } |
| 384 | }, |
| 385 | |
Joe Onorato | c83bb73 | 2010-01-19 16:32:22 -0800 | [diff] [blame] | 386 | new Test("Times") { |
| 387 | public void run() |
| 388 | { |
| 389 | long now = System.currentTimeMillis(); |
| 390 | |
| 391 | timeNotification(7, "24 hours from now", now+(1000*60*60*24)); |
| 392 | timeNotification(6, "12:01:00 from now", now+(1000*60*60*12)+(60*1000)); |
| 393 | timeNotification(5, "12 hours from now", now+(1000*60*60*12)); |
| 394 | timeNotification(4, "now", now); |
| 395 | timeNotification(3, "11:59:00 ago", now-((1000*60*60*12)-(60*1000))); |
| 396 | timeNotification(2, "12 hours ago", now-(1000*60*60*12)); |
| 397 | timeNotification(1, "24 hours ago", now-(1000*60*60*24)); |
| 398 | } |
| 399 | }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | new StateStress("Stress - Ongoing / Latest", 100, 100, new Runnable[] { |
| 401 | new Runnable() { |
| 402 | public void run() { |
| 403 | Log.d(TAG, "Stress - Ongoing/Latest 0"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 404 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 405 | .setSmallIcon(R.drawable.icon3) |
| 406 | .setWhen(System.currentTimeMillis()) |
| 407 | .setContentTitle("Stress - Ongoing") |
| 408 | .setContentText("Notify me!!!") |
| 409 | .setOngoing(true) |
| 410 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | mNM.notify(1, n); |
| 412 | } |
| 413 | }, |
| 414 | new Runnable() { |
| 415 | public void run() { |
| 416 | Log.d(TAG, "Stress - Ongoing/Latest 1"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 417 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 418 | .setSmallIcon(R.drawable.icon4) |
| 419 | .setWhen(System.currentTimeMillis()) |
| 420 | .setContentTitle("Stress - Latest") |
| 421 | .setContentText("Notify me!!!") |
| 422 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | mNM.notify(1, n); |
| 424 | } |
| 425 | } |
| 426 | }), |
| 427 | |
| 428 | new Test("Long") { |
| 429 | public void run() |
| 430 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 431 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 432 | .setSmallIcon(R.drawable.icon1) |
| 433 | .setContentTitle(name) |
| 434 | .setDefaults(Notification.DEFAULT_SOUND) |
| 435 | .setVibrate(new long[] { |
| 436 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 437 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 438 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }) |
| 439 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | mNM.notify(1, n); |
| 441 | } |
| 442 | }, |
| 443 | |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 444 | new Test("Progress #1") { |
| 445 | public void run() { |
| 446 | final boolean PROGRESS_UPDATES_WHEN = true; |
| 447 | if (!mProgressDone) return; |
| 448 | mProgressDone = false; |
| 449 | Thread t = new Thread() { |
| 450 | public void run() { |
| 451 | int x = 0; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 452 | final Notification.Builder n = new Notification.Builder(NotificationTestList.this) |
| 453 | .setSmallIcon(R.drawable.icon1) |
| 454 | .setContentTitle(name) |
| 455 | .setOngoing(true); |
| 456 | |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 457 | while (!mProgressDone) { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 458 | n.setWhen(PROGRESS_UPDATES_WHEN |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 459 | ? System.currentTimeMillis() |
| 460 | : mActivityCreateTime); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 461 | n.setProgress(100, x, false); |
| 462 | n.setContentText("Progress: " + x + "%"); |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 463 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 464 | mNM.notify(500, n.build()); |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 465 | x = (x + 7) % 100; |
| 466 | |
| 467 | try { |
| 468 | Thread.sleep(1000); |
| 469 | } catch (InterruptedException e) { |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | }; |
| 475 | t.start(); |
| 476 | } |
| 477 | }, |
| 478 | |
| 479 | new Test("Stop Progress") { |
| 480 | public void run() { |
| 481 | mProgressDone = true; |
| 482 | mNM.cancel(500); |
| 483 | } |
| 484 | }, |
| 485 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 486 | new Test("Blue Lights") { |
| 487 | public void run() |
| 488 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 489 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 490 | .setSmallIcon(R.drawable.icon2) |
| 491 | .setContentTitle(name) |
| 492 | .setLights(0xff0000ff, 1, 0) |
| 493 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 494 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 495 | mNM.notify(1, n); |
| 496 | } |
| 497 | }, |
| 498 | |
| 499 | new Test("Red Lights") { |
| 500 | public void run() |
| 501 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 502 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 503 | .setSmallIcon(R.drawable.icon2) |
| 504 | .setContentTitle(name) |
| 505 | .setLights(0xffff0000, 1, 0) |
| 506 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 507 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 508 | mNM.notify(1, n); |
| 509 | } |
| 510 | }, |
| 511 | |
| 512 | new Test("Yellow Lights") { |
| 513 | public void run() |
| 514 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 515 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 516 | .setSmallIcon(R.drawable.icon2) |
| 517 | .setContentTitle(name) |
| 518 | .setLights(0xffffff00, 1, 0) |
| 519 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 520 | .build(); |
Mattias Östergren | b0fbe29 | 2010-03-05 09:44:15 +0100 | [diff] [blame] | 521 | mNM.notify(1, n); |
| 522 | } |
| 523 | }, |
| 524 | |
| 525 | new Test("Lights off") { |
| 526 | public void run() |
| 527 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 528 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 529 | .setSmallIcon(R.drawable.icon2) |
| 530 | .setContentTitle(name) |
| 531 | .setLights(0x00000000, 0, 0) |
| 532 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 533 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 534 | mNM.notify(1, n); |
| 535 | } |
| 536 | }, |
| 537 | |
| 538 | new Test("Blue Blinking Slow") { |
| 539 | public void run() |
| 540 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 541 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 542 | .setSmallIcon(R.drawable.icon2) |
| 543 | .setContentTitle(name) |
| 544 | .setLights(0xff0000ff, 1300, 1300) |
| 545 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 546 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 547 | mNM.notify(1, n); |
| 548 | } |
| 549 | }, |
| 550 | |
| 551 | new Test("Blue Blinking Fast") { |
| 552 | public void run() |
| 553 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 554 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 555 | .setSmallIcon(R.drawable.icon2) |
| 556 | .setContentTitle(name) |
| 557 | .setLights(0xff0000ff, 300, 300) |
| 558 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 559 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 560 | mNM.notify(1, n); |
| 561 | } |
| 562 | }, |
| 563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | new Test("Default All") { |
| 565 | public void run() |
| 566 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 567 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 568 | .setSmallIcon(R.drawable.icon2) |
| 569 | .setContentTitle(name) |
| 570 | .setDefaults(Notification.DEFAULT_ALL) |
| 571 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | mNM.notify(1, n); |
| 573 | } |
| 574 | }, |
| 575 | |
| 576 | new Test("Default All, once") { |
| 577 | public void run() |
| 578 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 579 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 580 | .setSmallIcon(R.drawable.icon2) |
| 581 | .setContentTitle(name) |
| 582 | .setOnlyAlertOnce(true) |
| 583 | .setDefaults(Notification.DEFAULT_ALL) |
| 584 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | mNM.notify(1, n); |
| 586 | } |
| 587 | }, |
| 588 | |
| 589 | new Test("Resource Sound") { |
| 590 | public void run() |
| 591 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 592 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 593 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 594 | .setContentTitle(name) |
| 595 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 596 | getPackageName() + "/raw/ringer")) |
| 597 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | Log.d(TAG, "n.sound=" + n.sound); |
| 599 | |
| 600 | mNM.notify(1, n); |
| 601 | } |
| 602 | }, |
| 603 | |
| 604 | new Test("Sound and Cancel") { |
| 605 | public void run() |
| 606 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 607 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 608 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 609 | .setContentTitle(name) |
| 610 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 611 | getPackageName() + "/raw/ringer")) |
| 612 | .build(); |
| 613 | Log.d(TAG, "n.sound=" + n.sound); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | |
| 615 | mNM.notify(1, n); |
| 616 | SystemClock.sleep(200); |
| 617 | mNM.cancel(1); |
| 618 | } |
| 619 | }, |
| 620 | |
| 621 | new Test("Vibrate") { |
| 622 | public void run() |
| 623 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 624 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 625 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 626 | .setContentTitle(name) |
| 627 | .setVibrate(new long[]{0, 700, 500, 1000}) |
| 628 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | |
| 630 | mNM.notify(1, n); |
| 631 | } |
| 632 | }, |
| 633 | |
| 634 | new Test("Vibrate and cancel") { |
| 635 | public void run() |
| 636 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 637 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 638 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 639 | .setContentTitle(name) |
| 640 | .setVibrate(new long[]{0, 700, 500, 1000}) |
| 641 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | |
| 643 | mNM.notify(1, n); |
| 644 | SystemClock.sleep(500); |
| 645 | mNM.cancel(1); |
| 646 | } |
| 647 | }, |
| 648 | |
| 649 | new Test("Vibrate pattern") { |
| 650 | public void run() |
| 651 | { |
| 652 | mVibrator.vibrate(new long[] { 250, 1000, 500, 2000 }, -1); |
| 653 | } |
| 654 | }, |
| 655 | |
| 656 | new Test("Vibrate pattern repeating") { |
| 657 | public void run() |
| 658 | { |
| 659 | mVibrator.vibrate(new long[] { 250, 1000, 500 }, 1); |
| 660 | } |
| 661 | }, |
| 662 | |
| 663 | new Test("Vibrate 3s") { |
| 664 | public void run() |
| 665 | { |
| 666 | mVibrator.vibrate(3000); |
| 667 | } |
| 668 | }, |
| 669 | |
| 670 | new Test("Vibrate 100s") { |
| 671 | public void run() |
| 672 | { |
| 673 | mVibrator.vibrate(100000); |
| 674 | } |
| 675 | }, |
| 676 | |
| 677 | new Test("Vibrate off") { |
| 678 | public void run() |
| 679 | { |
| 680 | mVibrator.cancel(); |
| 681 | } |
| 682 | }, |
| 683 | |
| 684 | new Test("Cancel #1") { |
| 685 | public void run() { |
| 686 | mNM.cancel(1); |
| 687 | } |
| 688 | }, |
| 689 | |
| 690 | new Test("Cancel #1 in 3 sec") { |
| 691 | public void run() { |
| 692 | mHandler.postDelayed(new Runnable() { |
| 693 | public void run() { |
| 694 | Log.d(TAG, "Cancelling now..."); |
| 695 | mNM.cancel(1); |
| 696 | } |
| 697 | }, 3000); |
| 698 | } |
| 699 | }, |
| 700 | |
| 701 | new Test("Cancel #2") { |
| 702 | public void run() { |
| 703 | mNM.cancel(2); |
| 704 | } |
| 705 | }, |
| 706 | |
| 707 | new Test("Persistent #1") { |
| 708 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 709 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 710 | .setSmallIcon(R.drawable.icon1) |
| 711 | .setWhen(mActivityCreateTime) |
| 712 | .setContentTitle(name) |
| 713 | .setContentText("This is a notification!!!") |
| 714 | .setContentIntent(makeIntent()) |
| 715 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | mNM.notify(1, n); |
| 717 | } |
| 718 | }, |
| 719 | |
| 720 | new Test("Persistent #1 in 3 sec") { |
| 721 | public void run() { |
| 722 | mHandler.postDelayed(new Runnable() { |
| 723 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 724 | String message = " " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | + "tick tock tick tock\n\nSometimes notifications can " |
| 726 | + "be really long and wrap to more than one line.\n" |
| 727 | + "Sometimes." |
| 728 | + "Ohandwhathappensifwehaveonereallylongstringarewesure" |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 729 | + "thatwesegmentitcorrectly?\n"; |
| 730 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 731 | .setSmallIcon(R.drawable.icon1) |
| 732 | .setContentTitle(name) |
| 733 | .setContentText("This is still a notification!!!") |
| 734 | .setContentIntent(makeIntent()) |
| 735 | .setStyle(new Notification.BigTextStyle().bigText(message)) |
| 736 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | mNM.notify(1, n); |
| 738 | } |
| 739 | }, 3000); |
| 740 | } |
| 741 | }, |
| 742 | |
| 743 | new Test("Persistent #2") { |
| 744 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 745 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 746 | .setSmallIcon(R.drawable.icon1) |
| 747 | .setWhen(mActivityCreateTime) |
| 748 | .setContentTitle(name) |
| 749 | .setContentText("This is a notification!!!") |
| 750 | .setContentIntent(makeIntent()) |
| 751 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | mNM.notify(2, n); |
| 753 | } |
| 754 | }, |
| 755 | |
Joe Onorato | 68065e0 | 2010-02-03 20:21:41 -0800 | [diff] [blame] | 756 | new Test("Persistent #3") { |
| 757 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 758 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 759 | .setSmallIcon(R.drawable.icon1) |
| 760 | .setWhen(mActivityCreateTime) |
| 761 | .setContentTitle(name) |
| 762 | .setContentText("This is a notification!!!") |
| 763 | .setContentIntent(makeIntent()) |
| 764 | .build(); |
Joe Onorato | 68065e0 | 2010-02-03 20:21:41 -0800 | [diff] [blame] | 765 | mNM.notify(3, n); |
| 766 | } |
| 767 | }, |
| 768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | new Test("Persistent #2 Vibrate") { |
| 770 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 771 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 772 | .setSmallIcon(R.drawable.icon1) |
| 773 | .setWhen(mActivityCreateTime) |
| 774 | .setContentTitle(name) |
| 775 | .setContentText("This is a notification!!!") |
| 776 | .setContentIntent(makeIntent()) |
| 777 | .setDefaults(Notification.DEFAULT_VIBRATE) |
| 778 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | mNM.notify(2, n); |
| 780 | } |
| 781 | }, |
| 782 | |
Joe Onorato | d2b1f00 | 2010-06-04 10:42:41 -0700 | [diff] [blame] | 783 | new Test("Persistent #1 - different icon") { |
| 784 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 785 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 786 | .setSmallIcon(R.drawable.icon2) |
| 787 | .setWhen(mActivityCreateTime) |
| 788 | .setContentTitle(name) |
| 789 | .setContentText("This is a notification!!!") |
| 790 | .setContentIntent(makeIntent()) |
| 791 | .build(); |
Joe Onorato | d2b1f00 | 2010-06-04 10:42:41 -0700 | [diff] [blame] | 792 | mNM.notify(1, n); |
| 793 | } |
| 794 | }, |
| 795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | new Test("Chronometer Start") { |
| 797 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 798 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 799 | .setSmallIcon(R.drawable.icon1) |
| 800 | .setWhen(System.currentTimeMillis()) |
| 801 | .setContentTitle(name) |
| 802 | .setContentIntent(makeIntent()) |
| 803 | .setOngoing(true) |
| 804 | .setUsesChronometer(true) |
| 805 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | mNM.notify(2, n); |
| 807 | } |
| 808 | }, |
| 809 | |
| 810 | new Test("Chronometer Stop") { |
| 811 | public void run() { |
| 812 | mHandler.postDelayed(new Runnable() { |
| 813 | public void run() { |
| 814 | Log.d(TAG, "Chronometer Stop"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 815 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 816 | .setSmallIcon(R.drawable.icon1) |
| 817 | .setWhen(System.currentTimeMillis()) |
| 818 | .setContentTitle(name) |
| 819 | .setContentIntent(makeIntent()) |
| 820 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | mNM.notify(2, n); |
| 822 | } |
| 823 | }, 3000); |
| 824 | } |
| 825 | }, |
| 826 | |
| 827 | new Test("Sequential Persistent") { |
| 828 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 829 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 830 | mNM.notify(2, notificationWithNumbers(name, 2)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | } |
| 832 | }, |
| 833 | |
| 834 | new Test("Replace Persistent") { |
| 835 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 836 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 837 | mNM.notify(1, notificationWithNumbers(name, 1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | } |
| 839 | }, |
| 840 | |
| 841 | new Test("Run and Cancel (n=1)") { |
| 842 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 843 | mNM.notify(1, notificationWithNumbers(name, 1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | mNM.cancel(1); |
| 845 | } |
| 846 | }, |
| 847 | |
| 848 | new Test("Run an Cancel (n=2)") { |
| 849 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 850 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 851 | mNM.notify(2, notificationWithNumbers(name, 2)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | mNM.cancel(2); |
| 853 | } |
| 854 | }, |
| 855 | |
| 856 | // Repeatedly notify and cancel -- triggers bug #670627 |
| 857 | new Test("Bug 670627") { |
| 858 | public void run() { |
| 859 | for (int i = 0; i < 10; i++) { |
| 860 | Log.d(TAG, "Add two notifications"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 861 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 862 | mNM.notify(2, notificationWithNumbers(name, 2)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | Log.d(TAG, "Cancel two notifications"); |
| 864 | mNM.cancel(1); |
| 865 | mNM.cancel(2); |
| 866 | } |
| 867 | } |
| 868 | }, |
| 869 | |
| 870 | new Test("Ten Notifications") { |
| 871 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 872 | for (int i = 0; i < 10; i++) { |
| 873 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 874 | .setSmallIcon(kNumberedIconResIDs[i]) |
| 875 | .setContentTitle("Persistent #" + i) |
| 876 | .setContentText("Notify me!!!" + i) |
| 877 | .setOngoing(i < 2) |
| 878 | .setNumber(i) |
| 879 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | mNM.notify((i+1)*10, n); |
| 881 | } |
| 882 | } |
| 883 | }, |
| 884 | |
| 885 | new Test("Cancel eight notifications") { |
| 886 | public void run() { |
| 887 | for (int i = 1; i < 9; i++) { |
| 888 | mNM.cancel((i+1)*10); |
| 889 | } |
| 890 | } |
| 891 | }, |
| 892 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 893 | new Test("Cancel the other two notifications") { |
| 894 | public void run() { |
| 895 | mNM.cancel(10); |
| 896 | mNM.cancel(100); |
| 897 | } |
| 898 | }, |
| 899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | new Test("Persistent with numbers 1") { |
| 901 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 902 | mNM.notify(1, notificationWithNumbers(name, 1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | } |
| 904 | }, |
| 905 | |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 906 | new Test("Persistent with numbers 22") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 908 | mNM.notify(1, notificationWithNumbers(name, 22)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | } |
| 910 | }, |
| 911 | |
| 912 | new Test("Persistent with numbers 333") { |
| 913 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 914 | mNM.notify(1, notificationWithNumbers(name, 333)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | } |
| 916 | }, |
| 917 | |
| 918 | new Test("Persistent with numbers 4444") { |
| 919 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 920 | mNM.notify(1, notificationWithNumbers(name, 4444)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | } |
| 922 | }, |
| 923 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 924 | new Test("PRIORITY_HIGH") { |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 925 | public void run() { |
| 926 | Notification n = new Notification.Builder(NotificationTestList.this) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 927 | .setSmallIcon(R.drawable.notification5) |
| 928 | .setContentTitle("High priority") |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 929 | .setContentText("This should appear before all others") |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 930 | .setPriority(Notification.PRIORITY_HIGH) |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 931 | .build(); |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 932 | |
| 933 | int[] idOut = new int[1]; |
| 934 | try { |
| 935 | INotificationManager directLine = mNM.getService(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 936 | directLine.enqueueNotificationWithTag( |
| 937 | getPackageName(), |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 938 | getPackageName(), |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 939 | null, |
| 940 | 100, |
| 941 | n, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 942 | idOut, |
| 943 | UserHandle.myUserId()); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 944 | } catch (android.os.RemoteException ex) { |
| 945 | // oh well |
| 946 | } |
| 947 | } |
| 948 | }, |
| 949 | |
| 950 | new Test("PRIORITY_MAX") { |
| 951 | public void run() { |
| 952 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 953 | .setSmallIcon(R.drawable.notification9) |
| 954 | .setContentTitle("MAX priority") |
| 955 | .setContentText("This might appear as an intruder alert") |
| 956 | .setPriority(Notification.PRIORITY_MAX) |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 957 | .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 958 | |
| 959 | int[] idOut = new int[1]; |
| 960 | try { |
| 961 | INotificationManager directLine = mNM.getService(); |
| 962 | directLine.enqueueNotificationWithTag( |
| 963 | getPackageName(), |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 964 | getPackageName(), |
| 965 | null, |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 966 | 200, |
| 967 | n, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 968 | idOut, |
| 969 | UserHandle.myUserId()); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 970 | } catch (android.os.RemoteException ex) { |
| 971 | // oh well |
| 972 | } |
| 973 | } |
| 974 | }, |
| 975 | |
| 976 | new Test("PRIORITY_MIN") { |
| 977 | public void run() { |
| 978 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 979 | .setSmallIcon(R.drawable.notification0) |
| 980 | .setContentTitle("MIN priority") |
| 981 | .setContentText("You should not see this") |
| 982 | .setPriority(Notification.PRIORITY_MIN) |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 983 | .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 984 | |
| 985 | int[] idOut = new int[1]; |
| 986 | try { |
| 987 | INotificationManager directLine = mNM.getService(); |
| 988 | directLine.enqueueNotificationWithTag( |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 989 | getPackageName(), |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 990 | getPackageName(), |
| 991 | null, |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 992 | 1, |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 993 | n, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 994 | idOut, |
| 995 | UserHandle.myUserId()); |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 996 | } catch (android.os.RemoteException ex) { |
| 997 | // oh well |
| 998 | } |
| 999 | } |
| 1000 | }, |
| 1001 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1002 | new Test("Crash") { |
| 1003 | public void run() |
| 1004 | { |
| 1005 | PowerManager.WakeLock wl |
Christian Mehlmauer | ef36752 | 2010-05-31 23:08:30 +0200 | [diff] [blame] | 1006 | = ((PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE)) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1007 | .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher"); |
| 1008 | wl.acquire(); |
| 1009 | mHandler.postDelayed(new Runnable() { |
| 1010 | public void run() { |
| 1011 | throw new RuntimeException("Die!"); |
| 1012 | } |
| 1013 | }, 10000); |
| 1014 | |
| 1015 | } |
| 1016 | }, |
| 1017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | }; |
| 1019 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1020 | private Notification notificationWithNumbers(String name, int num) { |
| 1021 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 1022 | .setSmallIcon((num >= 0 && num < kNumberedIconResIDs.length) |
| 1023 | ? kNumberedIconResIDs[num] |
| 1024 | : kUnnumberedIconResID) |
| 1025 | .setContentTitle(name) |
| 1026 | .setContentText("Number=" + num) |
| 1027 | .setNumber(num) |
| 1028 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | return n; |
| 1030 | } |
| 1031 | |
| 1032 | private PendingIntent makeIntent() { |
| 1033 | Intent intent = new Intent(Intent.ACTION_MAIN); |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 1034 | intent.addCategory(Intent.CATEGORY_HOME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | return PendingIntent.getActivity(this, 0, intent, 0); |
| 1036 | } |
| 1037 | |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 1038 | private PendingIntent makeIntent2() { |
| 1039 | Intent intent = new Intent(this, StatusBarTest.class); |
| 1040 | return PendingIntent.getActivity(this, 0, intent, 0); |
| 1041 | } |
| 1042 | |
| 1043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | class StateStress extends Test { |
| 1045 | StateStress(String name, int pause, int iterations, Runnable[] tasks) { |
| 1046 | super(name); |
| 1047 | mPause = pause; |
| 1048 | mTasks = tasks; |
| 1049 | mIteration = iterations; |
| 1050 | } |
| 1051 | Runnable[] mTasks; |
| 1052 | int mNext; |
| 1053 | int mIteration; |
| 1054 | long mPause; |
| 1055 | Runnable mRunnable = new Runnable() { |
| 1056 | public void run() { |
| 1057 | mTasks[mNext].run(); |
| 1058 | mNext++; |
| 1059 | if (mNext >= mTasks.length) { |
| 1060 | mNext = 0; |
| 1061 | mIteration--; |
| 1062 | if (mIteration <= 0) { |
| 1063 | return; |
| 1064 | } |
| 1065 | } |
| 1066 | mHandler.postDelayed(mRunnable, mPause); |
| 1067 | } |
| 1068 | }; |
| 1069 | public void run() { |
| 1070 | mNext = 0; |
| 1071 | mHandler.postDelayed(mRunnable, mPause); |
| 1072 | } |
| 1073 | } |
Joe Onorato | c83bb73 | 2010-01-19 16:32:22 -0800 | [diff] [blame] | 1074 | |
| 1075 | void timeNotification(int n, String label, long time) { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1076 | mNM.notify(n, new Notification.Builder(NotificationTestList.this) |
| 1077 | .setSmallIcon(R.drawable.ic_statusbar_missedcall) |
| 1078 | .setWhen(time) |
| 1079 | .setContentTitle(label) |
| 1080 | .setContentText(new java.util.Date(time).toString()) |
| 1081 | .build()); |
Joe Onorato | c83bb73 | 2010-01-19 16:32:22 -0800 | [diff] [blame] | 1082 | |
| 1083 | } |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1084 | |
| 1085 | Bitmap loadBitmap(int resId) { |
| 1086 | BitmapDrawable bd = (BitmapDrawable)getResources().getDrawable(resId); |
| 1087 | return Bitmap.createBitmap(bd.getBitmap()); |
| 1088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | } |
| 1090 | |